From 9ff714ea2d645a239449e86073346531762c9f06 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 30 Apr 2017 21:27:40 +0200 Subject: [PATCH] try to fix cob graph --- .../IobCobCalculator/IobCobCalculatorPlugin.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 4941639528..f3316e4e9a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -352,11 +352,22 @@ public class IobCobCalculatorPlugin implements PluginBase { return iobTotal; } + private static Long findPreviousTimeFromBucketedData(long time) { + for (int index = 0; index < bucketed_data.size(); index++) { + if (bucketed_data.get(index).timeIndex < time) + return bucketed_data.get(index).timeIndex; + } + return null; + } + public static AutosensData getAutosensData(long time) { long now = new Date().getTime(); if (time > now) return null; - time = roundUpTime(time); + Long previous = findPreviousTimeFromBucketedData(time); + if (previous == null) + return null; + time = roundUpTime(previous); AutosensData data = autosensDataTable.get(time); if (data != null) { //log.debug(">>> Cache hit " + data.log(time));