Merge pull request #1183 from triplem/autosens_fix

Autosens fix
This commit is contained in:
Milos Kozak 2018-07-11 17:30:29 +03:00 committed by GitHub
commit 613802b12c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 19 deletions

View file

@ -1,18 +1,6 @@
package info.nightscout.androidaps.interfaces; 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.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. * Created by mike on 24.06.2017.

View file

@ -39,6 +39,7 @@ import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin;
import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.T;
import static info.nightscout.utils.DateUtil.now; import static info.nightscout.utils.DateUtil.now;
@ -131,8 +132,8 @@ public class IobCobCalculatorPlugin extends PluginBase {
public static long roundUpTime(long time) { public static long roundUpTime(long time) {
if (time % 60000 == 0) if (time % 60000 == 0)
return time; return time;
long rouded = (time / 60000 + 1) * 60000; long rounded = (time / 60000 + 1) * 60000;
return rouded; return rounded;
} }
void loadBgData(long start) { void loadBgData(long start) {
@ -293,7 +294,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long oldestDataAvailable = TreatmentsPlugin.getPlugin().oldestDataAvailable(); 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()); log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());
return getBGDataFrom; return getBGDataFrom;
} }
@ -377,11 +378,13 @@ public class IobCobCalculatorPlugin extends PluginBase {
public AutosensData getAutosensData(long time) { public AutosensData getAutosensData(long time) {
synchronized (dataLock) { synchronized (dataLock) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (time > now) if (time > now) {
return null; return null;
}
Long previous = findPreviousTimeFromBucketedData(time); Long previous = findPreviousTimeFromBucketedData(time);
if (previous == null) if (previous == null) {
return null; return null;
}
time = roundUpTime(previous); time = roundUpTime(previous);
AutosensData data = autosensDataTable.get(time); AutosensData data = autosensDataTable.get(time);
if (data != null) { if (data != null) {

View file

@ -53,6 +53,8 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
@Override @Override
public AutosensResult detectSensitivity(long fromTime, long toTime) { 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<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable();
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
@ -67,7 +69,9 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
return new AutosensResult(); 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) { if (current == null) {
log.debug("No current autosens data available"); log.debug("No current autosens data available");
return new AutosensResult(); return new AutosensResult();