Skip to content

Commit 5952689

Browse files
marionbarkerdm61bjorkertps2
authored
Add Integral Retrospective Correction Option to Algorithm Experiments (#2008)
* sign * add irc to settings * rc selection view * rc selection in settings * rc selection in data manager * rc subtitle test * add irc file * enable irc * correct report of discrepancies * watch updates * sign * merge fixes * clean SettingsView * refactor enabled RC algo * fix IRC description * update RC algo upon settings change * default IRC * fix rebase to Loop dev * Restore automatic signing * Isolation of code and moved settings to Experimental Section * Removed unnecessary xcscheme files * moved up algorithmExperimentsSection * copy paste error * dark mode fix * dark mode fix * make consistent with dev updates * Glucose Based Partial Application Factor (#1988) * Add Dosing Strategy: automaticBolusSlidingScale * Reverse order of two new constants * revert to dev for dosing strategy selection * revert to dev for dosing strategy selection * Rename to effectiveBolusApplicationFactor, change to flag inside existing automaticBolus case * Add applyLinearRamp slider to Dosing Strategy * Update constants * Modify explanation seen by user * missed one phrase * Update explanation seen by user, modify font * Enable swapping of original and replacment protocols, minimize LoopKit changes * Restore to dev branch version prior to pr1988_update merge * Restore to dev branch version prior to update for PR 1988 * Updates per requested changes for Loop PR 1988 * Renaming, adjusting views, logging * Wording change * Logging error fixed * dead code * missed rename * dark mode fix * Updated algorithm experiments view and glucose based partial application view * Put algorithm experiments behind feature flag --------- Co-authored-by: Jonas Björkert <jonas@bjorkert.se> Co-authored-by: Pete Schwamb <pete@schwamb.net> * Wording tweak * Font adjustments * Change settings.enabledRetrospectiveCorrectionAlgorithm back to var * Reorg some files --------- Co-authored-by: @dm61 <maksimov@colorado.edu> Co-authored-by: Jonas Björkert <jonas@bjorkert.se> Co-authored-by: Jonas Björkert <bjorkert@me.com> Co-authored-by: Pete Schwamb <pete@schwamb.net>
1 parent 3b3c682 commit 5952689

13 files changed

+404
-66
lines changed

Common/Extensions/GlucoseRangeSchedule.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ extension GlucoseRangeSchedule {
1313
func minQuantity(at date: Date) -> HKQuantity {
1414
return HKQuantity(unit: unit, doubleValue: value(at: date).minValue)
1515
}
16+
func maxQuantity(at date: Date) -> HKQuantity {
17+
return HKQuantity(unit: unit, doubleValue: value(at: date).maxValue)
18+
}
1619
}
1720

1821

Loop.xcodeproj/project.pbxproj

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
89F9119424358E4500ECCAF3 /* CarbAbsorptionTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F9119324358E4500ECCAF3 /* CarbAbsorptionTime.swift */; };
332332
89F9119624358E6900ECCAF3 /* BolusPickerValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F9119524358E6900ECCAF3 /* BolusPickerValues.swift */; };
333333
89FE21AD24AC57E30033F501 /* Collection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89FE21AC24AC57E30033F501 /* Collection.swift */; };
334+
9E1B653A26F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E1B653926F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift */; };
334335
A90EF53C25DEF06200F32D61 /* PluginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16DA84122E8E112008624C2 /* PluginManager.swift */; };
335336
A90EF54425DEF0A000F32D61 /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4374B5EE209D84BE00D17AA8 /* OSLog.swift */; };
336337
A91D2A3F26CF0FF80023B075 /* IconTitleSubtitleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91D2A3E26CF0FF80023B075 /* IconTitleSubtitleTableViewCell.swift */; };
@@ -518,6 +519,7 @@
518519
C1FB428D21791D2500FAB378 /* PumpManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C3B6F620BBCAA30026CAFA /* PumpManager.swift */; };
519520
C1FB428F217921D600FAB378 /* PumpManagerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1FB428E217921D600FAB378 /* PumpManagerUI.swift */; };
520521
C1FB4290217922A100FAB378 /* PumpManagerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1FB428E217921D600FAB378 /* PumpManagerUI.swift */; };
522+
DD3DBD292A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */; };
521523
DDC389F62A2B61750066E2E8 /* ApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */; };
522524
DDC389F82A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */; };
523525
DDC389FA2A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F92A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift */; };
@@ -1321,6 +1323,7 @@
13211323
89F9119324358E4500ECCAF3 /* CarbAbsorptionTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarbAbsorptionTime.swift; sourceTree = "<group>"; };
13221324
89F9119524358E6900ECCAF3 /* BolusPickerValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusPickerValues.swift; sourceTree = "<group>"; };
13231325
89FE21AC24AC57E30033F501 /* Collection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Collection.swift; sourceTree = "<group>"; };
1326+
9E1B653926F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegralRetrospectiveCorrection.swift; sourceTree = "<group>"; };
13241327
A900531A28D60862000BC15B /* Loop.shortcut */ = {isa = PBXFileReference; lastKnownFileType = file; path = Loop.shortcut; sourceTree = "<group>"; };
13251328
A900531B28D608CA000BC15B /* Cancel Override.shortcut */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Cancel Override.shortcut"; sourceTree = "<group>"; };
13261329
A900531C28D6090D000BC15B /* Loop Remote Overrides.shortcut */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Loop Remote Overrides.shortcut"; sourceTree = "<group>"; };
@@ -1692,6 +1695,7 @@
16921695
C1FF3D4B29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
16931696
C1FF3D4C29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
16941697
C1FF3D4D29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1698+
DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegralRetrospectiveCorrectionSelectionView.swift; sourceTree = "<group>"; };
16951699
DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationFactorStrategy.swift; sourceTree = "<group>"; };
16961700
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseBasedApplicationFactorStrategy.swift; sourceTree = "<group>"; };
16971701
DDC389F92A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantApplicationFactorStrategy.swift; sourceTree = "<group>"; };
@@ -2040,31 +2044,35 @@
20402044
children = (
20412045
43511CDF21FD80E400566C63 /* RetrospectiveCorrection.swift */,
20422046
43511CE021FD80E400566C63 /* StandardRetrospectiveCorrection.swift */,
2047+
9E1B653926F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift */,
20432048
);
20442049
path = RetrospectiveCorrection;
20452050
sourceTree = "<group>";
20462051
};
20472052
43757D131C06F26C00910CB9 /* Models */ = {
20482053
isa = PBXGroup;
20492054
children = (
2050-
A99A114029A581D6007919CE /* Remote */,
2051-
43511CDD21FD80AD00566C63 /* RetrospectiveCorrection */,
2052-
A9FB75F0252BE320004C7D3F /* BolusDosingDecision.swift */,
2053-
C17824A41E1AD4D100D9D25C /* ManualBolusRecommendation.swift */,
2055+
DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */,
20542056
B4E2022F2661063E009421B5 /* AutomaticDosingStatus.swift */,
2057+
A9FB75F0252BE320004C7D3F /* BolusDosingDecision.swift */,
2058+
DDC389F92A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift */,
2059+
C1EF747128D6A44A00C8C083 /* CrashRecoveryManager.swift */,
2060+
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */,
20552061
B40D07C6251A89D500C1C6D7 /* GlucoseDisplay.swift */,
20562062
43C2FAE01EB656A500364AFF /* GlucoseEffectVelocity.swift */,
2063+
C1C660D0252E4DD5009B5C32 /* LoopConstants.swift */,
20572064
436A0DA41D236A2A00104B24 /* LoopError.swift */,
2065+
E9C00EF424C623EF00628F35 /* LoopSettings+Loop.swift */,
20582066
A9B996EF27235191002DC09C /* LoopWarning.swift */,
2067+
C17824A41E1AD4D100D9D25C /* ManualBolusRecommendation.swift */,
20592068
4F526D601DF8D9A900A04910 /* NetBasal.swift */,
20602069
438D42F81D7C88BC003244B0 /* PredictionInputEffect.swift */,
2061-
4328E0311CFC068900E199AA /* WatchContext+LoopKit.swift */,
2062-
E9C00EF424C623EF00628F35 /* LoopSettings+Loop.swift */,
2063-
A987CD4824A58A0100439ADC /* ZipArchive.swift */,
2070+
A99A114029A581D6007919CE /* Remote */,
2071+
43511CDD21FD80AD00566C63 /* RetrospectiveCorrection */,
20642072
C19008FD25225D3900721625 /* SimpleBolusCalculator.swift */,
20652073
C1E3862428247B7100F561A4 /* StoredLoopNotRunningNotification.swift */,
2066-
C1C660D0252E4DD5009B5C32 /* LoopConstants.swift */,
2067-
C1EF747128D6A44A00C8C083 /* CrashRecoveryManager.swift */,
2074+
4328E0311CFC068900E199AA /* WatchContext+LoopKit.swift */,
2075+
A987CD4824A58A0100439ADC /* ZipArchive.swift */,
20682076
);
20692077
path = Models;
20702078
sourceTree = "<group>";
@@ -2324,7 +2332,6 @@
23242332
isa = PBXGroup;
23252333
children = (
23262334
A98556842493F901000FD662 /* AlertStore+SimulatedCoreData.swift */,
2327-
DDC389FB2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift */,
23282335
C1D289B422F90A52003FFBD9 /* BasalDeliveryState.swift */,
23292336
A9F703722489BC8500C98AD8 /* CarbStore+SimulatedCoreData.swift */,
23302337
C17824991E1999FA00D9D25C /* CaseCountable.swift */,
@@ -2407,11 +2414,13 @@
24072414
438D42FA1D7D11A4003244B0 /* PredictionInputEffectTableViewCell.swift */,
24082415
439706E522D2E84900C81566 /* PredictionSettingTableViewCell.swift */,
24092416
1DE09BA824A3E23F009EE9F9 /* SettingsView.swift */,
2417+
DDC389FB2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift */,
24102418
C1DE5D22251BFC4D00439E49 /* SimpleBolusView.swift */,
24112419
43F64DD81D9C92C900D24DC6 /* TitleSubtitleTableViewCell.swift */,
24122420
4311FB9A1F37FE1B00D4C0A7 /* TitleSubtitleTextFieldTableViewCell.swift */,
24132421
C1AF062229426300002C1B19 /* ManualGlucoseEntryRow.swift */,
24142422
DDC389FD2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift */,
2423+
DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */,
24152424
);
24162425
path = Views;
24172426
sourceTree = "<group>";
@@ -2453,9 +2462,6 @@
24532462
C1F2075B26D6F9B0007AB7EB /* ProfileExpirationAlerter.swift */,
24542463
A96DAC2B2838F31200D94E38 /* SharedLogging.swift */,
24552464
7E69CFFB2A16A77E00203CBD /* ResetLoopManager.swift */,
2456-
DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */,
2457-
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */,
2458-
DDC389F92A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift */,
24592465
);
24602466
path = Managers;
24612467
sourceTree = "<group>";
@@ -3878,6 +3884,7 @@
38783884
A9CBE45A248ACBE1008E7BA2 /* DosingDecisionStore+SimulatedCoreData.swift in Sources */,
38793885
A9C62D8A2331703100535612 /* ServicesManager.swift in Sources */,
38803886
43DBF0531C93EC8200B3C386 /* DeviceDataManager.swift in Sources */,
3887+
9E1B653A26F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift in Sources */,
38813888
A9347F2F24E7508A00C99C34 /* WatchHistoricalCarbs.swift in Sources */,
38823889
A9B996F027235191002DC09C /* LoopWarning.swift in Sources */,
38833890
C17824A01E19CF9800D9D25C /* GlucoseThresholdTableViewController.swift in Sources */,
@@ -3912,6 +3919,7 @@
39123919
C178249A1E1999FA00D9D25C /* CaseCountable.swift in Sources */,
39133920
B4F3D25124AF890C0095CE44 /* BluetoothStateManager.swift in Sources */,
39143921
1DDE273D24AEA4B000796622 /* SettingsViewModel.swift in Sources */,
3922+
DD3DBD292A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift in Sources */,
39153923
A9347F3124E7521800C99C34 /* CarbBackfillRequestUserInfo.swift in Sources */,
39163924
A9CBE458248AB564008E7BA2 /* DoseStore+SimulatedCoreData.swift in Sources */,
39173925
897A5A9924C22DE800C4E71D /* BolusEntryViewModel.swift in Sources */,

Loop/Managers/LoopDataManager.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,9 +2120,11 @@ extension LoopDataManager {
21202120
}),
21212121
"]",
21222122

2123+
"integralRetrospectiveCorrectionEnabled: \(UserDefaults.standard.integralRetrospectiveCorrectionEnabled)",
2124+
21232125
"retrospectiveGlucoseDiscrepancies: [",
21242126
"* GlucoseEffect(start, mg/dL)",
2125-
(state.retrospectiveGlucoseDiscrepancies ?? []).reduce(into: "", { (entries, entry) in
2127+
(manager.retrospectiveGlucoseDiscrepancies ?? []).reduce(into: "", { (entries, entry) in
21262128
entries.append("* \(entry.startDate), \(entry.quantity.doubleValue(for: .milligramsPerDeciliter))\n")
21272129
}),
21282130
"]",

Loop/Managers/GlucoseBasedApplicationFactorStrategy.swift renamed to Loop/Models/GlucoseBasedApplicationFactorStrategy.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,3 @@ struct GlucoseBasedApplicationFactorStrategy: ApplicationFactorStrategy {
4040
return effectiveBolusApplicationFactor
4141
}
4242
}
43-
44-
extension UserDefaults {
45-
private enum Key: String {
46-
case GlucoseBasedApplicationFactorEnabled = "com.loopkit.algorithmExperiments.glucoseBasedApplicationFactorEnabled"
47-
}
48-
49-
var glucoseBasedApplicationFactorEnabled: Bool {
50-
get {
51-
bool(forKey: Key.GlucoseBasedApplicationFactorEnabled.rawValue) as Bool
52-
}
53-
set {
54-
set(newValue, forKey: Key.GlucoseBasedApplicationFactorEnabled.rawValue)
55-
}
56-
}
57-
}

Loop/Models/LoopSettings+Loop.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,20 @@ extension LoopSettings {
1919
}
2020

2121
static let retrospectiveCorrectionEffectDuration = TimeInterval(hours: 1)
22-
23-
/// Creates an instance of the enabled retrospective correction implementation
22+
23+
/// Creates an instance of the enabled retrospective correction implementation
2424
var enabledRetrospectiveCorrectionAlgorithm: RetrospectiveCorrection {
25-
return StandardRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
25+
var enabledRetrospectiveCorrectionAlgorithm: RetrospectiveCorrection
26+
27+
let isIntegralRetrospectiveCorrectionEnabled = UserDefaults.standard.integralRetrospectiveCorrectionEnabled
28+
29+
if isIntegralRetrospectiveCorrectionEnabled {
30+
enabledRetrospectiveCorrectionAlgorithm = IntegralRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
31+
} else {
32+
enabledRetrospectiveCorrectionAlgorithm = StandardRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
33+
}
34+
35+
return enabledRetrospectiveCorrectionAlgorithm
2636
}
37+
2738
}

0 commit comments

Comments
 (0)