Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@
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 */; };
9E9C350626F69B2A0077F908 /* RetrospectiveCorrectionSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E9C350526F69B2A0077F908 /* RetrospectiveCorrectionSelectionView.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 +517,8 @@
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 */; };
DD3DBD272A33AEC8000F8B5B /* SettingsView+algorithmExperimentsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3DBD262A33AEC8000F8B5B /* SettingsView+algorithmExperimentsSection.swift */; };
DD3DBD292A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.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 @@ -1317,7 +1318,6 @@
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>"; };
9E9C350526F69B2A0077F908 /* RetrospectiveCorrectionSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrospectiveCorrectionSelectionView.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 +1687,8 @@
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>"; };
DD3DBD262A33AEC8000F8B5B /* SettingsView+algorithmExperimentsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsView+algorithmExperimentsSection.swift"; sourceTree = "<group>"; };
DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegralRetrospectiveCorrectionSelectionView.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 @@ -2351,6 +2353,7 @@
C13DA2AF24F6C7690098BB29 /* UIViewController.swift */,
430B29922041F5B200BA9F93 /* UserDefaults+Loop.swift */,
A9B607AF247F000F00792BE4 /* UserNotifications+Loop.swift */,
DD3DBD262A33AEC8000F8B5B /* SettingsView+algorithmExperimentsSection.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -2400,7 +2403,7 @@
43F64DD81D9C92C900D24DC6 /* TitleSubtitleTableViewCell.swift */,
4311FB9A1F37FE1B00D4C0A7 /* TitleSubtitleTextFieldTableViewCell.swift */,
C1AF062229426300002C1B19 /* ManualGlucoseEntryRow.swift */,
9E9C350526F69B2A0077F908 /* RetrospectiveCorrectionSelectionView.swift */,
DD3DBD282A33AFE9000F8B5B /* IntegralRetrospectiveCorrectionSelectionView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -3876,9 +3879,9 @@
892D7C5123B54A15008A9656 /* CarbEntryViewController.swift in Sources */,
B4E202302661063E009421B5 /* AutomaticDosingStatus.swift in Sources */,
C191D2A125B3ACAA00C26C0B /* DosingStrategySelectionView.swift in Sources */,
9E9C350626F69B2A0077F908 /* RetrospectiveCorrectionSelectionView.swift in Sources */,
A977A2F424ACFECF0059C207 /* CriticalEventLogExportManager.swift in Sources */,
89CA2B32226C18B8004D9350 /* TestingScenariosTableViewController.swift in Sources */,
DD3DBD272A33AEC8000F8B5B /* SettingsView+algorithmExperimentsSection.swift in Sources */,
43E93FB71E469A5100EAB8DB /* HKUnit.swift in Sources */,
43C05CAF21EB2C24006FB252 /* NSBundle.swift in Sources */,
A91D2A3F26CF0FF80023B075 /* IconTitleSubtitleTableViewCell.swift in Sources */,
Expand All @@ -3898,6 +3901,7 @@
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 */,
Expand Down
25 changes: 25 additions & 0 deletions Loop/Extensions/SettingsView+algorithmExperimentsSection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// SettingsView+algorithmExperimentsSection.swift
// Loop
//
// Created by Jonas Björkert on 2023-06-03.
// Copyright © 2023 LoopKit Authors. All rights reserved.
//
import Foundation
import SwiftUI
import LoopKitUI

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

NavigationLink(destination: IntegralRetrospectiveCorrectionSelectionView(isIntegralRetrospectiveCorrectionEnabled: $isIntegralRetrospectiveCorrectionEnabled)) {
HStack {
Text("Integral Retrospective Correction")
Spacer()
Text(isIntegralRetrospectiveCorrectionEnabled ? "On" : "Off")
}
}
}
}
}
4 changes: 0 additions & 4 deletions Loop/Managers/AnalyticsServicesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ final class AnalyticsServicesManager {
if newValue.dosingEnabled != oldValue.dosingEnabled {
logEvent("Closed loop enabled change")
}

if newValue.retrospectiveCorrection != oldValue.retrospectiveCorrection {
logEvent("Retrospective correction change")
}

if newValue.basalRateSchedule?.timeZone != oldValue.basalRateSchedule?.timeZone {
logEvent("Therapy schedule time zone change")
Expand Down
13 changes: 5 additions & 8 deletions Loop/Managers/LoopDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class LoopDataManager {
NotificationCenter.default.removeObserver(observer)
}
}

init(
lastLoopCompleted: Date?,
basalDeliveryState: PumpManagerStatus.BasalDeliveryState?,
Expand Down Expand Up @@ -123,9 +123,8 @@ final class LoopDataManager {

self.trustedTimeOffset = trustedTimeOffset

/// Creates an instance of the enabled retrospective correction implementation
retrospectiveCorrection = settings.enabledRetrospectiveCorrectionAlgorithm(retrospectiveCorrection: settings.retrospectiveCorrection)

retrospectiveCorrection = settings.enabledRetrospectiveCorrectionAlgorithm()

overrideIntentObserver = UserDefaults.appGroup?.observe(\.intentExtensionOverrideToSet, options: [.new], changeHandler: {[weak self] (defaults, change) in
guard let name = change.newValue??.lowercased(), let appGroup = UserDefaults.appGroup else {
return
Expand Down Expand Up @@ -318,10 +317,6 @@ final class LoopDataManager {
self.insulinEffect = nil
}
}

if newValue.retrospectiveCorrection != oldValue.retrospectiveCorrection {
retrospectiveCorrection = settings.enabledRetrospectiveCorrectionAlgorithm(retrospectiveCorrection: settings.retrospectiveCorrection)
}

notify(forChange: .preferences)
analyticsServicesManager.didChangeLoopSettings(from: oldValue, to: newValue)
Expand Down Expand Up @@ -2109,6 +2104,8 @@ extension LoopDataManager {
}),
"]",

"isExperimentalIntegralRetrospectiveCorrectionEnabled: \(UserDefaults.standard.bool(forKey: "isExperimentalIntegralRetrospectiveCorrectionEnabled"))",

"retrospectiveGlucoseDiscrepancies: [",
"* GlucoseEffect(start, mg/dL)",
(manager.retrospectiveGlucoseDiscrepancies ?? []).reduce(into: "", { (entries, entry) in
Expand Down
13 changes: 8 additions & 5 deletions Loop/Models/LoopSettings+Loop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ extension LoopSettings {
static let retrospectiveCorrectionEffectDuration = TimeInterval(hours: 1)

/// Creates an instance of the enabled retrospective correction implementation
func enabledRetrospectiveCorrectionAlgorithm(retrospectiveCorrection: RetrospectiveCorrectionOptions) -> RetrospectiveCorrection {
func enabledRetrospectiveCorrectionAlgorithm() -> RetrospectiveCorrection {
var enabledRetrospectiveCorrectionAlgorithm: RetrospectiveCorrection
switch retrospectiveCorrection {
case .standardRetrospectiveCorrection:
enabledRetrospectiveCorrectionAlgorithm = StandardRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
case .integralRetrospectiveCorrection:

let isIntegralRetrospectiveCorrectionEnabled = UserDefaults.standard.bool(forKey: "isExperimentalIntegralRetrospectiveCorrectionEnabled")

if isIntegralRetrospectiveCorrectionEnabled {
enabledRetrospectiveCorrectionAlgorithm = IntegralRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
} else {
enabledRetrospectiveCorrectionAlgorithm = StandardRetrospectiveCorrection(effectDuration: LoopSettings.retrospectiveCorrectionEffectDuration)
}

return enabledRetrospectiveCorrectionAlgorithm
}

Expand Down
9 changes: 5 additions & 4 deletions Loop/View Controllers/PredictionTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,9 @@ class PredictionTableViewController: LoopChartsTableViewController, Identifiable
format: NSLocalizedString("Predicted: %1$@\nActual: %2$@ (%3$@)", comment: "Format string describing retrospective glucose prediction comparison. (1: Predicted glucose)(2: Actual glucose)(3: difference)"),
values[0], values[1], values[2]
)
switch deviceManager.settings.retrospectiveCorrection {
case .standardRetrospectiveCorrection:
subtitleText = String(format: "%@\n%@", subtitleText, retro)
case .integralRetrospectiveCorrection:
let isIntegralRetrospectiveCorrectionEnabled = UserDefaults.standard.bool(forKey: "isExperimentalIntegralRetrospectiveCorrectionEnabled")

if isIntegralRetrospectiveCorrectionEnabled {
var integralEffectDisplay = "?"
var totalEffectDisplay = "?"
if let totalEffect = self.totalRetrospectiveCorrection {
Expand All @@ -293,6 +292,8 @@ class PredictionTableViewController: LoopChartsTableViewController, Identifiable
integralEffectDisplay, totalEffectDisplay
)
subtitleText = String(format: "%@\n%@", retro, integralRetro)
} else {
subtitleText = String(format: "%@\n%@", subtitleText, retro)
}

}
Expand Down
7 changes: 0 additions & 7 deletions Loop/View Controllers/StatusTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,6 @@ final class StatusTableViewController: LoopChartsTableViewController {
initialDosingEnabled: deviceManager.loopManager.settings.dosingEnabled,
isClosedLoopAllowed: automaticDosingStatus.$isAutomaticDosingAllowed,
automaticDosingStrategy: deviceManager.loopManager.settings.automaticDosingStrategy,
retrospectiveCorrection: deviceManager.loopManager.settings.retrospectiveCorrection,
availableSupports: supportManager.availableSupports,
isOnboardingComplete: onboardingManager.isComplete,
therapySettingsViewModelDelegate: deviceManager,
Expand Down Expand Up @@ -2133,12 +2132,6 @@ extension StatusTableViewController: SettingsViewModelDelegate {
var closedLoopDescriptiveText: String? {
return deviceManager.closedLoopDisallowedLocalizedDescription
}

func retrospectiveCorrectionChanged(_ retrospectiveCorrection: RetrospectiveCorrectionOptions) {
self.deviceManager.loopManager.mutateSettings { settings in
settings.retrospectiveCorrection = retrospectiveCorrection
}
}

func dosingEnabledChanged(_ value: Bool) {
deviceManager.loopManager.mutateSettings { settings in
Expand Down
10 changes: 0 additions & 10 deletions Loop/View Models/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public protocol SettingsViewModelDelegate: AnyObject {
func dosingEnabledChanged(_: Bool)
func dosingStrategyChanged(_: AutomaticDosingStrategy)
func didTapIssueReport()
func retrospectiveCorrectionChanged(_: RetrospectiveCorrectionOptions)
var closedLoopDescriptiveText: String? { get }
}

Expand Down Expand Up @@ -93,12 +92,6 @@ public class SettingsViewModel: ObservableObject {
delegate?.dosingStrategyChanged(automaticDosingStrategy)
}
}

@Published var retrospectiveCorrection: RetrospectiveCorrectionOptions {
didSet {
delegate?.retrospectiveCorrectionChanged(retrospectiveCorrection)
}
}

var closedLoopPreference: Bool {
didSet {
Expand All @@ -120,7 +113,6 @@ public class SettingsViewModel: ObservableObject {
initialDosingEnabled: Bool,
isClosedLoopAllowed: Published<Bool>.Publisher,
automaticDosingStrategy: AutomaticDosingStrategy,
retrospectiveCorrection: RetrospectiveCorrectionOptions,
availableSupports: [SupportUI],
isOnboardingComplete: Bool,
therapySettingsViewModelDelegate: TherapySettingsViewModelDelegate?,
Expand All @@ -138,7 +130,6 @@ public class SettingsViewModel: ObservableObject {
self.closedLoopPreference = initialDosingEnabled
self.isClosedLoopAllowed = false
self.automaticDosingStrategy = automaticDosingStrategy
self.retrospectiveCorrection = retrospectiveCorrection
self.availableSupports = availableSupports
self.isOnboardingComplete = isOnboardingComplete
self.therapySettingsViewModelDelegate = therapySettingsViewModelDelegate
Expand Down Expand Up @@ -187,7 +178,6 @@ extension SettingsViewModel {
initialDosingEnabled: true,
isClosedLoopAllowed: FakeClosedLoopAllowedPublisher().$mockIsClosedLoopAllowed,
automaticDosingStrategy: .automaticBolus,
retrospectiveCorrection: .standardRetrospectiveCorrection,
availableSupports: [],
isOnboardingComplete: false,
therapySettingsViewModelDelegate: nil,
Expand Down
Loading