- added methods to return correct Extended bolus size

- using exetended bolus size
This commit is contained in:
Andy Rozman 2018-08-30 16:22:25 +01:00
parent c167728935
commit 679b4b2668
3 changed files with 47 additions and 39 deletions

View file

@ -23,7 +23,7 @@ public class DoseSettings {
public DoseSettings(float step, int durationStep, int maxDuration, float minDose)
{
this(step, durationStep, maxDuration, minDose, null);
this(step, durationStep, maxDuration, minDose, Float.MAX_VALUE);
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.PumpCommon.utils;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpCommon.data.DoseSettings;
import info.nightscout.androidaps.plugins.PumpCommon.defs.DoseStepSize;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpCapability;
import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpTempBasalType;
@ -12,64 +13,73 @@ import info.nightscout.androidaps.plugins.PumpCommon.defs.PumpType;
public class PumpUtil {
public static double determineCorrectBolusSize(double bolusAmount, PumpType pumpType)
{
if (bolusAmount == 0.0d || pumpType==null)
{
public static double determineCorrectBolusSize(double bolusAmount, PumpType pumpType) {
if (bolusAmount == 0.0d || pumpType == null) {
return bolusAmount;
}
double bolusStepSize;
if (pumpType.getSpecialBolusSize()==null)
{
if (pumpType.getSpecialBolusSize() == null) {
bolusStepSize = pumpType.getBolusSize();
}
else
{
} else {
DoseStepSize specialBolusSize = pumpType.getSpecialBolusSize();
bolusStepSize = specialBolusSize.getStepSizeForAmount((float)bolusAmount);
}
return Math.round(bolusAmount/bolusStepSize) * bolusStepSize;
return Math.round(bolusAmount / bolusStepSize) * bolusStepSize;
}
public static double determineCorrectBasalSize(Double basalAmount, PumpType pumpType)
{
if ( basalAmount == null || basalAmount == 0.0d || pumpType==null)
{
public static double determineCorrectExtendedBolusSize(double bolusAmount, PumpType pumpType) {
if (bolusAmount == 0.0d || pumpType == null) {
return bolusAmount;
}
double bolusStepSize;
if (pumpType.getExtendedBolusSettings() == null) { // this should be never null
return 0.0d;
}
DoseSettings extendedBolusSettings = pumpType.getExtendedBolusSettings();
bolusStepSize = extendedBolusSettings.getStep();
if (bolusAmount > extendedBolusSettings.getMaxDose()) {
bolusAmount = extendedBolusSettings.getMaxDose();
}
return Math.round(bolusAmount / bolusStepSize) * bolusStepSize;
}
public static double determineCorrectBasalSize(Double basalAmount, PumpType pumpType) {
if (basalAmount == null || basalAmount == 0.0d || pumpType == null) {
return basalAmount;
}
double basalStepSize;
if (pumpType.getBaseBasalSpecialSteps()==null)
{
if (pumpType.getBaseBasalSpecialSteps() == null) {
basalStepSize = pumpType.getBaseBasalStep();
}
else
{
} else {
DoseStepSize specialBolusSize = pumpType.getBaseBasalSpecialSteps();
basalStepSize = specialBolusSize.getStepSizeForAmount(basalAmount.floatValue());
}
if (basalAmount> pumpType.getTbrSettings().getMaxDose())
if (basalAmount > pumpType.getTbrSettings().getMaxDose())
basalAmount = pumpType.getTbrSettings().getMaxDose().doubleValue();
return Math.round(basalAmount/basalStepSize) * basalStepSize;
return Math.round(basalAmount / basalStepSize) * basalStepSize;
}
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType)
{
public static void setPumpDescription(PumpDescription pumpDescription, PumpType pumpType) {
// reset
pumpDescription.resetSettings();
@ -85,14 +95,11 @@ public class PumpUtil {
pumpDescription.isTempBasalCapable = pumpCapability.hasCapability(PumpCapability.TempBasal);
if (pumpType.getPumpTempBasalType()==PumpTempBasalType.Percent)
{
if (pumpType.getPumpTempBasalType() == PumpTempBasalType.Percent) {
pumpDescription.tempBasalStyle = PumpDescription.PERCENT;
pumpDescription.maxTempPercent = pumpType.getTbrSettings().getMaxDose().intValue();
pumpDescription.tempPercentStep = (int)pumpType.getTbrSettings().getStep();
}
else
{
} else {
pumpDescription.tempBasalStyle = PumpDescription.ABSOLUTE;
pumpDescription.maxTempAbsolute = pumpType.getTbrSettings().getMaxDose();
pumpDescription.tempAbsoluteStep = pumpType.getTbrSettings().getStep();
@ -101,8 +108,10 @@ public class PumpUtil {
pumpDescription.tempDurationStep = pumpType.getTbrSettings().getDurationStep();
pumpDescription.tempMaxDuration = pumpType.getTbrSettings().getMaxDuration();
pumpDescription.tempDurationStep15mAllowed = pumpType.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration15minAllowed);
pumpDescription.tempDurationStep30mAllowed = pumpType.getSpecialBasalDurations().hasCapability(PumpCapability.BasalRate_Duration30minAllowed);
pumpDescription.tempDurationStep15mAllowed = pumpType.getSpecialBasalDurations()
.hasCapability(PumpCapability.BasalRate_Duration15minAllowed);
pumpDescription.tempDurationStep30mAllowed = pumpType.getSpecialBasalDurations()
.hasCapability(PumpCapability.BasalRate_Duration30minAllowed);
pumpDescription.isSetBasalProfileCapable = pumpCapability.hasCapability(PumpCapability.BasalProfileSet);
pumpDescription.basalStep = pumpType.getBaseBasalStep();
@ -118,5 +127,4 @@ public class PumpUtil {
}
}

View file

@ -263,10 +263,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
@Override
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
if (this.pumpType!=null)
{
detailedBolusInfo.insulin = PumpUtil.determineCorrectBolusSize(detailedBolusInfo.insulin, this.pumpType);
}
detailedBolusInfo.insulin = PumpUtil.determineCorrectBolusSize(detailedBolusInfo.insulin, this.pumpType);
PumpEnactResult result = new PumpEnactResult();
result.success = true;
@ -362,6 +359,9 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
PumpEnactResult result = cancelExtendedBolus();
if (!result.success)
return result;
insulin = PumpUtil.determineCorrectExtendedBolusSize(insulin, this.pumpType);
ExtendedBolus extendedBolus = new ExtendedBolus();
extendedBolus.date = System.currentTimeMillis();
extendedBolus.insulin = insulin;