Ivan Valkou %!s(int64=5) %!d(string=hai) anos
pai
achega
f42067d34b

+ 0 - 8
FreeAPS/OpenAPS/JavaScriptWorker.swift

@@ -51,12 +51,4 @@ final class JavaScriptWorker {
         let joined = arguments.map(\.string).joined(separator: ",")
         return json(for: "\(function)(\(joined))")
     }
-
-    func setEnviromentValue(_ value: JSON, forKey key: String) {
-        evaluate(string: "freeaps.\(key) = \(value.string);")
-    }
-
-    var log: String {
-        context.objectForKeyedSubscript("freeapsLog")!.toString()!
-    }
 }

+ 36 - 4
FreeAPS/OpenAPS/OpenAPS.swift

@@ -17,16 +17,24 @@ final class OpenAPS {
         let carbs = loadJSON(name: "carbhistory")
         let glucose = loadJSON(name: "glucose")
         let currentTemp = loadJSON(name: "temp_basal")
-        let autosens = Autosens(ratio: 1)
         let reservoir = 100
         let tsMilliseconds: Double = 1527924300000
 
+        let autosensResult = autosense(
+            pumpHistory: pumphistory,
+            profile: profile,
+            carbs: carbs,
+            glucose: glucose,
+            basalprofile: basalProfile,
+            temptargets: "null"
+        )
+        print("AUTOSENS: \(autosensResult)")
 
         let iobResult = iob(
             pumphistory: pumphistory,
             profile: profile,
             clock: clock,
-            autosens: autosens,
+            autosens: autosensResult,
             pumphistory24: "null"
         )
         print("IOB: \(iobResult)")
@@ -50,13 +58,12 @@ final class OpenAPS {
             currentTemp: currentTemp,
             iob: iobResult,
             profile: profile,
-            aurosens: autosens,
+            aurosens: autosensResult,
             meal: mealResult,
             microBolusAllowed: true,
             reservoir: reservoir,
             tsMilliseconds: tsMilliseconds
         )
-
         print("SUGGESTED: \(suggested)")
     }
 
@@ -128,6 +135,31 @@ final class OpenAPS {
         )
     }
 
+    func autosense(
+        pumpHistory: JSON,
+        profile: JSON,
+        carbs: JSON,
+        glucose: JSON,
+        basalprofile: JSON,
+        temptargets: JSON
+    ) -> JSON {
+        let jsWorker = JavaScriptWorker()
+        jsWorker.evaluate(script: Script(name:"autosens-bundle"))
+        jsWorker.evaluate(script: Script(name:"prepare-autosens"))
+
+        return jsWorker.call(
+            function: "generate",
+            with: [
+                pumpHistory,
+                profile,
+                carbs,
+                glucose,
+                basalprofile,
+                temptargets
+            ]
+        )
+    }
+
     private func loadJSON(name: String) -> String {
         try! String(contentsOf: Bundle.main.url(forResource: "json/\(name)", withExtension: "json")!)
     }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2 - 0
javascript/autosens-bundle.js


+ 22 - 0
javascript/prepare-autosens.js

@@ -0,0 +1,22 @@
+var printLog = function(...args) {};
+var process = { stderr: { write: printLog } };
+
+function generate(pumphistory_data, profile_data, carb_data, glucose_data, basalprofile, temptarget_data) {
+    var iob_inputs = {
+        history: pumphistory_data,
+        profile: profile_data
+    };
+
+    var detection_inputs = {
+        iob_inputs: iob_inputs,
+        carbs: carb_data,
+        glucose_data: glucose_data,
+        basalprofile: basalprofile,
+        temptargets: temptarget_data
+    };
+    detection_inputs.deviations = 96;
+    var ratio8h = freeaps(detection_inputs);
+    detection_inputs.deviations = 288;
+    var ratio24h = freeaps(detection_inputs);
+    return ratio8h.ratio < ratio24h.ratio ? ratio8h : ratio24h
+}

+ 1 - 8
javascript/prepare-determine-basal.js

@@ -1,10 +1,3 @@
-var freeapsLog = ""
-var printLog = function(...args) {
-    args.forEach(element => freeapsLog.log += JSON.stringify(element) + " ");
-    freeapsLog += "\n";
-}
-
+var printLog = function(...args) {};
 tempBasalFunctions = freeaps;
-
 var process = { stderr: { write: printLog } };
-var console = { log: freeaps.print, error: printLog };

+ 1 - 0
json/profile.json

@@ -70,6 +70,7 @@
   "dia": 6,
   "bolus_increment": 0.1,
   "current_basal": 1.0,
+  "rewind_resets_autosens": true,
   "basalprofile": [
     {
       "minutes": 0,