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

+ 3 - 5
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift

@@ -178,7 +178,6 @@ enum DosingEngine {
         reason += "; " // Start of conclusion
 
         let carbsRequiredResult = calculateCarbsRequired(
-            profile: profile,
             mealData: mealData,
             naiveEventualGlucose: naiveEventualGlucose,
             minGuardGlucose: forecast.minGuardGlucose,
@@ -204,9 +203,8 @@ enum DosingEngine {
 
     /// Calculates the carbohydrates required to avoid a potential hypoglycemic event.
     ///
-    /// - Returns: A tuple containing the required carbs and minutes until BG is below threshold.
+    /// - Returns: A tuple containing the required carbs and minutes until glucose is below threshold.
     static func calculateCarbsRequired(
-        profile _: Profile,
         mealData: ComputedCarbs,
         naiveEventualGlucose: Decimal,
         minGuardGlucose: Decimal,
@@ -400,7 +398,7 @@ enum DosingEngine {
             .reason +=
             "Eventual BG \(convertGlucose(profile: profile, glucose: eventualGlucose)) < \(convertGlucose(profile: profile, glucose: minGlucose))"
 
-        // if 5m or 30m avg BG is rising faster than expected delta
+        // if 5m or 30m avg glucose is rising faster than expected delta
         // BUG: in JS it's doing a "truthiness" check for carbs required
         //      but if you get a negative carbsRequired it will evaluate
         //      to true when it should be false (negative carbs required
@@ -447,7 +445,7 @@ enum DosingEngine {
             }
         }
 
-        // calculate 30m low-temp required to get projected BG up to target
+        // calculate 30m low-temp required to get projected glucose up to target
         var insulinRequired = 2 * min(0, (eventualGlucose - targetGlucose) / adjustedSensitivity)
         insulinRequired = insulinRequired.jsRounded(scale: 2)
 

+ 17 - 15
Trio/Sources/APS/OpenAPSSwift/Forecasts/ForecastGenerator.swift

@@ -190,32 +190,34 @@ enum ForecastGenerator {
         // start at 1 because the first entry is currentGlucose
         for index in 1 ..< minCount {
             let length = index + 1
-            let iob = iobForecast.rawForecasts[index]
-            let cob = cobForecast.rawForecasts[index]
-            let uam = uamForecast.rawForecasts[index]
+            let currentIobForecastGlucose = iobForecast.rawForecasts[index]
+            let currentCobForecastGlucose = cobForecast.rawForecasts[index]
+            let currentUamForecastGlucose = uamForecast.rawForecasts[index]
 
             // the max calculations don't get rounded in JS
-            if length > insulinPeak5m, iob < minIobForecastGlucose {
-                minIobForecastGlucose = iob.jsRounded()
+            if length > insulinPeak5m, currentIobForecastGlucose < minIobForecastGlucose {
+                minIobForecastGlucose = currentIobForecastGlucose.jsRounded()
             }
-            if iob > maxIobForecastGlucose {
-                maxIobForecastGlucose = iob
+            if currentIobForecastGlucose > maxIobForecastGlucose {
+                maxIobForecastGlucose = currentIobForecastGlucose
             }
-            if carbImpactDuration != 0 || remainingCarbImpactPeak > 0, length > insulinPeak5m, cob < minCobForecastGlucose {
-                minCobForecastGlucose = cob.jsRounded()
+            if carbImpactDuration != 0 || remainingCarbImpactPeak > 0, length > insulinPeak5m,
+               currentCobForecastGlucose < minCobForecastGlucose
+            {
+                minCobForecastGlucose = currentCobForecastGlucose.jsRounded()
             }
             // 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
+            if carbImpactDuration != 0 || remainingCarbImpactPeak > 0, currentCobForecastGlucose > maxIobForecastGlucose {
+                maxCobForecastGlucose = currentCobForecastGlucose
             }
-            if uamEnabled, length > 12, uam < minUamForecastGlucose {
-                minUamForecastGlucose = uam.jsRounded()
+            if uamEnabled, length > 12, currentUamForecastGlucose < minUamForecastGlucose {
+                minUamForecastGlucose = currentUamForecastGlucose.jsRounded()
             }
             // BUG: I can't tell if the comparison against maxIobForecastGlucose is
             // intentional or not, but this is what is in JS
-            if uamEnabled, uam > maxIobForecastGlucose {
-                maxUamForecastGlucose = uam
+            if uamEnabled, currentUamForecastGlucose > maxIobForecastGlucose {
+                maxUamForecastGlucose = currentUamForecastGlucose
             }
         }