فهرست منبع

Address reviewer feedback

Sam King 8 ماه پیش
والد
کامیت
40c7b18e4d

+ 0 - 6
Model/JSONImporter.swift

@@ -553,7 +553,6 @@ extension Determination: Codable {
         isf = try container.decodeIfPresent(Decimal.self, forKey: .isf)
         current_target = try container.decodeIfPresent(Decimal.self, forKey: .current_target)
         tdd = try container.decodeIfPresent(Decimal.self, forKey: .tdd)
-        insulinForManualBolus = try container.decodeIfPresent(Decimal.self, forKey: .insulinForManualBolus)
         manualBolusErrorString = try container.decodeIfPresent(Decimal.self, forKey: .manualBolusErrorString)
         minDelta = try container.decodeIfPresent(Decimal.self, forKey: .minDelta)
         expectedDelta = try container.decodeIfPresent(Decimal.self, forKey: .expectedDelta)
@@ -595,7 +594,6 @@ extension Determination: Codable {
         try container.encodeIfPresent(isf, forKey: .isf)
         try container.encodeIfPresent(current_target, forKey: .current_target)
         try container.encodeIfPresent(tdd, forKey: .tdd)
-        try container.encodeIfPresent(insulinForManualBolus, forKey: .insulinForManualBolus)
         try container.encodeIfPresent(manualBolusErrorString, forKey: .manualBolusErrorString)
         try container.encodeIfPresent(minDelta, forKey: .minDelta)
         try container.encodeIfPresent(expectedDelta, forKey: .expectedDelta)
@@ -637,9 +635,6 @@ extension Determination: Codable {
         guard let manualBolusErrorString = manualBolusErrorString else {
             throw JSONImporterError.missingRequiredPropertyInDetermination("manualBolusErrorString")
         }
-        guard let insulinForManualBolus = insulinForManualBolus else {
-            throw JSONImporterError.missingRequiredPropertyInDetermination("insulinForManualBolus")
-        }
         guard let cob = cob else {
             throw JSONImporterError.missingRequiredPropertyInDetermination("COB")
         }
@@ -676,7 +671,6 @@ extension Determination: Codable {
         newOrefDetermination.deliverAt = deliverAt
         newOrefDetermination.timestamp = timestamp
         newOrefDetermination.enacted = received ?? false
-        newOrefDetermination.insulinForManualBolus = decimalToNSDecimalNumber(insulinForManualBolus)
         newOrefDetermination.carbRatio = decimalToNSDecimalNumber(carbRatio)
         newOrefDetermination.glucose = decimalToNSDecimalNumber(bg)
         newOrefDetermination.reservoir = decimalToNSDecimalNumber(reservoir)

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

@@ -40,7 +40,6 @@ final class OpenAPS {
             newOrefDetermination.currentTarget = self.decimalToNSDecimalNumber(determination.current_target)
             newOrefDetermination.eventualBG = determination.eventualBG.map(NSDecimalNumber.init)
             newOrefDetermination.deliverAt = determination.deliverAt
-            newOrefDetermination.insulinForManualBolus = self.decimalToNSDecimalNumber(determination.insulinForManualBolus)
             newOrefDetermination.carbRatio = self.decimalToNSDecimalNumber(determination.carbRatio)
             newOrefDetermination.glucose = self.decimalToNSDecimalNumber(determination.bg)
             newOrefDetermination.reservoir = self.decimalToNSDecimalNumber(determination.reservoir)

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

@@ -109,7 +109,6 @@ enum DeterminationGenerator {
                 timestamp: currentTime,
                 tdd: nil,
                 current_target: profile.targetBg,
-                insulinForManualBolus: nil,
                 manualBolusErrorString: nil,
                 minDelta: nil,
                 expectedDelta: nil,
@@ -128,7 +127,6 @@ enum DeterminationGenerator {
             trioCustomOrefVariables: trioCustomOrefVariables
         )
 
-        // TODO: We need to add the dynamicIsfResult to our forcasting functions
         if let dynamicIsfResult = dynamicIsfResult {
             autosensData = Autosens(
                 ratio: dynamicIsfResult.ratio,
@@ -330,7 +328,6 @@ enum DeterminationGenerator {
             timestamp: currentTime,
             tdd: nil,
             current_target: nil,
-            insulinForManualBolus: smbDecision.insulinForManualBolus,
             manualBolusErrorString: smbDecision.manualBolusError.map { Decimal($0) },
             minDelta: nil,
             expectedDelta: expectedDelta,
@@ -375,6 +372,9 @@ enum DeterminationGenerator {
             return determination
         }
 
+        // TODO: how to handle output?
+        // TODO: how to handle logging?
+
         return determination
     }
 
@@ -491,7 +491,6 @@ enum DeterminationGenerator {
                 timestamp: currentTime,
                 tdd: nil,
                 current_target: profile.targetBg,
-                insulinForManualBolus: nil,
                 manualBolusErrorString: nil,
                 minDelta: minDelta,
                 expectedDelta: nil,
@@ -525,7 +524,6 @@ enum DeterminationGenerator {
                 timestamp: currentTime,
                 tdd: nil,
                 current_target: profile.targetBg,
-                insulinForManualBolus: nil,
                 manualBolusErrorString: nil,
                 minDelta: minDelta,
                 expectedDelta: nil,
@@ -559,7 +557,6 @@ enum DeterminationGenerator {
                 timestamp: currentTime,
                 tdd: nil,
                 current_target: profile.targetBg,
-                insulinForManualBolus: nil,
                 manualBolusErrorString: nil,
                 minDelta: minDelta,
                 expectedDelta: nil,

+ 19 - 26
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift

@@ -10,7 +10,6 @@ enum DosingEngine {
     struct SMBDecision {
         let isEnabled: Bool
         let manualBolusError: Int?
-        let insulinForManualBolus: Decimal?
         let minGuardGlucose: Decimal?
         let reason: String?
     }
@@ -111,9 +110,9 @@ enum DosingEngine {
         meal: ComputedCarbs,
         currentGlucose: Decimal,
         adjustedTargetGlucose: Decimal,
-        adjustedSensitivity: Decimal,
+        adjustedSensitivity _: Decimal,
         minGuardGlucose: Decimal,
-        eventualGlucose: Decimal,
+        eventualGlucose _: Decimal,
         threshold: Decimal,
         glucoseStatus: GlucoseStatus,
         trioCustomOrefVariables: TrioCustomOrefVariables,
@@ -133,12 +132,10 @@ enum DosingEngine {
         // in one place. Note: We can't shortcut the return value because
         // the determineBasal logic always evaluates this logic
         var manualBolusError: Int?
-        var insulinForManualBolus: Decimal?
         var minGuardGlucoseDecision: Decimal?
         var reason: String?
         if smbIsEnabled, minGuardGlucose < threshold {
             manualBolusError = 1
-            insulinForManualBolus = ((eventualGlucose - adjustedTargetGlucose) / adjustedSensitivity).jsRounded(scale: 2)
             minGuardGlucoseDecision = minGuardGlucose
             smbIsEnabled = false
         }
@@ -153,7 +150,6 @@ enum DosingEngine {
         return SMBDecision(
             isEnabled: smbIsEnabled,
             manualBolusError: manualBolusError,
-            insulinForManualBolus: insulinForManualBolus,
             minGuardGlucose: minGuardGlucoseDecision,
             reason: reason
         )
@@ -289,12 +285,12 @@ enum DosingEngine {
         threshold: Decimal,
         overrideFactor: Decimal,
         profile: Profile,
-        eventualGlucose: Decimal,
+        eventualGlucose _: Decimal,
         adjustedSensitivity: Decimal,
         targetGlucose: Decimal,
         currentTemp: TempBasal,
         determination: Determination
-    ) throws -> (setTempBasal: Bool, determination: Determination) {
+    ) throws -> (shouldSetTempBasal: Bool, determination: Determination) {
         var newDetermination = determination
 
         guard let currentBasal = profile.currentBasal else {
@@ -312,43 +308,40 @@ enum DosingEngine {
             newDetermination
                 .reason +=
                 "IOB \(iobString) < \(suspendString) and minDelta \(minDeltaString) > expectedDelta \(expectedDeltaString); "
-            return (setTempBasal: false, determination: newDetermination)
+            return (shouldSetTempBasal: false, determination: newDetermination)
         } else if currentGlucose < threshold || minGuardGlucose < threshold {
             let minGuardGlucoseString = String(describing: convertGlucose(profile: profile, glucose: minGuardGlucose))
             let thresholdString = String(describing: convertGlucose(profile: profile, glucose: threshold))
             newDetermination.reason += "minGuardBG \(minGuardGlucoseString) < \(thresholdString)"
 
-            let bgUndershoot = targetGlucose - minGuardGlucose
+            let glucoseUndershoot = targetGlucose - minGuardGlucose
             if minGuardGlucose < threshold {
                 newDetermination.manualBolusErrorString = 2
                 newDetermination.minGuardBG = minGuardGlucose
             }
 
-            newDetermination.insulinForManualBolus = ((eventualGlucose - targetGlucose) / adjustedSensitivity)
-                .rounded(toPlaces: 2)
-
-            let worstCaseInsulinReq = bgUndershoot / adjustedSensitivity
-            var durationReq = (60 * worstCaseInsulinReq / (currentBasal * overrideFactor)).rounded()
-            durationReq = (durationReq / 30).rounded() * 30
-            durationReq = max(30, min(120, durationReq))
+            let worstCaseInsulinRequired = glucoseUndershoot / adjustedSensitivity
+            var durationRequired = (60 * worstCaseInsulinRequired / (currentBasal * overrideFactor)).jsRounded()
+            durationRequired = (durationRequired / 30).jsRounded() * 30
+            durationRequired = max(30, min(120, durationRequired))
 
             let finalDetermination = try TempBasalFunctions.setTempBasal(
                 rate: 0,
-                duration: durationReq,
+                duration: durationRequired,
                 profile: profile,
                 determination: newDetermination,
                 currentTemp: currentTemp
             )
-            return (setTempBasal: true, determination: finalDetermination)
+            return (shouldSetTempBasal: true, determination: finalDetermination)
         }
 
-        return (setTempBasal: false, determination: determination)
+        return (shouldSetTempBasal: false, determination: determination)
     }
 
     /// Determines if a neutral temp basal should be skipped to avoid pump alerts.
     ///
     /// - Returns: A tuple containing:
-    ///   - `setTempBasal`: A `Bool` that is `true` if `determineBasal` should exit and apply the recommendation immediately.
+    ///   - `shouldSetTempBasal`: A `Bool` that is `true` if `determineBasal` should exit and apply the recommendation immediately.
     ///   - `determination`: The (potentially modified) determination object.
     static func skipNeutralTempBasal(
         smbIsEnabled: Bool,
@@ -356,9 +349,9 @@ enum DosingEngine {
         clock: Date,
         currentTemp: TempBasal,
         determination: Determination
-    ) throws -> (setTempBasal: Bool, determination: Determination) {
+    ) throws -> (shouldSetTempBasal: Bool, determination: Determination) {
         guard profile.skipNeutralTemps else {
-            return (setTempBasal: false, determination: determination)
+            return (shouldSetTempBasal: false, determination: determination)
         }
         guard let totalMinutes = clock.minutesSinceMidnight else {
             throw CalendarError.invalidCalendar
@@ -366,7 +359,7 @@ enum DosingEngine {
 
         let minute = totalMinutes % 60
         guard minute >= 55 else {
-            return (setTempBasal: false, determination: determination)
+            return (shouldSetTempBasal: false, determination: determination)
         }
 
         if !smbIsEnabled {
@@ -383,11 +376,11 @@ enum DosingEngine {
                 determination: newDetermination,
                 currentTemp: currentTemp
             )
-            return (setTempBasal: true, determination: finalDetermination)
+            return (shouldSetTempBasal: true, determination: finalDetermination)
         } else {
             // In the JS, this path logs to the console but does not modify determination.
             // We will do nothing here to match that behavior.
-            return (setTempBasal: false, determination: determination)
+            return (shouldSetTempBasal: false, determination: determination)
         }
     }
 }

+ 0 - 1
Trio/Sources/APS/Storage/DeterminationStorage.swift

@@ -183,7 +183,6 @@ final class BaseDeterminationStorage: DeterminationStorage, Injectable {
                         isf: self.decimal(from: orefDetermination.insulinSensitivity),
                         timestamp: orefDetermination.timestamp,
                         current_target: self.decimal(from: orefDetermination.currentTarget),
-                        insulinForManualBolus: self.decimal(from: orefDetermination.insulinForManualBolus),
                         manualBolusErrorString: self.decimal(from: orefDetermination.manualBolusErrorString),
                         minDelta: self.decimal(from: orefDetermination.minDelta),
                         expectedDelta: self.decimal(from: orefDetermination.expectedDelta),

+ 0 - 1
Trio/Sources/Models/Determination.swift

@@ -29,7 +29,6 @@ struct Determination: JSON, Equatable {
     var tdd: Decimal?
 
     var current_target: Decimal?
-    var insulinForManualBolus: Decimal?
     var manualBolusErrorString: Decimal?
     var minDelta: Decimal?
     var expectedDelta: Decimal?

+ 0 - 1
Trio/Sources/Modules/Treatments/TreatmentsStateModel.swift

@@ -875,7 +875,6 @@ extension Treatments.StateModel {
                     carbsReq: 0,
                     temp: nil,
                     reservoir: 0,
-                    insulinForManualBolus: 0,
                     manualBolusErrorString: 0,
                     carbRatio: 0,
                     received: false

+ 0 - 1
TrioTests/JSONImporterTests.swift

@@ -276,7 +276,6 @@ class BundleReference {}
         #expect(determination.reservoir == Decimal(string: "3735928559").map(NSDecimalNumber.init))
         #expect(determination.insulinSensitivity == Decimal(string: "4.6").map(NSDecimalNumber.init))
         #expect(determination.currentTarget == Decimal(string: "94").map(NSDecimalNumber.init))
-        #expect(determination.insulinForManualBolus == Decimal(string: "0.8").map(NSDecimalNumber.init))
         #expect(determination.manualBolusErrorString == Decimal(string: "0").map(NSDecimalNumber.init))
         #expect(determination.minDelta == NSDecimalNumber(5))
         #expect(determination.expectedDelta == Decimal(string: "-5.9").map(NSDecimalNumber.init))

+ 8 - 9
TrioTests/OpenAPSSwiftTests/DetermineBasalEarlyExitTests.swift

@@ -3,7 +3,7 @@ import Testing
 @testable import Trio
 
 @Suite("DetermineBasal early exits before core dosing logic") struct DetermineBasalEarlyExitTests {
-    private func createDefaultInputs() -> (
+    private func createDefaultInputs(currentTime: Date = Date()) -> (
         profile: Profile,
         preferences: Preferences,
         currentTemp: TempBasal,
@@ -15,7 +15,6 @@ import Testing
         trioCustomOrefVariables: TrioCustomOrefVariables,
         currentTime: Date
     ) {
-        let currentTime = Date()
         var profile = Profile()
         profile.maxIob = 2.5
         profile.dia = 3
@@ -470,7 +469,7 @@ import Testing
 
     // Test 9 from JS
     @Test("should low-temp if BG is below threshold") func lowGlucoseSuspend() throws {
-        var (
+        let (
             profile,
             preferences,
             currentTemp,
@@ -514,6 +513,11 @@ import Testing
 
     // Test 10 from JS
     @Test("should cancel temp before the hour if not doing SMB") func skipNeutralTemp() throws {
+        // Create a date that is 56 minutes past the hour
+        var components = Calendar.current.dateComponents(in: .current, from: Date())
+        components.minute = 56
+        let currentTime = Calendar.current.date(from: components)!
+
         var (
             profile,
             preferences,
@@ -525,15 +529,10 @@ import Testing
             glucoseStatus,
             trioCustomOrefVariables,
             _
-        ) = createDefaultInputs()
+        ) = createDefaultInputs(currentTime: currentTime)
 
         profile.skipNeutralTemps = true
 
-        // Create a date that is 56 minutes past the hour
-        var components = Calendar.current.dateComponents(in: .current, from: Date())
-        components.minute = 56
-        let currentTime = Calendar.current.date(from: components)!
-
         let result = try DeterminationGenerator.determineBasal(
             profile: profile,
             preferences: preferences,

+ 0 - 1
TrioTests/OpenAPSSwiftTests/DetermineBasalEnableSmbTests.swift

@@ -161,7 +161,6 @@ import Testing
         #expect(decision.isEnabled == false)
         #expect(decision.manualBolusError == 1)
         #expect(decision.minGuardGlucose == 65)
-        #expect(decision.insulinForManualBolus != nil)
     }
 
     @Test("Should disable SMB when maxDelta is too high") func disableWhenMaxDeltaTooHigh() throws {

+ 0 - 1
TrioTests/OpenAPSSwiftTests/SetTempBasalTests.swift

@@ -48,7 +48,6 @@ import Testing
             timestamp: Date(),
             tdd: nil,
             current_target: nil,
-            insulinForManualBolus: nil,
             manualBolusErrorString: nil,
             minDelta: nil,
             expectedDelta: nil,