Skip to content

Commit

Permalink
Implement alternative Bolus calculator (Artificial-Pancreas#286)
Browse files Browse the repository at this point in the history
*New alternative bolus calc and toggle function in bolus calculator settings to switch between bolus calculators

* add options for fatty meals in bolus calc config settings and apply a custom override factor

* fix problem with DecimalTextFields which throw error UIViewAlertForUnsatisfiableConstraints
  • Loading branch information
mountrcg committed Oct 29, 2023
1 parent dc1bb1a commit 02d8e0b
Show file tree
Hide file tree
Showing 17 changed files with 1,031 additions and 299 deletions.
52 changes: 52 additions & 0 deletions FreeAPS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@
BA00D96F7B2FF169A06FB530 /* CGMStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C018D1680307A31C9ED7120 /* CGMStateModel.swift */; };
BA90041DC8991147E5C8C3AA /* CalibrationsRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 500371C09F54F89A97D65FDB /* CalibrationsRootView.swift */; };
BD2B464E0745FBE7B79913F4 /* NightscoutConfigProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BF768BD6264FF7D71D66767 /* NightscoutConfigProvider.swift */; };
BD2FF1A02AE29D43005D1C5D /* CheckboxToggleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD2FF19F2AE29D43005D1C5D /* CheckboxToggleStyle.swift */; };
BD7DA9A52AE06DFC00601B20 /* BolusCalculatorConfigDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD7DA9A42AE06DFC00601B20 /* BolusCalculatorConfigDataFlow.swift */; };
BD7DA9A72AE06E2B00601B20 /* BolusCalculatorConfigProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD7DA9A62AE06E2B00601B20 /* BolusCalculatorConfigProvider.swift */; };
BD7DA9A92AE06E9200601B20 /* BolusCalculatorStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD7DA9A82AE06E9200601B20 /* BolusCalculatorStateModel.swift */; };
BD7DA9AC2AE06EB900601B20 /* BolusCalculatorConfigRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD7DA9AB2AE06EB900601B20 /* BolusCalculatorConfigRootView.swift */; };
BDFD165A2AE40438007F0DDA /* AlternativeBolusCalcRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFD16592AE40438007F0DDA /* AlternativeBolusCalcRootView.swift */; };
BDFD165C2AE40688007F0DDA /* DefaultBolusCalcRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFD165B2AE40688007F0DDA /* DefaultBolusCalcRootView.swift */; };
BF1667ADE69E4B5B111CECAE /* ManualTempBasalProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 680C4420C9A345D46D90D06C /* ManualTempBasalProvider.swift */; };
C967DACD3B1E638F8B43BE06 /* ManualTempBasalStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFCFE0781F9074C2917890E8 /* ManualTempBasalStateModel.swift */; };
CA370FC152BC98B3D1832968 /* BasalProfileEditorRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF8BCB0C37DEB5EC377B9612 /* BasalProfileEditorRootView.swift */; };
Expand Down Expand Up @@ -821,6 +828,13 @@
B9CAAEFB2AE70836000F68BC /* branch.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = branch.txt; sourceTree = SOURCE_ROOT; };
BA49538D56989D8DA6FCF538 /* TargetsEditorDataFlow.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = TargetsEditorDataFlow.swift; sourceTree = "<group>"; };
BC210C0F3CB6D3C86E5DED4E /* LibreConfigRootView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = LibreConfigRootView.swift; sourceTree = "<group>"; };
BD2FF19F2AE29D43005D1C5D /* CheckboxToggleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxToggleStyle.swift; sourceTree = "<group>"; };
BD7DA9A42AE06DFC00601B20 /* BolusCalculatorConfigDataFlow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusCalculatorConfigDataFlow.swift; sourceTree = "<group>"; };
BD7DA9A62AE06E2B00601B20 /* BolusCalculatorConfigProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusCalculatorConfigProvider.swift; sourceTree = "<group>"; };
BD7DA9A82AE06E9200601B20 /* BolusCalculatorStateModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusCalculatorStateModel.swift; sourceTree = "<group>"; };
BD7DA9AB2AE06EB900601B20 /* BolusCalculatorConfigRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusCalculatorConfigRootView.swift; sourceTree = "<group>"; };
BDFD16592AE40438007F0DDA /* AlternativeBolusCalcRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlternativeBolusCalcRootView.swift; sourceTree = "<group>"; };
BDFD165B2AE40688007F0DDA /* DefaultBolusCalcRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultBolusCalcRootView.swift; sourceTree = "<group>"; };
BF8BCB0C37DEB5EC377B9612 /* BasalProfileEditorRootView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BasalProfileEditorRootView.swift; sourceTree = "<group>"; };
C19984D62EFC0035A9E9644D /* BolusProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BolusProvider.swift; sourceTree = "<group>"; };
C377490C77661D75E8C50649 /* ManualTempBasalRootView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ManualTempBasalRootView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1157,6 +1171,7 @@
3811DE0325C9D31700A708ED /* Modules */ = {
isa = PBXGroup;
children = (
BD7DA9A32AE06DBA00601B20 /* BolusCalculatorConfig */,
190EBCC229FF134900BA767D /* StatConfig */,
CE94597C29E9E1CD0047C9C6 /* WatchConfig */,
19F95FF129F10F9C00314DDC /* Stat */,
Expand Down Expand Up @@ -2042,6 +2057,35 @@
isa = PBXGroup;
children = (
10A0C32B0DAB52726EF9B6D9 /* BolusRootView.swift */,
BDFD165B2AE40688007F0DDA /* DefaultBolusCalcRootView.swift */,
BDFD16592AE40438007F0DDA /* AlternativeBolusCalcRootView.swift */,
);
path = View;
sourceTree = "<group>";
};
BD2FF19E2AE29D24005D1C5D /* Components */ = {
isa = PBXGroup;
children = (
BD2FF19F2AE29D43005D1C5D /* CheckboxToggleStyle.swift */,
);
path = Components;
sourceTree = "<group>";
};
BD7DA9A32AE06DBA00601B20 /* BolusCalculatorConfig */ = {
isa = PBXGroup;
children = (
BD7DA9A42AE06DFC00601B20 /* BolusCalculatorConfigDataFlow.swift */,
BD7DA9A62AE06E2B00601B20 /* BolusCalculatorConfigProvider.swift */,
BD7DA9A82AE06E9200601B20 /* BolusCalculatorStateModel.swift */,
BD7DA9AA2AE06E9600601B20 /* View */,
);
path = BolusCalculatorConfig;
sourceTree = "<group>";
};
BD7DA9AA2AE06E9600601B20 /* View */ = {
isa = PBXGroup;
children = (
BD7DA9AB2AE06EB900601B20 /* BolusCalculatorConfigRootView.swift */,
);
path = View;
sourceTree = "<group>";
Expand All @@ -2060,6 +2104,7 @@
C2C98283C436DB934D7E7994 /* Bolus */ = {
isa = PBXGroup;
children = (
BD2FF19E2AE29D24005D1C5D /* Components */,
C8D1A7CA8C10C4403D4BBFA7 /* BolusDataFlow.swift */,
C19984D62EFC0035A9E9644D /* BolusProvider.swift */,
223EC0494F55A91E3EA69EF4 /* BolusStateModel.swift */,
Expand Down Expand Up @@ -2636,6 +2681,7 @@
3811DE6125C9D4D500A708ED /* ViewModifiers.swift in Sources */,
3811DEAC25C9D88300A708ED /* NightscoutManager.swift in Sources */,
19A910302A24BF6300C8951B /* StatsView.swift in Sources */,
BD7DA9A92AE06E9200601B20 /* BolusCalculatorStateModel.swift in Sources */,
CEB434E528B8FF5D00B70274 /* UIColor.swift in Sources */,
190EBCCB29FF13CB00BA767D /* StatConfigRootView.swift in Sources */,
3811DEA925C9D88300A708ED /* AppearanceManager.swift in Sources */,
Expand Down Expand Up @@ -2667,6 +2713,7 @@
193F6CDD2A512C8F001240FD /* Loops.swift in Sources */,
38B4F3CB25E502E200E76A18 /* WeakObjectSet.swift in Sources */,
38E989DD25F5021400C0CED0 /* PumpStatus.swift in Sources */,
BDFD165A2AE40438007F0DDA /* AlternativeBolusCalcRootView.swift in Sources */,
38E98A2525F52C9300C0CED0 /* IssueReporter.swift in Sources */,
190EBCC429FF136900BA767D /* StatConfigDataFlow.swift in Sources */,
3811DEB025C9D88300A708ED /* BaseKeychain.swift in Sources */,
Expand All @@ -2692,6 +2739,7 @@
9825E5E923F0B8FA80C8C7C7 /* NightscoutConfigStateModel.swift in Sources */,
38A43598262E0E4900E80935 /* FetchAnnouncementsManager.swift in Sources */,
642F76A05A4FF530463A9FD0 /* NightscoutConfigRootView.swift in Sources */,
BD7DA9AC2AE06EB900601B20 /* BolusCalculatorConfigRootView.swift in Sources */,
AD3D2CD42CD01B9EB8F26522 /* PumpConfigDataFlow.swift in Sources */,
53F2382465BF74DB1A967C8B /* PumpConfigProvider.swift in Sources */,
5D16287A969E64D18CE40E44 /* PumpConfigStateModel.swift in Sources */,
Expand Down Expand Up @@ -2733,6 +2781,7 @@
DBA5254DBB2586C98F61220C /* ISFEditorProvider.swift in Sources */,
1BBB001DAD60F3B8CEA4B1C7 /* ISFEditorStateModel.swift in Sources */,
F816826028DB441800054060 /* BluetoothTransmitter.swift in Sources */,
BD7DA9A72AE06E2B00601B20 /* BolusCalculatorConfigProvider.swift in Sources */,
38192E0D261BAF980094D973 /* ConvenienceExtensions.swift in Sources */,
FEFA5C0F299F810B00765C17 /* Core_Data.xcdatamodeld in Sources */,
88AB39B23C9552BD6E0C9461 /* ISFEditorRootView.swift in Sources */,
Expand Down Expand Up @@ -2772,6 +2821,7 @@
CE82E02728E869DF00473A9C /* AlertEntry.swift in Sources */,
38E4451E274DB04600EC9A94 /* AppDelegate.swift in Sources */,
5BFA1C2208114643B77F8CEB /* AddTempTargetProvider.swift in Sources */,
BD2FF1A02AE29D43005D1C5D /* CheckboxToggleStyle.swift in Sources */,
E0D4F80527513ECF00BDF1FE /* HealthKitSample.swift in Sources */,
919DBD08F13BAFB180DF6F47 /* AddTempTargetStateModel.swift in Sources */,
8BC2F5A29AD1ED08AC0EE013 /* AddTempTargetRootView.swift in Sources */,
Expand All @@ -2784,6 +2834,7 @@
69A31254F2451C20361D172F /* BolusStateModel.swift in Sources */,
0CEA2EA070AB041AF3E3745B /* BolusRootView.swift in Sources */,
1967DFC029D053AC00759F30 /* IconSelection.swift in Sources */,
BDFD165C2AE40688007F0DDA /* DefaultBolusCalcRootView.swift in Sources */,
19D4E4EB29FC6A9F00351451 /* TIRforChart.swift in Sources */,
FEFFA7A22929FE49007B8193 /* UIDevice+Extensions.swift in Sources */,
F90692D3274B9A130037068D /* AppleHealthKitRootView.swift in Sources */,
Expand Down Expand Up @@ -2811,6 +2862,7 @@
F5CA3DB1F9DC8B05792BBFAA /* CGMDataFlow.swift in Sources */,
BA00D96F7B2FF169A06FB530 /* CGMStateModel.swift in Sources */,
61962FCAF8A2D222553AC5A3 /* LibreConfigDataFlow.swift in Sources */,
BD7DA9A52AE06DFC00601B20 /* BolusCalculatorConfigDataFlow.swift in Sources */,
6EADD581738D64431902AC0A /* LibreConfigProvider.swift in Sources */,
CE94598729E9E4110047C9C6 /* WatchConfigRootView.swift in Sources */,
903D18976088B09110BCBE29 /* LibreConfigStateModel.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion FreeAPS.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"package": "SwiftCharts",
"repositoryURL": "https://github.com/ivanschuetz/SwiftCharts.git",
"repositoryURL": "https://github.com/ivanschuetz/SwiftCharts",
"state": {
"branch": "master",
"revision": "c354c1945bb35a1f01b665b22474f6db28cba4a2",
Expand Down
4 changes: 4 additions & 0 deletions FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@
"animatedBackground" : false
"displayCalendarEmojis" : false,
"displayCalendarIOBandCOB" : false,
"overrideFactor": 0.8,
"useCalc": false,
"fattyMeals": false,
"fattyMealFactor": 0.7
"maxCarbs": 1000
}
20 changes: 20 additions & 0 deletions FreeAPS/Sources/Models/FreeAPSSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct FreeAPSSettings: JSON, Equatable {
var maxCarbs: Decimal = 1000
var displayFatAndProteinOnWatch: Bool = false
var onlyAutotuneBasals: Bool = false
var overrideFactor: Decimal = 0.8
var useCalc: Bool = false
var fattyMeals: Bool = false
var fattyMealFactor: Decimal = 0.7
}

extension FreeAPSSettings: Decodable {
Expand Down Expand Up @@ -139,6 +143,22 @@ extension FreeAPSSettings: Decodable {
settings.individualAdjustmentFactor = individualAdjustmentFactor
}

if let useCalc = try? container.decode(Bool.self, forKey: .useCalc) {
settings.useCalc = useCalc
}

if let fattyMeals = try? container.decode(Bool.self, forKey: .fattyMeals) {
settings.fattyMeals = fattyMeals
}

if let fattyMealFactor = try? container.decode(Decimal.self, forKey: .fattyMealFactor) {
settings.fattyMealFactor = fattyMealFactor
}

if let overrideFactor = try? container.decode(Decimal.self, forKey: .overrideFactor) {
settings.overrideFactor = overrideFactor
}

if let timeCap = try? container.decode(Int.self, forKey: .timeCap) {
settings.timeCap = timeCap
}
Expand Down
6 changes: 6 additions & 0 deletions FreeAPS/Sources/Modules/Bolus/BolusProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ extension Bolus {
storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
}

func getProfile() -> CarbRatios {
storage.retrieve(OpenAPS.Settings.carbRatios, as: CarbRatios.self)
?? CarbRatios(from: OpenAPS.defaults(for: OpenAPS.Settings.carbRatios))
?? CarbRatios(units: .grams, schedule: [])
}

func pumpSettings() -> PumpSettings {
storage.retrieve(OpenAPS.Settings.settings, as: PumpSettings.self)
?? PumpSettings(from: OpenAPS.defaults(for: OpenAPS.Settings.settings))
Expand Down
Loading

0 comments on commit 02d8e0b

Please sign in to comment.