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 b6620b4e7c..2081e43929 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 @@ -312,7 +312,7 @@ public class IobCobCalculatorPlugin extends PluginBase { //log.debug(">>> calculateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString()); } IobTotal bolusIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTreatments(time).round(); - IobTotal basalIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTempBasals(time, profile).round(); + IobTotal basalIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTempBasals(time, profile, true, now).round(); if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) { // Add expected zero temp basal for next 240 mins IobTotal basalIobWithZeroTemp = basalIob.copy(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index e50c88456c..55129cdc7b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -338,12 +338,24 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public IobTotal getCalculationToTimeTempBasals(long time, Profile profile) { + return getCalculationToTimeTempBasals(time, profile, false, 0); + } + + public IobTotal getCalculationToTimeTempBasals(long time, Profile profile, boolean truncate, long truncateTime) { IobTotal total = new IobTotal(time); synchronized (tempBasals) { for (Integer pos = 0; pos < tempBasals.size(); pos++) { TemporaryBasal t = tempBasals.get(pos); if (t.date > time) continue; - IobTotal calc = t.iobCalc(time, profile); + IobTotal calc; + if(truncate && t.end() > truncateTime){ + TemporaryBasal dummyTemp = new TemporaryBasal(); + dummyTemp.copyFrom(t); + dummyTemp.cutEndTo(truncateTime); + calc = dummyTemp.iobCalc(time, profile); + } else { + calc = t.iobCalc(time, profile); + } //log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob); total.plus(calc); } @@ -354,7 +366,15 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface for (Integer pos = 0; pos < extendedBoluses.size(); pos++) { ExtendedBolus e = extendedBoluses.get(pos); if (e.date > time) continue; - IobTotal calc = e.iobCalc(time); + IobTotal calc; + if(truncate && e.end() > truncateTime){ + ExtendedBolus dummyExt = new ExtendedBolus(); + dummyExt.copyFrom(e); + dummyExt.cutEndTo(truncateTime); + calc = dummyExt.iobCalc(time); + } else { + calc = e.iobCalc(time); + } totalExt.plus(calc); } }