From 5422a8bc202e7262798701011947ff342faa0c5d Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Tue, 3 Jul 2018 22:10:33 +0200 Subject: [PATCH 1/4] Cleanup Imports, added a TODO --- .../androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java index f6d5a4ef2a..8c20e2f295 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java @@ -53,6 +53,8 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { @Override public AutosensResult detectSensitivity(long fromTime, long toTime) { + // todo this method is called from the IobCobCalculatorPlugin, which leads to a circular + // dependency, this should be avoided LongSparseArray autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); Profile profile = MainApp.getConfigBuilder().getProfile(); From a978225428b014f8f312cfd4776cb8beee2df5ac Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Tue, 3 Jul 2018 22:11:01 +0200 Subject: [PATCH 2/4] Cleanup Imports --- .../androidaps/interfaces/SensitivityInterface.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java index 25dab4494b..81af28eaa4 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java @@ -1,18 +1,6 @@ package info.nightscout.androidaps.interfaces; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; -import info.nightscout.utils.Round; -import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; /** * Created by mike on 24.06.2017. From c78117e356880c6420f8d753398e47d86cddb64b Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Tue, 3 Jul 2018 22:35:06 +0200 Subject: [PATCH 3/4] recall getAutosensData, if it is null --- .../IobCobCalculatorPlugin.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) 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 d6fc244eef..25c34e7f43 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 @@ -39,6 +39,7 @@ import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; +import info.nightscout.utils.T; import static info.nightscout.utils.DateUtil.now; @@ -131,8 +132,8 @@ public class IobCobCalculatorPlugin extends PluginBase { public static long roundUpTime(long time) { if (time % 60000 == 0) return time; - long rouded = (time / 60000 + 1) * 60000; - return rouded; + long rounded = (time / 60000 + 1) * 60000; + return rounded; } void loadBgData(long start) { @@ -293,7 +294,7 @@ public class IobCobCalculatorPlugin extends PluginBase { long now = System.currentTimeMillis(); long oldestDataAvailable = TreatmentsPlugin.getPlugin().oldestDataAvailable(); - long getBGDataFrom = Math.max(oldestDataAvailable, (long) (now - 60 * 60 * 1000L * (24 + MainApp.getConfigBuilder().getProfile().getDia()))); + long getBGDataFrom = Math.max(oldestDataAvailable, (long) (now - T.hours(1).msecs() * (24 + MainApp.getConfigBuilder().getProfile().getDia()))); log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); return getBGDataFrom; } @@ -375,20 +376,31 @@ public class IobCobCalculatorPlugin extends PluginBase { @Nullable public AutosensData getAutosensData(long time) { + return this.getAutosensData(time, true); + } + + // just a dirty workaround to avoid problems using a too fresh time + // should get reworked... + private AutosensData getAutosensData(long time, boolean firstCall) { synchronized (dataLock) { long now = System.currentTimeMillis(); - if (time > now) + if (time > now) { return null; + } Long previous = findPreviousTimeFromBucketedData(time); - if (previous == null) + if (previous == null) { return null; + } time = roundUpTime(previous); AutosensData data = autosensDataTable.get(time); if (data != null) { //log.debug(">>> getAutosensData Cache hit " + data.log(time)); return data; } else { - //log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString()); +// log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString()); + if (firstCall) { + return this.getAutosensData(time - T.mins(5).msecs(), false); + } return null; } } From afaf729df10926d1299a1f83b61b9e2e7bbc9fbf Mon Sep 17 00:00:00 2001 From: "Markus M. May" Date: Wed, 4 Jul 2018 20:42:31 +0200 Subject: [PATCH 4/4] Try to rework the ugly fix --- .../plugins/IobCobCalculator/IobCobCalculatorPlugin.java | 9 --------- .../plugins/Sensitivity/SensitivityOref1Plugin.java | 4 +++- 2 files changed, 3 insertions(+), 10 deletions(-) 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 25c34e7f43..3f2cac2c1b 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 @@ -376,12 +376,6 @@ public class IobCobCalculatorPlugin extends PluginBase { @Nullable public AutosensData getAutosensData(long time) { - return this.getAutosensData(time, true); - } - - // just a dirty workaround to avoid problems using a too fresh time - // should get reworked... - private AutosensData getAutosensData(long time, boolean firstCall) { synchronized (dataLock) { long now = System.currentTimeMillis(); if (time > now) { @@ -398,9 +392,6 @@ public class IobCobCalculatorPlugin extends PluginBase { return data; } else { // log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString()); - if (firstCall) { - return this.getAutosensData(time - T.mins(5).msecs(), false); - } return null; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java index 8c20e2f295..ef220a6730 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java @@ -69,7 +69,9 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { return new AutosensResult(); } - AutosensData current = IobCobCalculatorPlugin.getPlugin().getAutosensData(toTime); // this is running inside lock already + // the current + AutosensData current = IobCobCalculatorPlugin.getPlugin() + .getLastAutosensDataSynchronized("SensitivityOref1Plugin"); // this is running inside lock already if (current == null) { log.debug("No current autosens data available"); return new AutosensResult();