recall getAutosensData, if it is null
This commit is contained in:
parent
a978225428
commit
c78117e356
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -375,20 +376,31 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public AutosensData getAutosensData(long time) {
|
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) {
|
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) {
|
||||||
//log.debug(">>> getAutosensData Cache hit " + data.log(time));
|
//log.debug(">>> getAutosensData Cache hit " + data.log(time));
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} 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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue