Sfoglia il codice sorgente

Merge pull request #454 from kingst/oref-swift-iob-bug

Ignore `lastTemp.duration` properties in IoB comparison for oref-swift
Deniz Cengiz 1 anno fa
parent
commit
eb72205d1d

+ 15 - 13
Trio/Sources/APS/OpenAPSSwift/Logging/AlgorithmComparison.swift

@@ -91,22 +91,12 @@ struct AlgorithmComparison: Codable {
     let swiftException: AlgorithmException?
     let comparisonError: AlgorithmException?
     let version: String?
+    let isSimulator: Bool?
+    let isDebugBuild: Bool?
 
     // Inputs for mismatches
     let iobInput: IobInputs?
 
-    #if targetEnvironment(simulator)
-        static let isSimulator = true
-    #else
-        static let isSimulator = false
-    #endif
-
-    #if DEBUG
-        static let isDebugBuild = true
-    #else
-        static let isDebugBuild = false
-    #endif
-
     init(
         function: OrefFunction,
         resultType: ComparisonResultType,
@@ -132,6 +122,18 @@ struct AlgorithmComparison: Codable {
         self.comparisonError = comparisonError
         iobInput = iobInputs
         timezone = TimeZone.current.identifier
-        version = "1"
+        version = "2"
+
+        #if targetEnvironment(simulator)
+            isSimulator = true
+        #else
+            isSimulator = false
+        #endif
+
+        #if DEBUG
+            isDebugBuild = true
+        #else
+            isDebugBuild = false
+        #endif
     }
 }

+ 3 - 1
Trio/Sources/APS/OpenAPSSwift/Logging/OrefFunction.swift

@@ -53,7 +53,9 @@ enum OrefFunction: String, Codable {
                 "bolusiob": 0.25,
                 "netbasalinsulin": 0.25,
                 "bolusinsulin": 0.25,
-                "duration": 0.1
+                // Please see this issue for context on duration:
+                // https://github.com/nightscout/Trio-dev/issues/453
+                "duration": 120
             ]
         }
     }

+ 5 - 5
TrioTests/OpenAPSSwiftTests/IobHistoryTests.swift

@@ -523,7 +523,7 @@ import Testing
         #expect(treatments.netInsulin().isWithin(0.01, of: 0.2))
     }
 
-    @Test("should produce -0.5 IoB") func zerosIoBAroundSuspend() async throws {
+    @Test("should produce -0.7 IoB") func zerosIoBAroundSuspend() async throws {
         let basalprofile = [
             BasalProfileEntry(
                 start: "00:00:00",
@@ -564,16 +564,16 @@ import Testing
         profile.maxDailyBasal = 0.65
         profile.suspendZerosIob = true
 
+        let autosens = Autosens(ratio: 1.4, newisf: 29)
+
         let treatments = try IobHistory.calcTempTreatments(
             history: pumpHistory,
             profile: profile,
             clock: now,
-            autosens: nil,
+            autosens: autosens,
             zeroTempDuration: nil
         )
 
-        let tempBasals = treatments.filter { $0.type == .tempBasal }
-        print(treatments)
-        #expect(treatments.netInsulin().isWithin(0.01, of: -0.5))
+        #expect(treatments.netInsulin().isWithin(0.01, of: -0.7))
     }
 }