Procházet zdrojové kódy

Reorder auto ISF settings. Fix variable settings of weighted average.

Jon Mårtensson před 4 roky
rodič
revize
8537ba65e8

+ 5 - 1
FreeAPS/Sources/APS/APSManager.swift

@@ -589,6 +589,8 @@ final class BaseAPSManager: APSManager, Injectable {
 
 
             storage.save(enacted, as: OpenAPS.Enact.enacted)
             storage.save(enacted, as: OpenAPS.Enact.enacted)
 
 
+            let preferences = settingsManager.preferences
+
             let currentTDD = enacted.tdd ?? 0
             let currentTDD = enacted.tdd ?? 0
 
 
             // Add to tdd.json
             // Add to tdd.json
@@ -616,7 +618,9 @@ final class BaseAPSManager: APSManager, Injectable {
                 }
                 }
 
 
                 let average7 = total / indeces
                 let average7 = total / indeces
-                let weighted_average = 0.65 * currentTDD + 0.35 * average7
+                let weight = preferences.weightPercentage
+
+                let weighted_average = weight * currentTDD + (1 - weight) * average7
                 let averages = TDD_averages(
                 let averages = TDD_averages(
                     average_7days: average7,
                     average_7days: average7,
                     weightedAverage: weighted_average,
                     weightedAverage: weighted_average,

+ 26 - 52
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift

@@ -5,7 +5,7 @@ extension PreferencesEditor {
     final class StateModel: BaseStateModel<Provider>, PreferencesSettable { private(set) var preferences = Preferences()
     final class StateModel: BaseStateModel<Provider>, PreferencesSettable { private(set) var preferences = Preferences()
         @Published var unitsIndex = 1
         @Published var unitsIndex = 1
         @Published var allowAnnouncements = false
         @Published var allowAnnouncements = false
-        @Published var insulinReqFraction: Decimal = 0.7
+        @Published var insulinReqFraction: Decimal = 2.0
         @Published var skipBolusScreenAfterCarbs = false
         @Published var skipBolusScreenAfterCarbs = false
 
 
         @Published var sections: [FieldSection] = []
         @Published var sections: [FieldSection] = []
@@ -129,10 +129,10 @@ extension PreferencesEditor {
                     settable: self
                     settable: self
                 ),
                 ),
                 Field(
                 Field(
-                    displayName: "Weighted Average of TDD. Weight of past 24 hours of TDD",
+                    displayName: "Weighted Average of TDD. Weight of past 24 hours:",
                     type: .decimal(keypath: \.weightPercentage),
                     type: .decimal(keypath: \.weightPercentage),
                     infoText: NSLocalizedString(
                     infoText: NSLocalizedString(
-                        "Default is 0.65 (65 %) * past 24 hours. The rest will be from 7 days TDD average (0.35). To only use past 24 hours, set this to 1.",
+                        "Has to be > 0 and <= 1. Default is 0.65 (65 %) * past 24 hours. The rest will be from 7 days TDD average (0.35). To only use past 24 hours, set this to 1.",
                         comment: "Weight of past 24 hours of TDD"
                         comment: "Weight of past 24 hours of TDD"
                     ),
                     ),
                     settable: self
                     settable: self
@@ -436,16 +436,7 @@ extension PreferencesEditor {
                 )
                 )
             ]
             ]
 
 
-            let xpmToogles = [
-                Field(
-                    displayName: "Enable Floating Carbs",
-                    type: .boolean(keypath: \.floatingcarbs),
-                    infoText: NSLocalizedString(
-                        "Defaults to false. If true, then dose slightly more aggressively by using all entered carbs for calculating COBpredBGs. This avoids backing off too quickly as COB decays. Even with this option, oref0 still switches gradually from using COBpredBGs to UAMpredBGs proportionally to how many carbs are left as COB. Summary: use all entered carbs in the future for predBGs & don't decay them as COB, only once they are actual.",
-                        comment: "Floating Carbs"
-                    ),
-                    settable: self
-                ),
+            let autoISF = [
                 Field(
                 Field(
                     displayName: "Enable AutoISF",
                     displayName: "Enable AutoISF",
                     type: .boolean(keypath: \.autoisf),
                     type: .boolean(keypath: \.autoisf),
@@ -454,6 +445,18 @@ extension PreferencesEditor {
                         comment: "Enable AutoISF"
                         comment: "Enable AutoISF"
                     ),
                     ),
                     settable: self
                     settable: self
+                )
+            ]
+
+            let autoISFsettings = [
+                Field(
+                    displayName: "Enable Floating Carbs",
+                    type: .boolean(keypath: \.floatingcarbs),
+                    infoText: NSLocalizedString(
+                        "Defaults to false. If true, then dose slightly more aggressively by using all entered carbs for calculating COBpredBGs. This avoids backing off too quickly as COB decays. Even with this option, oref0 still switches gradually from using COBpredBGs to UAMpredBGs proportionally to how many carbs are left as COB. Summary: use all entered carbs in the future for predBGs & don't decay them as COB, only once they are actual.",
+                        comment: "Floating Carbs"
+                    ),
+                    settable: self
                 ),
                 ),
                 Field(
                 Field(
                     displayName: "Enable AutoISF with COB",
                     displayName: "Enable AutoISF with COB",
@@ -472,9 +475,7 @@ extension PreferencesEditor {
                         comment: "Enable BG accel in autoISF"
                         comment: "Enable BG accel in autoISF"
                     ),
                     ),
                     settable: self
                     settable: self
-                )
-            ]
-            let xpmSettings = [
+                ),
                 Field(
                 Field(
                     displayName: "AutoISF HourlyMaxChange",
                     displayName: "AutoISF HourlyMaxChange",
                     type: .decimal(keypath: \.autoISFhourlyChange),
                     type: .decimal(keypath: \.autoISFhourlyChange),
@@ -492,9 +493,7 @@ extension PreferencesEditor {
                         comment: "AutoISF Max"
                         comment: "AutoISF Max"
                     ),
                     ),
                     settable: self
                     settable: self
-                )
-            ]
-            let xpmSMB = [
+                ),
                 Field(
                 Field(
                     displayName: "SMB Max RangeExtension",
                     displayName: "SMB Max RangeExtension",
                     type: .decimal(keypath: \.smbMaxRangeExtension),
                     type: .decimal(keypath: \.smbMaxRangeExtension),
@@ -539,9 +538,7 @@ extension PreferencesEditor {
                         comment: "SMB DeliveryRatio Minimum"
                         comment: "SMB DeliveryRatio Minimum"
                     ),
                     ),
                     settable: self
                     settable: self
-                )
-            ]
-            let xpmParabolicFit = [
+                ),
                 Field(
                 Field(
                     displayName: "ISF weight while BG accelerates",
                     displayName: "ISF weight while BG accelerates",
                     type: .decimal(keypath: \.bgAccelISFweight),
                     type: .decimal(keypath: \.bgAccelISFweight),
@@ -568,9 +565,7 @@ extension PreferencesEditor {
                         comment: "AutoISF Min"
                         comment: "AutoISF Min"
                     ),
                     ),
                     settable: self
                     settable: self
-                )
-            ]
-            let xpmAutoISF = [
+                ),
                 Field(
                 Field(
                     displayName: "ISF weight for higher BG's",
                     displayName: "ISF weight for higher BG's",
                     type: .decimal(keypath: \.higherISFrangeWeight),
                     type: .decimal(keypath: \.higherISFrangeWeight),
@@ -597,9 +592,7 @@ extension PreferencesEditor {
                         comment: "ISF higher delta BG weight"
                         comment: "ISF higher delta BG weight"
                     ),
                     ),
                     settable: self
                     settable: self
-                )
-            ]
-            let xpmPostPrandial = [
+                ),
                 Field(
                 Field(
                     displayName: "Enable always postprandial ISF adaption",
                     displayName: "Enable always postprandial ISF adaption",
                     type: .boolean(keypath: \.postMealISFalways),
                     type: .boolean(keypath: \.postMealISFalways),
@@ -649,34 +642,15 @@ extension PreferencesEditor {
                     fields: otherSettings
                     fields: otherSettings
                 ),
                 ),
                 FieldSection(
                 FieldSection(
-                    displayName: NSLocalizedString("XPM toggles", comment: "Switch on/off experimental stuff"),
-                    fields: xpmToogles
-                ),
-                FieldSection(
-                    displayName: NSLocalizedString("autoISF general settings", comment: "Experimental stuff settings"),
-                    fields: xpmSettings
-                ),
-                FieldSection(
-                    displayName: NSLocalizedString("SMB Delivery Ratio settings", comment: "Experimental settings for SMBs"),
-                    fields: xpmSMB
-                ),
-                FieldSection(
-                    displayName: NSLocalizedString("autoISF 2.1 settings", comment: "Experimental settings for autoISF 2.1"),
-                    fields: xpmAutoISF
-                ),
-                FieldSection(
-                    displayName: NSLocalizedString(
-                        "autoISF 2.2 Parabolic Fit settings",
-                        comment: "Experimental settings for autoISF 2.2"
-                    ),
-                    fields: xpmParabolicFit
+                    displayName: NSLocalizedString("Use Auto ISF", comment: "Switch on/off experimental stuff"),
+                    fields: autoISF
                 ),
                 ),
                 FieldSection(
                 FieldSection(
                     displayName: NSLocalizedString(
                     displayName: NSLocalizedString(
-                        "autoISF 2.1 Post-prandial settings",
-                        comment: "Experimental settings for autoISF 2.1"
+                        "Auto ISF Settings. Forget about these if Auto ISF is toggled off",
+                        comment: "AutoISF Settings"
                     ),
                     ),
-                    fields: xpmPostPrandial
+                    fields: autoISFsettings
                 )
                 )
             ]
             ]
         }
         }