Prechádzať zdrojové kódy

Include enableSMB in the testing JS output

Sam King 9 mesiacov pred
rodič
commit
090e22dcec

+ 2 - 0
Model/JSONImporter.swift

@@ -528,6 +528,7 @@ extension Determination: Codable {
         case carbRatio = "CR"
         case received
         case receivedAlt = "recieved"
+        case enableSMB
     }
 
     init(from decoder: Decoder) throws {
@@ -604,6 +605,7 @@ extension Determination: Codable {
         try container.encodeIfPresent(threshold, forKey: .threshold)
         try container.encodeIfPresent(carbRatio, forKey: .carbRatio)
         try container.encodeIfPresent(received, forKey: .received) // always encode the correct spelling
+        try container.encodeIfPresent(enableSMB, forKey: .enableSMB)
     }
 
     func checkForRequiredFields() throws {

+ 84 - 83
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasalGenerator.swift

@@ -101,50 +101,6 @@ enum DeterminationGenerator {
             trioCustomOrefVariables: trioCustomOrefVariables
         )
 
-        // Safety check: current temp vs. last temp in iob
-        guard let lastTempTarget = iobData.first?.lastTemp else {
-            throw DeterminationError.missingIob
-        }
-        if !checkCurrentTempBasalRateSafety(
-            currentTemp: currentTemp,
-            lastTempTarget: lastTempTarget,
-            currentTime: currentTime
-        ) {
-            let reason =
-                "Safety check: currentTemp does not match lastTemp in IOB or lastTemp ended long ago; canceling temp basal."
-            return Determination(
-                id: UUID(),
-                reason: reason,
-                units: nil,
-                insulinReq: nil,
-                eventualBG: nil,
-                sensitivityRatio: nil,
-                rate: 0,
-                duration: 0,
-                iob: iobData.first?.iob,
-                cob: nil,
-                predictions: nil,
-                deliverAt: currentTime,
-                carbsReq: nil,
-                temp: .absolute,
-                bg: glucoseStatus.glucose,
-                reservoir: nil,
-                isf: profile.sens,
-                timestamp: currentTime,
-                tdd: nil,
-                current_target: profile.targetBg,
-                insulinForManualBolus: nil,
-                manualBolusErrorString: nil,
-                minDelta: nil,
-                expectedDelta: nil,
-                minGuardBG: nil,
-                minPredBG: nil,
-                threshold: nil,
-                carbRatio: profile.carbRatio,
-                received: false
-            )
-        }
-
         let (adjustedGlucoseTargets, threshold) = adjustGlucoseTargets(
             profile: profile,
             autosens: autosensData,
@@ -271,52 +227,97 @@ enum DeterminationGenerator {
 
         // TODO: STOPPING at LINE 1264
 
-        // FIXME: properly populate all fields!
-        var temporaryResult = Determination(
-            id: UUID(),
-            reason: dosingInputs.reason,
-            units: nil,
-            insulinReq: nil,
-            eventualBG: Int(forecastResult.eventualGlucose),
-            sensitivityRatio: sensitivityRatio, // this would only the AS-adjusted one for now
-            rate: nil,
-            duration: nil,
-            iob: iobData.first?.iob,
-            cob: mealData.mealCOB,
-            predictions: Predictions(
-                iob: forecastResult.iob.map { Int($0.jsRounded()) },
-                zt: forecastResult.zt.map { Int($0.jsRounded()) },
-                cob: forecastResult.cob?.map { Int($0.jsRounded()) },
-                uam: forecastResult.uam?.map { Int($0.jsRounded()) }
-            ),
-            deliverAt: currentTime,
-            carbsReq: dosingInputs.carbsRequired?.carbs,
-            temp: nil,
-            bg: currentGlucose,
-            reservoir: nil,
-            isf: nil,
-            timestamp: currentTime,
-            tdd: nil,
-            current_target: nil,
-            insulinForManualBolus: nil,
-            manualBolusErrorString: nil,
-            minDelta: nil,
-            expectedDelta: expectedDelta,
-            minGuardBG: forecastResult.minGuardGlucose,
-            minPredBG: forecastResult.minForecastedGlucose,
-            threshold: threshold.jsRounded(),
-            carbRatio: forecastResult.adjustedCarbRatio.jsRounded(scale: 1),
-            received: false,
-        )
+        var determination: Determination
+        // Safety check: current temp vs. last temp in iob
+        guard let lastTempTarget = iobData.first?.lastTemp else {
+            throw DeterminationError.missingIob
+        }
+        if !checkCurrentTempBasalRateSafety(
+            currentTemp: currentTemp,
+            lastTempTarget: lastTempTarget,
+            currentTime: currentTime
+        ) {
+            let reason =
+                "Safety check: currentTemp does not match lastTemp in IOB or lastTemp ended long ago; canceling temp basal."
+            determination = Determination(
+                id: UUID(),
+                reason: reason,
+                units: nil,
+                insulinReq: nil,
+                eventualBG: nil,
+                sensitivityRatio: nil,
+                rate: 0,
+                duration: 0,
+                iob: iobData.first?.iob,
+                cob: nil,
+                predictions: nil,
+                deliverAt: currentTime,
+                carbsReq: nil,
+                temp: .absolute,
+                bg: glucoseStatus.glucose,
+                reservoir: nil,
+                isf: profile.sens,
+                timestamp: currentTime,
+                tdd: nil,
+                current_target: profile.targetBg,
+                insulinForManualBolus: nil,
+                manualBolusErrorString: nil,
+                minDelta: nil,
+                expectedDelta: nil,
+                minGuardBG: nil,
+                minPredBG: nil,
+                threshold: nil,
+                carbRatio: profile.carbRatio,
+                received: false
+            )
+        } else {
+            // FIXME: properly populate all fields!
+            determination = Determination(
+                id: UUID(),
+                reason: dosingInputs.reason,
+                units: nil,
+                insulinReq: nil,
+                eventualBG: Int(forecastResult.eventualGlucose),
+                sensitivityRatio: sensitivityRatio, // this would only the AS-adjusted one for now
+                rate: nil,
+                duration: nil,
+                iob: iobData.first?.iob,
+                cob: mealData.mealCOB,
+                predictions: Predictions(
+                    iob: forecastResult.iob.map { Int($0.jsRounded()) },
+                    zt: forecastResult.zt.map { Int($0.jsRounded()) },
+                    cob: forecastResult.cob?.map { Int($0.jsRounded()) },
+                    uam: forecastResult.uam?.map { Int($0.jsRounded()) }
+                ),
+                deliverAt: currentTime,
+                carbsReq: dosingInputs.carbsRequired?.carbs,
+                temp: nil,
+                bg: currentGlucose,
+                reservoir: nil,
+                isf: nil,
+                timestamp: currentTime,
+                tdd: nil,
+                current_target: nil,
+                insulinForManualBolus: nil,
+                manualBolusErrorString: nil,
+                minDelta: nil,
+                expectedDelta: expectedDelta,
+                minGuardBG: forecastResult.minGuardGlucose,
+                minPredBG: forecastResult.minForecastedGlucose,
+                threshold: threshold.jsRounded(),
+                carbRatio: forecastResult.adjustedCarbRatio.jsRounded(scale: 1),
+                received: false,
+            )
+        }
 
         if includeDebugOutputs {
-            temporaryResult.enableSMB = smbDecision.isEnabled
+            determination.enableSMB = smbDecision.isEnabled
         }
 
         // TODO: how to handle output?
         // TODO: how to handle logging?
 
-        return temporaryResult
+        return determination
     }
 
     static func checkDeterminationInputs(

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

@@ -77,6 +77,7 @@ extension Determination {
         case threshold
         case carbRatio = "CR"
         case received
+        case enableSMB
     }
 }
 

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 1 - 1
TrioTests/OpenAPSSwiftTests/javascript/bundle/determine-basal.js