Explorar el Código

Fix rounding for special case in insulinRequired calc

Sam King hace 5 meses
padre
commit
10f0fd084e

+ 3 - 1
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DosingEngine.swift

@@ -687,7 +687,9 @@ enum DosingEngine {
 
         if insulinRequired > maxIob - currentIob {
             newDetermination.reason += "max_iob \(maxIob), "
-            insulinRequired = (maxIob - currentIob).jsRounded(scale: 2)
+            // Important: on this path insulinRequired gets rounded
+            // to three decimal places, not 2 like on the default path
+            insulinRequired = (maxIob - currentIob).jsRounded(scale: 3)
         }
         newDetermination.insulinReq = insulinRequired
         return (insulinRequired, newDetermination)

+ 1 - 1
TrioTests/OpenAPSSwiftTests/DetermineBasalJsonTests.swift

@@ -103,7 +103,7 @@ import Testing
         // this test is meant for one-off analysis so it's ok to hard code
         // a file, just make sure to _not_ check in updates to this to
         // avoid polluting our change logs
-        let algorithmComparison = try await HttpFiles.downloadFile(at: "/files/711a7571-ab38-4b36-ab6a-6edbec3fc54f.3.json")
+        let algorithmComparison = try await HttpFiles.downloadFile(at: "/files/795a9cf2-3d83-4f82-9dae-0035ed266da4.1.json")
         let determineBasalInput = algorithmComparison.determineBasalInput!
 
         let encoder = JSONCoding.encoder