Treat future IOB as if the current TBR was cancelled
This commit is contained in:
parent
5df59d8fe3
commit
9889d34512
2 changed files with 24 additions and 3 deletions
|
@ -312,7 +312,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
//log.debug(">>> calculateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString());
|
||||
}
|
||||
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)) {
|
||||
// Add expected zero temp basal for next 240 mins
|
||||
IobTotal basalIobWithZeroTemp = basalIob.copy();
|
||||
|
|
|
@ -338,12 +338,24 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
|
||||
@Override
|
||||
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);
|
||||
synchronized (tempBasals) {
|
||||
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
||||
TemporaryBasal t = tempBasals.get(pos);
|
||||
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);
|
||||
total.plus(calc);
|
||||
}
|
||||
|
@ -354,7 +366,16 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
||||
ExtendedBolus e = extendedBoluses.get(pos);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue