IOB: fix calculation for EB
This commit is contained in:
parent
52e3432132
commit
8bac468306
4 changed files with 21 additions and 10 deletions
|
@ -42,7 +42,6 @@ import info.nightscout.androidaps.interfaces.ActivePlugin;
|
|||
import info.nightscout.androidaps.interfaces.Config;
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit;
|
||||
import info.nightscout.androidaps.interfaces.IobCobCalculator;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.Profile;
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
|
|
|
@ -537,7 +537,11 @@ class IobCobCalculatorPlugin @Inject constructor(
|
|||
for (pos in extendedBoluses.indices) {
|
||||
val e = extendedBoluses[pos]
|
||||
if (e.timestamp > toTime) continue
|
||||
if (e.end > now) e.duration = now - e.timestamp
|
||||
if (e.end > now) {
|
||||
val newDuration = now - e.timestamp
|
||||
e.amount *= newDuration.toDouble() / e.duration
|
||||
e.duration = newDuration
|
||||
}
|
||||
val profile = profileFunction.getProfile(e.timestamp) ?: return total
|
||||
val calc = e.iobCalc(toTime, profile, activePlugin.activeInsulin)
|
||||
total.plus(calc)
|
||||
|
@ -632,7 +636,11 @@ class IobCobCalculatorPlugin @Inject constructor(
|
|||
val e = extendedBoluses[pos]
|
||||
if (e.timestamp > toTime) continue
|
||||
val profile = profileFunction.getProfile(e.timestamp) ?: continue
|
||||
if (e.end > now) e.duration = now - e.timestamp
|
||||
if (e.end > now) {
|
||||
val newDuration = now - e.timestamp
|
||||
e.amount *= newDuration.toDouble() / e.duration
|
||||
e.duration = newDuration
|
||||
}
|
||||
val calc = e.iobCalc(toTime, profile, activePlugin.activeInsulin)
|
||||
totalExt.plus(calc)
|
||||
}
|
||||
|
@ -667,7 +675,11 @@ class IobCobCalculatorPlugin @Inject constructor(
|
|||
val e = extendedBoluses[pos]
|
||||
if (e.timestamp > toTime) continue
|
||||
val profile = profileFunction.getProfile(e.timestamp) ?: continue
|
||||
if (e.end > now) e.duration = now - e.timestamp
|
||||
if (e.end > now) {
|
||||
val newDuration = now - e.timestamp
|
||||
e.amount *= newDuration.toDouble() / e.duration
|
||||
e.duration = newDuration
|
||||
}
|
||||
val calc = e.iobCalc(toTime, profile, lastAutosensResult, exercise_mode, half_basal_exercise_target, isTempTarget, activePlugin.activeInsulin)
|
||||
totalExt.plus(calc)
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ fun extendedBolusFromJson(jsonObject: JSONObject): ExtendedBolus? {
|
|||
val pumpSerial = JsonHelper.safeGetStringAllowNull(jsonObject, "pumpSerial", null)
|
||||
|
||||
if (timestamp == 0L) return null
|
||||
if (duration == 0L) return null
|
||||
if (duration == 0L && durationInMilliseconds == 0L) return null
|
||||
if (amount == 0.0) return null
|
||||
|
||||
return ExtendedBolus(
|
||||
|
@ -135,7 +135,7 @@ fun ExtendedBolus.iobCalc(time: Long, profile: Profile, insulinInterface: Insuli
|
|||
val dia = profile.dia
|
||||
val diaAgo = time - dia * 60 * 60 * 1000
|
||||
val aboutFiveMinIntervals = ceil(realDuration / 5.0).toInt()
|
||||
val spacing = realDuration / aboutFiveMinIntervals
|
||||
val spacing = realDuration / aboutFiveMinIntervals.toDouble()
|
||||
for (j in 0L until aboutFiveMinIntervals) {
|
||||
// find middle of the interval
|
||||
val calcDate = (timestamp + j * spacing * 60 * 1000 + 0.5 * spacing * 60 * 1000).toLong()
|
||||
|
|
|
@ -134,14 +134,14 @@ fun TemporaryBasal.toStringShort(): String =
|
|||
|
||||
fun TemporaryBasal.iobCalc(time: Long, profile: Profile, insulinInterface: Insulin): IobTotal {
|
||||
val result = IobTotal(time)
|
||||
val realDuration: Int = getPassedDurationToTimeInMinutes(time)
|
||||
val realDuration = getPassedDurationToTimeInMinutes(time)
|
||||
var netBasalAmount = 0.0
|
||||
if (realDuration > 0) {
|
||||
var netBasalRate: Double
|
||||
val dia = profile.dia
|
||||
val diaAgo = time - dia * 60 * 60 * 1000
|
||||
val aboutFiveMinIntervals = ceil(realDuration / 5.0).toInt()
|
||||
val tempBolusSpacing = (realDuration / aboutFiveMinIntervals).toDouble()
|
||||
val tempBolusSpacing = realDuration / aboutFiveMinIntervals.toDouble()
|
||||
for (j in 0L until aboutFiveMinIntervals) {
|
||||
// find middle of the interval
|
||||
val calcDate = (timestamp + j * tempBolusSpacing * 60 * 1000 + 0.5 * tempBolusSpacing * 60 * 1000).toLong()
|
||||
|
@ -175,7 +175,7 @@ fun TemporaryBasal.iobCalc(time: Long, profile: Profile, insulinInterface: Insul
|
|||
|
||||
fun TemporaryBasal.iobCalc(time: Long, profile: Profile, lastAutosensResult: AutosensResult, exercise_mode: Boolean, half_basal_exercise_target: Int, isTempTarget: Boolean, insulinInterface: Insulin): IobTotal {
|
||||
val result = IobTotal(time)
|
||||
val realDuration: Double = getPassedDurationToTimeInMinutes(time).toDouble()
|
||||
val realDuration = getPassedDurationToTimeInMinutes(time)
|
||||
var netBasalAmount = 0.0
|
||||
var sensitivityRatio = lastAutosensResult.ratio
|
||||
val normalTarget = 100.0
|
||||
|
@ -190,7 +190,7 @@ fun TemporaryBasal.iobCalc(time: Long, profile: Profile, lastAutosensResult: Aut
|
|||
val dia = profile.dia
|
||||
val diaAgo = time - dia * 60 * 60 * 1000
|
||||
val aboutFiveMinIntervals = ceil(realDuration / 5.0).toInt()
|
||||
val tempBolusSpacing = realDuration / aboutFiveMinIntervals
|
||||
val tempBolusSpacing = realDuration / aboutFiveMinIntervals.toDouble()
|
||||
for (j in 0L until aboutFiveMinIntervals) {
|
||||
// find middle of the interval
|
||||
val calcDate = (timestamp + j * tempBolusSpacing * 60 * 1000 + 0.5 * tempBolusSpacing * 60 * 1000).toLong()
|
||||
|
|
Loading…
Reference in a new issue