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

Add rounding to getGlucoseStatus to match JS

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

+ 1 - 1
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasal+Helpers.swift

@@ -57,7 +57,7 @@ extension DeterminationGenerator {
             // only use readings >38 mg/dL (to skip code values, <39)
             guard entry.glucose > 38 else { continue }
 
-            let minutesAgo = mostRecentGlucoseDate.timeIntervalSince(entry.date) / 60
+            let minutesAgo = (mostRecentGlucoseDate.timeIntervalSince(entry.date) / 60).rounded()
             guard minutesAgo != 0 else { continue }
             // compute mg/dL per 5 m as a Decimal:
             let change = Decimal(mostRecentGlucoseReading - entry.glucose)

+ 1 - 1
Trio/Sources/APS/OpenAPSSwift/DetermineBasal/DetermineBasalGenerator.swift

@@ -151,7 +151,7 @@ enum DeterminationGenerator {
             withZeroTemp: true
         )
 
-        guard let currentGlucoseImpact = glucoseImpactSeries.first else {
+        guard let currentGlucoseImpact = glucoseImpactSeries.first?.rounded(scale: 2) else {
             throw DeterminationError.determinationError
         }
 

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

@@ -72,7 +72,10 @@ enum OrefFunction: String, Codable {
                 // in Swift but not in JS
                 "timestamp",
                 "minGuardBG",
-                "minPredBG"
+                "minPredBG",
+                // We haven't implemented DynamicISF support for forecasting yet
+                "predBGs",
+                "eventualBG"
             ])
         }
     }

+ 2 - 2
TrioTests/OpenAPSSwiftTests/DetermineBasalJsonTests.swift

@@ -97,13 +97,13 @@ import Testing
         #expect(comparison.resultType == .matching)
     }
 
-    @Test("Format determineBasal inputs for running in JS", .enabled(if: false)) func formatInputs() async throws {
+    @Test("Format determineBasal inputs for running in JS", .enabled(if: true)) func formatInputs() async throws {
         let openAps = OpenAPSFixed()
 
         // 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/f1d04efa-c39b-4f0a-9955-65ab663ff9fb.0.json")
+        let algorithmComparison = try await HttpFiles.downloadFile(at: "/files/0341b91d-c75b-462b-b5a1-5aee9e973bc8.1.json")
         let determineBasalInput = algorithmComparison.determineBasalInput!
 
         let encoder = JSONCoding.encoder