|
@@ -717,31 +717,14 @@ final class OpenAPS {
|
|
|
pumphistory = pumpHistoryArray.removingDuplicateSuspendResumeEvents().rawJSON
|
|
pumphistory = pumpHistoryArray.removingDuplicateSuspendResumeEvents().rawJSON
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let startJavascriptAt = Date()
|
|
|
|
|
- let jsResult = await iobJavascript(pumphistory: pumphistory, profile: profile, clock: clock, autosens: autosens)
|
|
|
|
|
- let javascriptDuration = Date().timeIntervalSince(startJavascriptAt)
|
|
|
|
|
-
|
|
|
|
|
- // Important: we want to make sure that this flag ensures that none
|
|
|
|
|
- // of the native code runs
|
|
|
|
|
- guard useSwiftOref else {
|
|
|
|
|
|
|
+ if useSwiftOref {
|
|
|
|
|
+ let (swiftResult, _) = OpenAPSSwift
|
|
|
|
|
+ .iob(pumphistory: pumphistory, profile: profile, clock: clock, autosens: autosens)
|
|
|
|
|
+ return try swiftResult.returnOrThrow()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let jsResult = await iobJavascript(pumphistory: pumphistory, profile: profile, clock: clock, autosens: autosens)
|
|
|
return try jsResult.returnOrThrow()
|
|
return try jsResult.returnOrThrow()
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- let startSwiftAt = Date()
|
|
|
|
|
- let (swiftResult, iobInputs) = OpenAPSSwift
|
|
|
|
|
- .iob(pumphistory: pumphistory, profile: profile, clock: clock, autosens: autosens)
|
|
|
|
|
- let swiftDuration = Date().timeIntervalSince(startSwiftAt)
|
|
|
|
|
-
|
|
|
|
|
- JSONCompare.logDifferences(
|
|
|
|
|
- function: .iob,
|
|
|
|
|
- swift: swiftResult,
|
|
|
|
|
- swiftDuration: swiftDuration,
|
|
|
|
|
- javascript: jsResult,
|
|
|
|
|
- javascriptDuration: javascriptDuration,
|
|
|
|
|
- iobInputs: iobInputs
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- return try jsResult.returnOrThrow()
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func iobJavascript(pumphistory: JSON, profile: JSON, clock: JSON, autosens: JSON) async -> OrefFunctionResult {
|
|
func iobJavascript(pumphistory: JSON, profile: JSON, clock: JSON, autosens: JSON) async -> OrefFunctionResult {
|
|
@@ -777,26 +760,19 @@ final class OpenAPS {
|
|
|
glucose: JSON,
|
|
glucose: JSON,
|
|
|
useSwiftOref: Bool
|
|
useSwiftOref: Bool
|
|
|
) async throws -> RawJSON {
|
|
) async throws -> RawJSON {
|
|
|
- let startJavascriptAt = Date()
|
|
|
|
|
- let jsResult = await mealJavascript(
|
|
|
|
|
- pumphistory: pumphistory,
|
|
|
|
|
- profile: profile,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- clock: clock,
|
|
|
|
|
- carbs: carbs,
|
|
|
|
|
- glucose: glucose
|
|
|
|
|
- )
|
|
|
|
|
- let javascriptDuration = Date().timeIntervalSince(startJavascriptAt)
|
|
|
|
|
-
|
|
|
|
|
- // Important: we want to make sure that this flag ensures that none
|
|
|
|
|
- // of the native code runs
|
|
|
|
|
- guard useSwiftOref else {
|
|
|
|
|
- return try jsResult.returnOrThrow()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let startSwiftAt = Date()
|
|
|
|
|
- let (swiftResult, mealInputs) = OpenAPSSwift
|
|
|
|
|
- .meal(
|
|
|
|
|
|
|
+ if useSwiftOref {
|
|
|
|
|
+ let (swiftResult, _) = OpenAPSSwift
|
|
|
|
|
+ .meal(
|
|
|
|
|
+ pumphistory: pumphistory,
|
|
|
|
|
+ profile: profile,
|
|
|
|
|
+ basalProfile: basalProfile,
|
|
|
|
|
+ clock: clock,
|
|
|
|
|
+ carbs: carbs,
|
|
|
|
|
+ glucose: glucose
|
|
|
|
|
+ )
|
|
|
|
|
+ return try swiftResult.returnOrThrow()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let jsResult = await mealJavascript(
|
|
|
pumphistory: pumphistory,
|
|
pumphistory: pumphistory,
|
|
|
profile: profile,
|
|
profile: profile,
|
|
|
basalProfile: basalProfile,
|
|
basalProfile: basalProfile,
|
|
@@ -804,18 +780,8 @@ final class OpenAPS {
|
|
|
carbs: carbs,
|
|
carbs: carbs,
|
|
|
glucose: glucose
|
|
glucose: glucose
|
|
|
)
|
|
)
|
|
|
- let swiftDuration = Date().timeIntervalSince(startSwiftAt)
|
|
|
|
|
-
|
|
|
|
|
- JSONCompare.logDifferences(
|
|
|
|
|
- function: .meal,
|
|
|
|
|
- swift: swiftResult,
|
|
|
|
|
- swiftDuration: swiftDuration,
|
|
|
|
|
- javascript: jsResult,
|
|
|
|
|
- javascriptDuration: javascriptDuration,
|
|
|
|
|
- mealInputs: mealInputs
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- return try jsResult.returnOrThrow()
|
|
|
|
|
|
|
+ return try jsResult.returnOrThrow()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func mealJavascript(
|
|
private func mealJavascript(
|
|
@@ -860,46 +826,29 @@ final class OpenAPS {
|
|
|
temptargets: JSON,
|
|
temptargets: JSON,
|
|
|
useSwiftOref: Bool
|
|
useSwiftOref: Bool
|
|
|
) async throws -> RawJSON {
|
|
) async throws -> RawJSON {
|
|
|
- let startJavascriptAt = Date()
|
|
|
|
|
- let jsResult = await autosenseJavascript(
|
|
|
|
|
- glucose: glucose,
|
|
|
|
|
- pumpHistory: pumpHistory,
|
|
|
|
|
- basalprofile: basalprofile,
|
|
|
|
|
- profile: profile,
|
|
|
|
|
- carbs: carbs,
|
|
|
|
|
- temptargets: temptargets
|
|
|
|
|
- )
|
|
|
|
|
- let javascriptDuration = Date().timeIntervalSince(startJavascriptAt)
|
|
|
|
|
-
|
|
|
|
|
- // Important: we want to make sure that this flag ensures that none
|
|
|
|
|
- // of the native code runs
|
|
|
|
|
- guard useSwiftOref else {
|
|
|
|
|
- return try jsResult.returnOrThrow()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let startSwiftAt = Date()
|
|
|
|
|
- let (swiftResult, autosensInputs) = OpenAPSSwift
|
|
|
|
|
- .autosense(
|
|
|
|
|
|
|
+ if useSwiftOref {
|
|
|
|
|
+ let (swiftResult, _) = OpenAPSSwift
|
|
|
|
|
+ .autosense(
|
|
|
|
|
+ glucose: glucose,
|
|
|
|
|
+ pumpHistory: pumpHistory,
|
|
|
|
|
+ basalProfile: basalprofile,
|
|
|
|
|
+ profile: profile,
|
|
|
|
|
+ carbs: carbs,
|
|
|
|
|
+ tempTargets: temptargets,
|
|
|
|
|
+ clock: Date()
|
|
|
|
|
+ )
|
|
|
|
|
+ return try swiftResult.returnOrThrow()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let jsResult = await autosenseJavascript(
|
|
|
glucose: glucose,
|
|
glucose: glucose,
|
|
|
pumpHistory: pumpHistory,
|
|
pumpHistory: pumpHistory,
|
|
|
- basalProfile: basalprofile,
|
|
|
|
|
|
|
+ basalprofile: basalprofile,
|
|
|
profile: profile,
|
|
profile: profile,
|
|
|
carbs: carbs,
|
|
carbs: carbs,
|
|
|
- tempTargets: temptargets,
|
|
|
|
|
- clock: Date()
|
|
|
|
|
|
|
+ temptargets: temptargets
|
|
|
)
|
|
)
|
|
|
- let swiftDuration = Date().timeIntervalSince(startSwiftAt)
|
|
|
|
|
-
|
|
|
|
|
- JSONCompare.logDifferences(
|
|
|
|
|
- function: .autosens,
|
|
|
|
|
- swift: swiftResult,
|
|
|
|
|
- swiftDuration: swiftDuration,
|
|
|
|
|
- javascript: jsResult,
|
|
|
|
|
- javascriptDuration: javascriptDuration,
|
|
|
|
|
- autosensInputs: autosensInputs
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- return try jsResult.returnOrThrow()
|
|
|
|
|
|
|
+ return try jsResult.returnOrThrow()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func autosenseJavascript(
|
|
private func autosenseJavascript(
|
|
@@ -951,58 +900,42 @@ final class OpenAPS {
|
|
|
useSwiftOref: Bool
|
|
useSwiftOref: Bool
|
|
|
) async throws -> RawJSON {
|
|
) async throws -> RawJSON {
|
|
|
let clock = Date()
|
|
let clock = Date()
|
|
|
- let startJavascriptAt = Date()
|
|
|
|
|
- let jsResult = await determineBasalJavascript(
|
|
|
|
|
- glucose: glucose,
|
|
|
|
|
- currentTemp: currentTemp,
|
|
|
|
|
- iob: iob,
|
|
|
|
|
- profile: profile,
|
|
|
|
|
- autosens: autosens,
|
|
|
|
|
- meal: meal,
|
|
|
|
|
- microBolusAllowed: microBolusAllowed,
|
|
|
|
|
- reservoir: reservoir,
|
|
|
|
|
- pumpHistory: pumpHistory,
|
|
|
|
|
- preferences: preferences,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- trioCustomOrefVariables: trioCustomOrefVariables,
|
|
|
|
|
- clock: clock
|
|
|
|
|
- )
|
|
|
|
|
- let javascriptDuration = Date().timeIntervalSince(startJavascriptAt)
|
|
|
|
|
|
|
|
|
|
- // Important: we want to make sure that this flag ensures that none
|
|
|
|
|
- // of the native code runs
|
|
|
|
|
- guard useSwiftOref else {
|
|
|
|
|
|
|
+ if useSwiftOref {
|
|
|
|
|
+ let (swiftResult, determineBasalInputs) = OpenAPSSwift.determineBasal(
|
|
|
|
|
+ glucose: glucose,
|
|
|
|
|
+ currentTemp: currentTemp,
|
|
|
|
|
+ iob: iob,
|
|
|
|
|
+ profile: profile,
|
|
|
|
|
+ autosens: autosens,
|
|
|
|
|
+ meal: meal,
|
|
|
|
|
+ microBolusAllowed: microBolusAllowed,
|
|
|
|
|
+ reservoir: reservoir,
|
|
|
|
|
+ pumpHistory: pumpHistory,
|
|
|
|
|
+ preferences: preferences,
|
|
|
|
|
+ basalProfile: basalProfile,
|
|
|
|
|
+ trioCustomOrefVariables: trioCustomOrefVariables,
|
|
|
|
|
+ clock: clock
|
|
|
|
|
+ )
|
|
|
|
|
+ return try swiftResult.returnOrThrow()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let jsResult = await determineBasalJavascript(
|
|
|
|
|
+ glucose: glucose,
|
|
|
|
|
+ currentTemp: currentTemp,
|
|
|
|
|
+ iob: iob,
|
|
|
|
|
+ profile: profile,
|
|
|
|
|
+ autosens: autosens,
|
|
|
|
|
+ meal: meal,
|
|
|
|
|
+ microBolusAllowed: microBolusAllowed,
|
|
|
|
|
+ reservoir: reservoir,
|
|
|
|
|
+ pumpHistory: pumpHistory,
|
|
|
|
|
+ preferences: preferences,
|
|
|
|
|
+ basalProfile: basalProfile,
|
|
|
|
|
+ trioCustomOrefVariables: trioCustomOrefVariables,
|
|
|
|
|
+ clock: clock
|
|
|
|
|
+ )
|
|
|
return try jsResult.returnOrThrow()
|
|
return try jsResult.returnOrThrow()
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- let startSwiftAt = Date()
|
|
|
|
|
- let (swiftResult, determineBasalInputs) = OpenAPSSwift.determineBasal(
|
|
|
|
|
- glucose: glucose,
|
|
|
|
|
- currentTemp: currentTemp,
|
|
|
|
|
- iob: iob,
|
|
|
|
|
- profile: profile,
|
|
|
|
|
- autosens: autosens,
|
|
|
|
|
- meal: meal,
|
|
|
|
|
- microBolusAllowed: microBolusAllowed,
|
|
|
|
|
- reservoir: reservoir,
|
|
|
|
|
- pumpHistory: pumpHistory,
|
|
|
|
|
- preferences: preferences,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- trioCustomOrefVariables: trioCustomOrefVariables,
|
|
|
|
|
- clock: clock
|
|
|
|
|
- )
|
|
|
|
|
- let swiftDuration = Date().timeIntervalSince(startSwiftAt)
|
|
|
|
|
-
|
|
|
|
|
- JSONCompare.logDifferences(
|
|
|
|
|
- function: .determineBasal,
|
|
|
|
|
- swift: swiftResult,
|
|
|
|
|
- swiftDuration: swiftDuration,
|
|
|
|
|
- javascript: jsResult,
|
|
|
|
|
- javascriptDuration: javascriptDuration,
|
|
|
|
|
- determineBasalInputs: determineBasalInputs
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- return try jsResult.returnOrThrow()
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func determineBasalJavascript(
|
|
private func determineBasalJavascript(
|
|
@@ -1031,10 +964,6 @@ final class OpenAPS {
|
|
|
Script(name: Bundle.determineBasal)
|
|
Script(name: Bundle.determineBasal)
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
- if let middleware = self.middlewareScript(name: OpenAPS.Middleware.determineBasal) {
|
|
|
|
|
- worker.evaluate(script: middleware)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
let result = worker.call(function: Function.generate, with: [
|
|
let result = worker.call(function: Function.generate, with: [
|
|
|
iob,
|
|
iob,
|
|
|
currentTemp,
|
|
currentTemp,
|
|
@@ -1128,52 +1057,35 @@ final class OpenAPS {
|
|
|
useSwiftOref: Bool,
|
|
useSwiftOref: Bool,
|
|
|
clock: Date
|
|
clock: Date
|
|
|
) async throws -> RawJSON {
|
|
) async throws -> RawJSON {
|
|
|
- let startJavascriptAt = Date()
|
|
|
|
|
- let jsResult = await makeProfileJavascript(
|
|
|
|
|
- preferences: preferences,
|
|
|
|
|
- pumpSettings: pumpSettings,
|
|
|
|
|
- bgTargets: bgTargets,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- isf: isf,
|
|
|
|
|
- carbRatio: carbRatio,
|
|
|
|
|
- tempTargets: tempTargets,
|
|
|
|
|
- model: model,
|
|
|
|
|
- autotune: autotune,
|
|
|
|
|
- trioSettings: trioSettings
|
|
|
|
|
- )
|
|
|
|
|
- let javascriptDuration = Date().timeIntervalSince(startJavascriptAt)
|
|
|
|
|
-
|
|
|
|
|
- // Important: we want to make sure that this flag ensures that none
|
|
|
|
|
- // of the native code runs
|
|
|
|
|
- guard useSwiftOref else {
|
|
|
|
|
|
|
+ if useSwiftOref {
|
|
|
|
|
+ let (swiftResult, makeProfileInputs) = OpenAPSSwift.makeProfile(
|
|
|
|
|
+ preferences: preferences,
|
|
|
|
|
+ pumpSettings: pumpSettings,
|
|
|
|
|
+ bgTargets: bgTargets,
|
|
|
|
|
+ basalProfile: basalProfile,
|
|
|
|
|
+ isf: isf,
|
|
|
|
|
+ carbRatio: carbRatio,
|
|
|
|
|
+ tempTargets: tempTargets,
|
|
|
|
|
+ model: model,
|
|
|
|
|
+ trioSettings: trioSettings,
|
|
|
|
|
+ clock: clock
|
|
|
|
|
+ )
|
|
|
|
|
+ return try swiftResult.returnOrThrow()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let jsResult = await makeProfileJavascript(
|
|
|
|
|
+ preferences: preferences,
|
|
|
|
|
+ pumpSettings: pumpSettings,
|
|
|
|
|
+ bgTargets: bgTargets,
|
|
|
|
|
+ basalProfile: basalProfile,
|
|
|
|
|
+ isf: isf,
|
|
|
|
|
+ carbRatio: carbRatio,
|
|
|
|
|
+ tempTargets: tempTargets,
|
|
|
|
|
+ model: model,
|
|
|
|
|
+ autotune: autotune,
|
|
|
|
|
+ trioSettings: trioSettings
|
|
|
|
|
+ )
|
|
|
return try jsResult.returnOrThrow()
|
|
return try jsResult.returnOrThrow()
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- let startSwiftAt = Date()
|
|
|
|
|
- let (swiftResult, makeProfileInputs) = OpenAPSSwift.makeProfile(
|
|
|
|
|
- preferences: preferences,
|
|
|
|
|
- pumpSettings: pumpSettings,
|
|
|
|
|
- bgTargets: bgTargets,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- isf: isf,
|
|
|
|
|
- carbRatio: carbRatio,
|
|
|
|
|
- tempTargets: tempTargets,
|
|
|
|
|
- model: model,
|
|
|
|
|
- trioSettings: trioSettings,
|
|
|
|
|
- clock: clock
|
|
|
|
|
- )
|
|
|
|
|
- let swiftDuration = Date().timeIntervalSince(startSwiftAt)
|
|
|
|
|
-
|
|
|
|
|
- JSONCompare.logDifferences(
|
|
|
|
|
- function: .makeProfile,
|
|
|
|
|
- swift: swiftResult,
|
|
|
|
|
- swiftDuration: swiftDuration,
|
|
|
|
|
- javascript: jsResult,
|
|
|
|
|
- javascriptDuration: javascriptDuration,
|
|
|
|
|
- makeProfileInputs: makeProfileInputs
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- return try jsResult.returnOrThrow()
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private func loadJSON(name: String) -> String {
|
|
private func loadJSON(name: String) -> String {
|
|
@@ -1193,23 +1105,6 @@ final class OpenAPS {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private func middlewareScript(name: String) -> Script? {
|
|
|
|
|
- if let body = storage.retrieveRaw(name) {
|
|
|
|
|
- return Script(name: name, body: body)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if let url = Foundation.Bundle.main.url(forResource: "javascript/\(name)", withExtension: "") {
|
|
|
|
|
- do {
|
|
|
|
|
- let body = try String(contentsOf: url)
|
|
|
|
|
- return Script(name: name, body: body)
|
|
|
|
|
- } catch {
|
|
|
|
|
- debug(.openAPS, "Failed to load script \(name): \(error)")
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return nil
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
static func defaults(for file: String) -> RawJSON {
|
|
static func defaults(for file: String) -> RawJSON {
|
|
|
let prefix = file.hasSuffix(".json") ? "json/defaults" : "javascript"
|
|
let prefix = file.hasSuffix(".json") ? "json/defaults" : "javascript"
|
|
|
guard let url = Foundation.Bundle.main.url(forResource: "\(prefix)/\(file)", withExtension: "") else {
|
|
guard let url = Foundation.Bundle.main.url(forResource: "\(prefix)/\(file)", withExtension: "") else {
|