Просмотр исходного кода

Add missing glucose checks to Autosens

There was a missing check in autosens for glucose < 40, this PR adds
this check.

It also includes new testing JS for determineBasal and autosens to
increase the precision for rounding.
Sam King 9 месяцев назад
Родитель
Сommit
48b1196edd

+ 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