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

incorrect targetBg value + fix forecasting calculations

Sam King 6 месяцев назад
Родитель
Сommit
fdd03df380

+ 5 - 2
Trio/Sources/APS/OpenAPSSwift/Forecasts/ForecastGenerator.swift

@@ -119,7 +119,7 @@ enum ForecastGenerator {
             remainingCarbImpactPeak: carbImpactParams.remainingCarbImpactPeak,
             remainingCarbImpactPeak: carbImpactParams.remainingCarbImpactPeak,
             fractionCarbsLeft: mealData.carbs > 0 ? mealData.mealCOB / mealData.carbs : Decimal(0),
             fractionCarbsLeft: mealData.carbs > 0 ? mealData.mealCOB / mealData.carbs : Decimal(0),
             threshold: threshold,
             threshold: threshold,
-            targetGlucose: profile.targetBg ?? 100,
+            targetGlucose: profile.minBg ?? 100,
             currentGlucose: glucose
             currentGlucose: glucose
         )
         )
 
 
@@ -204,7 +204,9 @@ enum ForecastGenerator {
             if carbImpactDuration != 0 || remainingCarbImpactPeak > 0, length > insulinPeak5m, cob < minCobForecastGlucose {
             if carbImpactDuration != 0 || remainingCarbImpactPeak > 0, length > insulinPeak5m, cob < minCobForecastGlucose {
                 minCobForecastGlucose = cob.jsRounded()
                 minCobForecastGlucose = cob.jsRounded()
             }
             }
-            if carbImpactDuration != 0 || remainingCarbImpactPeak > 0, cob > maxCobForecastGlucose {
+            // BUG: I can't tell if the comparison against maxIobForecastGlucose is
+            // intentional or not, but this is what is in JS
+            if carbImpactDuration != 0 || remainingCarbImpactPeak > 0, cob > maxIobForecastGlucose {
                 maxCobForecastGlucose = cob
                 maxCobForecastGlucose = cob
             }
             }
             if uamEnabled, length > 12, uam < minUamForecastGlucose {
             if uamEnabled, length > 12, uam < minUamForecastGlucose {
@@ -313,6 +315,7 @@ enum ForecastGenerator {
             minZTUAMForecastGlucose = ((uamResult.minForecastGlucose + ztResult.minGuardGlucose) / 2)
             minZTUAMForecastGlucose = ((uamResult.minForecastGlucose + ztResult.minGuardGlucose) / 2)
                 .rounded()
                 .rounded()
         }
         }
+        minZTUAMForecastGlucose = minZTUAMForecastGlucose.jsRounded()
 
 
         // 2. avgForecastGlucose blending (like avgPredBG)
         // 2. avgForecastGlucose blending (like avgPredBG)
         let avgerageForecastGlucose: Decimal
         let avgerageForecastGlucose: Decimal

+ 1 - 1
TrioTests/OpenAPSSwiftTests/DetermineBasalJsonTests.swift

@@ -103,7 +103,7 @@ import Testing
         // this test is meant for one-off analysis so it's ok to hard code
         // this test is meant for one-off analysis so it's ok to hard code
         // a file, just make sure to _not_ check in updates to this to
         // a file, just make sure to _not_ check in updates to this to
         // avoid polluting our change logs
         // avoid polluting our change logs
-        let algorithmComparison = try await HttpFiles.downloadFile(at: "/files/6cf9c03d-7650-4d82-99ce-fd324bc2302c.1.json")
+        let algorithmComparison = try await HttpFiles.downloadFile(at: "/files/363f5452-9a76-436a-9d0e-b577d26231ee.0.json")
         let determineBasalInput = algorithmComparison.determineBasalInput!
         let determineBasalInput = algorithmComparison.determineBasalInput!
 
 
         let encoder = JSONCoding.encoder
         let encoder = JSONCoding.encoder