Просмотр исходного кода

Display dynamic sensitivity
Localize

(cherry picked from commit 780346819ffa4153680bb4b66150f97e6cb67bd2)

Jon Mårtensson 2 лет назад
Родитель
Сommit
e20634f75c

+ 6 - 0
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -1043,6 +1043,12 @@ Enact a temp Basal or a temp target */
 /* Debug option view Autosense */
 "Autosense" = "Autosense";
 
+/* Insulin sensitivity config header */
+"Dynamic Sensitivity" = "Dynamic Sensitivity";
+
+/* Autotune config */
+"Only Autotune Basal Insulin" = "Only Autotune Basal Insulin";
+
 /* Debug option view Pump History */
 "Pump History" = "Pump History";
 

+ 1 - 0
FreeAPS/Sources/Modules/ISFEditor/ISFEditorDataFlow.swift

@@ -28,4 +28,5 @@ protocol ISFEditorProvider: Provider {
     func saveProfile(_ profile: InsulinSensitivities)
     var autosense: Autosens { get }
     var autotune: Autotune? { get }
+    var suggestion: Suggestion? { get }
 }

+ 4 - 0
FreeAPS/Sources/Modules/ISFEditor/ISFEditorProvider.swift

@@ -20,6 +20,10 @@ extension ISFEditor {
                 ?? Autosens(ratio: 1, newisf: nil, timestamp: nil)
         }
 
+        var suggestion: Suggestion? {
+            storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
+        }
+
         var autotune: Autotune? {
             storage.retrieve(OpenAPS.Settings.autotune, as: Autotune.self)
         }

+ 20 - 3
FreeAPS/Sources/Modules/ISFEditor/View/ISFEditorRootView.swift

@@ -38,16 +38,33 @@ extension ISFEditor {
                     }
                 }
                 if let newISF = state.autosensISF {
-                    Section(header: Text("Autosens")) {
+                    Section(
+                        header: !state.settingsManager.preferences
+                            .useNewFormula ? Text("Autosens") : Text("Dynamic Sensitivity")
+                    ) {
+                        let dynamicRatio = state.provider.suggestion?.sensitivityRatio ?? 0
+                        let dynamicISF = state.provider.suggestion?.isf ?? 0
                         HStack {
                             Text("Sensitivity Ratio")
                             Spacer()
-                            Text(rateFormatter.string(from: state.autosensRatio as NSNumber) ?? "1")
+                            Text(
+                                rateFormatter
+                                    .string(from: (
+                                        !state.settingsManager.preferences.useNewFormula ? state
+                                            .autosensRatio : dynamicRatio
+                                    ) as NSNumber) ?? "1"
+                            )
                         }
                         HStack {
                             Text("Calculated Sensitivity")
                             Spacer()
-                            Text(rateFormatter.string(from: newISF as NSNumber) ?? "0")
+                            Text(
+                                rateFormatter
+                                    .string(from: (
+                                        !state.settingsManager.preferences
+                                            .useNewFormula ? newISF : dynamicISF
+                                    ) as NSNumber) ?? "0"
+                            )
                             Text(state.units.rawValue + "/U").foregroundColor(.secondary)
                         }
                     }