fix temp basal iob calculation
This commit is contained in:
parent
5ef034b4fc
commit
0aad00808c
2 changed files with 62 additions and 2 deletions
|
@ -20,7 +20,7 @@ public class IobTotal {
|
||||||
public Double hightempinsulin;
|
public Double hightempinsulin;
|
||||||
|
|
||||||
public Double netInsulin = 0d; // for calculations from temp basals only
|
public Double netInsulin = 0d; // for calculations from temp basals only
|
||||||
public Double netRatio = 0d; // for calculations from temp basals only
|
public Double netRatio = 0d; // net ratio at start of temp basal
|
||||||
|
|
||||||
long time;
|
long time;
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,64 @@ public class TempBasal {
|
||||||
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
||||||
|
|
||||||
|
if (profile == null)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
int realDuration = getDurationToTime(time);
|
||||||
|
Double netBasalAmount = 0d;
|
||||||
|
|
||||||
|
if (realDuration > 0) {
|
||||||
|
Double netBasalRate = 0d;
|
||||||
|
|
||||||
|
int aboutFiveMinIntervals = (int) Math.ceil(realDuration / 5d);
|
||||||
|
|
||||||
|
result.netRatio = netBasalRate;
|
||||||
|
|
||||||
|
double tempBolusSpacing = realDuration / aboutFiveMinIntervals;
|
||||||
|
for (Long j = 0L; j < aboutFiveMinIntervals; j++) {
|
||||||
|
// find middle of the interval
|
||||||
|
Long date = (long) (timeStart.getTime() + j * tempBolusSpacing * 60 * 1000 + 0.5d * tempBolusSpacing * 60 * 1000);
|
||||||
|
|
||||||
|
Double basalRate = profile.getBasal(NSProfile.secondsFromMidnight(date));
|
||||||
|
if (isExtended) {
|
||||||
|
netBasalRate = this.absolute;
|
||||||
|
} else {
|
||||||
|
if (this.isAbsolute) {
|
||||||
|
netBasalRate = this.absolute - basalRate;
|
||||||
|
} else {
|
||||||
|
netBasalRate = (this.percent - 100) / 100d * basalRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double tempBolusSize = netBasalRate * tempBolusSpacing / 60d;
|
||||||
|
netBasalAmount += tempBolusSize;
|
||||||
|
|
||||||
|
Treatment tempBolusPart = new Treatment(insulinInterface);
|
||||||
|
tempBolusPart.insulin = tempBolusSize;
|
||||||
|
tempBolusPart.created_at = new Date(date);
|
||||||
|
|
||||||
|
Iob aIOB = insulinInterface.iobCalc(tempBolusPart, time, profile.getDia());
|
||||||
|
result.basaliob += aIOB.iobContrib;
|
||||||
|
result.activity += aIOB.activityContrib;
|
||||||
|
Double dia_ago = time - profile.getDia() * 60 * 60 * 1000;
|
||||||
|
if (date > dia_ago && date <= time) {
|
||||||
|
result.netbasalinsulin += tempBolusPart.insulin;
|
||||||
|
if (tempBolusPart.insulin > 0) {
|
||||||
|
result.hightempinsulin += tempBolusPart.insulin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.netInsulin = netBasalAmount;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public IobTotal old_iobCalc(long time) {
|
||||||
|
IobTotal result = new IobTotal(time);
|
||||||
|
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||||
|
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
||||||
|
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
@ -116,6 +174,7 @@ public class TempBasal {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Determine end of basal
|
// Determine end of basal
|
||||||
public long getTimeEnd() {
|
public long getTimeEnd() {
|
||||||
|
@ -184,7 +243,8 @@ public class TempBasal {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// closed end
|
// closed end
|
||||||
if (timeStart.getTime() < time.getTime() && timeEnd.getTime() > time.getTime()) return true; // in interval
|
if (timeStart.getTime() < time.getTime() && timeEnd.getTime() > time.getTime())
|
||||||
|
return true; // in interval
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue