浏览代码

feat(algo): Update error conditions for early exits; remove 400 dosing guard #588

Deniz Cengiz 6 月之前
父节点
当前提交
75b436b26d

+ 1 - 2
Trio/Sources/APS/OpenAPS/OpenAPS.swift

@@ -454,8 +454,7 @@ final class OpenAPS {
                 start: (activeOverrides.first?.start ?? 0) as Decimal,
                 start: (activeOverrides.first?.start ?? 0) as Decimal,
                 end: (activeOverrides.first?.end ?? 0) as Decimal,
                 end: (activeOverrides.first?.end ?? 0) as Decimal,
                 smbMinutes: activeOverrides.first?.smbMinutes?.decimalValue ?? maxSMBBasalMinutes,
                 smbMinutes: activeOverrides.first?.smbMinutes?.decimalValue ?? maxSMBBasalMinutes,
-                uamMinutes: activeOverrides.first?.uamMinutes?.decimalValue ?? maxUAMBasalMinutes,
-                shouldProtectDueToHIGH: GlucoseStored.glucoseIsHIGH(glucose)
+                uamMinutes: activeOverrides.first?.uamMinutes?.decimalValue ?? maxUAMBasalMinutes
             )
             )
 
 
             // Save and return contents of Trio's custom oref variables
             // Save and return contents of Trio's custom oref variables

+ 6 - 7
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasalGenerator.swift

@@ -535,15 +535,14 @@ enum DeterminationGenerator {
             glucose == 38 ||
             glucose == 38 ||
             noise >= 3 ||
             noise >= 3 ||
             minAgo > 12 ||
             minAgo > 12 ||
-            minAgo < -5 ||
-            (shortAvgDelta == 0 && longAvgDelta == 0)
+            minAgo < -5
 
 
         // === IF ERROR, CANCEL/SHORTEN TEMPS ===
         // === IF ERROR, CANCEL/SHORTEN TEMPS ===
         guard errorDetected, let currentTemp = currentTemp else { return nil }
         guard errorDetected, let currentTemp = currentTemp else { return nil }
 
 
-        if currentTemp.rate >= basal {
-            // Cancel high temp: set 0U/hr for 0m (neutralizes)
-            let reasonWithAction = reason + ". Canceling high temp basal of \(currentTemp.rate)U/hr."
+        if currentTemp.rate >= basal { // high temp is running
+            // Replace high temp with neutral temp at scheduled basal rate for 30min
+            let reasonWithAction = reason + ". Replacing high temp basal of \(currentTemp.rate)U/hr with neutral temp of \(basal)U/hr"
             return Determination(
             return Determination(
                 id: UUID(),
                 id: UUID(),
                 reason: reasonWithAction,
                 reason: reasonWithAction,
@@ -551,8 +550,8 @@ enum DeterminationGenerator {
                 insulinReq: nil,
                 insulinReq: nil,
                 eventualBG: nil,
                 eventualBG: nil,
                 sensitivityRatio: nil,
                 sensitivityRatio: nil,
-                rate: 0,
-                duration: 0,
+                rate: basal,
+                duration: 30,
                 iob: nil,
                 iob: nil,
                 cob: nil,
                 cob: nil,
                 predictions: nil,
                 predictions: nil,

+ 0 - 4
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift

@@ -30,10 +30,6 @@ enum DosingEngine {
             return false
             return false
         }
         }
 
 
-        if trioCustomOrefVariables.shouldProtectDueToHIGH {
-            return false
-        }
-
         if !profile.allowSMBWithHighTemptarget, profile.temptargetSet == true, adjustedTargetGlucose > 100 {
         if !profile.allowSMBWithHighTemptarget, profile.temptargetSet == true, adjustedTargetGlucose > 100 {
             return false
             return false
         }
         }

+ 1 - 5
Trio/Sources/Models/TrioCustomOrefVariables.swift

@@ -21,7 +21,6 @@ struct TrioCustomOrefVariables: JSON, Equatable {
     var end: Decimal
     var end: Decimal
     var smbMinutes: Decimal
     var smbMinutes: Decimal
     var uamMinutes: Decimal
     var uamMinutes: Decimal
-    var shouldProtectDueToHIGH: Bool
 
 
     init(
     init(
         average_total_data: Decimal,
         average_total_data: Decimal,
@@ -43,8 +42,7 @@ struct TrioCustomOrefVariables: JSON, Equatable {
         start: Decimal,
         start: Decimal,
         end: Decimal,
         end: Decimal,
         smbMinutes: Decimal,
         smbMinutes: Decimal,
-        uamMinutes: Decimal,
-        shouldProtectDueToHIGH: Bool
+        uamMinutes: Decimal
     ) {
     ) {
         self.average_total_data = average_total_data
         self.average_total_data = average_total_data
         self.weightedAverage = weightedAverage
         self.weightedAverage = weightedAverage
@@ -66,7 +64,6 @@ struct TrioCustomOrefVariables: JSON, Equatable {
         self.end = end
         self.end = end
         self.smbMinutes = smbMinutes
         self.smbMinutes = smbMinutes
         self.uamMinutes = uamMinutes
         self.uamMinutes = uamMinutes
-        self.shouldProtectDueToHIGH = shouldProtectDueToHIGH
     }
     }
 }
 }
 
 
@@ -92,6 +89,5 @@ extension TrioCustomOrefVariables {
         case end
         case end
         case smbMinutes
         case smbMinutes
         case uamMinutes
         case uamMinutes
-        case shouldProtectDueToHIGH
     }
     }
 }
 }

+ 1 - 2
TrioTests/OpenAPSSwiftTests/DetermineBasalEarlyExitTests.swift

@@ -113,8 +113,7 @@ import Testing
             start: 0,
             start: 0,
             end: 0,
             end: 0,
             smbMinutes: 30,
             smbMinutes: 30,
-            uamMinutes: 30,
-            shouldProtectDueToHIGH: false
+            uamMinutes: 30
         )
         )
 
 
         return (
         return (

+ 1 - 17
TrioTests/OpenAPSSwiftTests/DetermineBasalEnableSmbTests.swift

@@ -64,8 +64,7 @@ import Testing
             start: 0,
             start: 0,
             end: 0,
             end: 0,
             smbMinutes: 0,
             smbMinutes: 0,
-            uamMinutes: 0,
-            shouldProtectDueToHIGH: false
+            uamMinutes: 0
         )
         )
 
 
         return (
         return (
@@ -110,21 +109,6 @@ import Testing
         #expect(decision.isEnabled == false)
         #expect(decision.isEnabled == false)
     }
     }
 
 
-    @Test("Should disable SMB when shouldProtectDueToHIGH is true") func disableWhenProtectDueToHigh() throws {
-        var inputs = createDefaultInputs()
-        inputs.trioCustomOrefVariables.shouldProtectDueToHIGH = true
-        inputs.profile.enableSMBAlways = true // Ensure protection takes precedence
-
-        let decision = try DosingEngine.makeSMBDosingDecision(
-            profile: inputs.profile, meal: inputs.meal, currentGlucose: inputs.currentGlucose,
-            adjustedTargetGlucose: inputs.adjustedTargetGlucose,
-            minGuardGlucose: inputs.minGuardGlucose,
-            threshold: inputs.threshold, glucoseStatus: inputs.glucoseStatus,
-            trioCustomOrefVariables: inputs.trioCustomOrefVariables, clock: inputs.clock
-        )
-        #expect(decision.isEnabled == false)
-    }
-
     @Test("Should disable SMB with high temp target when not allowed") func disableWithHighTempTarget() throws {
     @Test("Should disable SMB with high temp target when not allowed") func disableWithHighTempTarget() throws {
         var inputs = createDefaultInputs()
         var inputs = createDefaultInputs()
         inputs.profile.allowSMBWithHighTemptarget = false
         inputs.profile.allowSMBWithHighTemptarget = false

+ 1 - 2
TrioTests/OpenAPSSwiftTests/DynamicISFTests.swift

@@ -55,8 +55,7 @@ import Testing
             start: 0,
             start: 0,
             end: 0,
             end: 0,
             smbMinutes: 30,
             smbMinutes: 30,
-            uamMinutes: 30,
-            shouldProtectDueToHIGH: false
+            uamMinutes: 30
         )
         )
 
 
         return (profile, preferences, glucose, trioVars)
         return (profile, preferences, glucose, trioVars)