Kaynağa Gözat

Merge pull request #608 from nightscout/oref-swift-move-to-js-rounding

Fix remaining `determineBasal` inconsistencies
Sam King 5 ay önce
ebeveyn
işleme
a5548d8027

+ 8 - 8
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasal+Helpers.swift

@@ -92,11 +92,11 @@ extension DeterminationGenerator {
         let longAvg: Decimal = longDeltas.mean
         let longAvg: Decimal = longDeltas.mean
 
 
         return GlucoseStatus(
         return GlucoseStatus(
-            delta: lastDelta.rounded(toPlaces: 2),
+            delta: lastDelta.jsRounded(scale: 2),
             glucose: mostRecentGlucoseReading,
             glucose: mostRecentGlucoseReading,
             noise: Int(sorted[0].noise ?? 0),
             noise: Int(sorted[0].noise ?? 0),
             shortAvgDelta: shortAvg.jsRounded(scale: 2),
             shortAvgDelta: shortAvg.jsRounded(scale: 2),
-            longAvgDelta: longAvg.rounded(toPlaces: 2),
+            longAvgDelta: longAvg.jsRounded(scale: 2),
             date: mostRecentGlucoseDate,
             date: mostRecentGlucoseDate,
             lastCalIndex: nil,
             lastCalIndex: nil,
             device: "", // FIXME: will be filled once this gets moved back to GlucoseStorage
             device: "", // FIXME: will be filled once this gets moved back to GlucoseStorage
@@ -240,18 +240,18 @@ extension DeterminationGenerator {
             if (profile.sensitivityRaisesTarget && autosens.ratio < 1) ||
             if (profile.sensitivityRaisesTarget && autosens.ratio < 1) ||
                 (profile.resistanceLowersTarget && autosens.ratio > 1)
                 (profile.resistanceLowersTarget && autosens.ratio > 1)
             {
             {
-                minGlucose = ((minGlucose - 60) / autosens.ratio + 60).rounded(toPlaces: 0)
-                maxGlucose = ((maxGlucose - 60) / autosens.ratio + 60).rounded(toPlaces: 0)
-                targetGlucose = max(80, ((targetGlucose - 60) / autosens.ratio + 60).rounded(toPlaces: 0))
+                minGlucose = ((minGlucose - 60) / autosens.ratio + 60).jsRounded()
+                maxGlucose = ((maxGlucose - 60) / autosens.ratio + 60).jsRounded()
+                targetGlucose = max(80, ((targetGlucose - 60) / autosens.ratio + 60).jsRounded())
             }
             }
         }
         }
 
 
         // Raise target for noisy/CGM data
         // Raise target for noisy/CGM data
         if noise >= 2 {
         if noise >= 2 {
             let noisyCGMTargetMultiplier = max(1.1, profile.noisyCGMTargetMultiplier)
             let noisyCGMTargetMultiplier = max(1.1, profile.noisyCGMTargetMultiplier)
-            minGlucose = min(200, minGlucose * noisyCGMTargetMultiplier).rounded(toPlaces: 0)
-            targetGlucose = min(200, targetGlucose * noisyCGMTargetMultiplier).rounded(toPlaces: 0)
-            maxGlucose = min(200, maxGlucose * noisyCGMTargetMultiplier).rounded(toPlaces: 0)
+            minGlucose = min(200, minGlucose * noisyCGMTargetMultiplier).jsRounded()
+            targetGlucose = min(200, targetGlucose * noisyCGMTargetMultiplier).jsRounded()
+            maxGlucose = min(200, maxGlucose * noisyCGMTargetMultiplier).jsRounded()
         }
         }
 
 
         // Calculate threshold: minGlucose thresholds: 80->60, 90->65, etc.
         // Calculate threshold: minGlucose thresholds: 80->60, 90->65, etc.

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

@@ -222,7 +222,7 @@ enum DeterminationGenerator {
 
 
         let naiveEventualGlucose: Decimal
         let naiveEventualGlucose: Decimal
         if currentIob > 0 {
         if currentIob > 0 {
-            naiveEventualGlucose = (currentGlucose - (currentIob * adjustedSensitivity)).rounded(toPlaces: 0)
+            naiveEventualGlucose = (currentGlucose - (currentIob * adjustedSensitivity)).jsRounded()
         } else {
         } else {
             naiveEventualGlucose =
             naiveEventualGlucose =
                 (
                 (
@@ -235,7 +235,7 @@ enum DeterminationGenerator {
                                 )
                                 )
                         )
                         )
                 )
                 )
-                .rounded(toPlaces: 0)
+                .jsRounded()
         }
         }
 
 
         let eventualGlucose = naiveEventualGlucose + deviation
         let eventualGlucose = naiveEventualGlucose + deviation

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

@@ -249,7 +249,7 @@ enum DosingEngine {
         guard carbSensitivityFactor > 0 else { return (carbs: 0, minutes: minutesAboveThreshold) }
         guard carbSensitivityFactor > 0 else { return (carbs: 0, minutes: minutesAboveThreshold) }
 
 
         var carbsRequired = (glucoseUndershoot - zeroTempEffect) / carbSensitivityFactor - cobForCarbsRequired
         var carbsRequired = (glucoseUndershoot - zeroTempEffect) / carbSensitivityFactor - cobForCarbsRequired
-        carbsRequired = carbsRequired.rounded(toPlaces: 0)
+        carbsRequired = carbsRequired.jsRounded()
 
 
         return (carbs: carbsRequired, minutes: minutesAboveThreshold)
         return (carbs: carbsRequired, minutes: minutesAboveThreshold)
     }
     }

+ 1 - 1
Trio/Sources/APS/OpenAPSSwift/Forecasts/CarbImpactParams.swift

@@ -17,7 +17,7 @@ struct CarbImpactParams {
         currentTime: Date
         currentTime: Date
     ) -> CarbImpactParams {
     ) -> CarbImpactParams {
         let maxCarbAbsorptionRate: Decimal = 30 // g/h
         let maxCarbAbsorptionRate: Decimal = 30 // g/h
-        let maxCarbImpact = (maxCarbAbsorptionRate * carbSensitivityFactor * 5 / 60).rounded(toPlaces: 1)
+        let maxCarbImpact = (maxCarbAbsorptionRate * carbSensitivityFactor * 5 / 60).jsRounded(scale: 1)
         let cappedCarbImpact = min(carbImpact, maxCarbImpact)
         let cappedCarbImpact = min(carbImpact, maxCarbImpact)
 
 
         let remainingCarbAbsorptionTime = ForecastGenerator.calculateRemainingCarbAbsorptionTime(
         let remainingCarbAbsorptionTime = ForecastGenerator.calculateRemainingCarbAbsorptionTime(

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

@@ -322,17 +322,17 @@ enum ForecastGenerator {
         if uamResult.minForecastGlucose < 999, cobResult.minForecastGlucose < 999 {
         if uamResult.minForecastGlucose < 999, cobResult.minForecastGlucose < 999 {
             avgerageForecastGlucose = (
             avgerageForecastGlucose = (
                 (1 - fractionCarbsLeft) * uamResult.lastForecastGlucose + fractionCarbsLeft * cobResult.lastForecastGlucose
                 (1 - fractionCarbsLeft) * uamResult.lastForecastGlucose + fractionCarbsLeft * cobResult.lastForecastGlucose
-            ).rounded()
+            ).jsRounded()
         } else if cobResult.minForecastGlucose < 999 {
         } else if cobResult.minForecastGlucose < 999 {
             avgerageForecastGlucose =
             avgerageForecastGlucose =
                 ((iobResult.lastForecastGlucose + cobResult.lastForecastGlucose) / 2)
                 ((iobResult.lastForecastGlucose + cobResult.lastForecastGlucose) / 2)
-                    .rounded()
+                    .jsRounded()
         } else if uamResult.minForecastGlucose < 999 {
         } else if uamResult.minForecastGlucose < 999 {
             avgerageForecastGlucose =
             avgerageForecastGlucose =
                 ((iobResult.lastForecastGlucose + uamResult.lastForecastGlucose) / 2)
                 ((iobResult.lastForecastGlucose + uamResult.lastForecastGlucose) / 2)
-                    .rounded()
+                    .jsRounded()
         } else {
         } else {
-            avgerageForecastGlucose = iobResult.lastForecastGlucose.rounded()
+            avgerageForecastGlucose = iobResult.lastForecastGlucose.jsRounded()
         }
         }
         let adjustedAverageForecastGlucose = max(avgerageForecastGlucose, ztResult.minGuardGlucose)
         let adjustedAverageForecastGlucose = max(avgerageForecastGlucose, ztResult.minGuardGlucose)
 
 
@@ -344,16 +344,16 @@ enum ForecastGenerator {
                     fractionCarbsLeft * cobResult.minGuardGlucose + (1 - fractionCarbsLeft) * uamResult.minGuardGlucose
                     fractionCarbsLeft * cobResult.minGuardGlucose + (1 - fractionCarbsLeft) * uamResult.minGuardGlucose
                 ).jsRounded()
                 ).jsRounded()
             } else {
             } else {
-                minGuardGlucose = cobResult.minGuardGlucose.rounded()
+                minGuardGlucose = cobResult.minGuardGlucose.jsRounded()
             }
             }
         } else if enableUAM {
         } else if enableUAM {
-            minGuardGlucose = uamResult.minGuardGlucose.rounded()
+            minGuardGlucose = uamResult.minGuardGlucose.jsRounded()
         } else {
         } else {
-            minGuardGlucose = iobResult.minGuardGlucose.rounded()
+            minGuardGlucose = iobResult.minGuardGlucose.jsRounded()
         }
         }
 
 
         // 4. minForecastedGlucose ("minPredBG")
         // 4. minForecastedGlucose ("minPredBG")
-        var minForecastedGlucose: Decimal = iobResult.minForecastGlucose.rounded()
+        var minForecastedGlucose: Decimal = iobResult.minForecastGlucose.jsRounded()
         if carbs > 0 {
         if carbs > 0 {
             if !enableUAM, cobResult.minForecastGlucose < 999 {
             if !enableUAM, cobResult.minForecastGlucose < 999 {
                 minForecastedGlucose = max(iobResult.minForecastGlucose, cobResult.minForecastGlucose)
                 minForecastedGlucose = max(iobResult.minForecastGlucose, cobResult.minForecastGlucose)
@@ -364,14 +364,14 @@ enum ForecastGenerator {
                     iobResult.minForecastGlucose,
                     iobResult.minForecastGlucose,
                     cobResult.minForecastGlucose,
                     cobResult.minForecastGlucose,
                     blendedMinForecastGlucose
                     blendedMinForecastGlucose
-                ).rounded()
+                ).jsRounded()
             } else if enableUAM {
             } else if enableUAM {
                 minForecastedGlucose = minZTUAMForecastGlucose
                 minForecastedGlucose = minZTUAMForecastGlucose
             } else {
             } else {
                 minForecastedGlucose = minGuardGlucose
                 minForecastedGlucose = minGuardGlucose
             }
             }
         } else if enableUAM {
         } else if enableUAM {
-            minForecastedGlucose = max(iobResult.minForecastGlucose, minZTUAMForecastGlucose).rounded()
+            minForecastedGlucose = max(iobResult.minForecastGlucose, minZTUAMForecastGlucose).jsRounded()
         }
         }
 
 
         // Clamp minForecastedGlucose to not exceed adjustedAvgForecastGlucose
         // Clamp minForecastedGlucose to not exceed adjustedAvgForecastGlucose

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 1
TrioTests/OpenAPSSwiftTests/javascript/bundle/basal-set-temp.js


Dosya farkı çok büyük olduğundan ihmal edildi
+ 1 - 1
TrioTests/OpenAPSSwiftTests/javascript/bundle/determine-basal.js