Explorar el Código

Add setting for using the Swift Oref algorithm

Sam King hace 1 año
padre
commit
9e8b820a7a

+ 6 - 0
FreeAPS/Sources/Models/Preferences.swift

@@ -53,6 +53,7 @@ struct Preferences: JSON, Equatable {
     var enableSMB_high_bg_target: Decimal = 110
     var threshold_setting: Decimal = 60
     var updateInterval: Decimal = 20
+    var useSwiftOref: Bool = true
 }
 
 extension Preferences {
@@ -108,6 +109,7 @@ extension Preferences {
         case enableSMB_high_bg_target
         case threshold_setting
         case updateInterval
+        case useSwiftOref
     }
 }
 
@@ -328,6 +330,10 @@ extension Preferences: Decodable {
             preferences.updateInterval = updateInterval
         }
 
+        if let useSwiftOref = try? container.decode(Bool.self, forKey: .useSwiftOref) {
+            preferences.useSwiftOref = useSwiftOref
+        }
+
         self = preferences
     }
 }

+ 3 - 0
FreeAPS/Sources/Modules/AlgorithmAdvancedSettings/AlgorithmAdvancedSettingsStateModel.swift

@@ -21,6 +21,7 @@ extension AlgorithmAdvancedSettings {
         @Published var remainingCarbsFraction: Decimal = 1.0
         @Published var remainingCarbsCap: Decimal = 90
         @Published var noisyCGMTargetMultiplier: Decimal = 1.3
+        @Published var useSwiftOref: Bool = true
 
         var insulinActionCurve: Decimal = 10
 
@@ -45,6 +46,8 @@ extension AlgorithmAdvancedSettings {
             subscribePreferencesSetting(\.remainingCarbsCap, on: $remainingCarbsCap) { remainingCarbsCap = $0 }
             subscribePreferencesSetting(\.noisyCGMTargetMultiplier, on: $noisyCGMTargetMultiplier) {
                 noisyCGMTargetMultiplier = $0 }
+            subscribePreferencesSetting(\.useSwiftOref, on: $useSwiftOref) {
+                useSwiftOref = $0 }
 
             insulinActionCurve = pumpSettings.insulinActionCurve
         }

+ 26 - 0
FreeAPS/Sources/Modules/AlgorithmAdvancedSettings/View/AlgorithmAdvancedSettingsRootView.swift

@@ -338,6 +338,32 @@ extension AlgorithmAdvancedSettings {
                         Text("Note: A CGM is considered noisy when it provides inconsistent readings.")
                     }
                 )
+                SettingInputSection(
+                    decimalValue: $decimalPlaceholder,
+                    booleanValue: $state.useSwiftOref,
+                    shouldDisplayHint: $shouldDisplayHint,
+                    selectedVerboseHint: Binding(
+                        get: { selectedVerboseHint },
+                        set: {
+                            selectedVerboseHint = $0.map { AnyView($0) }
+                            hintLabel = NSLocalizedString("Use Swift Oref", comment: "Use Swift Oref")
+                        }
+                    ),
+                    units: state.units,
+                    type: .boolean,
+                    label: NSLocalizedString("Use Swift Oref", comment: "Use Swift Oref"),
+                    miniHint: "Enables the Swift implementation of the Oref algorithm",
+                    verboseHint:
+                    VStack(alignment: .leading, spacing: 10) {
+                        Text("Default: ON").bold()
+                        Text(
+                            "The Use Swift Oref option enables our native implementation of the Oref algorithm."
+                        )
+                        Text(
+                            "Note: When enabled, we log anonymous information about differences between the Swift and Javascript Oref implementations for development."
+                        )
+                    }
+                )
             }
             .listSectionSpacing(sectionSpacing)
             .sheet(isPresented: $shouldDisplayHint) {