فهرست منبع

repack js and remove glucoseGetLast swift function

Den 5 سال پیش
والد
کامیت
71ee08b89f

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
FreeAPS/Resources/javascript/bundle/basal-set-temp.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
FreeAPS/Resources/javascript/bundle/determine-basal.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
FreeAPS/Resources/javascript/bundle/glucose-get-last.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
FreeAPS/Resources/javascript/bundle/iob.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
FreeAPS/Resources/javascript/bundle/meal.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1 - 1
FreeAPS/Resources/javascript/bundle/profile.js


+ 22 - 3
FreeAPS/Resources/javascript/prepare/determine-basal.js

@@ -1,3 +1,22 @@
-var printLog = function(...args) {};
-tempBasalFunctions = freeaps;
-var process = { stderr: { write: printLog } };
+//для 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_data, currenttemp, glucose_data, profile, autosens_input = false, meal_input = false, microbolus = false, reservoir_input = false){
+    var glucose_status = freeaps_glucoseGetLast(glucose_data);
+    var autosens_data = null;
+
+    if (autosens_input) {
+        autosens_data = autosens_input;
+    }
+
+    var reservoir_data = null;
+    if (reservoir_input) {
+        reservoir_data = reservoir_input;
+    }
+
+    var meal_data = { };
+    if (meal_input) {
+        meal_data = meal_input;
+    }
+
+    return freeaps_determineBasal(glucose_status, currenttemp, iob_data, profile, autosens_data, meal_data, freeaps_basalSetTemp, microbolus, reservoir_data, null);
+}

+ 10 - 10
FreeAPS/Resources/javascript/prepare/iob.js

@@ -1,14 +1,14 @@
-function generate(pumphistory_data, profile_data, clock_data, autosens_data, pumphistory_24_data) {
+//для monitor/iob.json параметры: monitor/pumphistory-24h-zoned.json settings/profile.json monitor/clock-zoned.json settings/autosens.json
+function generate(pumphistory_data, profile_data, clock_data, autosens_data = null){
     var inputs = {
-        history: pumphistory_data,
-        history24: pumphistory_24_data,
-        profile: profile_data,
-        clock: clock_data
+        history: pumphistory_data
+        , history24: null
+        , profile: profile_data
+        , clock: clock_data
     };
-    if (autosens_data)  {
-        inputs.autosens = autosens_data;
-    }
 
-    return freeaps(inputs);
+      if ( autosens_data ) {
+        inputs.autosens = autosens_data;
+      }
+      return freeaps_iob(inputs);
 }
-

+ 22 - 8
FreeAPS/Resources/javascript/prepare/meal.js

@@ -1,14 +1,28 @@
-function generate(pumphistory_data, profile_data, basalprofile_data, clock_data, carb_data, glucose_data) {
+//для monitor/meal.json параметры: monitor/pumphistory-24h-zoned.json settings/profile.json monitor/clock-zoned.json monitor/glucose.json settings/basal_profile.json monitor/carbhistory.json
+function generate(pumphistory_data, profile_data, clock_data, glucose_data, basalprofile_data, carbhistory = false){
+    if ( typeof(profile_data.carb_ratio) === 'undefined' || profile_data.carb_ratio < 3 ) {
+        return {"error":"Error: carb_ratio " + profile_data.carb_ratio + " out of bounds"};
+    }
+
+    var carb_data = { };
+    if (carbhistory) {
+        carb_data = carbhistory;
+    }
+
+    if (typeof basalprofile_data[0] === 'undefined') {
+        return {"error":"Error: bad basalprofile_data: " + JSON.stringify(basalprofile_data)};
+    }
+
     var inputs = {
-        history: pumphistory_data,
-        profile: profile_data,
-        basalprofile: basalprofile_data,
-        clock: clock_data,
-        carbs: carb_data,
-        glucose: glucose_data
+      history: pumphistory_data
+    , profile: profile_data
+    , basalprofile: basalprofile_data
+    , clock: clock_data
+    , carbs: carb_data
+    , glucose: glucose_data
     };
 
-    var recentCarbs = freeaps(inputs);
+    var recentCarbs = freeaps_meal(inputs);
 
     if (glucose_data.length < 36) {
         console.error("Not enough glucose data to calculate carb absorption; found:", glucose_data.length);

+ 81 - 28
FreeAPS/Resources/javascript/prepare/profile.js

@@ -1,34 +1,87 @@
-function exportDefaults () {
-    return freeaps.displayedDefaults();
-}
+//для 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){
+    if (bgtargets_data.units !== 'mg/dL') {
+        if (bgtargets_data.units === 'mmol/L') {
+            for (var i = 0, len = bgtargets_data.targets.length; i < len; i++) {
+                bgtargets_data.targets[i].high = bgtargets_data.targets[i].high * 18;
+                bgtargets_data.targets[i].low = bgtargets_data.targets[i].low * 18;
+            }
+            bgtargets_data.units = 'mg/dL';
+        } else {
+            return { "error" : 'BG Target data is expected to be expressed in mg/dL or mmol/L. Found '+bgtargets_data.units};
+        }
+    }
 
-function generate(preferences, pumpsettings_data, bgtargets_data, basalprofile_data, isf_data, carbratio_data, temptargets_data, model_data, autotune_data) {
-    var inputs = { };
-        //add all preferences to the inputs
-        for (var pref in preferences) {
-          if (preferences.hasOwnProperty(pref)) {
-            inputs[pref] = preferences[pref];
-          }
+    if (isf_data.units !== 'mg/dL') {
+        if (isf_data.units === 'mmol/L') {
+            for (var i = 0, len = isf_data.sensitivities.length; i < len; i++) {
+                isf_data.sensitivities[i].sensitivity = isf_data.sensitivities[i].sensitivity * 18;
+            }
+            isf_data.units = 'mg/dL';
+        } else {
+            return { "error" : 'ISF is expected to be expressed in mg/dL or mmol/L. Found '+isf_data.units};
         }
+    }
+
+    var autotune_data = { };
+    if (autotune_input) {
+        autotune_data = autotune_input;
+    }
+
+    var temptargets_data = { };
+    if (temptargets_input) {
+        temptargets_data = temptargets_input;
+    }
+
+    var model_data = { };
+    if(model_input){
+        model_data = model_input.replace(/"/gi, '');
+    }
 
-        //make sure max_iob is set or default to 0
-        inputs.max_iob = inputs.max_iob || 0;
-
-        //set these after to make sure nothing happens if they are also set in preferences
-        inputs.settings = pumpsettings_data;
-        inputs.targets = bgtargets_data;
-        inputs.basals = basalprofile_data;
-        inputs.isf = isf_data;
-        inputs.carbratio = carbratio_data;
-        inputs.temptargets = temptargets_data;
-        inputs.model = model_data;
-        inputs.autotune = autotune_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; }
+    var carbratio_data = { };
+    if (carbratio_input){
+        var errors = [ ];
+        if (!(carbratio_input.schedule && carbratio_input.schedule[0].start && carbratio_input.schedule[0].ratio)) {
+          errors.push("Carb ratio data should have an array called schedule with a start and ratio fields.");
         }
+        if (carbratio_input.units !== 'grams' && carbratio_input.units !== 'exchanges')  {
+          errors.push("Carb ratio should have units field set to 'grams' or 'exchanges'.");
+        }
+        if (errors.length) {
+          return { "error" : errors.join(' ')};
+        }
+        carbratio_data = carbratio_input;
+    }
+
+    var preferences = { };
+    if(preferences_input){
+        preferences = preferences_input;
+    }
+
+    var inputs = { };
+    //add all preferences to the inputs
+    for (var pref in preferences) {
+      if (preferences.hasOwnProperty(pref)) {
+        inputs[pref] = preferences[pref];
+      }
+    }
+
+    inputs.max_iob = inputs.max_iob || 0;
+    //set these after to make sure nothing happens if they are also set in preferences
+    inputs.settings = pumpsettings_data;
+    inputs.targets = bgtargets_data;
+    inputs.basals = basalprofile_data;
+    inputs.isf = isf_data;
+    inputs.carbratio = carbratio_data;
+    inputs.temptargets = temptargets_data;
+    inputs.model = model_data;
+    inputs.autotune = autotune_data;
 
-        return freeaps(inputs);
+    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; }
+    }
+    return freeaps_profile(inputs);
 }

+ 24 - 48
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -83,28 +83,23 @@ final class OpenAPS {
                 pumphistory: pumpHistory,
                 profile: profile,
                 clock: clock,
-                autosens: autosens.isEmpty ? .null : autosens,
-                pumphistory24: RawJSON.null
+                autosens: autosens.isEmpty ? .null : autosens
             )
 
             try? self.storage.save(iob, as: Monitor.iob)
 
             // determine-basal
-            let glucoseStatus = self.glucoseGetLast(glucose: glucose)
             let reservoir = self.loadFileFromStorage(name: Monitor.reservoir)
 
-            let ms = (Date(clock.rawJSON) ?? Date()).timeIntervalSince1970 * 1000
-
             let suggested = self.determineBasal(
-                glucoseStatus: glucoseStatus,
+                glucose: glucose,
                 currentTemp: tempBasal,
                 iob: iob,
                 profile: profile,
-                aurosens: autosens.isEmpty ? .null : autosens,
+                autosens: autosens.isEmpty ? .null : autosens,
                 meal: meal,
                 microBolusAllowed: true,
-                reservoir: reservoir,
-                tsMilliseconds: ms
+                reservoir: reservoir
             )
             print("SUGGESTED: \(suggested)")
 
@@ -124,7 +119,6 @@ final class OpenAPS {
             let glucose = self.loadJSON(name: "glucose")
             let currentTemp = self.loadJSON(name: "temp_basal")
             let reservoir = 100
-            let tsMilliseconds: Double = 1_527_924_300_000
 
             let preferences = self.exportDefaultPreferences()
 
@@ -145,8 +139,7 @@ final class OpenAPS {
                 pumphistory: pumphistory,
                 profile: profile,
                 clock: clock,
-                autosens: autosensResult,
-                pumphistory24: RawJSON.null
+                autosens: autosensResult
             )
             print("IOB: \(iobResult)")
 
@@ -162,19 +155,15 @@ final class OpenAPS {
             print("MEAL: \(mealResult)")
             try? self.storage.save(mealResult, as: Monitor.meal)
 
-            let glucoseStatus = self.glucoseGetLast(glucose: glucose)
-            print("GLUCOSE STATUS: \(glucoseStatus)")
-
             let suggested = self.determineBasal(
-                glucoseStatus: glucoseStatus,
+                glucose: glucose,
                 currentTemp: currentTemp,
                 iob: iobResult,
                 profile: profile,
                 aurosens: autosensResult,
                 meal: mealResult,
                 microBolusAllowed: true,
-                reservoir: reservoir,
-                tsMilliseconds: tsMilliseconds
+                reservoir: reservoir
             )
             print("SUGGESTED: \(suggested)")
 
@@ -269,7 +258,7 @@ final class OpenAPS {
         }
     }
 
-    private func iob(pumphistory: JSON, profile: JSON, clock: JSON, autosens: JSON, pumphistory24: JSON) -> RawJSON {
+    private func iob(pumphistory: JSON, profile: JSON, clock: JSON, autosens: JSON) -> RawJSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
             worker.evaluate(script: Script(name: Bundle.iob))
@@ -278,8 +267,7 @@ final class OpenAPS {
                 pumphistory,
                 profile,
                 clock,
-                autosens,
-                pumphistory24
+                autosens
             ])
         }
     }
@@ -292,10 +280,10 @@ final class OpenAPS {
             return worker.call(function: Function.generate, with: [
                 pumphistory,
                 profile,
-                basalProfile,
                 clock,
-                carbs,
-                glucose
+                glucose,
+                basalProfile,
+                carbs
             ])
         }
     }
@@ -340,44 +328,33 @@ final class OpenAPS {
         }
     }
 
-    private func glucoseGetLast(glucose: JSON) -> RawJSON {
-        dispatchPrecondition(condition: .onQueue(processQueue))
-        return jsWorker.inCommonContext { worker in
-            worker.evaluate(script: Script(name: Bundle.getLastGlucose))
-            return worker.call(function: Function.freeaps, with: [glucose])
-        }
-    }
-
     private func determineBasal(
-        glucoseStatus: JSON,
+        glucose: JSON,
         currentTemp: JSON,
         iob: JSON,
         profile: JSON,
-        aurosens: JSON,
+        autosens: JSON,
         meal: JSON,
         microBolusAllowed: Bool,
-        reservoir: JSON,
-        tsMilliseconds: Double
+        reservoir: JSON
     ) -> RawJSON {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
             worker.evaluate(script: Script(name: Bundle.basalSetTemp))
-            worker.evaluate(script: Script(name: Prepare.determineBasal))
+            worker.evaluate(script: Script(name: Bundle.getLastGlucose))
             worker.evaluate(script: Script(name: Bundle.determineBasal))
-
+            worker.evaluate(script: Script(name: Prepare.determineBasal))
             return worker.call(
-                function: Function.freeaps,
+                function: Function.generate,
                 with: [
-                    glucoseStatus,
-                    currentTemp,
                     iob,
+                    currentTemp,
+                    glucose,
                     profile,
-                    aurosens,
+                    autosens,
                     meal,
-                    Function.tempBasalFunctions,
                     microBolusAllowed,
-                    reservoir,
-                    tsMilliseconds
+                    reservoir
                 ]
             )
         }
@@ -434,15 +411,14 @@ final class OpenAPS {
         return jsWorker.inCommonContext { worker in
             worker.evaluate(script: Script(name: Bundle.profile))
             worker.evaluate(script: Script(name: Prepare.profile))
-
             return worker.call(
                 function: Function.generate,
                 with: [
-                    preferences,
                     pumpSettings,
                     bgTargets,
-                    basalProfile,
                     isf,
+                    basalProfile,
+                    preferences,
                     carbRatio,
                     tempTargets,
                     model,