Explorar o código

Add logic to skip inputs if we hit a known IoB corner case

Sam King hai 5 meses
pai
achega
b6789c3fe6
Modificáronse 1 ficheiros con 21 adicións e 0 borrados
  1. 21 0
      TrioTests/OpenAPSSwiftTests/IobJsonTests.swift

+ 21 - 0
TrioTests/OpenAPSSwiftTests/IobJsonTests.swift

@@ -98,6 +98,27 @@ import Testing
             autosens: try JSONBridge.to(iobInputs.autosens)
         )
 
+        // In suspendedPrior mode (first suspend/resume event is a Resume), JS incorrectly
+        // returns pre-resume temp basals in lastTemp because history.js line 566 uses
+        // tempHistory instead of splitHistory. Swift correctly handles this case.
+        if case let .success(jsRawJson) = iobResultJavascript,
+           let jsIobEntries = try? JSONBridge.iobResult(from: jsRawJson),
+           let jsLastTempDate = jsIobEntries.first?.lastTemp?.date
+        {
+            let suspendResumeEvents = iobInputs.history
+                .filter { $0.type == .pumpSuspend || $0.type == .pumpResume }
+                .sorted { $0.timestamp < $1.timestamp }
+            if let firstEvent = suspendResumeEvents.first,
+               firstEvent.type == .pumpResume
+            {
+                let firstResumeTime = UInt64(firstEvent.timestamp.timeIntervalSince1970 * 1000)
+                if jsLastTempDate < firstResumeTime {
+                    print("Skipping, known issue with JS lastTemp in suspendedPrior mode")
+                    return
+                }
+            }
+        }
+
         let comparison = JSONCompare.createComparison(
             function: .iob,
             swift: iobResultSwift,