synchronize interval access from other classes
This commit is contained in:
parent
123b171f58
commit
42263e979e
|
@ -188,11 +188,13 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses())
|
if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses())
|
||||||
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
synchronized (extendedBoluses) {
|
||||||
ExtendedBolus e = extendedBoluses.get(pos);
|
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
||||||
if (e.date > time) continue;
|
ExtendedBolus e = extendedBoluses.get(pos);
|
||||||
IobTotal calc = e.iobCalc(time);
|
if (e.date > time) continue;
|
||||||
total.plus(calc);
|
IobTotal calc = e.iobCalc(time);
|
||||||
|
total.plus(calc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
@ -292,20 +294,24 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
@Override
|
@Override
|
||||||
public IobTotal getCalculationToTimeTempBasals(long time) {
|
public IobTotal getCalculationToTimeTempBasals(long time) {
|
||||||
IobTotal total = new IobTotal(time);
|
IobTotal total = new IobTotal(time);
|
||||||
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
synchronized (tempBasals) {
|
||||||
TemporaryBasal t = tempBasals.get(pos);
|
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
||||||
if (t.date > time) continue;
|
TemporaryBasal t = tempBasals.get(pos);
|
||||||
IobTotal calc = t.iobCalc(time);
|
if (t.date > time) continue;
|
||||||
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
|
IobTotal calc = t.iobCalc(time);
|
||||||
total.plus(calc);
|
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
|
||||||
|
total.plus(calc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
||||||
IobTotal totalExt = new IobTotal(time);
|
IobTotal totalExt = new IobTotal(time);
|
||||||
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
synchronized (extendedBoluses) {
|
||||||
ExtendedBolus e = extendedBoluses.get(pos);
|
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
||||||
if (e.date > time) continue;
|
ExtendedBolus e = extendedBoluses.get(pos);
|
||||||
IobTotal calc = e.iobCalc(time);
|
if (e.date > time) continue;
|
||||||
totalExt.plus(calc);
|
IobTotal calc = e.iobCalc(time);
|
||||||
|
totalExt.plus(calc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Convert to basal iob
|
// Convert to basal iob
|
||||||
totalExt.basaliob = totalExt.iob;
|
totalExt.basaliob = totalExt.iob;
|
||||||
|
@ -420,12 +426,18 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
@Override
|
@Override
|
||||||
public long oldestDataAvailable() {
|
public long oldestDataAvailable() {
|
||||||
long oldestTime = System.currentTimeMillis();
|
long oldestTime = System.currentTimeMillis();
|
||||||
if (tempBasals.size() > 0)
|
synchronized (tempBasals) {
|
||||||
oldestTime = Math.min(oldestTime, tempBasals.get(0).date);
|
if (tempBasals.size() > 0)
|
||||||
if (extendedBoluses.size() > 0)
|
oldestTime = Math.min(oldestTime, tempBasals.get(0).date);
|
||||||
oldestTime = Math.min(oldestTime, extendedBoluses.get(0).date);
|
}
|
||||||
if (treatments.size() > 0)
|
synchronized (extendedBoluses) {
|
||||||
oldestTime = Math.min(oldestTime, treatments.get(treatments.size() - 1).date);
|
if (extendedBoluses.size() > 0)
|
||||||
|
oldestTime = Math.min(oldestTime, extendedBoluses.get(0).date);
|
||||||
|
}
|
||||||
|
synchronized (treatments) {
|
||||||
|
if (treatments.size() > 0)
|
||||||
|
oldestTime = Math.min(oldestTime, treatments.get(treatments.size() - 1).date);
|
||||||
|
}
|
||||||
oldestTime -= 15 * 60 * 1000L; // allow 15 min before
|
oldestTime -= 15 * 60 * 1000L; // allow 15 min before
|
||||||
return oldestTime;
|
return oldestTime;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue