Merge pull request #934 from MilosKozak/future-iob-array

For review: Future iob array
This commit is contained in:
Milos Kozak 2018-04-27 10:52:21 +02:00 committed by GitHub
commit 584b0f7824
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View file

@ -312,7 +312,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
//log.debug(">>> calculateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString()); //log.debug(">>> calculateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString());
} }
IobTotal bolusIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTreatments(time).round(); IobTotal bolusIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTreatments(time).round();
IobTotal basalIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTempBasals(time, profile).round(); IobTotal basalIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTempBasals(time, profile, true, now).round();
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) { if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) {
// Add expected zero temp basal for next 240 mins // Add expected zero temp basal for next 240 mins
IobTotal basalIobWithZeroTemp = basalIob.copy(); IobTotal basalIobWithZeroTemp = basalIob.copy();

View file

@ -338,12 +338,24 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
@Override @Override
public IobTotal getCalculationToTimeTempBasals(long time, Profile profile) { public IobTotal getCalculationToTimeTempBasals(long time, Profile profile) {
return getCalculationToTimeTempBasals(time, profile, false, 0);
}
public IobTotal getCalculationToTimeTempBasals(long time, Profile profile, boolean truncate, long truncateTime) {
IobTotal total = new IobTotal(time); IobTotal total = new IobTotal(time);
synchronized (tempBasals) { synchronized (tempBasals) {
for (Integer pos = 0; pos < tempBasals.size(); pos++) { for (Integer pos = 0; pos < tempBasals.size(); pos++) {
TemporaryBasal t = tempBasals.get(pos); TemporaryBasal t = tempBasals.get(pos);
if (t.date > time) continue; if (t.date > time) continue;
IobTotal calc = t.iobCalc(time, profile); IobTotal calc;
if(truncate && t.end() > truncateTime){
TemporaryBasal dummyTemp = new TemporaryBasal();
dummyTemp.copyFrom(t);
dummyTemp.cutEndTo(truncateTime);
calc = dummyTemp.iobCalc(time, profile);
} else {
calc = t.iobCalc(time, profile);
}
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob); //log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
total.plus(calc); total.plus(calc);
} }
@ -354,7 +366,15 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) { for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
ExtendedBolus e = extendedBoluses.get(pos); ExtendedBolus e = extendedBoluses.get(pos);
if (e.date > time) continue; if (e.date > time) continue;
IobTotal calc = e.iobCalc(time); IobTotal calc;
if(truncate && e.end() > truncateTime){
ExtendedBolus dummyExt = new ExtendedBolus();
dummyExt.copyFrom(e);
dummyExt.cutEndTo(truncateTime);
calc = dummyExt.iobCalc(time);
} else {
calc = e.iobCalc(time);
}
totalExt.plus(calc); totalExt.plus(calc);
} }
} }