Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b7ebfe5
sign
dm61 Sep 17, 2021
8521cdc
add irc to settings
dm61 Sep 17, 2021
05d0c45
rc selection view
dm61 Sep 18, 2021
c5af247
rc selection in settings
dm61 Sep 18, 2021
6f2baf6
rc selection in data manager
dm61 Sep 19, 2021
f1f0220
rc subtitle test
dm61 Sep 19, 2021
fb7822b
add irc file
dm61 Sep 19, 2021
e171aee
enable irc
dm61 Sep 19, 2021
e104150
correct report of discrepancies
dm61 Oct 2, 2021
6f7d774
watch updates
dm61 May 15, 2023
fc7441e
sign
dm61 May 16, 2023
434ebe2
merge fixes
dm61 May 16, 2023
2344062
clean SettingsView
dm61 May 16, 2023
3d18c4c
refactor enabled RC algo
dm61 May 17, 2023
2ab9cd8
fix IRC description
dm61 May 17, 2023
603c1a0
update RC algo upon settings change
dm61 May 18, 2023
f75ff7c
default IRC
dm61 May 18, 2023
b94cdbe
fix rebase to Loop dev
dm61 May 21, 2023
3729d26
Restore automatic signing
marionbarker Jun 7, 2023
c725f7b
Merge branch 'dev' into prep_irc
marionbarker Jun 7, 2023
dadb4ef
Isolation of code and moved settings to Experimental Section
bjorkert Jun 10, 2023
f4c1fcb
Merge pull request #1 from LoopAndLearn/irc_pr
bjorkert Jun 10, 2023
7fe37e4
Removed unnecessary xcscheme files
bjorkert Jun 10, 2023
2fcf9c2
moved up algorithmExperimentsSection
bjorkert Jun 10, 2023
15e21a4
Merge pull request #2 from LoopAndLearn/remove_watchapp_xcschemes
marionbarker Jun 10, 2023
3c951df
copy paste error
bjorkert Jun 13, 2023
6cad39a
Merge pull request #3 from loopandlearn/rename_preview
marionbarker Jun 13, 2023
d236c06
dark mode fix
bjorkert Jun 17, 2023
512c64f
dark mode fix
bjorkert Jun 17, 2023
7950a5e
Merge pull request #4 from loopandlearn/dark_mode_fix
marionbarker Jun 17, 2023
49803c2
Merge branch 'dev' into prep_irc
marionbarker Jun 18, 2023
a9a7891
make consistent with dev updates
marionbarker Jun 18, 2023
7961bb7
Merge branch 'dev' into prep_irc
marionbarker Jun 18, 2023
a927001
Glucose Based Partial Application Factor (#1988)
marionbarker Jun 25, 2023
3b3c682
Wording tweak
ps2 Jun 25, 2023
9fd433d
Update to match glucose based partial application UI design and prefe…
ps2 Jun 25, 2023
21cec6b
Font adjustments
ps2 Jun 25, 2023
7518c70
Change settings.enabledRetrospectiveCorrectionAlgorithm back to var
ps2 Jun 25, 2023
5e5ba65
Reorg some files
ps2 Jun 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Common/Extensions/GlucoseRangeSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ extension GlucoseRangeSchedule {
func minQuantity(at date: Date) -> HKQuantity {
return HKQuantity(unit: unit, doubleValue: value(at: date).minValue)
}
func maxQuantity(at date: Date) -> HKQuantity {
return HKQuantity(unit: unit, doubleValue: value(at: date).maxValue)
}
}


Expand Down
9 changes: 8 additions & 1 deletion Common/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct FeatureFlagConfiguration: Decodable {
let adultChildInsulinModelSelectionEnabled: Bool
let profileExpirationSettingsViewEnabled: Bool
let missedMealNotifications: Bool
let allowAlgorithmExperiments: Bool


fileprivate init() {
Expand Down Expand Up @@ -229,6 +230,11 @@ struct FeatureFlagConfiguration: Decodable {
self.missedMealNotifications = true
#endif

#if ALLOW_ALGORITHM_EXPERIMENTS
self.allowAlgorithmExperiments = true
#else
self.allowAlgorithmExperiments = false
#endif
}
}

Expand Down Expand Up @@ -263,7 +269,8 @@ extension FeatureFlagConfiguration : CustomDebugStringConvertible {
"* dynamicCarbAbsorptionEnabled: \(dynamicCarbAbsorptionEnabled)",
"* adultChildInsulinModelSelectionEnabled: \(adultChildInsulinModelSelectionEnabled)",
"* profileExpirationSettingsViewEnabled: \(profileExpirationSettingsViewEnabled)",
"* missedMealNotifications: \(missedMealNotifications)"
"* missedMealNotifications: \(missedMealNotifications)",
"* allowAlgorithmExperiments: \(allowAlgorithmExperiments)"
].joined(separator: "\n")
}
}
Expand Down
46 changes: 37 additions & 9 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
89F9119424358E4500ECCAF3 /* CarbAbsorptionTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F9119324358E4500ECCAF3 /* CarbAbsorptionTime.swift */; };
89F9119624358E6900ECCAF3 /* BolusPickerValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F9119524358E6900ECCAF3 /* BolusPickerValues.swift */; };
89FE21AD24AC57E30033F501 /* Collection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89FE21AC24AC57E30033F501 /* Collection.swift */; };
9E1B653A26F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E1B653926F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift */; };
A90EF53C25DEF06200F32D61 /* PluginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16DA84122E8E112008624C2 /* PluginManager.swift */; };
A90EF54425DEF0A000F32D61 /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4374B5EE209D84BE00D17AA8 /* OSLog.swift */; };
A91D2A3F26CF0FF80023B075 /* IconTitleSubtitleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91D2A3E26CF0FF80023B075 /* IconTitleSubtitleTableViewCell.swift */; };
Expand Down Expand Up @@ -518,6 +519,12 @@
C1FB428D21791D2500FAB378 /* PumpManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C3B6F620BBCAA30026CAFA /* PumpManager.swift */; };
C1FB428F217921D600FAB378 /* PumpManagerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1FB428E217921D600FAB378 /* PumpManagerUI.swift */; };
C1FB4290217922A100FAB378 /* PumpManagerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1FB428E217921D600FAB378 /* PumpManagerUI.swift */; };
DD3DBD292A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */; };
DDC389F62A2B61750066E2E8 /* ApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */; };
DDC389F82A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */; };
DDC389FA2A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F92A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift */; };
DDC389FC2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389FB2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift */; };
DDC389FE2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389FD2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift */; };
E90909D124E34AC500F963D2 /* high_and_rising_with_cob_momentum_effect.json in Resources */ = {isa = PBXBuildFile; fileRef = E90909CC24E34AC500F963D2 /* high_and_rising_with_cob_momentum_effect.json */; };
E90909D224E34AC500F963D2 /* high_and_rising_with_cob_insulin_effect.json in Resources */ = {isa = PBXBuildFile; fileRef = E90909CD24E34AC500F963D2 /* high_and_rising_with_cob_insulin_effect.json */; };
E90909D324E34AC500F963D2 /* high_and_rising_with_cob_predicted_glucose.json in Resources */ = {isa = PBXBuildFile; fileRef = E90909CE24E34AC500F963D2 /* high_and_rising_with_cob_predicted_glucose.json */; };
Expand Down Expand Up @@ -1316,6 +1323,7 @@
89F9119324358E4500ECCAF3 /* CarbAbsorptionTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarbAbsorptionTime.swift; sourceTree = "<group>"; };
89F9119524358E6900ECCAF3 /* BolusPickerValues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BolusPickerValues.swift; sourceTree = "<group>"; };
89FE21AC24AC57E30033F501 /* Collection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Collection.swift; sourceTree = "<group>"; };
9E1B653926F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegralRetrospectiveCorrection.swift; sourceTree = "<group>"; };
A900531A28D60862000BC15B /* Loop.shortcut */ = {isa = PBXFileReference; lastKnownFileType = file; path = Loop.shortcut; sourceTree = "<group>"; };
A900531B28D608CA000BC15B /* Cancel Override.shortcut */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Cancel Override.shortcut"; sourceTree = "<group>"; };
A900531C28D6090D000BC15B /* Loop Remote Overrides.shortcut */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Loop Remote Overrides.shortcut"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1687,6 +1695,12 @@
C1FF3D4B29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
C1FF3D4C29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
C1FF3D4D29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/InfoPlist.strings; sourceTree = "<group>"; };
DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegralRetrospectiveCorrectionSelectionView.swift; sourceTree = "<group>"; };
DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationFactorStrategy.swift; sourceTree = "<group>"; };
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseBasedApplicationFactorStrategy.swift; sourceTree = "<group>"; };
DDC389F92A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantApplicationFactorStrategy.swift; sourceTree = "<group>"; };
DDC389FB2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsView+algorithmExperimentsSection.swift"; sourceTree = "<group>"; };
DDC389FD2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseBasedApplicationFactorSelectionView.swift; sourceTree = "<group>"; };
E90909CC24E34AC500F963D2 /* high_and_rising_with_cob_momentum_effect.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = high_and_rising_with_cob_momentum_effect.json; sourceTree = "<group>"; };
E90909CD24E34AC500F963D2 /* high_and_rising_with_cob_insulin_effect.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = high_and_rising_with_cob_insulin_effect.json; sourceTree = "<group>"; };
E90909CE24E34AC500F963D2 /* high_and_rising_with_cob_predicted_glucose.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = high_and_rising_with_cob_predicted_glucose.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2030,31 +2044,35 @@
children = (
43511CDF21FD80E400566C63 /* RetrospectiveCorrection.swift */,
43511CE021FD80E400566C63 /* StandardRetrospectiveCorrection.swift */,
9E1B653926F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift */,
);
path = RetrospectiveCorrection;
sourceTree = "<group>";
};
43757D131C06F26C00910CB9 /* Models */ = {
isa = PBXGroup;
children = (
A99A114029A581D6007919CE /* Remote */,
43511CDD21FD80AD00566C63 /* RetrospectiveCorrection */,
A9FB75F0252BE320004C7D3F /* BolusDosingDecision.swift */,
C17824A41E1AD4D100D9D25C /* ManualBolusRecommendation.swift */,
DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */,
B4E2022F2661063E009421B5 /* AutomaticDosingStatus.swift */,
A9FB75F0252BE320004C7D3F /* BolusDosingDecision.swift */,
DDC389F92A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift */,
C1EF747128D6A44A00C8C083 /* CrashRecoveryManager.swift */,
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */,
B40D07C6251A89D500C1C6D7 /* GlucoseDisplay.swift */,
43C2FAE01EB656A500364AFF /* GlucoseEffectVelocity.swift */,
C1C660D0252E4DD5009B5C32 /* LoopConstants.swift */,
436A0DA41D236A2A00104B24 /* LoopError.swift */,
E9C00EF424C623EF00628F35 /* LoopSettings+Loop.swift */,
A9B996EF27235191002DC09C /* LoopWarning.swift */,
C17824A41E1AD4D100D9D25C /* ManualBolusRecommendation.swift */,
4F526D601DF8D9A900A04910 /* NetBasal.swift */,
438D42F81D7C88BC003244B0 /* PredictionInputEffect.swift */,
4328E0311CFC068900E199AA /* WatchContext+LoopKit.swift */,
E9C00EF424C623EF00628F35 /* LoopSettings+Loop.swift */,
A987CD4824A58A0100439ADC /* ZipArchive.swift */,
A99A114029A581D6007919CE /* Remote */,
43511CDD21FD80AD00566C63 /* RetrospectiveCorrection */,
C19008FD25225D3900721625 /* SimpleBolusCalculator.swift */,
C1E3862428247B7100F561A4 /* StoredLoopNotRunningNotification.swift */,
C1C660D0252E4DD5009B5C32 /* LoopConstants.swift */,
C1EF747128D6A44A00C8C083 /* CrashRecoveryManager.swift */,
4328E0311CFC068900E199AA /* WatchContext+LoopKit.swift */,
A987CD4824A58A0100439ADC /* ZipArchive.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -2396,10 +2414,13 @@
438D42FA1D7D11A4003244B0 /* PredictionInputEffectTableViewCell.swift */,
439706E522D2E84900C81566 /* PredictionSettingTableViewCell.swift */,
1DE09BA824A3E23F009EE9F9 /* SettingsView.swift */,
DDC389FB2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift */,
C1DE5D22251BFC4D00439E49 /* SimpleBolusView.swift */,
43F64DD81D9C92C900D24DC6 /* TitleSubtitleTableViewCell.swift */,
4311FB9A1F37FE1B00D4C0A7 /* TitleSubtitleTextFieldTableViewCell.swift */,
C1AF062229426300002C1B19 /* ManualGlucoseEntryRow.swift */,
DDC389FD2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift */,
DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -3863,6 +3884,7 @@
A9CBE45A248ACBE1008E7BA2 /* DosingDecisionStore+SimulatedCoreData.swift in Sources */,
A9C62D8A2331703100535612 /* ServicesManager.swift in Sources */,
43DBF0531C93EC8200B3C386 /* DeviceDataManager.swift in Sources */,
9E1B653A26F7D14E00D5BD24 /* IntegralRetrospectiveCorrection.swift in Sources */,
A9347F2F24E7508A00C99C34 /* WatchHistoricalCarbs.swift in Sources */,
A9B996F027235191002DC09C /* LoopWarning.swift in Sources */,
C17824A01E19CF9800D9D25C /* GlucoseThresholdTableViewController.swift in Sources */,
Expand All @@ -3872,6 +3894,7 @@
C1201E2C23ECDBD0002DA84A /* WatchContextRequestUserInfo.swift in Sources */,
1D49795824E7289700948F05 /* ServicesViewModel.swift in Sources */,
1D4A3E2D2478628500FD601B /* StoredAlert+CoreDataClass.swift in Sources */,
DDC389FA2A2B62470066E2E8 /* ConstantApplicationFactorStrategy.swift in Sources */,
892D7C5123B54A15008A9656 /* CarbEntryViewController.swift in Sources */,
B4E202302661063E009421B5 /* AutomaticDosingStatus.swift in Sources */,
C191D2A125B3ACAA00C26C0B /* DosingStrategySelectionView.swift in Sources */,
Expand All @@ -3896,13 +3919,15 @@
C178249A1E1999FA00D9D25C /* CaseCountable.swift in Sources */,
B4F3D25124AF890C0095CE44 /* BluetoothStateManager.swift in Sources */,
1DDE273D24AEA4B000796622 /* SettingsViewModel.swift in Sources */,
DD3DBD292A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift in Sources */,
A9347F3124E7521800C99C34 /* CarbBackfillRequestUserInfo.swift in Sources */,
A9CBE458248AB564008E7BA2 /* DoseStore+SimulatedCoreData.swift in Sources */,
897A5A9924C22DE800C4E71D /* BolusEntryViewModel.swift in Sources */,
4374B5EF209D84BF00D17AA8 /* OSLog.swift in Sources */,
1DB619AC270BAD3D006C9D07 /* VersionUpdateViewModel.swift in Sources */,
A9C62D882331703100535612 /* Service.swift in Sources */,
89CAB36324C8FE96009EE3CE /* PredictedGlucoseChartView.swift in Sources */,
DDC389F82A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift in Sources */,
4F6663941E905FD2009E74FC /* ChartColorPalette+Loop.swift in Sources */,
A9F703732489BC8500C98AD8 /* CarbStore+SimulatedCoreData.swift in Sources */,
4328E0351CFC0AE100E199AA /* WatchDataManager.swift in Sources */,
Expand Down Expand Up @@ -3933,6 +3958,7 @@
E9B080B1253BDA6300BAD8F8 /* UserDefaults+LoopIntents.swift in Sources */,
C1AF062329426300002C1B19 /* ManualGlucoseEntryRow.swift in Sources */,
C148CEE724FD91BD00711B3B /* DeliveryUncertaintyAlertManager.swift in Sources */,
DDC389FC2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift in Sources */,
1D12D3B92548EFDD00B53E8B /* main.swift in Sources */,
435400341C9F878D00D5819C /* SetBolusUserInfo.swift in Sources */,
A9DCF32A25B0FABF00C89088 /* LoopUIColorPalette+Default.swift in Sources */,
Expand Down Expand Up @@ -3967,13 +3993,15 @@
A97F250825E056D500F0EE19 /* OnboardingManager.swift in Sources */,
438D42F91D7C88BC003244B0 /* PredictionInputEffect.swift in Sources */,
892A5D692230C41D008961AB /* RangeReplaceableCollection.swift in Sources */,
DDC389F62A2B61750066E2E8 /* ApplicationFactorStrategy.swift in Sources */,
4F70C2101DE8FAC5006380B7 /* ExtensionDataManager.swift in Sources */,
43DFB62320D4CAE7008A7BAE /* PumpManager.swift in Sources */,
A9FB75F1252BE320004C7D3F /* BolusDosingDecision.swift in Sources */,
892A5D59222F0A27008961AB /* Debug.swift in Sources */,
431A8C401EC6E8AB00823B9C /* CircleMaskView.swift in Sources */,
1D05219D2469F1F5000EBBDE /* AlertStore.swift in Sources */,
439897371CD2F80600223065 /* AnalyticsServicesManager.swift in Sources */,
DDC389FE2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift in Sources */,
A9C62D842331700E00535612 /* DiagnosticLog+Subsystem.swift in Sources */,
895FE0952201234000FCF18A /* OverrideSelectionViewController.swift in Sources */,
C1EF747228D6A44A00C8C083 /* CrashRecoveryManager.swift in Sources */,
Expand Down
25 changes: 22 additions & 3 deletions Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,23 @@ extension LoopDataManager {
return self.delegate?.roundBolusVolume(units: units) ?? units
}

let maxAutomaticBolus = min(iobHeadroom, maxBolus! * LoopConstants.bolusPartialApplicationFactor)
// Create dosing strategy based on user setting
let applicationFactorStrategy: ApplicationFactorStrategy = UserDefaults.standard.glucoseBasedApplicationFactorEnabled
? GlucoseBasedApplicationFactorStrategy()
: ConstantApplicationFactorStrategy()

let correctionRangeSchedule = settings.effectiveGlucoseTargetRangeSchedule()

let effectiveBolusApplicationFactor = applicationFactorStrategy.calculateDosingFactor(
for: glucose.quantity,
correctionRangeSchedule: correctionRangeSchedule!,
settings: settings
)

self.logger.debug(" *** Glucose: %{public}@, effectiveBolusApplicationFactor: %.2f", glucose.quantity.description, effectiveBolusApplicationFactor)

// If a user customizes maxPartialApplicationFactor > 1; this respects maxBolus
let maxAutomaticBolus = min(iobHeadroom, maxBolus! * min(effectiveBolusApplicationFactor, 1.0))

dosingRecommendation = predictedGlucose.recommendedAutomaticDose(
to: glucoseTargetRange!,
Expand All @@ -1708,7 +1724,7 @@ extension LoopDataManager {
model: doseStore.insulinModelProvider.model(for: pumpInsulinType),
basalRates: basalRateSchedule!,
maxAutomaticBolus: maxAutomaticBolus,
partialApplicationFactor: LoopConstants.bolusPartialApplicationFactor * self.timeBasedDoseApplicationFactor,
partialApplicationFactor: effectiveBolusApplicationFactor * self.timeBasedDoseApplicationFactor,
lastTempBasal: lastTempBasal,
volumeRounder: volumeRounder,
rateRounder: rateRounder,
Expand Down Expand Up @@ -2104,9 +2120,11 @@ extension LoopDataManager {
}),
"]",

"integralRetrospectiveCorrectionEnabled: \(UserDefaults.standard.integralRetrospectiveCorrectionEnabled)",

"retrospectiveGlucoseDiscrepancies: [",
"* GlucoseEffect(start, mg/dL)",
(state.retrospectiveGlucoseDiscrepancies ?? []).reduce(into: "", { (entries, entry) in
(manager.retrospectiveGlucoseDiscrepancies ?? []).reduce(into: "", { (entries, entry) in
entries.append("* \(entry.startDate), \(entry.quantity.doubleValue(for: .milligramsPerDeciliter))\n")
}),
"]",
Expand All @@ -2128,6 +2146,7 @@ extension LoopDataManager {
"insulinOnBoard: \(String(describing: manager.insulinOnBoard))",
"error: \(String(describing: state.error))",
"overrideInUserDefaults: \(String(describing: UserDefaults.appGroup?.intentExtensionOverrideToSet))",
"glucoseBasedApplicationFactorEnabled: \(UserDefaults.standard.glucoseBasedApplicationFactorEnabled)",
"",
String(reflecting: self.retrospectiveCorrection),
"",
Expand Down
20 changes: 20 additions & 0 deletions Loop/Models/ApplicationFactorStrategy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// ApplicationFactorStrategy.swift
// Loop
//
// Created by Jonas Björkert on 2023-06-03.
// Copyright © 2023 LoopKit Authors. All rights reserved.
//

import Foundation
import HealthKit
import LoopKit
import LoopCore

protocol ApplicationFactorStrategy {
func calculateDosingFactor(
for glucose: HKQuantity,
correctionRangeSchedule: GlucoseRangeSchedule,
settings: LoopSettings
) -> Double
}
Loading