From ebd449a21d5cf3ce87f51beb9b6e45b0f6029646 Mon Sep 17 00:00:00 2001 From: Paul Plant <37302780+paulplant@users.noreply.github.com> Date: Wed, 6 Apr 2022 09:53:09 +0200 Subject: [PATCH] Update GlucoseChartManager.swift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - treatmentEntry.date window opened by ±50ms to avoid not returning treatments by date due to the ChartPoint class introducing small rounding errors. --- xdrip/Managers/Charts/GlucoseChartManager.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xdrip/Managers/Charts/GlucoseChartManager.swift b/xdrip/Managers/Charts/GlucoseChartManager.swift index 8fd74b29..c02cf163 100644 --- a/xdrip/Managers/Charts/GlucoseChartManager.swift +++ b/xdrip/Managers/Charts/GlucoseChartManager.swift @@ -1250,7 +1250,8 @@ public class GlucoseChartManager { /// - returns: a double with the actual value for the treatment requested private func getTreatmentValueFromTimeStamp(treatmentDate: ChartAxisValueDate, treatmentType: TreatmentType, treatmentEntryAccessor: TreatmentEntryAccessor, on managedObjectContext: NSManagedObjectContext) -> Double { - let treatmentEntries = treatmentEntryAccessor.getTreatments(fromDate: treatmentDate.date, toDate: treatmentDate.date, on: managedObjectContext) + // We need to increase slightly the "window" that we are using to locate the treament. The ChartPoint class seems to slightly round the values which might result in not getting an exact match. ±1ms seems to work, but we'll leave it at ±50ms just to be sure. + let treatmentEntries = treatmentEntryAccessor.getTreatments(fromDate: Date(timeInterval: -0.05, since: treatmentDate.date), toDate: Date(timeInterval: 0.05, since: treatmentDate.date), on: managedObjectContext) // intialize the treatmentValue that we will return var treatmentValue: Double = 0