From e62397cd48e2854ece736cc1fd50c114a9de7992 Mon Sep 17 00:00:00 2001 From: Johan Degraeve Date: Wed, 29 Jan 2020 18:11:23 +0100 Subject: [PATCH] fix #68 calculation of diff with previous value not correct if readings less than 5 minutes apart Calculation of diff was taking the slope and then multiplied with 5 minutes. This seems not correct (strange nobody every noticed ?) Probably because originally this was written for Dexcom transmitters, which give a reading every 5 minutes. Although there too the diff is not correct if time difference > 5 minutes (10 minutes, 15, ...) This changes will give another diff value in home screen, speak reading, watch, notification, text in alert. Triggering of alerts is not impacted. --- xdrip/Core Data/classes/BgReading+CoreDataClass.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xdrip/Core Data/classes/BgReading+CoreDataClass.swift b/xdrip/Core Data/classes/BgReading+CoreDataClass.swift index 7575b3407..e6ed52ec0 100644 --- a/xdrip/Core Data/classes/BgReading+CoreDataClass.swift +++ b/xdrip/Core Data/classes/BgReading+CoreDataClass.swift @@ -169,7 +169,9 @@ public class BgReading: NSManagedObject { return "???"; } - let value = currentSlope(previousBgReading: previousBgReading) * 5 * 60 * 1000; + // delta value recalculated aligned with time difference between previous and this reading + let value = currentSlope(previousBgReading: previousBgReading) * timeStamp.timeIntervalSince(previousBgReading.timeStamp) * 1000; + if(abs(value) > 100){ // a delta > 100 will not happen with real BG values -> problematic sensor data return "ERR";