From 81ad4c54f3fb544ae3e856952e0751555b774f0e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 25 Jun 2018 22:20:00 +0200 Subject: [PATCH] fix bug when uncomplete autosens was stored to the cache --- .../plugins/IobCobCalculator/AutosensResult.java | 4 ++++ .../plugins/IobCobCalculator/IobCobOref1Thread.java | 3 ++- .../androidaps/plugins/IobCobCalculator/IobCobThread.java | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java index 4e0f8ef107..6602038fb4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensResult.java @@ -32,4 +32,8 @@ public class AutosensResult { return ret; } + @Override + public String toString() { + return json().toString(); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java index c140a3faa2..7289d901ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java @@ -332,7 +332,8 @@ public class IobCobOref1Thread extends Thread { autosensData.extraDeviation.add(0d); previous = autosensData; - autosensDataTable.put(bgTime, autosensData); + if (bgTime < now()) + autosensDataTable.put(bgTime, autosensData); if (Config.logAutosensData) log.debug("Running detectSensitivity from: " + DateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + DateUtil.dateAndTimeString(bgTime)); autosensData.autosensRatio = iobCobCalculatorPlugin.detectSensitivity(oldestTimeWithData, bgTime).ratio; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java index d43738d8ae..2ba476996f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java @@ -261,10 +261,14 @@ public class IobCobThread extends Thread { //log.debug("TIME: " + new Date(bgTime).toString() + " BG: " + bg + " SENS: " + sens + " DELTA: " + delta + " AVGDELTA: " + avgDelta + " IOB: " + iob.iob + " ACTIVITY: " + iob.activity + " BGI: " + bgi + " DEVIATION: " + deviation); previous = autosensData; - autosensDataTable.put(bgTime, autosensData); + if (bgTime < now()) + autosensDataTable.put(bgTime, autosensData); if (Config.logAutosensData) log.debug("Running detectSensitivity from: " + DateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + DateUtil.dateAndTimeString(bgTime)); - autosensData.autosensRatio = iobCobCalculatorPlugin.detectSensitivity(oldestTimeWithData, bgTime).ratio; + AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivity(oldestTimeWithData, bgTime); + if (Config.logAutosensData) + log.debug("Sensitivity result: " + sensitivity.toString()); + autosensData.autosensRatio = sensitivity.ratio; if (Config.logAutosensData) log.debug(autosensData.toString()); }