Ivan Valkou 5 лет назад
Родитель
Сommit
6ad874fa41

+ 2 - 2
FreeAPS.xcodeproj/project.pbxproj

@@ -970,7 +970,7 @@
 				CODE_SIGN_ENTITLEMENTS = FreeAPS/Resources/FreeAPS.entitlements;
 				CODE_SIGN_STYLE = Automatic;
 				DEVELOPMENT_ASSET_PATHS = "\"FreeAPS/Preview Content\"";
-				DEVELOPMENT_TEAM = 777258T3K8;
+				DEVELOPMENT_TEAM = BA7ZHP4963;
 				ENABLE_PREVIEWS = YES;
 				INFOPLIST_FILE = FreeAPS/Resources/Info.plist;
 				IPHONEOS_DEPLOYMENT_TARGET = 14.0;
@@ -993,7 +993,7 @@
 				CODE_SIGN_ENTITLEMENTS = FreeAPS/Resources/FreeAPS.entitlements;
 				CODE_SIGN_STYLE = Automatic;
 				DEVELOPMENT_ASSET_PATHS = "\"FreeAPS/Preview Content\"";
-				DEVELOPMENT_TEAM = 777258T3K8;
+				DEVELOPMENT_TEAM = BA7ZHP4963;
 				ENABLE_PREVIEWS = YES;
 				INFOPLIST_FILE = FreeAPS/Resources/Info.plist;
 				IPHONEOS_DEPLOYMENT_TARGET = 14.0;

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
FreeAPS/Resources/javascript/bundle/autotune-core.js


Разница между файлами не показана из-за своего большого размера
+ 1 - 1
FreeAPS/Resources/javascript/bundle/autotune-prep.js


+ 34 - 0
FreeAPS/Resources/javascript/prepare/profile.js

@@ -0,0 +1,34 @@
+function exportDefaults () {
+    return freeaps.displayedDefaults();
+}
+
+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];
+          }
+        }
+
+        //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; }
+        }
+
+        return freeaps(inputs);
+}

+ 46 - 0
FreeAPS/Sources/APS/OpenAPS/OpenAPS.swift

@@ -19,6 +19,10 @@ final class OpenAPS {
             let reservoir = 100
             let tsMilliseconds: Double = 1_527_924_300_000
 
+            let preferences = self.exportDefaultPreferences()
+
+            print("DEFAULT PREFERENCES: \(preferences)")
+
             let autosensResult = self.autosense(
                 pumpHistory: pumphistory,
                 profile: profile,
@@ -230,6 +234,48 @@ final class OpenAPS {
         }
     }
 
+    private func exportDefaultPreferences() -> JSON {
+        dispatchPrecondition(condition: .onQueue(processQueue))
+        return jsWorker.inCommonContext { worker in
+            worker.evaluate(script: Script(name: "bundle/profile"))
+            worker.evaluate(script: Script(name: "prepare/profile"))
+            return worker.call(function: "exportDefaults", with: [])
+        }
+    }
+
+    private func makeProfile(
+        preferences: JSON,
+        pumpSettings: JSON,
+        bgTargets: JSON,
+        basalProfile: JSON,
+        isf: JSON,
+        carbRatio: JSON,
+        tempTargets: JSON,
+        model: JSON,
+        autotune: JSON
+    ) -> JSON {
+        dispatchPrecondition(condition: .onQueue(processQueue))
+        return jsWorker.inCommonContext { worker in
+            worker.evaluate(script: Script(name: "bundle/profile"))
+            worker.evaluate(script: Script(name: "prepare/profile"))
+
+            return worker.call(
+                function: "generate",
+                with: [
+                    preferences,
+                    pumpSettings,
+                    bgTargets,
+                    basalProfile,
+                    isf,
+                    carbRatio,
+                    tempTargets,
+                    model,
+                    autotune
+                ]
+            )
+        }
+    }
+
     private func loadJSON(name: String) -> String {
         try! String(contentsOf: Bundle.main.url(forResource: "json/\(name)", withExtension: "json")!)
     }