From 1b385c10e3c7b9e07dfb0794e3dea3a08fa9b680 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 17 Jan 2017 16:19:34 +0100 Subject: [PATCH] fix iob calculation in the past --- .../androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 2 +- .../androidaps/plugins/TempBasals/TempBasalsPlugin.java | 1 + .../androidaps/plugins/Treatments/TreatmentsPlugin.java | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index 8255174f5a..1773adeae7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -184,8 +184,8 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTempBasals().oldestDataAvaialable(); - log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); List bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia()))), false); + log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString() + " (" + bgReadings.size() + " records)"); AutosensResult autosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime()); determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java index ec2dbe408e..8ffc049d83 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsPlugin.java @@ -173,6 +173,7 @@ public class TempBasalsPlugin implements PluginBase, TempBasalsInterface { IobTotal total = new IobTotal(time); for (Integer pos = 0; pos < tempBasals.size(); pos++) { TempBasal t = tempBasals.get(pos); + if (t.timeStart.getTime() > time) continue; IobTotal calc = t.iobCalc(now); total.plus(calc); } 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 91ebbc2e6a..debf697402 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 @@ -123,6 +123,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { Date now = new Date(time); for (Integer pos = 0; pos < treatments.size(); pos++) { Treatment t = treatments.get(pos); + if (t.created_at.getTime() > time) continue; Iob tIOB = t.iobCalc(now, dia); total.iob += tIOB.iobContrib; total.activity += tIOB.activityContrib;