fix comparing bolus size granularity

This commit is contained in:
Milos Kozak 2019-06-21 11:41:50 +02:00
parent af0d4f23b1
commit 7b15cfb395
6 changed files with 74 additions and 121 deletions

View file

@ -13,10 +13,10 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
@ -196,7 +196,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (pump != null) { if (pump != null) {
double rounded = Round.roundTo(insulin.value(), pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulin.value())); double rounded = pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulin.value());
insulin.setIfDifferent(rounded, MainApp.gs(R.string.pumplimit), this); insulin.setIfDifferent(rounded, MainApp.gs(R.string.pumplimit), this);
} }
return insulin; return insulin;
@ -213,7 +213,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (pump != null) { if (pump != null) {
double rounded = Round.roundTo(insulin.value(), pump.getPumpDescription().pumpType.determineCorrectExtendedBolusSize(insulin.value())); double rounded = pump.getPumpDescription().pumpType.determineCorrectExtendedBolusSize(insulin.value());
insulin.setIfDifferent(rounded, MainApp.gs(R.string.pumplimit), this); insulin.setIfDifferent(rounded, MainApp.gs(R.string.pumplimit), this);
} }
return insulin; return insulin;

View file

@ -787,7 +787,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (wizard.getCalculatedTotalInsulin() > 0d && quickWizardEntry.carbs() > 0d) { if (wizard.getCalculatedTotalInsulin() > 0d && quickWizardEntry.carbs() > 0d) {
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(quickWizardEntry.carbs())).value(); Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(quickWizardEntry.carbs())).value();
if (Math.abs(wizard.getInsulinAfterConstraints() - wizard.getCalculatedTotalInsulin()) >= pump.getPumpDescription().pumpType.determineCorrectBolusSize(wizard.getInsulinAfterConstraints()) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) { if (Math.abs(wizard.getInsulinAfterConstraints() - wizard.getCalculatedTotalInsulin()) >= pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(wizard.getInsulinAfterConstraints()) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
OKDialog.show(getContext(), MainApp.gs(R.string.treatmentdeliveryerror), MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput), null); OKDialog.show(getContext(), MainApp.gs(R.string.treatmentdeliveryerror), MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput), null);
return; return;
} }

View file

@ -225,7 +225,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener
} }
} }
if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints)) if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints))
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>"); actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>");
int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration); int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);

View file

@ -141,7 +141,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
if (recordOnlyCheckbox.isChecked()) { if (recordOnlyCheckbox.isChecked()) {
confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusrecordedonly) + "</font>"; confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusrecordedonly) + "</font>";
} }
if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints) || !Objects.equals(carbsAfterConstraints, carbs)) if (Math.abs(insulinAfterConstraints - insulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints) || !Objects.equals(carbsAfterConstraints, carbs))
confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>"; confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>";
} }
if (carbsAfterConstraints > 0) if (carbsAfterConstraints > 0)

View file

@ -7,83 +7,83 @@ import java.util.Map;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings; import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings;
import info.nightscout.androidaps.utils.Round;
/** /**
* Created by andy on 02/05/2018. * Created by andy on 02/05/2018.
* * <p>
* Most of this defintions is intended for VirtualPump only, but they can be used by other plugins. * Most of this defintions is intended for VirtualPump only, but they can be used by other plugins.
*/ */
public enum PumpType { public enum PumpType {
GenericAAPS("Generic AAPS", 0.1d, null, // GenericAAPS("Generic AAPS", 0.1d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, // PumpTempBasalType.Percent, //
new DoseSettings(10,30, 24*60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // new DoseSettings(10, 30, 24 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.01d, null, PumpCapability.VirtualPumpCapabilities), // 0.01d, 0.01d, null, PumpCapability.VirtualPumpCapabilities), //
// Cellnovo // Cellnovo
Cellnovo1("Cellnovo", 0.05d, null, // Cellnovo1("Cellnovo", 0.05d, null, //
new DoseSettings(0.05d, 30, 24*60, 1d, null), new DoseSettings(0.05d, 30, 24 * 60, 1d, null),
PumpTempBasalType.Percent, PumpTempBasalType.Percent,
new DoseSettings(5,30, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, // new DoseSettings(5, 30, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), //
// Accu-Chek // Accu-Chek
AccuChekCombo("Accu-Chek Combo", 0.1d, null, // AccuChekCombo("Accu-Chek Combo", 0.1d, null, //
new DoseSettings(0.1d, 15, 12*60, 0.1d), // new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
PumpTempBasalType.Percent, PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12*60,0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.01d, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), // 0.01d, 0.01d, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), //
AccuChekSpirit("Accu-Chek Spirit", 0.1d, null, // AccuChekSpirit("Accu-Chek Spirit", 0.1d, null, //
new DoseSettings(0.1d, 15, 12*60, 0.1d), // new DoseSettings(0.1d, 15, 12 * 60, 0.1d), //
PumpTempBasalType.Percent, PumpTempBasalType.Percent,
new DoseSettings(10, 15, 12*60,0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.01d, 0.1d, null, PumpCapability.VirtualPumpCapabilities), // 0.01d, 0.1d, null, PumpCapability.VirtualPumpCapabilities), //
AccuChekInsight("Accu-Chek Insight", 0.05d, DoseStepSize.InsightBolus, // AccuChekInsight("Accu-Chek Insight", 0.05d, DoseStepSize.InsightBolus, //
new DoseSettings(0.05d, 15, 24*60, 0.05d), // new DoseSettings(0.05d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent, PumpTempBasalType.Percent,
new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, null, PumpCapability.InsightCapabilities), // 0.02d, 0.01d, null, PumpCapability.InsightCapabilities), //
AccuChekInsightBluetooth("Accu-Chek Insight", 0.01d, null, // AccuChekInsightBluetooth("Accu-Chek Insight", 0.01d, null, //
new DoseSettings(0.01d, 15, 24*60, 0.05d), // new DoseSettings(0.01d, 15, 24 * 60, 0.05d), //
PumpTempBasalType.Percent, PumpTempBasalType.Percent,
new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), // 0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), //
// Animas // Animas
AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus? AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus?
new DoseSettings(0.05d, 30, 12*60, 0.05d), // new DoseSettings(0.05d, 30, 12 * 60, 0.05d), //
PumpTempBasalType.Percent, // PumpTempBasalType.Percent, //
new DoseSettings(10, 30, 24*60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, // new DoseSettings(10, 30, 24 * 60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), // 0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), //
AnimasPing("Animas Ping", AnimasVibe), AnimasPing("Animas Ping", AnimasVibe),
// Dana // Dana
DanaR("DanaR", 0.05d, null, // DanaR("DanaR", 0.05d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, // PumpTempBasalType.Percent, //
new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, // new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.04d, 0.01d, null, PumpCapability.DanaCapabilities), 0.04d, 0.01d, null, PumpCapability.DanaCapabilities),
DanaRKorean("DanaR Korean", 0.05d, null, // DanaRKorean("DanaR Korean", 0.05d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, // PumpTempBasalType.Percent, //
new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, // new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, //
0.1d, 0.01d, null, PumpCapability.DanaCapabilities), 0.1d, 0.01d, null, PumpCapability.DanaCapabilities),
DanaRS("DanaRS", 0.05d, null, // DanaRS("DanaRS", 0.05d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Percent, // PumpTempBasalType.Percent, //
new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, // new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.04d, 0.01d, null, PumpCapability.DanaWithHistoryCapabilities), 0.04d, 0.01d, null, PumpCapability.DanaWithHistoryCapabilities),
DanaRv2("DanaRv2", DanaRS), DanaRv2("DanaRv2", DanaRS),
@ -91,40 +91,40 @@ public enum PumpType {
// Insulet // Insulet
Insulet_Omnipod("Insulet Omnipod", 0.05d, null, // Insulet_Omnipod("Insulet Omnipod", 0.05d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, // PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 12*60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr new DoseSettings(0.05d, 30, 12 * 60, 0d, 30.0d), PumpCapability.BasalRate_Duration30minAllowed, // cannot exceed max basal rate 30u/hr
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities),
// Medtronic // Medtronic
Medtronic_512_712("Medtronic 512/712", 0.05d, null, // Medtronic_512_712("Medtronic 512/712", 0.05d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, // PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // TODO 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // TODO
Medtronic_515_715("Medtronic 515/715", Medtronic_512_712), Medtronic_515_715("Medtronic 515/715", Medtronic_512_712),
Medtronic_522_722("Medtronic 522/722", Medtronic_512_712), Medtronic_522_722("Medtronic 522/722", Medtronic_512_712),
Medtronic_523_723_Revel("Medtronic 523/723 (Revel)", 0.05d, null, // Medtronic_523_723_Revel("Medtronic 523/723 (Revel)", 0.05d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, // PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), // 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO
Medtronic_640G("Medtronic 640G", 0.025d, null, // Medtronic_640G("Medtronic 640G", 0.025d, null, //
new DoseSettings(0.05d, 30, 8*60, 0.05d), // new DoseSettings(0.05d, 30, 8 * 60, 0.05d), //
PumpTempBasalType.Absolute, // PumpTempBasalType.Absolute, //
new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, //
0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), // 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), //
// Tandem // Tandem
TandemTSlim("Tandem t:slim", 0.01d, null, // TandemTSlim("Tandem t:slim", 0.01d, null, //
new DoseSettings(0.01d,15, 8*60, 0.4d), new DoseSettings(0.01d, 15, 8 * 60, 0.4d),
PumpTempBasalType.Percent, PumpTempBasalType.Percent,
new DoseSettings(1,15, 8*60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // new DoseSettings(1, 15, 8 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, //
0.1d, 0.001d, null, PumpCapability.VirtualPumpCapabilities), 0.1d, 0.001d, null, PumpCapability.VirtualPumpCapabilities),
TandemTFlex("Tandem t:flex", TandemTSlim), // TandemTFlex("Tandem t:flex", TandemTSlim), //
@ -146,10 +146,9 @@ public enum PumpType {
private PumpCapability pumpCapability; private PumpCapability pumpCapability;
private PumpType parent; private PumpType parent;
private static Map<String,PumpType> mapByDescription; private static Map<String, PumpType> mapByDescription;
static static {
{
mapByDescription = new HashMap<>(); mapByDescription = new HashMap<>();
for (PumpType pumpType : values()) { for (PumpType pumpType : values()) {
@ -158,14 +157,12 @@ public enum PumpType {
} }
PumpType(String description, PumpType parent) PumpType(String description, PumpType parent) {
{
this.description = description; this.description = description;
this.parent = parent; this.parent = parent;
} }
PumpType(String description, PumpType parent, PumpCapability pumpCapability) PumpType(String description, PumpType parent, PumpCapability pumpCapability) {
{
this.description = description; this.description = description;
this.parent = parent; this.parent = parent;
this.pumpCapability = pumpCapability; this.pumpCapability = pumpCapability;
@ -173,17 +170,15 @@ public enum PumpType {
PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, // PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, // DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, // PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
{
this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability); this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability);
} }
PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, // PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, //
DoseSettings extendedBolusSettings, // DoseSettings extendedBolusSettings, //
PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, // PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, //
double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) {
{
this.description = description; this.description = description;
this.bolusSize = bolusSize; this.bolusSize = bolusSize;
this.specialBolusSize = specialBolusSize; this.specialBolusSize = specialBolusSize;
@ -261,20 +256,15 @@ public enum PumpType {
} }
private boolean isParentSet() private boolean isParentSet() {
{ return this.parent != null;
return this.parent!=null;
} }
public static PumpType getByDescription(String desc) public static PumpType getByDescription(String desc) {
{ if (mapByDescription.containsKey(desc)) {
if (mapByDescription.containsKey(desc))
{
return mapByDescription.get(desc); return mapByDescription.get(desc);
} } else {
else
{
return PumpType.GenericAAPS; return PumpType.GenericAAPS;
} }
} }
@ -282,7 +272,7 @@ public enum PumpType {
public String getFullDescription(String i18nTemplate, boolean hasExtendedBasals) { public String getFullDescription(String i18nTemplate, boolean hasExtendedBasals) {
String unit = getPumpTempBasalType()==PumpTempBasalType.Percent ? "%" : ""; String unit = getPumpTempBasalType() == PumpTempBasalType.Percent ? "%" : "";
DoseSettings eb = getExtendedBolusSettings(); DoseSettings eb = getExtendedBolusSettings();
DoseSettings tbr = getTbrSettings(); DoseSettings tbr = getTbrSettings();
@ -291,24 +281,22 @@ public enum PumpType {
return String.format(i18nTemplate, // return String.format(i18nTemplate, //
getStep("" + getBolusSize(), getSpecialBolusSize()), // getStep("" + getBolusSize(), getSpecialBolusSize()), //
eb.getStep(), eb.getDurationStep(), eb.getMaxDuration()/60, // eb.getStep(), eb.getDurationStep(), eb.getMaxDuration() / 60, //
getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), // getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), //
tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit, tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit,
tbr.getDurationStep(), tbr.getMaxDuration()/60, extendedNote); tbr.getDurationStep(), tbr.getMaxDuration() / 60, extendedNote);
} }
private String getBaseBasalRange() private String getBaseBasalRange() {
{
Double maxValue = getBaseBasalMaxValue(); Double maxValue = getBaseBasalMaxValue();
return maxValue==null ? "" + getBaseBasalMinValue() : getBaseBasalMinValue() + "-" + maxValue; return maxValue == null ? "" + getBaseBasalMinValue() : getBaseBasalMinValue() + "-" + maxValue;
} }
private String getStep(String step, DoseStepSize stepSize) private String getStep(String step, DoseStepSize stepSize) {
{ if (stepSize != null)
if (stepSize!=null)
return step + " [" + stepSize.getDescription() + "] *"; return step + " [" + stepSize.getDescription() + "] *";
else else
return "" + step; return "" + step;
@ -316,18 +304,15 @@ public enum PumpType {
public boolean hasExtendedBasals() { public boolean hasExtendedBasals() {
return ((getBaseBasalSpecialSteps() !=null) || (getSpecialBolusSize() != null)); return ((getBaseBasalSpecialSteps() != null) || (getSpecialBolusSize() != null));
} }
public PumpCapability getSpecialBasalDurations() { public PumpCapability getSpecialBasalDurations() {
if (isParentSet()) if (isParentSet()) {
{
return parent.getSpecialBasalDurations(); return parent.getSpecialBasalDurations();
} } else {
else
{
return specialBasalDurations == null ? // return specialBasalDurations == null ? //
PumpCapability.BasalRate_Duration15and30minNotAllowed : specialBasalDurations; PumpCapability.BasalRate_Duration15and30minNotAllowed : specialBasalDurations;
} }
@ -338,20 +323,24 @@ public enum PumpType {
return bolusAmount; return bolusAmount;
} }
double bolusStepSize; double bolusStepSize = getBolusSize();
if (getSpecialBolusSize() == null) { if (getSpecialBolusSize() != null) {
bolusStepSize = getBolusSize();
} else {
DoseStepSize specialBolusSize = getSpecialBolusSize(); DoseStepSize specialBolusSize = getSpecialBolusSize();
bolusStepSize = specialBolusSize.getStepSizeForAmount(bolusAmount);
bolusStepSize = specialBolusSize.getStepSizeForAmount((double)bolusAmount);
} }
return Math.round(bolusAmount / bolusStepSize) * bolusStepSize; return Round.roundTo(bolusAmount, bolusStepSize);
} }
public double determineCorrectBolusStepSize(double bolusAmount) {
DoseStepSize specialBolusSize = getSpecialBolusSize();
if (specialBolusSize != null)
return specialBolusSize.getStepSizeForAmount(bolusAmount);
return getBolusSize();
}
public double determineCorrectExtendedBolusSize(double bolusAmount) { public double determineCorrectExtendedBolusSize(double bolusAmount) {
if (bolusAmount == 0.0d) { if (bolusAmount == 0.0d) {
return bolusAmount; return bolusAmount;
@ -371,7 +360,7 @@ public enum PumpType {
bolusAmount = extendedBolusSettings.getMaxDose(); bolusAmount = extendedBolusSettings.getMaxDose();
} }
return Math.round(bolusAmount / bolusStepSize) * bolusStepSize; return Round.roundTo(bolusAmount, bolusStepSize);
} }
@ -393,7 +382,7 @@ public enum PumpType {
if (basalAmount > getTbrSettings().getMaxDose()) if (basalAmount > getTbrSettings().getMaxDose())
basalAmount = getTbrSettings().getMaxDose().doubleValue(); basalAmount = getTbrSettings().getMaxDose().doubleValue();
return Math.round(basalAmount / basalStepSize) * basalStepSize; return Round.roundTo(basalAmount, basalStepSize);
} }
} }

View file

@ -157,43 +157,7 @@ class BolusWizard(val profile: Profile,
return calculatedTotalInsulin return calculatedTotalInsulin
} }
/*
fun log(): String {
val sb = StringBuilder()
sb.append("TempTarget=").append(tempTarget?.toString() ?: "null").append("; ")
sb.append("Carbs=").append(carbs).append("; ")
sb.append("Bg=").append(bg).append("; ")
sb.append("Cob=").append(cob).append("; ")
sb.append("Correction=").append(correction).append("; ")
sb.append("PercentageCorrection=").append(percentageCorrection).append("; ")
sb.append("IncludeBolusIOB=").append(includeBolusIOB).append("; ")
sb.append("IncludeBasalIOB=").append(includeBasalIOB).append("; ")
sb.append("Superbolus=").append(useSuperBolus).append("; ")
sb.append("Trend=").append(useTrend).append("; ")
sb.append("Profile=").append(profile.data?.toString()).append("; ")
sb.append("\n")
sb.append("targetBGLow=").append(targetBGLow).append("; ")
sb.append("targetBGHigh=").append(targetBGHigh).append("; ")
sb.append("bgDiff=").append(bgDiff).append("; ")
sb.append("insulinFromBG=").append(insulinFromBG).append("; ")
sb.append("insulinFromCarbs=").append(insulinFromCarbs).append("; ")
sb.append("insulingFromBolusIOB=").append(insulingFromBolusIOB).append("; ")
sb.append("insulingFromBasalsIOB=").append(insulingFromBasalsIOB).append("; ")
sb.append("insulinFromCorrection=").append(insulinFromCorrection).append("; ")
sb.append("insulinFromSuperBolus=").append(insulinFromSuperBolus).append("; ")
sb.append("insulinFromCOB=").append(insulinFromCOB).append("; ")
sb.append("insulinFromTrend=").append(insulinFromTrend).append("; ")
sb.append("\n")
sb.append("calculatedTotalInsulin=").append(calculatedTotalInsulin).append("; ")
sb.append("totalBeforePercentageAdjustment=").append(totalBeforePercentageAdjustment).append("; ")
sb.append("carbsEquivalent=").append(carbsEquivalent).append("; ")
return sb.toString()
}
*/
fun nsJSON(): JSONObject { fun nsJSON(): JSONObject {
val boluscalcJSON = JSONObject() val boluscalcJSON = JSONObject()
try { try {
@ -242,7 +206,7 @@ class BolusWizard(val profile: Profile,
if (carbs > 0) if (carbs > 0)
confirmMessage += "<br/>" + MainApp.gs(R.string.carbs) + ": " + "<font color='" + MainApp.gc(R.color.carbs) + "'>" + carbs + "g" + "</font>" confirmMessage += "<br/>" + MainApp.gs(R.string.carbs) + ": " + "<font color='" + MainApp.gc(R.color.carbs) + "'>" + carbs + "g" + "</font>"
if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.getPumpDescription().pumpType.determineCorrectBolusSize(insulinAfterConstraints)) { if (Math.abs(insulinAfterConstraints - calculatedTotalInsulin) > pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) {
confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>" confirmMessage += "<br/><font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>"
} }