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));