瀏覽代碼

Merge pull request #574 from nightscout/oref-swift-add-precision-to-js-rounding

Add missing glucose checks to Autosens
Deniz Cengiz 9 月之前
父節點
當前提交
ae0baefea1

+ 11 - 2
Trio/Sources/APS/OpenAPSSwift/Autosens/AutosensGenerator.swift

@@ -61,8 +61,17 @@ struct AutosensGenerator {
         // run through the simulation loop
         var state = SimulationState(meals: meals)
         var deviations: [Decimal] = []
-        // in JS the simulation loop starts at index 3
-        for (prevGlucose, currGlucose) in zip(bucketedData.dropFirst(2), bucketedData.dropFirst(3)) {
+        // in JS the simulation loop starts at index 3 but checks for i-1 (prev)
+        // and i-3 (old) values for computations
+        var oldGlucoseIndex = 0
+        for (oldGlucose, (prevGlucose, currGlucose)) in zip(
+            bucketedData,
+            zip(bucketedData.dropFirst(2), bucketedData.dropFirst(3))
+        ) {
+            if oldGlucose.glucose < 40 || prevGlucose.glucose < 40 || currGlucose.glucose < 40 {
+                continue
+            }
+
             guard let isfProfile = profile.isfProfile?.toInsulinSensitivities() else {
                 throw AutosensError.missingIsfProfile
             }

文件差異過大導致無法顯示
+ 1 - 1
TrioTests/OpenAPSSwiftTests/javascript/bundle/autosens.js


文件差異過大導致無法顯示
+ 1 - 1
TrioTests/OpenAPSSwiftTests/javascript/bundle/determine-basal.js