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

Skip lastTemp completely, it's just too broken around suspends and resumes

Sam King 5 месяцев назад
Родитель
Сommit
aeb0cd2453

+ 13 - 4
Trio/Sources/APS/OpenAPSSwift/Logging/JSONCompare.swift

@@ -259,6 +259,7 @@ enum JSONCompare {
         var differences: [String: ValueDifference] = [:]
         var differences: [String: ValueDifference] = [:]
         let approximateKeys = function.approximateMatchingNumbers()
         let approximateKeys = function.approximateMatchingNumbers()
         let flexibleArrayKeys = function.flexibleArrayKeys()
         let flexibleArrayKeys = function.flexibleArrayKeys()
+        let propertiesToSkip = function.propertiesToSkip()
 
 
         // Check all keys present in either dictionary
         // Check all keys present in either dictionary
         Set(jsDict.keys).union(swiftDict.keys).forEach { key in
         Set(jsDict.keys).union(swiftDict.keys).forEach { key in
@@ -271,6 +272,7 @@ enum JSONCompare {
                 approximately: approximateKeys[key],
                 approximately: approximateKeys[key],
                 approximateKeys: approximateKeys,
                 approximateKeys: approximateKeys,
                 flexibleArrayKeys: flexibleArrayKeys,
                 flexibleArrayKeys: flexibleArrayKeys,
+                propertiesToSkip: propertiesToSkip,
                 currentPath: currentPath
                 currentPath: currentPath
             ) {
             ) {
                 differences[currentPath] = ValueDifference(
                 differences[currentPath] = ValueDifference(
@@ -317,6 +319,7 @@ enum JSONCompare {
         approximately: Double?,
         approximately: Double?,
         approximateKeys: [String: Double],
         approximateKeys: [String: Double],
         flexibleArrayKeys: [String],
         flexibleArrayKeys: [String],
+        propertiesToSkip: Set<String>,
         currentPath: String
         currentPath: String
     ) -> Bool {
     ) -> Bool {
         switch (value1, value2) {
         switch (value1, value2) {
@@ -341,22 +344,28 @@ enum JSONCompare {
                 return zip(a1.prefix(shortestCount), a2.prefix(shortestCount)).allSatisfy { v1, v2 in
                 return zip(a1.prefix(shortestCount), a2.prefix(shortestCount)).allSatisfy { v1, v2 in
                     valuesAreEqual(
                     valuesAreEqual(
                         v1, v2, approximately: approximately, approximateKeys: approximateKeys,
                         v1, v2, approximately: approximately, approximateKeys: approximateKeys,
-                        flexibleArrayKeys: flexibleArrayKeys, currentPath: currentPath
+                        flexibleArrayKeys: flexibleArrayKeys, propertiesToSkip: propertiesToSkip,
+                        currentPath: currentPath
                     )
                     )
                 }
                 }
             }
             }
             return a1.count == a2.count && zip(a1, a2).allSatisfy { v1, v2 in
             return a1.count == a2.count && zip(a1, a2).allSatisfy { v1, v2 in
                 valuesAreEqual(
                 valuesAreEqual(
                     v1, v2, approximately: approximately, approximateKeys: approximateKeys,
                     v1, v2, approximately: approximately, approximateKeys: approximateKeys,
-                    flexibleArrayKeys: flexibleArrayKeys, currentPath: currentPath
+                    flexibleArrayKeys: flexibleArrayKeys, propertiesToSkip: propertiesToSkip,
+                    currentPath: currentPath
                 )
                 )
             }
             }
         case let (.object(o1), .object(o2)):
         case let (.object(o1), .object(o2)):
-            return o1.keys == o2.keys && o1.keys.allSatisfy { key in
+            // Filter out properties that should be skipped during comparison
+            let keys1 = Set(o1.keys).subtracting(propertiesToSkip)
+            let keys2 = Set(o2.keys).subtracting(propertiesToSkip)
+            return keys1 == keys2 && keys1.allSatisfy { key in
                 guard let v1 = o1[key], let v2 = o2[key] else { return false }
                 guard let v1 = o1[key], let v2 = o2[key] else { return false }
                 return valuesAreEqual(
                 return valuesAreEqual(
                     v1, v2, approximately: approximateKeys[key], approximateKeys: approximateKeys,
                     v1, v2, approximately: approximateKeys[key], approximateKeys: approximateKeys,
-                    flexibleArrayKeys: flexibleArrayKeys, currentPath: "\(currentPath).\(key)"
+                    flexibleArrayKeys: flexibleArrayKeys, propertiesToSkip: propertiesToSkip,
+                    currentPath: "\(currentPath).\(key)"
                 )
                 )
             }
             }
         default:
         default:

+ 16 - 4
Trio/Sources/APS/OpenAPSSwift/Logging/OrefFunction.swift

@@ -92,10 +92,7 @@ enum OrefFunction: String, Codable {
                 "basaliob": 0.25,
                 "basaliob": 0.25,
                 "bolusiob": 0.25,
                 "bolusiob": 0.25,
                 "netbasalinsulin": 0.25,
                 "netbasalinsulin": 0.25,
-                "bolusinsulin": 0.25,
-                // Please see this issue for context on duration:
-                // https://github.com/nightscout/Trio-dev/issues/453
-                "duration": 120
+                "bolusinsulin": 0.25
             ]
             ]
         case .meal:
         case .meal:
             return [
             return [
@@ -147,4 +144,19 @@ enum OrefFunction: String, Codable {
             return []
             return []
         }
         }
     }
     }
+
+    /// Properties to skip during object comparison. Unlike keysToIgnore which filters
+    /// final differences, this skips properties during the recursive comparison itself.
+    /// This is needed for array return types where differences are recorded at the
+    /// element level rather than at individual property paths.
+    func propertiesToSkip() -> Set<String> {
+        switch self {
+        case .iob:
+            // Please see this issue for context on skipping lastTemp:
+            // https://github.com/nightscout/Trio-dev/issues/453
+            return Set(["lastTemp"])
+        default:
+            return Set()
+        }
+    }
 }
 }