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. 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..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 @@ -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; } @@ -377,18 +378,20 @@ public class IobCobCalculatorPlugin extends PluginBase { public AutosensData getAutosensData(long time) { 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()); 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 f6d5a4ef2a..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 @@ -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(); @@ -67,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();