Browse Source

Added uci > maxCI check to testing JS and Swift

Sam King 9 months ago
parent
commit
110636d952

+ 8 - 3
Trio/Sources/APS/OpenAPSSwift/Forecasts/ForecastGenerator.swift

@@ -35,11 +35,19 @@ enum ForecastGenerator {
         let minDelta = min(glucoseStatus.delta, glucoseStatus.shortAvgDelta)
         // this carbImpact is `ci` in JS
         var carbImpact = (minDelta - currentGlucoseImpact).jsRounded(scale: 1)
+        // this is `uci` in JS, it isn't limited by maxCI
+        var uamCarbImpact = (minDelta - currentGlucoseImpact).jsRounded(scale: 1)
         let maxCarbAbsorptionRate = Decimal(30)
         let maxCI = (maxCarbAbsorptionRate * carbSensitivityFactor * Decimal(5) / Decimal(60)).jsRounded(scale: 1)
         if carbImpact > maxCI {
             carbImpact = maxCI
         }
+        // BUG: JS was missing this check, so we added it to our testing JS
+        // carbImpact and uamCarbImpact are the same now, but we'll leave them
+        // as two separate variables to make it easier to debug
+        if uamCarbImpact > maxCI {
+            uamCarbImpact = maxCI
+        }
 
         let carbImpactParams = CarbImpactParams.calculate(
             carbSensitivityFactor: carbSensitivityFactor,
@@ -50,9 +58,6 @@ enum ForecastGenerator {
             currentTime: currentTime
         )
 
-        // this is `uci` in JS, it isn't limited by maxCI
-        let uamCarbImpact = (minDelta - currentGlucoseImpact).jsRounded(scale: 1)
-
         // JS oref initializes all xxxPredBGs array with current glucose, we do the same, then generate
         let iobForecast = forecastIOB(
             startingGlucose: glucose,

File diff suppressed because it is too large
+ 1 - 1
TrioTests/OpenAPSSwiftTests/javascript/bundle/determine-basal.js