فهرست منبع

Add preferences to middleware

Jon Mårtensson 4 سال پیش
والد
کامیت
6275982775

+ 3 - 3
FreeAPS/Resources/javascript/middleware/determine_basal.js

@@ -1,12 +1,12 @@
-function middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoir, clock, pumphistory) {
+function middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoir, clock, pumphistory, preferences) {
      
     // This middleware only works if you have added pumphistory to middleware in FreeAPS X code (my pumphistory branch).
     const BG = glucose[0].glucose;
     // Change to false to turn off Chris Wilson's formula
-    var chrisFormula = true;
+    var chrisFormula = preferences.enableChris;
     const minLimitChris = profile.autosens_min;
     const maxLimitChris = profile.autosens_max;
-    const adjustmentFactor = 1;
+    const adjustmentFactor = preferences.adjustmentFactor;
     const currentMinTarget = profile.min_bg;
     var exerciseSetting = false;
     var enoughData = false;

+ 2 - 2
FreeAPS/Resources/javascript/prepare/determine-basal.js

@@ -1,10 +1,10 @@
 //для enact/smb-suggested.json параметры: monitor/iob.json monitor/temp_basal.json monitor/glucose.json settings/profile.json settings/autosens.json --meal monitor/meal.json --microbolus --reservoir monitor/reservoir.json
 
-function generate(iob, currenttemp, glucose, profile, autosens = null, meal = null, microbolusAllowed = false, reservoir = null, clock = new Date(), pump_history) {
+function generate(iob, currenttemp, glucose, profile, autosens = null, meal = null, microbolusAllowed = false, reservoir = null, clock = new Date(), pump_history, preferences) {
 
     try {
         console.log("Pumphistory: %o", pump_history);
-        var middlewareReason = middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoir, clock, pump_history);
+        var middlewareReason = middleware(iob, currenttemp, glucose, profile, autosens, meal, reservoir, clock, pump_history, preferences);
         console.log("Middleware reason: " + (middlewareReason || "Nothing changed"));
     } catch (error) {
         console.log("Invalid middleware: " + error);

+ 8 - 3
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -55,6 +55,8 @@ final class OpenAPS {
                 // determine-basal
                 let reservoir = self.loadFileFromStorage(name: Monitor.reservoir)
 
+                let preferences = self.loadFileFromStorage(name: Settings.preferences)
+
                 let suggested = self.determineBasal(
                     glucose: glucose,
                     currentTemp: tempBasal,
@@ -64,7 +66,8 @@ final class OpenAPS {
                     meal: meal,
                     microBolusAllowed: true,
                     reservoir: reservoir,
-                    pumpHistory: pumpHistory
+                    pumpHistory: pumpHistory,
+                    preferences: preferences
                 )
                 debug(.openAPS, "SUGGESTED: \(suggested)")
 
@@ -292,7 +295,8 @@ final class OpenAPS {
         meal: JSON,
         microBolusAllowed: Bool,
         reservoir: JSON,
-        pumpHistory: JSON
+        pumpHistory: JSON,
+        preferences: JSON
     ) -> RawJSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
@@ -318,7 +322,8 @@ final class OpenAPS {
                     microBolusAllowed,
                     reservoir,
                     false, // clock
-                    pumpHistory
+                    pumpHistory,
+                    preferences
                 ]
             )
         }

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 6 - 0
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 6 - 0
FreeAPS/Sources/Localizations/Main/sv.lproj/Localizable.strings


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

@@ -62,6 +62,8 @@ struct Preferences: JSON {
     var bgBrakeISFweight: Decimal = 0
     var enableBGacceleration: Bool = false
     var maxDeltaBGthreshold: Decimal = 0.2
+    var adjustmentFactor: Decimal = 1.0
+    var enableChris: Bool = true
 }
 
 extension Preferences {
@@ -126,6 +128,8 @@ extension Preferences {
         case bgBrakeISFweight = "bgBrake_ISF_weight"
         case enableBGacceleration = "enable_BG_acceleration"
         case maxDeltaBGthreshold = "maxDelta_bg_threshold"
+        case adjustmentFactor
+        case enableChris
     }
 }
 

+ 25 - 0
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorStateModel.swift

@@ -91,6 +91,27 @@ extension PreferencesEditor {
 
             // MARK: - SMB fields
 
+            let dynamicISF = [
+                Field(
+                    displayName: "Adjustment factor",
+                    type: .decimal(keypath: \.adjustmentFactor),
+                    infoText: NSLocalizedString(
+                        "Adjust Chris' constant",
+                        comment: "Adjust Chris' constant"
+                    ),
+                    settable: self
+                ),
+                Field(
+                    displayName: "Enable Chris' dynamic ISF",
+                    type: .boolean(keypath: \.enableChris),
+                    infoText: NSLocalizedString(
+                        "Enable Chris' dynamif ISF",
+                        comment: "Enable Chris' dynamif ISF"
+                    ),
+                    settable: self
+                )
+            ]
+
             let smbFields = [
                 Field(
                     displayName: "Enable SMB Always",
@@ -583,6 +604,10 @@ extension PreferencesEditor {
                     displayName: NSLocalizedString("OpenAPS main settings", comment: "OpenAPS main settings"), fields: mainFields
                 ),
                 FieldSection(
+                    displayName: NSLocalizedString("Chris' dynamic ISF settings", comment: "Chris' dynamic ISF settings"),
+                    fields: dynamicISF
+                ),
+                FieldSection(
                     displayName: NSLocalizedString("OpenAPS SMB settings", comment: "OpenAPS SMB settings"), fields: smbFields
                 ),
                 FieldSection(