|
@@ -12,9 +12,7 @@ struct OpenAPSSwift {
|
|
|
model: JSON,
|
|
model: JSON,
|
|
|
trioSettings: JSON,
|
|
trioSettings: JSON,
|
|
|
clock: Date
|
|
clock: Date
|
|
|
- ) -> (OrefFunctionResult, MakeProfileInputs?) {
|
|
|
|
|
- var makeProfileInputs: MakeProfileInputs?
|
|
|
|
|
-
|
|
|
|
|
|
|
+ ) -> (OrefFunctionResult) {
|
|
|
do {
|
|
do {
|
|
|
let preferences = try JSONBridge.preferences(from: preferences)
|
|
let preferences = try JSONBridge.preferences(from: preferences)
|
|
|
let pumpSettings = try JSONBridge.pumpSettings(from: pumpSettings)
|
|
let pumpSettings = try JSONBridge.pumpSettings(from: pumpSettings)
|
|
@@ -26,19 +24,6 @@ struct OpenAPSSwift {
|
|
|
let model = JSONBridge.model(from: model)
|
|
let model = JSONBridge.model(from: model)
|
|
|
let trioSettings = try JSONBridge.trioSettings(from: trioSettings)
|
|
let trioSettings = try JSONBridge.trioSettings(from: trioSettings)
|
|
|
|
|
|
|
|
- makeProfileInputs = MakeProfileInputs(
|
|
|
|
|
- preferences: preferences,
|
|
|
|
|
- pumpSettings: pumpSettings,
|
|
|
|
|
- bgTargets: bgTargets,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- isf: isf,
|
|
|
|
|
- carbRatios: carbRatio,
|
|
|
|
|
- tempTargets: tempTargets,
|
|
|
|
|
- model: model,
|
|
|
|
|
- trioSettings: trioSettings,
|
|
|
|
|
- clock: clock
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
let profile = try ProfileGenerator.generate(
|
|
let profile = try ProfileGenerator.generate(
|
|
|
pumpSettings: pumpSettings,
|
|
pumpSettings: pumpSettings,
|
|
|
bgTargets: bgTargets,
|
|
bgTargets: bgTargets,
|
|
@@ -51,9 +36,9 @@ struct OpenAPSSwift {
|
|
|
clock: clock
|
|
clock: clock
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- return (try .success(JSONBridge.to(profile)), makeProfileInputs)
|
|
|
|
|
|
|
+ return (try .success(JSONBridge.to(profile)))
|
|
|
} catch {
|
|
} catch {
|
|
|
- return (.failure(error), makeProfileInputs)
|
|
|
|
|
|
|
+ return (.failure(error))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -71,9 +56,7 @@ struct OpenAPSSwift {
|
|
|
basalProfile: JSON,
|
|
basalProfile: JSON,
|
|
|
trioCustomOrefVariables: JSON,
|
|
trioCustomOrefVariables: JSON,
|
|
|
clock: Date
|
|
clock: Date
|
|
|
- ) -> (OrefFunctionResult, DetermineBasalInputs?) {
|
|
|
|
|
- var determineBasalInputs: DetermineBasalInputs?
|
|
|
|
|
-
|
|
|
|
|
|
|
+ ) -> (OrefFunctionResult) {
|
|
|
do {
|
|
do {
|
|
|
let glucose = try JSONBridge.glucose(from: glucose)
|
|
let glucose = try JSONBridge.glucose(from: glucose)
|
|
|
let currentTemp = try JSONBridge.currentTemp(from: currentTemp)
|
|
let currentTemp = try JSONBridge.currentTemp(from: currentTemp)
|
|
@@ -88,24 +71,8 @@ struct OpenAPSSwift {
|
|
|
let basalProfile = try JSONBridge.basalProfile(from: basalProfile)
|
|
let basalProfile = try JSONBridge.basalProfile(from: basalProfile)
|
|
|
let trioCustomOrefVariables = try JSONBridge.trioCustomOrefVariables(from: trioCustomOrefVariables)
|
|
let trioCustomOrefVariables = try JSONBridge.trioCustomOrefVariables(from: trioCustomOrefVariables)
|
|
|
|
|
|
|
|
- determineBasalInputs = DetermineBasalInputs(
|
|
|
|
|
- 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
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
guard let mealData = meal, let autosensData = autosens else {
|
|
guard let mealData = meal, let autosensData = autosens else {
|
|
|
- return (.failure(DeterminationError.missingInputs), determineBasalInputs)
|
|
|
|
|
|
|
+ return .failure(DeterminationError.missingInputs)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
let rawDetermination = try DeterminationGenerator.generate(
|
|
let rawDetermination = try DeterminationGenerator.generate(
|
|
@@ -122,19 +89,19 @@ struct OpenAPSSwift {
|
|
|
currentTime: clock
|
|
currentTime: clock
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- return (try .success(JSONBridge.to(rawDetermination)), determineBasalInputs)
|
|
|
|
|
|
|
+ return try .success(JSONBridge.to(rawDetermination))
|
|
|
|
|
|
|
|
} catch let determinationError as DeterminationError {
|
|
} catch let determinationError as DeterminationError {
|
|
|
// if we get a determination error we want to return it as a JSON
|
|
// if we get a determination error we want to return it as a JSON
|
|
|
// object that is { "error": "some error" }
|
|
// object that is { "error": "some error" }
|
|
|
do {
|
|
do {
|
|
|
let response = try JSONBridge.to(DeterminationErrorResponse(error: determinationError.localizedDescription))
|
|
let response = try JSONBridge.to(DeterminationErrorResponse(error: determinationError.localizedDescription))
|
|
|
- return (.success(response), determineBasalInputs)
|
|
|
|
|
|
|
+ return .success(response)
|
|
|
} catch {
|
|
} catch {
|
|
|
- return (.failure(determinationError), determineBasalInputs)
|
|
|
|
|
|
|
+ return .failure(determinationError)
|
|
|
}
|
|
}
|
|
|
} catch {
|
|
} catch {
|
|
|
- return (.failure(error), determineBasalInputs)
|
|
|
|
|
|
|
+ return .failure(error)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -145,9 +112,7 @@ struct OpenAPSSwift {
|
|
|
clock: JSON,
|
|
clock: JSON,
|
|
|
carbs: JSON,
|
|
carbs: JSON,
|
|
|
glucose: JSON
|
|
glucose: JSON
|
|
|
- ) -> (OrefFunctionResult, MealInputs?) {
|
|
|
|
|
- var mealInputs: MealInputs?
|
|
|
|
|
-
|
|
|
|
|
|
|
+ ) -> (OrefFunctionResult) {
|
|
|
do {
|
|
do {
|
|
|
let pumpHistory = try JSONBridge.pumpHistory(from: pumphistory)
|
|
let pumpHistory = try JSONBridge.pumpHistory(from: pumphistory)
|
|
|
let profile = try JSONBridge.profile(from: profile)
|
|
let profile = try JSONBridge.profile(from: profile)
|
|
@@ -156,15 +121,6 @@ struct OpenAPSSwift {
|
|
|
let carbs = try JSONBridge.carbs(from: carbs)
|
|
let carbs = try JSONBridge.carbs(from: carbs)
|
|
|
let glucose = try JSONBridge.glucose(from: glucose)
|
|
let glucose = try JSONBridge.glucose(from: glucose)
|
|
|
|
|
|
|
|
- mealInputs = MealInputs(
|
|
|
|
|
- pumpHistory: pumpHistory,
|
|
|
|
|
- profile: profile,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- clock: clock,
|
|
|
|
|
- carbs: carbs,
|
|
|
|
|
- glucose: glucose
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
let mealResult = try MealGenerator.generate(
|
|
let mealResult = try MealGenerator.generate(
|
|
|
pumpHistory: pumpHistory,
|
|
pumpHistory: pumpHistory,
|
|
|
profile: profile,
|
|
profile: profile,
|
|
@@ -174,23 +130,19 @@ struct OpenAPSSwift {
|
|
|
glucoseHistory: glucose
|
|
glucoseHistory: glucose
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- return try (.success(JSONBridge.to(mealResult)), mealInputs)
|
|
|
|
|
|
|
+ return try .success(JSONBridge.to(mealResult))
|
|
|
} catch {
|
|
} catch {
|
|
|
- return (.failure(error), mealInputs)
|
|
|
|
|
|
|
+ return .failure(error)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static func iob(pumphistory: JSON, profile: JSON, clock: JSON, autosens: JSON) -> (OrefFunctionResult, IobInputs?) {
|
|
|
|
|
- var iobInputs: IobInputs?
|
|
|
|
|
-
|
|
|
|
|
|
|
+ static func iob(pumphistory: JSON, profile: JSON, clock: JSON, autosens: JSON) -> (OrefFunctionResult) {
|
|
|
do {
|
|
do {
|
|
|
let pumpHistory = try JSONBridge.pumpHistory(from: pumphistory)
|
|
let pumpHistory = try JSONBridge.pumpHistory(from: pumphistory)
|
|
|
let profile = try JSONBridge.profile(from: profile)
|
|
let profile = try JSONBridge.profile(from: profile)
|
|
|
let clock = try JSONBridge.clock(from: clock)
|
|
let clock = try JSONBridge.clock(from: clock)
|
|
|
let autosens = try JSONBridge.autosens(from: autosens)
|
|
let autosens = try JSONBridge.autosens(from: autosens)
|
|
|
|
|
|
|
|
- iobInputs = IobInputs(history: pumpHistory, profile: profile, clock: clock, autosens: autosens)
|
|
|
|
|
-
|
|
|
|
|
let iobResult = try IobGenerator.generate(
|
|
let iobResult = try IobGenerator.generate(
|
|
|
history: pumpHistory,
|
|
history: pumpHistory,
|
|
|
profile: profile,
|
|
profile: profile,
|
|
@@ -198,9 +150,9 @@ struct OpenAPSSwift {
|
|
|
autosens: autosens
|
|
autosens: autosens
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- return try (.success(JSONBridge.to(iobResult)), iobInputs)
|
|
|
|
|
|
|
+ return try .success(JSONBridge.to(iobResult))
|
|
|
} catch {
|
|
} catch {
|
|
|
- return (.failure(error), iobInputs)
|
|
|
|
|
|
|
+ return .failure(error)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -213,9 +165,7 @@ struct OpenAPSSwift {
|
|
|
tempTargets: JSON,
|
|
tempTargets: JSON,
|
|
|
clock: JSON,
|
|
clock: JSON,
|
|
|
includeDeviationsForTesting: Bool = false
|
|
includeDeviationsForTesting: Bool = false
|
|
|
- ) -> (OrefFunctionResult, AutosensInputs?) {
|
|
|
|
|
- var autosensInputs: AutosensInputs?
|
|
|
|
|
-
|
|
|
|
|
|
|
+ ) -> (OrefFunctionResult) {
|
|
|
do {
|
|
do {
|
|
|
let glucose = try JSONBridge.glucose(from: glucose)
|
|
let glucose = try JSONBridge.glucose(from: glucose)
|
|
|
let pumpHistory = try JSONBridge.pumpHistory(from: pumpHistory)
|
|
let pumpHistory = try JSONBridge.pumpHistory(from: pumpHistory)
|
|
@@ -225,16 +175,6 @@ struct OpenAPSSwift {
|
|
|
let tempTargets = try JSONBridge.tempTargets(from: tempTargets)
|
|
let tempTargets = try JSONBridge.tempTargets(from: tempTargets)
|
|
|
let clock = try JSONBridge.clock(from: clock)
|
|
let clock = try JSONBridge.clock(from: clock)
|
|
|
|
|
|
|
|
- autosensInputs = AutosensInputs(
|
|
|
|
|
- glucose: glucose,
|
|
|
|
|
- history: pumpHistory,
|
|
|
|
|
- basalProfile: basalProfile,
|
|
|
|
|
- profile: profile,
|
|
|
|
|
- carbs: carbs,
|
|
|
|
|
- tempTargets: tempTargets,
|
|
|
|
|
- clock: clock
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
// this logic is from prepare/autosens.js
|
|
// this logic is from prepare/autosens.js
|
|
|
let ratio8h = try AutosensGenerator.generate(
|
|
let ratio8h = try AutosensGenerator.generate(
|
|
|
glucose: glucose,
|
|
glucose: glucose,
|
|
@@ -262,9 +202,9 @@ struct OpenAPSSwift {
|
|
|
|
|
|
|
|
let lowestRatio = ratio8h.ratio < ratio24h.ratio ? ratio8h : ratio24h
|
|
let lowestRatio = ratio8h.ratio < ratio24h.ratio ? ratio8h : ratio24h
|
|
|
|
|
|
|
|
- return try (.success(JSONBridge.to(lowestRatio)), autosensInputs)
|
|
|
|
|
|
|
+ return try .success(JSONBridge.to(lowestRatio))
|
|
|
} catch {
|
|
} catch {
|
|
|
- return (.failure(error), autosensInputs)
|
|
|
|
|
|
|
+ return .failure(error)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|