Преглед изворни кода

Test new AT toggle

(cherry picked from commit 40fd4b5c1e028b405774ae4224acfd0e509c08fa)
(cherry picked from commit 4f371d7c5597670d13e42e0cb202260c69c13333)
Jon Mårtensson пре 2 година
родитељ
комит
3b92de31d3

+ 0 - 6
FreeAPS/Resources/javascript/prepare/determine-basal.js

@@ -37,12 +37,6 @@ function generate(iob, currenttemp, glucose, profile, autosens = null, meal = nu
     if (basalProfile) {
         basalprofile = basalProfile;
     }
-    /*
-    var tdd_ = {};
-    if (tdd) {
-        tdd_ = tdd;
-    }
-     */
     
     var oref2_variables_ = {};
     if (oref2_variables) {

+ 10 - 3
FreeAPS/Resources/javascript/prepare/profile.js

@@ -1,7 +1,7 @@
 //для pumpprofile.json параметры: settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json settings/model.json
 //для profile.json параметры: settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json settings/model.json settings/autotune.json
 
-function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data, preferences_input = false, carbratio_input = false, temptargets_input = false, model_input = false, autotune_input = false) {
+function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data, preferences_input = false, carbratio_input = false, temptargets_input = false, model_input = false, autotune_input = false, freeaps_data) {
     if (bgtargets_data.units !== 'mg/dL') {
         if (bgtargets_data.units === 'mmol/L') {
             for (var i = 0, len = bgtargets_data.targets.length; i < len; i++) {
@@ -34,6 +34,11 @@ function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data
     if (temptargets_input) {
         temptargets_data = temptargets_input;
     }
+    
+    var freeaps = { };
+    if (freeaps_data) {
+        freeaps = freeaps_data;
+    }
 
     var model_data = { };
     if (model_input) {
@@ -81,8 +86,10 @@ function generate(pumpsettings_data, bgtargets_data, isf_data, basalprofile_data
 
     if (autotune_data) {
         if (autotune_data.basalprofile) { inputs.basals = autotune_data.basalprofile; }
-        if (autotune_data.isfProfile) { inputs.isf = autotune_data.isfProfile; }
-        if (autotune_data.carb_ratio) { inputs.carbratio.schedule[0].ratio = autotune_data.carb_ratio; }
+        if (!freeaps.onlyAutotuneBasals) {
+            if (autotune_data.isfProfile) { inputs.isf = autotune_data.isfProfile; }
+            if (autotune_data.carb_ratio) { inputs.carbratio.schedule[0].ratio = autotune_data.carb_ratio; }
+        }
     }
     return freeaps_profile(inputs);
 }

+ 9 - 4
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -389,6 +389,7 @@ final class OpenAPS {
                 let tempTargets = self.loadFileFromStorage(name: Settings.tempTargets)
                 let model = self.loadFileFromStorage(name: Settings.model)
                 let autotune = useAutotune ? self.loadFileFromStorage(name: Settings.autotune) : .empty
+                let freeaps = self.loadFileFromStorage(name: FreeAPS.settings)
 
                 let pumpProfile = self.makeProfile(
                     preferences: preferences,
@@ -399,7 +400,8 @@ final class OpenAPS {
                     carbRatio: cr,
                     tempTargets: tempTargets,
                     model: model,
-                    autotune: RawJSON.null
+                    autotune: RawJSON.null,
+                    freeaps: freeaps
                 )
 
                 let profile = self.makeProfile(
@@ -411,7 +413,8 @@ final class OpenAPS {
                     carbRatio: cr,
                     tempTargets: tempTargets,
                     model: model,
-                    autotune: autotune.isEmpty ? .null : autotune
+                    autotune: autotune.isEmpty ? .null : autotune,
+                    freeaps: freeaps
                 )
 
                 self.storage.save(pumpProfile, as: Settings.pumpProfile)
@@ -598,7 +601,8 @@ final class OpenAPS {
         carbRatio: JSON,
         tempTargets: JSON,
         model: JSON,
-        autotune: JSON
+        autotune: JSON,
+        freeaps: JSON
     ) -> RawJSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
@@ -616,7 +620,8 @@ final class OpenAPS {
                     carbRatio,
                     tempTargets,
                     model,
-                    autotune
+                    autotune,
+                    freeaps
                 ]
             )
         }

+ 5 - 0
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -42,6 +42,7 @@ struct FreeAPSSettings: JSON, Equatable {
     var rulerMarks: Bool = false
     var maxCarbs: Decimal = 1000
     var displayFatAndProteinOnWatch: Bool = false
+    var onlyAutotuneBasals: Bool = false
 }
 
 extension FreeAPSSettings: Decodable {
@@ -219,6 +220,10 @@ extension FreeAPSSettings: Decodable {
             settings.displayFatAndProteinOnWatch = displayFatAndProteinOnWatch
         }
 
+        if let onlyAutotuneBasals = try? container.decode(Bool.self, forKey: .onlyAutotuneBasals) {
+            settings.onlyAutotuneBasals = onlyAutotuneBasals
+        }
+
         self = settings
     }
 }

+ 2 - 0
FreeAPS/Sources/Modules/AutotuneConfig/AutotuneConfigStateModel.swift

@@ -5,6 +5,7 @@ extension AutotuneConfig {
     final class StateModel: BaseStateModel<Provider> {
         @Injected() var apsManager: APSManager!
         @Published var useAutotune = false
+        @Published var onlyAutotuneBasals = false
         @Published var autotune: Autotune?
         private(set) var units: GlucoseUnits = .mmolL
         @Published var publishedDate = Date()
@@ -21,6 +22,7 @@ extension AutotuneConfig {
             units = settingsManager.settings.units
             useAutotune = settingsManager.settings.useAutotune
             publishedDate = lastAutotuneDate
+            subscribeSetting(\.onlyAutotuneBasals, on: $onlyAutotuneBasals) { onlyAutotuneBasals = $0 }
 
             $useAutotune
                 .removeDuplicates()

+ 20 - 15
FreeAPS/Sources/Modules/AutotuneConfig/View/AutotuneConfigRootView.swift

@@ -31,6 +31,9 @@ extension AutotuneConfig {
             Form {
                 Section {
                     Toggle("Use Autotune", isOn: $state.useAutotune)
+                    if state.useAutotune {
+                        Toggle("Only Autotune Basal Insulin", isOn: $state.onlyAutotuneBasals)
+                    }
                 }
 
                 Section {
@@ -44,22 +47,24 @@ extension AutotuneConfig {
                 }
 
                 if let autotune = state.autotune {
-                    Section {
-                        HStack {
-                            Text("Carb ratio")
-                            Spacer()
-                            Text(isfFormatter.string(from: autotune.carbRatio as NSNumber) ?? "0")
-                            Text("g/U").foregroundColor(.secondary)
-                        }
-                        HStack {
-                            Text("Sensitivity")
-                            Spacer()
-                            if state.units == .mmolL {
-                                Text(isfFormatter.string(from: autotune.sensitivity.asMmolL as NSNumber) ?? "0")
-                            } else {
-                                Text(isfFormatter.string(from: autotune.sensitivity as NSNumber) ?? "0")
+                    if !state.onlyAutotuneBasals {
+                        Section {
+                            HStack {
+                                Text("Carb ratio")
+                                Spacer()
+                                Text(isfFormatter.string(from: autotune.carbRatio as NSNumber) ?? "0")
+                                Text("g/U").foregroundColor(.secondary)
+                            }
+                            HStack {
+                                Text("Sensitivity")
+                                Spacer()
+                                if state.units == .mmolL {
+                                    Text(isfFormatter.string(from: autotune.sensitivity.asMmolL as NSNumber) ?? "0")
+                                } else {
+                                    Text(isfFormatter.string(from: autotune.sensitivity as NSNumber) ?? "0")
+                                }
+                                Text(state.units.rawValue + "/U").foregroundColor(.secondary)
                             }
-                            Text(state.units.rawValue + "/U").foregroundColor(.secondary)
                         }
                     }
 

+ 1 - 1
FreeAPS/Sources/Modules/CREditor/View/CREditorRootView.swift

@@ -22,7 +22,7 @@ extension CREditor {
 
         var body: some View {
             Form {
-                if let autotune = state.autotune {
+                if let autotune = state.autotune, !state.settingsManager.settings.onlyAutotuneBasals {
                     Section(header: Text("Autotune")) {
                         HStack {
                             Text("Calculated Ratio")

+ 1 - 1
FreeAPS/Sources/Modules/ISFEditor/View/ISFEditorRootView.swift

@@ -23,7 +23,7 @@ extension ISFEditor {
 
         var body: some View {
             Form {
-                if let autotune = state.autotune {
+                if let autotune = state.autotune, !state.settingsManager.settings.onlyAutotuneBasals {
                     Section(header: Text("Autotune")) {
                         HStack {
                             Text("Calculated Sensitivity")