Skip to content

Commit 4b203de

Browse files
authored
Merge pull request LoopKit#2 from bjorkert/experimental
Renaming, Logging, View changes
2 parents 8b3f61e + 069cfc7 commit 4b203de

7 files changed

+78
-65
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@
517517
C1FB428F217921D600FAB378 /* PumpManagerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1FB428E217921D600FAB378 /* PumpManagerUI.swift */; };
518518
C1FB4290217922A100FAB378 /* PumpManagerUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1FB428E217921D600FAB378 /* PumpManagerUI.swift */; };
519519
DDC389F62A2B61750066E2E8 /* ApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */; };
520-
DDC389F82A2B620B0066E2E8 /* GlucoseBasedApplicationFactor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactor.swift */; };
520+
DDC389F82A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */; };
521521
DDC389FA2A2B62470066E2E8 /* ConstantDosingStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389F92A2B62470066E2E8 /* ConstantDosingStrategy.swift */; };
522522
DDC389FC2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389FB2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift */; };
523-
DDC389FE2A2C4C830066E2E8 /* EnhancedAutoBolusSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389FD2A2C4C830066E2E8 /* EnhancedAutoBolusSelectionView.swift */; };
523+
DDC389FE2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC389FD2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift */; };
524524
E90909D124E34AC500F963D2 /* high_and_rising_with_cob_momentum_effect.json in Resources */ = {isa = PBXBuildFile; fileRef = E90909CC24E34AC500F963D2 /* high_and_rising_with_cob_momentum_effect.json */; };
525525
E90909D224E34AC500F963D2 /* high_and_rising_with_cob_insulin_effect.json in Resources */ = {isa = PBXBuildFile; fileRef = E90909CD24E34AC500F963D2 /* high_and_rising_with_cob_insulin_effect.json */; };
526526
E90909D324E34AC500F963D2 /* high_and_rising_with_cob_predicted_glucose.json in Resources */ = {isa = PBXBuildFile; fileRef = E90909CE24E34AC500F963D2 /* high_and_rising_with_cob_predicted_glucose.json */; };
@@ -1689,10 +1689,10 @@
16891689
C1FF3D4C29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
16901690
C1FF3D4D29C786A900BDC1EC /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/InfoPlist.strings; sourceTree = "<group>"; };
16911691
DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationFactorStrategy.swift; sourceTree = "<group>"; };
1692-
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseBasedApplicationFactor.swift; sourceTree = "<group>"; };
1692+
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseBasedApplicationFactorStrategy.swift; sourceTree = "<group>"; };
16931693
DDC389F92A2B62470066E2E8 /* ConstantDosingStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantDosingStrategy.swift; sourceTree = "<group>"; };
16941694
DDC389FB2A2BC6670066E2E8 /* SettingsView+algorithmExperimentsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsView+algorithmExperimentsSection.swift"; sourceTree = "<group>"; };
1695-
DDC389FD2A2C4C830066E2E8 /* EnhancedAutoBolusSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnhancedAutoBolusSelectionView.swift; sourceTree = "<group>"; };
1695+
DDC389FD2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseBasedApplicationFactorSelectionView.swift; sourceTree = "<group>"; };
16961696
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>"; };
16971697
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>"; };
16981698
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>"; };
@@ -2406,7 +2406,7 @@
24062406
43F64DD81D9C92C900D24DC6 /* TitleSubtitleTableViewCell.swift */,
24072407
4311FB9A1F37FE1B00D4C0A7 /* TitleSubtitleTextFieldTableViewCell.swift */,
24082408
C1AF062229426300002C1B19 /* ManualGlucoseEntryRow.swift */,
2409-
DDC389FD2A2C4C830066E2E8 /* EnhancedAutoBolusSelectionView.swift */,
2409+
DDC389FD2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift */,
24102410
);
24112411
path = Views;
24122412
sourceTree = "<group>";
@@ -2449,7 +2449,7 @@
24492449
A96DAC2B2838F31200D94E38 /* SharedLogging.swift */,
24502450
7E69CFFB2A16A77E00203CBD /* ResetLoopManager.swift */,
24512451
DDC389F52A2B61750066E2E8 /* ApplicationFactorStrategy.swift */,
2452-
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactor.swift */,
2452+
DDC389F72A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift */,
24532453
DDC389F92A2B62470066E2E8 /* ConstantDosingStrategy.swift */,
24542454
);
24552455
path = Managers;
@@ -3913,7 +3913,7 @@
39133913
1DB619AC270BAD3D006C9D07 /* VersionUpdateViewModel.swift in Sources */,
39143914
A9C62D882331703100535612 /* Service.swift in Sources */,
39153915
89CAB36324C8FE96009EE3CE /* PredictedGlucoseChartView.swift in Sources */,
3916-
DDC389F82A2B620B0066E2E8 /* GlucoseBasedApplicationFactor.swift in Sources */,
3916+
DDC389F82A2B620B0066E2E8 /* GlucoseBasedApplicationFactorStrategy.swift in Sources */,
39173917
4F6663941E905FD2009E74FC /* ChartColorPalette+Loop.swift in Sources */,
39183918
A9F703732489BC8500C98AD8 /* CarbStore+SimulatedCoreData.swift in Sources */,
39193919
4328E0351CFC0AE100E199AA /* WatchDataManager.swift in Sources */,
@@ -3986,7 +3986,7 @@
39863986
431A8C401EC6E8AB00823B9C /* CircleMaskView.swift in Sources */,
39873987
1D05219D2469F1F5000EBBDE /* AlertStore.swift in Sources */,
39883988
439897371CD2F80600223065 /* AnalyticsServicesManager.swift in Sources */,
3989-
DDC389FE2A2C4C830066E2E8 /* EnhancedAutoBolusSelectionView.swift in Sources */,
3989+
DDC389FE2A2C4C830066E2E8 /* GlucoseBasedApplicationFactorSelectionView.swift in Sources */,
39903990
A9C62D842331700E00535612 /* DiagnosticLog+Subsystem.swift in Sources */,
39913991
895FE0952201234000FCF18A /* OverrideSelectionViewController.swift in Sources */,
39923992
C1EF747228D6A44A00C8C083 /* CrashRecoveryManager.swift in Sources */,

Loop/Extensions/SettingsView+algorithmExperimentsSection.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import LoopKitUI
1212

1313
extension SettingsView {
1414
internal var algorithmExperimentsSection: some View {
15-
Section(header: SectionHeader(label: NSLocalizedString("Algorithm Experiments", comment: "The title of the Algorithm Experiments section in settings"))) {
15+
Section(header: SectionHeader(label: NSLocalizedString("Algorithm Experiments ⚠️", comment: "The title of the Algorithm Experiments section in settings"))) {
1616

17-
NavigationLink(destination: EnhancedAutoBolusSelectionView(isEnhancedAutoBolusEnabled: $isEnhancedAutoBolusEnabled)) {
17+
NavigationLink(destination: GlucoseBasedApplicationFactorSelectionView(isGlucoseBasedApplicationFactorEnabled: $isGlucoseBasedApplicationFactorEnabled)) {
1818
HStack {
19-
Text("Enable Enhanced AutoBolus")
19+
Text("Glucose Based Partial Application")
2020
Spacer()
21-
Text(isEnhancedAutoBolusEnabled ? "On" : "Off")
21+
Text(isGlucoseBasedApplicationFactorEnabled ? "On" : "Off")
2222
}
2323
}
2424
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// GlucoseBasedApplicationFactor.swift
2+
// GlucoseBasedApplicationFactorStrategy.swift
33
// Loop
44
//
55
// Created by Jonas Björkert on 2023-06-03.
@@ -11,7 +11,7 @@ import HealthKit
1111
import LoopKit
1212
import LoopCore
1313

14-
struct GlucoseBasedApplicationFactor: ApplicationFactorStrategy {
14+
struct GlucoseBasedApplicationFactorStrategy: ApplicationFactorStrategy {
1515
static let minPartialApplicationFactor = 0.20 // min fraction of correction when glucose > minGlucoseSlidingScale
1616
static let maxPartialApplicationFactor = 0.80 // max fraction of correction when glucose > maxGlucoseSlidingScale
1717
// set minGlucoseSlidingScale based on user setting for correction range
@@ -30,12 +30,12 @@ struct GlucoseBasedApplicationFactor: ApplicationFactorStrategy {
3030
let lowerBoundTarget = correctionRange.lowerBound.doubleValue(for: .milligramsPerDeciliter)
3131

3232
// Calculate minimum glucose sliding scale and scaling fraction
33-
let minGlucoseSlidingScale = GlucoseBasedApplicationFactor.minGlucoseDeltaSlidingScale + lowerBoundTarget
34-
let scalingFraction = (GlucoseBasedApplicationFactor.maxPartialApplicationFactor - GlucoseBasedApplicationFactor.minPartialApplicationFactor) / (GlucoseBasedApplicationFactor.maxGlucoseSlidingScale - minGlucoseSlidingScale)
33+
let minGlucoseSlidingScale = GlucoseBasedApplicationFactorStrategy.minGlucoseDeltaSlidingScale + lowerBoundTarget
34+
let scalingFraction = (GlucoseBasedApplicationFactorStrategy.maxPartialApplicationFactor - GlucoseBasedApplicationFactorStrategy.minPartialApplicationFactor) / (GlucoseBasedApplicationFactorStrategy.maxGlucoseSlidingScale - minGlucoseSlidingScale)
3535
let scalingGlucose = max(currentGlucose - minGlucoseSlidingScale, 0.0)
3636

3737
// Calculate effectiveBolusApplicationFactor
38-
let effectiveBolusApplicationFactor = min(GlucoseBasedApplicationFactor.minPartialApplicationFactor + scalingGlucose * scalingFraction, GlucoseBasedApplicationFactor.maxPartialApplicationFactor)
38+
let effectiveBolusApplicationFactor = min(GlucoseBasedApplicationFactorStrategy.minPartialApplicationFactor + scalingGlucose * scalingFraction, GlucoseBasedApplicationFactorStrategy.maxPartialApplicationFactor)
3939

4040
return effectiveBolusApplicationFactor
4141
}

Loop/Managers/LoopDataManager.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,8 +1699,8 @@ extension LoopDataManager {
16991699
}
17001700

17011701
// Create dosing strategy based on user setting
1702-
let applicationFactorStrategy: ApplicationFactorStrategy = UserDefaults.standard.bool(forKey: "applyExperimentalEnhancedAutoBolus")
1703-
? GlucoseBasedApplicationFactor()
1702+
let applicationFactorStrategy: ApplicationFactorStrategy = UserDefaults.standard.bool(forKey: "applyExperimentalGlucoseBasedApplicationFactor")
1703+
? GlucoseBasedApplicationFactorStrategy()
17041704
: ConstantDosingStrategy()
17051705

17061706
let correctionRangeSchedule = settings.effectiveGlucoseTargetRangeSchedule()
@@ -1711,8 +1711,8 @@ extension LoopDataManager {
17111711
settings: settings
17121712
)
17131713

1714-
print(" *** Glucose, effectiveBolusApplicationFactor: ", glucose.quantity, Double(Int(100.0*effectiveBolusApplicationFactor))/100.0)
1715-
1714+
self.logger.debug(" *** Glucose: %{public}@, effectiveBolusApplicationFactor: %.2f", glucose.quantity.description, effectiveBolusApplicationFactor)
1715+
17161716
// If a user customizes maxPartialApplicationFactor > 1; this respects maxBolus
17171717
let maxAutomaticBolus = min(iobHeadroom, maxBolus! * min(effectiveBolusApplicationFactor, 1.0))
17181718

@@ -2144,7 +2144,7 @@ extension LoopDataManager {
21442144
"insulinOnBoard: \(String(describing: manager.insulinOnBoard))",
21452145
"error: \(String(describing: state.error))",
21462146
"overrideInUserDefaults: \(String(describing: UserDefaults.appGroup?.intentExtensionOverrideToSet))",
2147-
"applyExperimentalEnhancedAutoBolus: \(UserDefaults.standard.bool(forKey: "applyExperimentalEnhancedAutoBolus"))",
2147+
"applyExperimentalGlucoseBasedApplicationFactor: \(UserDefaults.standard.bool(forKey: "applyExperimentalGlucoseBasedApplicationFactor"))",
21482148
"",
21492149
String(reflecting: self.retrospectiveCorrection),
21502150
"",

Loop/Views/EnhancedAutoBolusSelectionView.swift

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// GlucoseBasedApplicationFactorSelectionView.swift
3+
// Loop
4+
//
5+
// Created by Jonas Björkert on 2023-06-04.
6+
// Copyright © 2023 LoopKit Authors. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import SwiftUI
11+
import LoopKit
12+
import LoopKitUI
13+
14+
public struct GlucoseBasedApplicationFactorSelectionView: View {
15+
@Binding var isGlucoseBasedApplicationFactorEnabled: Bool
16+
17+
public init(isGlucoseBasedApplicationFactorEnabled: Binding<Bool>) {
18+
self._isGlucoseBasedApplicationFactorEnabled = isGlucoseBasedApplicationFactorEnabled
19+
}
20+
21+
public var body: some View {
22+
List {
23+
automaticBolusSection
24+
}
25+
.navigationBarTitleDisplayMode(.inline)
26+
.toolbar {
27+
ToolbarItem(placement: .principal) {
28+
VStack {
29+
Text("Glucose Based")
30+
.font(.headline)
31+
Text("Partial Application")
32+
.font(.subheadline)
33+
}
34+
}
35+
}
36+
}
37+
38+
private var automaticBolusSection: some View {
39+
VStack {
40+
DescriptiveText(label: NSLocalizedString("Active only when Automatic Bolus is selected under Dosing Strategy.\n\nWhen Glucose Based Partial Application is disabled, Automatic Bolus Dosing Strategy uses a constant percentage of 40% when Loop recommends a bolus.\n\nWhen enabled, this experimental feature varies the percentage of recommended bolus delivered each cycle with glucose level. Near correction range, use 20% (similar to Temp Basal). Gradually increase to a maximum of 80% at high glucose (200 mg/dL, 11.1 mmol/L).\n\nPlease be aware that during fast rising glucose, such as after an unannounced meal, this feature, combined with Loop's velocity and retrospective correction effects, may result in a larger dose than your ISF would call for.", comment: "Description of Glucose Based Partial Application toggle."), color: .black)
41+
Section() {
42+
Toggle(NSLocalizedString("Glucose Based Partial Application", comment: "Title for Glucose Based Partial Application toggle"), isOn: $isGlucoseBasedApplicationFactorEnabled)
43+
.onChange(of: isGlucoseBasedApplicationFactorEnabled) { newValue in
44+
UserDefaults.standard.set(newValue, forKey: "applyExperimentalGlucoseBasedApplicationFactor")
45+
}
46+
}
47+
}
48+
}
49+
}
50+
51+
struct EnhancedAutoBolusSelectionView_Previews: PreviewProvider {
52+
static var previews: some View {
53+
GlucoseBasedApplicationFactorSelectionView(isGlucoseBasedApplicationFactorEnabled: .constant(true))
54+
}
55+
}

Loop/Views/SettingsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct SettingsView: View {
3131
@State private var deletePumpDataAlertIsPresented = false
3232
@State private var deleteCGMDataAlertIsPresented = false
3333
@State internal var enhancedAutoBolusIsPresented: Bool = false
34-
@State internal var isEnhancedAutoBolusEnabled = UserDefaults.standard.bool(forKey: "applyExperimentalEnhancedAutoBolus")
34+
@State internal var isGlucoseBasedApplicationFactorEnabled = UserDefaults.standard.bool(forKey: "applyExperimentalGlucoseBasedApplicationFactor")
3535

3636
var localizedAppNameAndVersion: String
3737

0 commit comments

Comments
 (0)