From 4fda6c4c4f564e08f475d0423d5f685b081c22fe Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 12 May 2019 10:52:25 +0200 Subject: [PATCH] fix basal rendering --- .../IobCobCalculatorPlugin.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java index 94b687b863..659af5ec56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java @@ -391,28 +391,30 @@ public class IobCobCalculatorPlugin extends PluginBase { } public BasalData getBasalData(Profile profile, long time) { - long now = System.currentTimeMillis(); - time = roundUpTime(time); - BasalData retval = basalDataTable.get(time); - if (retval == null) { - retval = new BasalData(); - TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(time); - retval.basal = profile.getBasal(time); - if (tb != null) { - retval.isTempBasalRunning = true; - retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time, profile); + synchronized (dataLock) { + long now = System.currentTimeMillis(); + time = roundUpTime(time); + BasalData retval = basalDataTable.get(time); + if (retval == null) { + retval = new BasalData(); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(time); + retval.basal = profile.getBasal(time); + if (tb != null) { + retval.isTempBasalRunning = true; + retval.tempBasalAbsolute = tb.tempBasalConvertedToAbsolute(time, profile); + } else { + retval.isTempBasalRunning = false; + retval.tempBasalAbsolute = retval.basal; + } + if (time < now) { + basalDataTable.append(time, retval); + } + //log.debug(">>> getBasalData Cache miss " + new Date(time).toLocaleString()); } else { - retval.isTempBasalRunning = false; - retval.tempBasalAbsolute = retval.basal; + //log.debug(">>> getBasalData Cache hit " + new Date(time).toLocaleString()); } - if (time < now) { - basalDataTable.append(time, retval); - } - //log.debug(">>> getBasalData Cache miss " + new Date(time).toLocaleString()); - } else { - //log.debug(">>> getBasalData Cache hit " + new Date(time).toLocaleString()); + return retval; } - return retval; } @Nullable