Просмотр исходного кода

Merge pull request #568 from nightscout/oref-swift-meal-skip-pump-suspended-tests

Fix inconsistency with determineBasal + skip meal tests when pump is suspended
Deniz Cengiz 10 месяцев назад
Родитель
Сommit
7d0713876a

+ 7 - 5
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasal+Helpers.swift

@@ -286,18 +286,20 @@ extension DeterminationGenerator {
               let lastTempDuration = lastTemp.duration else { return true }
         // TODO: throw error for malformed IobResult? Can this be malformed?
 
-        let lastTempAge = Int(currentTime.timeIntervalSince(lastTempDate) / 60) // in minutes
+        let lastTempAge = Int((currentTime.timeIntervalSince(lastTempDate) / 60).rounded()) // in minutes
 //        let tempModulus = Int(lastTempAge + currentTemp.duration) % 30 // only used in JS as output; will leave it here for now
 
         if currentTemp.rate != lastTemp.rate, lastTempAge > 10, currentTemp.duration > 0 {
             // Rates don’t match and temp is old: cancel temp
             return false
         }
-        let lastTempEnded = lastTempAge - Int(lastTempDuration) // TODO: check if this comes in minutes
+        if currentTemp.duration > 0 {
+            let lastTempEnded = lastTempAge - Int(lastTempDuration) // TODO: check if this comes in minutes
 
-        if lastTempEnded > 5, lastTempAge > 10 {
-            // Last temp ended long ago but temp is running: cancel temp
-            return false
+            if lastTempEnded > 5, lastTempAge > 10 {
+                // Last temp ended long ago but temp is running: cancel temp
+                return false
+            }
         }
 
         return true

+ 11 - 1
TrioTests/OpenAPSSwiftTests/MealJsonTests.swift

@@ -32,8 +32,18 @@ import Testing
                 continue
             }
 
-            timeZoneForTests.setTimezone(identifier: algorithmComparison.timezone)
+            // The JS implementation of IoB when the pump is suspend is so fundamentally
+            // broken that I wasn't able to fix it in JS. So we'll just skip these, but I
+            // verified them by hand and the Swift implementation appears to be correct
+            if let mostRecentPumpEvent = mealInputs.pumpHistory.filter({ $0.isExternal != true }).first {
+                if mostRecentPumpEvent.type == .pumpSuspend
+                {
+                    print("Skipping, known issue with JS and currently suspended pumps")
+                    continue
+                }
+            }
 
+            timeZoneForTests.setTimezone(identifier: algorithmComparison.timezone)
             try await checkFixedJsAgainstSwift(mealInputs: mealInputs)
             print("Checked \(filePath) \(algorithmComparison.timezone)")
             timeZoneForTests.resetTimezone()