treat 100% TBR as temp off
This commit is contained in:
parent
ae399f0bf5
commit
0321d4cd07
5 changed files with 58 additions and 41 deletions
|
@ -21,7 +21,11 @@ class CommandTempBasalPercent(
|
||||||
@Inject lateinit var activePlugin: ActivePlugin
|
@Inject lateinit var activePlugin: ActivePlugin
|
||||||
|
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
val r = activePlugin.activePump.setTempBasalPercent(percent, durationInMinutes, profile, enforceNew, tbrType)
|
val r =
|
||||||
|
if (percent == 100)
|
||||||
|
activePlugin.activePump.cancelTempBasal(enforceNew)
|
||||||
|
else
|
||||||
|
activePlugin.activePump.setTempBasalPercent(percent, durationInMinutes, profile, enforceNew, tbrType)
|
||||||
aapsLogger.debug(LTag.PUMPQUEUE, "Result percent: $percent durationInMinutes: $durationInMinutes success: ${r.success} enacted: ${r.enacted}")
|
aapsLogger.debug(LTag.PUMPQUEUE, "Result percent: $percent durationInMinutes: $durationInMinutes success: ${r.success} enacted: ${r.enacted}")
|
||||||
callback?.result(r)?.run()
|
callback?.result(r)?.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,10 +157,22 @@ class DanaRKoreanPlugin @Inject constructor(
|
||||||
//This should not be needed while using queue because connection should be done before calling this
|
//This should not be needed while using queue because connection should be done before calling this
|
||||||
var result = PumpEnactResult(injector)
|
var result = PumpEnactResult(injector)
|
||||||
val absoluteRateAfterConstraint = constraintChecker.applyBasalConstraints(Constraint(absoluteRate), profile).value()
|
val absoluteRateAfterConstraint = constraintChecker.applyBasalConstraints(Constraint(absoluteRate), profile).value()
|
||||||
val doTempOff = baseBasalRate - absoluteRateAfterConstraint == 0.0 && absoluteRateAfterConstraint >= 0.10
|
var doTempOff = baseBasalRate - absoluteRateAfterConstraint == 0.0 && absoluteRateAfterConstraint >= 0.10
|
||||||
val doLowTemp = absoluteRateAfterConstraint < baseBasalRate || absoluteRateAfterConstraint < 0.10
|
val doLowTemp = absoluteRateAfterConstraint < baseBasalRate || absoluteRateAfterConstraint < 0.10
|
||||||
val doHighTemp = absoluteRateAfterConstraint > baseBasalRate && !useExtendedBoluses
|
val doHighTemp = absoluteRateAfterConstraint > baseBasalRate && !useExtendedBoluses
|
||||||
val doExtendedTemp = absoluteRateAfterConstraint > baseBasalRate && useExtendedBoluses
|
val doExtendedTemp = absoluteRateAfterConstraint > baseBasalRate && useExtendedBoluses
|
||||||
|
|
||||||
|
var percentRate: Int = java.lang.Double.valueOf(absoluteRateAfterConstraint / baseBasalRate * 100).toInt()
|
||||||
|
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
||||||
|
if (absoluteRateAfterConstraint < 0.10) percentRate = 0
|
||||||
|
percentRate = if (percentRate < 100) Round.ceilTo(percentRate.toDouble(), 10.0).toInt() else Round.floorTo(percentRate.toDouble(), 10.0).toInt()
|
||||||
|
if (percentRate > pumpDescription.maxTempPercent) {
|
||||||
|
percentRate = pumpDescription.maxTempPercent
|
||||||
|
}
|
||||||
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: $percentRate")
|
||||||
|
|
||||||
|
if (percentRate == 100) doTempOff = true
|
||||||
|
|
||||||
if (doTempOff) {
|
if (doTempOff) {
|
||||||
// If extended in progress
|
// If extended in progress
|
||||||
if (danaPump.isExtendedInProgress && useExtendedBoluses) {
|
if (danaPump.isExtendedInProgress && useExtendedBoluses) {
|
||||||
|
@ -177,15 +189,6 @@ class DanaRKoreanPlugin @Inject constructor(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
if (doLowTemp || doHighTemp) {
|
if (doLowTemp || doHighTemp) {
|
||||||
var percentRate: Int = java.lang.Double.valueOf(absoluteRateAfterConstraint / baseBasalRate * 100).toInt()
|
|
||||||
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
|
||||||
if (absoluteRateAfterConstraint < 0.10) percentRate = 0
|
|
||||||
percentRate = if (percentRate < 100) Round.ceilTo(percentRate.toDouble(), 10.0).toInt() else Round.floorTo(percentRate.toDouble(), 10.0).toInt()
|
|
||||||
if (percentRate > pumpDescription.maxTempPercent) {
|
|
||||||
percentRate = pumpDescription.maxTempPercent
|
|
||||||
}
|
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: $percentRate")
|
|
||||||
|
|
||||||
// If extended in progress
|
// If extended in progress
|
||||||
if (danaPump.isExtendedInProgress && useExtendedBoluses) {
|
if (danaPump.isExtendedInProgress && useExtendedBoluses) {
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)")
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)")
|
||||||
|
|
|
@ -225,10 +225,21 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||||
|
|
||||||
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d;
|
boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d;
|
||||||
final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d;
|
final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d;
|
||||||
final boolean doHighTemp = absoluteRate > getBaseBasalRate();
|
final boolean doHighTemp = absoluteRate > getBaseBasalRate();
|
||||||
|
|
||||||
|
int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
||||||
|
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
||||||
|
if (absoluteRate < 0.10d) percentRate = 0;
|
||||||
|
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
||||||
|
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
||||||
|
if (percentRate > 500) // Special high temp 500/15min
|
||||||
|
percentRate = 500;
|
||||||
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate);
|
||||||
|
|
||||||
|
if (percentRate == 100) doTempOff = true;
|
||||||
|
|
||||||
if (doTempOff) {
|
if (doTempOff) {
|
||||||
// If temp in progress
|
// If temp in progress
|
||||||
if (danaPump.isTempBasalInProgress()) {
|
if (danaPump.isTempBasalInProgress()) {
|
||||||
|
@ -241,13 +252,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doLowTemp || doHighTemp) {
|
if (doLowTemp || doHighTemp) {
|
||||||
int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
|
||||||
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
|
||||||
if (absoluteRate < 0.10d) percentRate = 0;
|
|
||||||
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
|
||||||
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
|
||||||
if (percentRate > 500) // Special high temp 500/15min
|
|
||||||
percentRate = 500;
|
|
||||||
// Check if some temp is already in progress
|
// Check if some temp is already in progress
|
||||||
if (danaPump.isTempBasalInProgress()) {
|
if (danaPump.isTempBasalInProgress()) {
|
||||||
// Correct basal already set ?
|
// Correct basal already set ?
|
||||||
|
|
|
@ -209,11 +209,23 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||||
|
|
||||||
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d;
|
boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d && absoluteRate >= 0.10d;
|
||||||
final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d;
|
final boolean doLowTemp = absoluteRate < getBaseBasalRate() || absoluteRate < 0.10d;
|
||||||
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
|
final boolean doHighTemp = absoluteRate > getBaseBasalRate() && !useExtendedBoluses;
|
||||||
final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses;
|
final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses;
|
||||||
|
|
||||||
|
int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
||||||
|
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
||||||
|
if (absoluteRate < 0.10d) percentRate = 0;
|
||||||
|
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
||||||
|
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
||||||
|
if (percentRate > getPumpDescription().getMaxTempPercent()) {
|
||||||
|
percentRate = getPumpDescription().getMaxTempPercent();
|
||||||
|
}
|
||||||
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate);
|
||||||
|
|
||||||
|
if (percentRate == 100) doTempOff = true;
|
||||||
|
|
||||||
if (doTempOff) {
|
if (doTempOff) {
|
||||||
// If extended in progress
|
// If extended in progress
|
||||||
if (danaPump.isExtendedInProgress() && useExtendedBoluses) {
|
if (danaPump.isExtendedInProgress() && useExtendedBoluses) {
|
||||||
|
@ -231,16 +243,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doLowTemp || doHighTemp) {
|
if (doLowTemp || doHighTemp) {
|
||||||
int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
|
||||||
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
|
||||||
if (absoluteRate < 0.10d) percentRate = 0;
|
|
||||||
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
|
||||||
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
|
||||||
if (percentRate > getPumpDescription().getMaxTempPercent()) {
|
|
||||||
percentRate = getPumpDescription().getMaxTempPercent();
|
|
||||||
}
|
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate);
|
|
||||||
|
|
||||||
// If extended in progress
|
// If extended in progress
|
||||||
if (danaPump.isExtendedInProgress() && useExtendedBoluses) {
|
if (danaPump.isExtendedInProgress() && useExtendedBoluses) {
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)");
|
||||||
|
|
|
@ -325,9 +325,23 @@ class DanaRSPlugin @Inject constructor(
|
||||||
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult {
|
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult {
|
||||||
var result = PumpEnactResult(injector)
|
var result = PumpEnactResult(injector)
|
||||||
val absoluteAfterConstrain = constraintChecker.applyBasalConstraints(Constraint(absoluteRate), profile).value()
|
val absoluteAfterConstrain = constraintChecker.applyBasalConstraints(Constraint(absoluteRate), profile).value()
|
||||||
val doTempOff = baseBasalRate - absoluteAfterConstrain == 0.0
|
var doTempOff = baseBasalRate - absoluteAfterConstrain == 0.0
|
||||||
val doLowTemp = absoluteAfterConstrain < baseBasalRate
|
val doLowTemp = absoluteAfterConstrain < baseBasalRate
|
||||||
val doHighTemp = absoluteAfterConstrain > baseBasalRate
|
val doHighTemp = absoluteAfterConstrain > baseBasalRate
|
||||||
|
|
||||||
|
var percentRate = 0
|
||||||
|
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
||||||
|
if (absoluteAfterConstrain >= 0.10) {
|
||||||
|
percentRate = java.lang.Double.valueOf(absoluteAfterConstrain / baseBasalRate * 100).toInt()
|
||||||
|
} else {
|
||||||
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Requested basal < 0.10u/h. Setting 0u/h (doLowTemp || doHighTemp)")
|
||||||
|
}
|
||||||
|
percentRate = if (percentRate < 100) Round.ceilTo(percentRate.toDouble(), 10.0).toInt() else Round.floorTo(percentRate.toDouble(), 10.0).toInt()
|
||||||
|
if (percentRate > 500) // Special high temp 500/15min
|
||||||
|
percentRate = 500
|
||||||
|
|
||||||
|
if (percentRate == 100) doTempOff = true
|
||||||
|
|
||||||
if (doTempOff) {
|
if (doTempOff) {
|
||||||
// If temp in progress
|
// If temp in progress
|
||||||
if (danaPump.isTempBasalInProgress) {
|
if (danaPump.isTempBasalInProgress) {
|
||||||
|
@ -343,16 +357,6 @@ class DanaRSPlugin @Inject constructor(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
if (doLowTemp || doHighTemp) {
|
if (doLowTemp || doHighTemp) {
|
||||||
var percentRate = 0
|
|
||||||
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
|
|
||||||
if (absoluteAfterConstrain >= 0.10) {
|
|
||||||
percentRate = java.lang.Double.valueOf(absoluteAfterConstrain / baseBasalRate * 100).toInt()
|
|
||||||
} else {
|
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Requested basal < 0.10u/h. Setting 0u/h (doLowTemp || doHighTemp)")
|
|
||||||
}
|
|
||||||
percentRate = if (percentRate < 100) Round.ceilTo(percentRate.toDouble(), 10.0).toInt() else Round.floorTo(percentRate.toDouble(), 10.0).toInt()
|
|
||||||
if (percentRate > 500) // Special high temp 500/15min
|
|
||||||
percentRate = 500
|
|
||||||
// Check if some temp is already in progress
|
// Check if some temp is already in progress
|
||||||
if (danaPump.isTempBasalInProgress) {
|
if (danaPump.isTempBasalInProgress) {
|
||||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: currently running")
|
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: currently running")
|
||||||
|
|
Loading…
Reference in a new issue