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

Adjusted the ISF for overrides for the naiveEventualGlucose calculation

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

+ 6 - 0
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasal+Helpers.swift

@@ -384,6 +384,12 @@ extension Profile {
 
         return minBg
     }
+
+    /// Calculates the profile ISF at this point in time and applies any overrides to it
+    func profileSensitivity(at: Date, trioCustomOrefVaribales: TrioCustomOrefVariables) -> Decimal {
+        let sensitivity = sensitivityFor(time: at)
+        return trioCustomOrefVaribales.override(sensitivity: sensitivity)
+    }
 }
 
 extension TrioCustomOrefVariables {

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

@@ -179,8 +179,17 @@ enum DeterminationGenerator {
             naiveEventualGlucose = (currentGlucose - (currentIob * sensitivity)).rounded(toPlaces: 0)
         } else {
             naiveEventualGlucose =
-                (currentGlucose - (currentIob * min(profile.sens ?? profile.sensitivityFor(time: currentTime), sensitivity)))
-                    .rounded(toPlaces: 0)
+                (
+                    currentGlucose -
+                        (
+                            currentIob *
+                                min(
+                                    profile.profileSensitivity(at: currentTime, trioCustomOrefVaribales: trioCustomOrefVariables),
+                                    sensitivity
+                                )
+                        )
+                )
+                .rounded(toPlaces: 0)
         }
 
         let eventualGlucose = naiveEventualGlucose + deviation