Forráskód Böngészése

Variable renaming based on PR feedback

Sam King 9 hónapja
szülő
commit
de580783ea

+ 9 - 9
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasalGenerator.swift

@@ -94,7 +94,7 @@ enum DeterminationGenerator {
         }
 
         // this is the `sens` variable in JS, it's the adjusted sensitivity
-        let sens = computeAdjustedSensitivity(
+        let adjustedSensitivity = computeAdjustedSensitivity(
             sensitivity: profile.sens ?? profile.sensitivityFor(time: currentTime),
             sensitivityRatio: sensitivityRatio,
             trioCustomOrefVariables: trioCustomOrefVariables
@@ -155,10 +155,10 @@ enum DeterminationGenerator {
             noise: 1
         )
 
-        let glucoseImpactSeries = buildGlucoseImpactSeries(iobDataSeries: iobData, sensitivity: sens)
+        let glucoseImpactSeries = buildGlucoseImpactSeries(iobDataSeries: iobData, sensitivity: adjustedSensitivity)
         let glucoseImpactSeriesWithZeroTemp = buildGlucoseImpactSeries(
             iobDataSeries: iobData,
-            sensitivity: sens,
+            sensitivity: adjustedSensitivity,
             withZeroTemp: true
         )
 
@@ -187,7 +187,7 @@ enum DeterminationGenerator {
 
         let naiveEventualGlucose: Decimal
         if currentIob > 0 {
-            naiveEventualGlucose = (currentGlucose - (currentIob * sens)).rounded(toPlaces: 0)
+            naiveEventualGlucose = (currentGlucose - (currentIob * adjustedSensitivity)).rounded(toPlaces: 0)
         } else {
             naiveEventualGlucose =
                 (
@@ -196,7 +196,7 @@ enum DeterminationGenerator {
                             currentIob *
                                 min(
                                     profile.profileSensitivity(at: currentTime, trioCustomOrefVaribales: trioCustomOrefVariables),
-                                    sens
+                                    adjustedSensitivity
                                 )
                         )
                 )
@@ -207,7 +207,7 @@ enum DeterminationGenerator {
 
         // Safety: if we ever get an invalid Decimal (very rare with Decimal), handle
         guard eventualGlucose.isFinite else {
-            throw DeterminationError.eventualGlucoseCalculationError(sensitivity: sens, deviation: deviation)
+            throw DeterminationError.eventualGlucoseCalculationError(sensitivity: adjustedSensitivity, deviation: deviation)
         }
 
         let forecastResult = ForecastGenerator.generate(
@@ -223,7 +223,7 @@ enum DeterminationGenerator {
             trioCustomOrefVariables: trioCustomOrefVariables,
             dynamicIsfResult: dynamicIsfResult,
             targetGlucose: adjustedGlucoseTargets.targetGlucose,
-            adjustedSensitivity: sens,
+            adjustedSensitivity: adjustedSensitivity,
             sensitivityRatio: sensitivityRatio,
             naiveEventualGlucose: naiveEventualGlucose,
             eventualGlucose: eventualGlucose,
@@ -248,8 +248,8 @@ enum DeterminationGenerator {
             deviation: deviation,
             currentBasal: profile.currentBasal ?? profile.basalFor(time: currentTime),
             overrideFactor: trioCustomOrefVariables.overrideFactor(),
-            adjustedSensitivity: sens,
-            isfreason: "", // Placeholder
+            adjustedSensitivity: adjustedSensitivity,
+            isfReason: "", // Placeholder
             tddReason: "", // Placeholder
             targetLog: "" // Placeholder
         )

+ 6 - 6
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift

@@ -17,7 +17,7 @@ enum DosingEngine {
         currentBasal: Decimal,
         overrideFactor: Decimal,
         adjustedSensitivity: Decimal,
-        isfreason: String,
+        isfReason: String,
         tddReason: String,
         targetLog: String // This is a pre-formatted string from the JS
     ) -> DosingInputs {
@@ -26,7 +26,7 @@ enum DosingEngine {
         let lastUAMpredBG = forecast.uam?.last
 
         var reason =
-            "\(isfreason), COB: \(mealData.mealCOB), Dev: \(deviation), BGI: \(bgi), CR: \(forecast.adjustedCarbRatio), Target: \(targetLog), minPredBG \(forecast.minForecastedGlucose), minGuardBG \(forecast.minGuardGlucose), IOBpredBG \(lastIOBpredBG)"
+            "\(isfReason), COB: \(mealData.mealCOB), Dev: \(deviation), BGI: \(bgi), CR: \(forecast.adjustedCarbRatio), Target: \(targetLog), minPredBG \(forecast.minForecastedGlucose), minGuardBG \(forecast.minGuardGlucose), IOBpredBG \(lastIOBpredBG)"
 
         if let lastCOB = lastCOBpredBG {
             reason += ", COBpredBG \(lastCOB)"
@@ -90,10 +90,10 @@ enum DosingEngine {
         let useCOBprediction = mealData.mealCOB > 0 && (ci > 0 || remainingCIpeak > 0)
         let prediction = useCOBprediction ? cobPrediction : iobPrediction
 
-        // At this point in the JS the predictions have already been rounded
-        for (i, bg) in prediction.map({ $0.jsRounded() }).enumerated() {
-            if bg < threshold {
-                minutesAboveThreshold = Decimal(5) * Decimal(i)
+        // At this point in the JS the forecasts have already been rounded
+        for (index, glucose) in prediction.map({ $0.jsRounded() }).enumerated() {
+            if glucose < threshold {
+                minutesAboveThreshold = Decimal(5) * Decimal(index)
                 break
             }
         }

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

@@ -37,9 +37,9 @@ extension ForecastGenerator {
         let clampedResult = result.map { $0.clamp(lowerBound: 39, upperBound: 401) }
 
         return IndividualForecast(
-            predictions: ForecastGenerator.trimFlatTails(clampedResult, lookback: 13),
+            forecasts: ForecastGenerator.trimFlatTails(clampedResult, lookback: 13),
             minGuardGlucose: minGuardGlucose,
-            rawPredictions: rawResult,
+            rawForecasts: rawResult,
             duration: nil
         )
     }
@@ -91,9 +91,9 @@ extension ForecastGenerator {
         let clampedResult = result.map { $0.clamp(lowerBound: 39, upperBound: 1500) }
 
         return IndividualForecast(
-            predictions: ForecastGenerator.trimFlatTails(clampedResult, lookback: 13),
+            forecasts: ForecastGenerator.trimFlatTails(clampedResult, lookback: 13),
             minGuardGlucose: minGuardGlucose,
-            rawPredictions: rawResult,
+            rawForecasts: rawResult,
             duration: nil
         )
     }
@@ -170,9 +170,9 @@ extension ForecastGenerator {
         let clampedResult = result.map { $0.clamp(lowerBound: 39, upperBound: 401) }
 
         return IndividualForecast(
-            predictions: ForecastGenerator.trimFlatTails(clampedResult, lookback: 13),
+            forecasts: ForecastGenerator.trimFlatTails(clampedResult, lookback: 13),
             minGuardGlucose: minGuardGlucose,
-            rawPredictions: rawResult,
+            rawForecasts: rawResult,
             duration: uamDuration.jsRounded(scale: 1)
         )
     }
@@ -214,9 +214,9 @@ extension ForecastGenerator {
         }
         let clampedResult = result.map { $0.clamp(lowerBound: 39, upperBound: 401) }
         return IndividualForecast(
-            predictions: ForecastGenerator.trimZTTails(series: clampedResult, targetBG: targetBG),
+            forecasts: ForecastGenerator.trimZTTails(series: clampedResult, targetBG: targetBG),
             minGuardGlucose: minGuardGlucose,
-            rawPredictions: rawResult,
+            rawForecasts: rawResult,
             duration: nil
         )
     }

+ 32 - 32
Trio/Sources/APS/OpenAPSSwift/Forecasts/ForecastGenerator.swift

@@ -126,27 +126,27 @@ enum ForecastGenerator {
         var eventualGlucose = eventualGlucose
         var finalCobForecast: [Decimal]?
         if mealData.mealCOB > 0, carbImpact > 0 || carbImpactParams.remainingCarbImpactPeak > 0 {
-            finalCobForecast = cobResult.predictions
-            if let lastCobGlucose = cobResult.predictions.last {
+            finalCobForecast = cobResult.forecasts
+            if let lastCobGlucose = cobResult.forecasts.last {
                 eventualGlucose = max(eventualGlucose, lastCobGlucose)
             }
         }
 
         var finalUamForecast: [Decimal]?
         if profile.enableUAM, carbImpact > 0 || carbImpactParams.remainingCarbImpactPeak > 0 {
-            finalUamForecast = uamResult.predictions
-            if let lastUamGlucose = uamResult.predictions.last {
+            finalUamForecast = uamResult.forecasts
+            if let lastUamGlucose = uamResult.forecasts.last {
                 eventualGlucose = max(eventualGlucose, lastUamGlucose)
             }
         }
 
         return ForecastResult(
-            iob: iobResult.predictions,
+            iob: iobResult.forecasts,
             cob: finalCobForecast,
             uam: finalUamForecast,
-            zt: ztResult.predictions,
-            internalCob: cobResult.predictions,
-            internalUam: uamResult.predictions,
+            zt: ztResult.forecasts,
+            internalCob: cobResult.forecasts,
+            internalUam: uamResult.forecasts,
             eventualGlucose: eventualGlucose,
             minForecastedGlucose: blendedForecasts.minForecastedGlucose,
             minGuardGlucose: blendedForecasts.minGuardGlucose,
@@ -156,8 +156,8 @@ enum ForecastGenerator {
         )
     }
 
-    /// This function does the min/max glucose predictions at the end of the main forecast loop
-    /// in JS. It operates on raw predictions and there is a cross dependency between IOB
+    /// This function does the min/max glucose forecasts at the end of the main forecast loop
+    /// in JS. It operates on raw forecasts and there is a cross dependency between IOB
     /// predictions and the UAM predictions, so we need to pull out this logic here
     static func calculateMinMaxPredictedGlucose(
         currentGlucose: Decimal,
@@ -172,9 +172,9 @@ enum ForecastGenerator {
         // FIXME: we need to make sure that these will all be the same length
         // but since they're running their loops on the same data they should be
         let minCount = min(
-            iobForecast.rawPredictions.count,
-            cobForecast.rawPredictions.count,
-            uamForecast.rawPredictions.count
+            iobForecast.rawForecasts.count,
+            cobForecast.rawForecasts.count,
+            uamForecast.rawForecasts.count
         )
 
         var maxIobForecastGlucose = currentGlucose
@@ -189,9 +189,9 @@ enum ForecastGenerator {
         // start at 1 because the first entry is currentGlucose
         for index in 1 ..< minCount {
             let length = index + 1
-            let iob = iobForecast.rawPredictions[index]
-            let cob = cobForecast.rawPredictions[index]
-            let uam = uamForecast.rawPredictions[index]
+            let iob = iobForecast.rawForecasts[index]
+            let cob = cobForecast.rawForecasts[index]
+            let uam = uamForecast.rawForecasts[index]
 
             // the max calculations don't get rounded in JS
             if length > insulinPeak5m, iob < minIobForecastGlucose {
@@ -217,23 +217,23 @@ enum ForecastGenerator {
         }
         return AllForecasts(
             iob: IOBForecast(
-                predictions: iobForecast.predictions,
+                forecasts: iobForecast.forecasts,
                 minGuardGlucose: iobForecast.minGuardGlucose,
                 minForecastGlucose: minIobForecastGlucose,
                 maxForecastGlucose: maxIobForecastGlucose
             ),
             zt: ZTForecast(
-                predictions: ztForecast.predictions,
+                forecasts: ztForecast.forecasts,
                 minGuardGlucose: ztForecast.minGuardGlucose
             ),
             cob: COBForecast(
-                predictions: cobForecast.predictions,
+                forecasts: cobForecast.forecasts,
                 minGuardGlucose: cobForecast.minGuardGlucose,
                 minForecastGlucose: minCobForecastGlucose,
                 maxForecastGlucose: maxCobForecastGlucose
             ),
             uam: UAMForecast(
-                predictions: uamForecast.predictions,
+                forecasts: uamForecast.forecasts,
                 minGuardGlucose: uamForecast.minGuardGlucose,
                 minForecastGlucose: minUamForecastGlucose,
                 maxForecastGlucose: maxUamForecastGlucose,
@@ -306,24 +306,24 @@ enum ForecastGenerator {
         }
 
         // 2. avgForecastGlucose blending (like avgPredBG)
-        let avgForecastGlucose: Decimal
+        let avgerageForecastGlucose: Decimal
         if uamResult.minForecastGlucose < 999, cobResult.minForecastGlucose < 999 {
-            avgForecastGlucose = (
-                (1 - fractionCarbsLeft) * (uamResult.predictions.last ?? currentGlucose) + fractionCarbsLeft *
-                    (cobResult.predictions.last ?? currentGlucose)
+            avgerageForecastGlucose = (
+                (1 - fractionCarbsLeft) * (uamResult.forecasts.last ?? currentGlucose) + fractionCarbsLeft *
+                    (cobResult.forecasts.last ?? currentGlucose)
             ).rounded()
         } else if cobResult.minForecastGlucose < 999 {
-            avgForecastGlucose =
-                (((iobResult.predictions.last ?? currentGlucose) + (cobResult.predictions.last ?? currentGlucose)) / 2)
+            avgerageForecastGlucose =
+                (((iobResult.forecasts.last ?? currentGlucose) + (cobResult.forecasts.last ?? currentGlucose)) / 2)
                     .rounded()
         } else if uamResult.minForecastGlucose < 999 {
-            avgForecastGlucose =
-                (((iobResult.predictions.last ?? currentGlucose) + (uamResult.predictions.last ?? currentGlucose)) / 2)
+            avgerageForecastGlucose =
+                (((iobResult.forecasts.last ?? currentGlucose) + (uamResult.forecasts.last ?? currentGlucose)) / 2)
                     .rounded()
         } else {
-            avgForecastGlucose = (iobResult.predictions.last ?? currentGlucose).rounded()
+            avgerageForecastGlucose = (iobResult.forecasts.last ?? currentGlucose).rounded()
         }
-        let adjustedAvgForecastGlucose = max(avgForecastGlucose, ztResult.minGuardGlucose)
+        let adjustedAverageForecastGlucose = max(avgerageForecastGlucose, ztResult.minGuardGlucose)
 
         // 3. minGuardGlucose
         let minGuardGlucose: Decimal
@@ -364,7 +364,7 @@ enum ForecastGenerator {
         }
 
         // Clamp minForecastedGlucose to not exceed adjustedAvgForecastGlucose
-        minForecastedGlucose = min(minForecastedGlucose, adjustedAvgForecastGlucose)
+        minForecastedGlucose = min(minForecastedGlucose, adjustedAverageForecastGlucose)
 
         // JS: If maxCOBPredBG > bg, don't trust UAM too much
         if cobResult.maxForecastGlucose > currentGlucose {
@@ -373,7 +373,7 @@ enum ForecastGenerator {
 
         return ForecastBlendingResult(
             minForecastedGlucose: minForecastedGlucose,
-            avgForecastedGlucose: adjustedAvgForecastGlucose,
+            avgForecastedGlucose: adjustedAverageForecastGlucose,
             minGuardGlucose: minGuardGlucose
         )
     }

+ 6 - 6
Trio/Sources/APS/OpenAPSSwift/Forecasts/ForecastResults.swift

@@ -1,21 +1,21 @@
 import Foundation
 
 struct IOBForecast {
-    let predictions: [Decimal] // The final, trimmed array for output
+    let forecasts: [Decimal] // The final, trimmed array for output
     let minGuardGlucose: Decimal // The absolute min of the untrimmed array
     let minForecastGlucose: Decimal // The min after the initial 90-min peak
     let maxForecastGlucose: Decimal // The absolute max of the untrimmed array
 }
 
 struct COBForecast {
-    let predictions: [Decimal] // The final, trimmed array for output
+    let forecasts: [Decimal] // The final, trimmed array for output
     let minGuardGlucose: Decimal // The absolute min of the untrimmed array
     let minForecastGlucose: Decimal // The min after the initial 90-min peak
     let maxForecastGlucose: Decimal // The absolute max of the untrimmed array
 }
 
 struct UAMForecast {
-    let predictions: [Decimal] // The final, trimmed array for output
+    let forecasts: [Decimal] // The final, trimmed array for output
     let minGuardGlucose: Decimal // The absolute min of the untrimmed array
     let minForecastGlucose: Decimal // The min after the initial 60-min peak
     let maxForecastGlucose: Decimal // The absolute max of the untrimmed array
@@ -23,14 +23,14 @@ struct UAMForecast {
 }
 
 struct ZTForecast {
-    let predictions: [Decimal] // The final, trimmed array for output
+    let forecasts: [Decimal] // The final, trimmed array for output
     let minGuardGlucose: Decimal // The absolute min of the untrimmed array
 }
 
 struct IndividualForecast {
-    let predictions: [Decimal]
+    let forecasts: [Decimal]
     let minGuardGlucose: Decimal
-    let rawPredictions: [Decimal]
+    let rawForecasts: [Decimal]
     let duration: Decimal? // only set by UAM
 }