Jelajahi Sumber

make autotune-prep javascripts as other methods (with prepare)

Den 5 tahun lalu
induk
melakukan
f2f29b2870

File diff ditekan karena terlalu besar
+ 1 - 1
FreeAPS/Resources/javascript/bundle/autotune-prep.js


+ 47 - 0
FreeAPS/Resources/javascript/prepare/autotune-prep.js

@@ -0,0 +1,47 @@
+function generate(pumphistory_data,profile_data,glucose_data,pumpprofile_data,carb_data={ },categorize_uam_as_basal=false,tune_insulin_curve=false){
+    if ( typeof(profile_data.carb_ratio) === 'undefined' || profile_data.carb_ratio < 2 ) {
+        if ( typeof(pumpprofile_data.carb_ratio) === 'undefined' || pumpprofile_data.carb_ratio < 2 ) {
+            console.log('{ "carbs": 0, "mealCOB": 0, "reason": "carb_ratios ' + profile_data.carb_ratio + ' and ' + pumpprofile_data.carb_ratio + ' out of bounds" }');
+            return console.error("Error: carb_ratios " + profile_data.carb_ratio + ' and ' + pumpprofile_data.carb_ratio + " out of bounds");
+        } else {
+            profile_data.carb_ratio = pumpprofile_data.carb_ratio;
+        }
+    }
+
+    // get insulin curve from pump profile that is maintained
+    profile_data.curve = pumpprofile_data.curve;
+
+    // Pump profile has an up to date copy of useCustomPeakTime from preferences
+    // If the preferences file has useCustomPeakTime use the previous autotune dia and PeakTime.
+    // Otherwise, use data from pump profile.
+    if (!pumpprofile_data.useCustomPeakTime) {
+      profile_data.dia = pumpprofile_data.dia;
+      profile_data.insulinPeakTime = pumpprofile_data.insulinPeakTime;
+    }
+
+    // Always keep the curve value up to date with what's in the user preferences
+    profile_data.curve = pumpprofile_data.curve;
+
+    // Have to sort history - NS sort doesn't account for different zulu and local timestamps
+    pumphistory_data.sort( function( firstValue, secondValue ){
+        try{
+            var a = new Date(firstValue.timestamp);
+            var b = new Date(secondValue.timestamp);
+            return b.getTime() - a.getTime();
+        }catch(e){
+            return 0;
+        }
+    } );
+
+    inputs = {
+      history: pumphistory_data
+    , profile: profile_data
+    , pumpprofile: pumpprofile_data
+    , carbs: carb_data
+    , glucose: glucose_data
+    , categorize_uam_as_basal: categorize_uam_as_basal
+    , tune_insulin_curve: tune_insulin_curve
+    };
+
+    return freeaps(inputs);
+}

+ 2 - 1
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -130,7 +130,8 @@ final class OpenAPS {
         dispatchPrecondition(condition: .onQueue(processQueue))
         return jsWorker.inCommonContext { worker in
             worker.evaluate(script: Script(name: "bundle/autotune-prep"))
-            return worker.call(function: "freeaps", with: [
+            worker.evaluate(script: Script(name: "prepare/autotune-prep"))
+            return worker.call(function: "generate", with: [
                 pumphistory,
                 profile,
                 glucose,