From 2397c8e0d20e2ba08d9363e87485d9addf34ba72 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Mon, 8 Apr 2019 22:42:02 +0100 Subject: [PATCH] - fixes to bolus decoding - PumpType set MedtronicCapabilities --- app/build.gradle | 6 +- .../plugins/pump/common/defs/PumpType.java | 217 +++++++++--------- .../pump/MedtronicPumpHistoryDecoder.java | 4 +- 3 files changed, 110 insertions(+), 117 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9ba6eeae52..26c79286a4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,7 +65,7 @@ android { multiDexEnabled true versionCode 1500 // dev_version: 2.2.3-dev - version "medtronic-0.8" + version "medtronic-0.9.0-SNAPSHOT" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' @@ -172,7 +172,6 @@ dependencies { wearApp project(':wear') implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.google.android.gms:play-services-wearable:16.0.1' implementation 'com.google.firebase:firebase-core:16.0.8' implementation("com.crashlytics.sdk.android:crashlytics:2.9.9@aar") { transitive = true; @@ -185,6 +184,7 @@ dependencies { implementation "com.android.support:cardview-v7:${supportLibraryVersion}" implementation "com.android.support:recyclerview-v7:${supportLibraryVersion}" implementation "com.android.support:gridlayout-v7:${supportLibraryVersion}" + implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation "com.android.support:design:${supportLibraryVersion}" implementation "com.android.support:percent:${supportLibraryVersion}" implementation "com.wdullaer:materialdatetimepicker:2.3.0" @@ -233,6 +233,8 @@ dependencies { testImplementation "com.google.truth:truth:0.39" testImplementation 'org.robolectric:robolectric:3.8' testImplementation "org.skyscreamer:jsonassert:1.5.0" + testImplementation "org.hamcrest:hamcrest-all:1.3" + testImplementation "uk.org.lidalia:slf4j-test:1.2.0" androidTestImplementation "org.mockito:mockito-core:2.8.47" androidTestImplementation "com.google.dexmaker:dexmaker:${dexmakerVersion}" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java index 9a7e351bf1..c14cf5eee2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/defs/PumpType.java @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.pump.common.defs; - import java.util.HashMap; import java.util.Map; @@ -8,8 +7,6 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings; - - /** * Created by andy on 02/05/2018. * @@ -19,113 +16,106 @@ import info.nightscout.androidaps.plugins.pump.common.data.DoseSettings; public enum PumpType { GenericAAPS("Generic AAPS", 0.1d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Percent, // - new DoseSettings(10,30, 24*60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // - 0.01d, 0.01d, null, PumpCapability.VirtualPumpCapabilities), // + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Percent, // + new DoseSettings(10, 30, 24 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // + 0.01d, 0.01d, null, PumpCapability.VirtualPumpCapabilities), // // Cellnovo Cellnovo1("Cellnovo", 0.05d, null, // - new DoseSettings(0.05d, 30, 24*60, 1d, null), - PumpTempBasalType.Percent, - new DoseSettings(5,30, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration30minAllowed, // - 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // + new DoseSettings(0.05d, 30, 24 * 60, 1d, null), PumpTempBasalType.Percent, new DoseSettings(5, 30, 24 * 60, 0d, + 200d), PumpCapability.BasalRate_Duration30minAllowed, // + 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // // Accu-Chek AccuChekCombo("Accu-Chek Combo", 0.1d, null, // - new DoseSettings(0.1d, 15, 12*60, 0.1d), // - PumpTempBasalType.Percent, - new DoseSettings(10, 15, 12*60,0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // - 0.01d, 0.01d, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), // + new DoseSettings(0.1d, 15, 12 * 60, 0.1d), // + PumpTempBasalType.Percent, new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // + 0.01d, 0.01d, DoseStepSize.ComboBasal, PumpCapability.ComboCapabilities), // AccuChekSpirit("Accu-Chek Spirit", 0.1d, null, // - new DoseSettings(0.1d, 15, 12*60, 0.1d), // - PumpTempBasalType.Percent, - new DoseSettings(10, 15, 12*60,0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // - 0.01d, 0.1d, null, PumpCapability.VirtualPumpCapabilities), // + new DoseSettings(0.1d, 15, 12 * 60, 0.1d), // + PumpTempBasalType.Percent, new DoseSettings(10, 15, 12 * 60, 0d, 500d), PumpCapability.BasalRate_Duration15and30minAllowed, // + 0.01d, 0.1d, null, PumpCapability.VirtualPumpCapabilities), // AccuChekInsight("Accu-Chek Insight", 0.05d, DoseStepSize.InsightBolus, // - new DoseSettings(0.05d, 15, 24*60, 0.05d), // - PumpTempBasalType.Percent, - new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // - 0.02d, 0.01d, null, PumpCapability.InsightCapabilities), // + new DoseSettings(0.05d, 15, 24 * 60, 0.05d), // + PumpTempBasalType.Percent, new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // + 0.02d, 0.01d, null, PumpCapability.InsightCapabilities), // AccuChekInsightBluetooth("Accu-Chek Insight", 0.01d, null, // - new DoseSettings(0.01d, 15, 24*60, 0.05d), // - PumpTempBasalType.Percent, - new DoseSettings(10, 15, 24*60,0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // - 0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), // + new DoseSettings(0.01d, 15, 24 * 60, 0.05d), // + PumpTempBasalType.Percent, new DoseSettings(10, 15, 24 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // + 0.02d, 0.01d, DoseStepSize.InsightBolus, PumpCapability.InsightCapabilities), // // Animas AnimasVibe("Animas Vibe", 0.05d, null, // AnimasBolus? - new DoseSettings(0.05d, 30, 12*60, 0.05d), // - PumpTempBasalType.Percent, // - new DoseSettings(10, 30, 24*60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, // - 0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), // + new DoseSettings(0.05d, 30, 12 * 60, 0.05d), // + PumpTempBasalType.Percent, // + new DoseSettings(10, 30, 24 * 60, 0d, 300d), PumpCapability.BasalRate_Duration30minAllowed, // + 0.025d, 5d, 0d, null, PumpCapability.VirtualPumpCapabilities), // AnimasPing("Animas Ping", AnimasVibe), // Dana DanaR("DanaR", 0.05d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Percent, // - new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, // - 0.04d, 0.01d, null, PumpCapability.DanaCapabilities), + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Percent, // + new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, // + 0.04d, 0.01d, null, PumpCapability.DanaCapabilities), DanaRKorean("DanaR Korean", 0.05d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Percent, // - new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, // - 0.1d, 0.01d, null, PumpCapability.DanaCapabilities), + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Percent, // + new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minNotAllowed, // + 0.1d, 0.01d, null, PumpCapability.DanaCapabilities), DanaRS("DanaRS", 0.05d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Percent, // - new DoseSettings(10d, 60, 24*60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, // - 0.04d, 0.01d, null, PumpCapability.DanaWithHistoryCapabilities), + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Percent, // + new DoseSettings(10d, 60, 24 * 60, 0d, 200d), PumpCapability.BasalRate_Duration15and30minAllowed, // + 0.04d, 0.01d, null, PumpCapability.DanaWithHistoryCapabilities), DanaRv2("DanaRv2", DanaRS), - // Insulet Insulet_Omnipod("Insulet Omnipod", 0.05d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Absolute, // - 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), + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Absolute, // + 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), // Medtronic Medtronic_512_712("Medtronic 512/712", 0.05d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Absolute, // - new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // - 0.05d, 0.05d, null, PumpCapability.VirtualPumpCapabilities), // TODO + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Absolute, // + new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // + 0.05d, 0.05d, null, PumpCapability.MedtronicCapabilities), // TODO Medtronic_515_715("Medtronic 515/715", Medtronic_512_712), Medtronic_522_722("Medtronic 522/722", Medtronic_512_712), Medtronic_523_723_Revel("Medtronic 523/723 (Revel)", 0.05d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Absolute, // - new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // - 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), // + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Absolute, // + new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // + 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.MedtronicCapabilities), // Medtronic_554_754_Veo("Medtronic 554/754 (Veo)", Medtronic_523_723_Revel), // TODO Medtronic_640G("Medtronic 640G", 0.025d, null, // - new DoseSettings(0.05d, 30, 8*60, 0.05d), // - PumpTempBasalType.Absolute, // - new DoseSettings(0.05d, 30, 24*60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // - 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), // + new DoseSettings(0.05d, 30, 8 * 60, 0.05d), // + PumpTempBasalType.Absolute, // + new DoseSettings(0.05d, 30, 24 * 60, 0d, 35d), PumpCapability.BasalRate_Duration30minAllowed, // + 0.025d, 0.025d, DoseStepSize.MedtronicVeoBasal, PumpCapability.VirtualPumpCapabilities), // // Tandem TandemTSlim("Tandem t:slim", 0.01d, null, // - new DoseSettings(0.01d,15, 8*60, 0.4d), - PumpTempBasalType.Percent, - new DoseSettings(1,15, 8*60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // - 0.1d, 0.001d, null, PumpCapability.VirtualPumpCapabilities), + new DoseSettings(0.01d, 15, 8 * 60, 0.4d), PumpTempBasalType.Percent, new DoseSettings(1, 15, 8 * 60, 0d, 250d), PumpCapability.BasalRate_Duration15and30minAllowed, // + 0.1d, 0.001d, null, PumpCapability.VirtualPumpCapabilities), TandemTFlex("Tandem t:flex", TandemTSlim), // TandemTSlimG4("Tandem t:slim G4", TandemTSlim), // @@ -146,10 +136,9 @@ public enum PumpType { private PumpCapability pumpCapability; private PumpType parent; - private static Map mapByDescription; + private static Map mapByDescription; - static - { + static { mapByDescription = new HashMap<>(); for (PumpType pumpType : values()) { @@ -158,32 +147,38 @@ public enum PumpType { } - PumpType(String description, PumpType parent) - { + PumpType(String description, PumpType parent) { this.description = description; this.parent = parent; } - PumpType(String description, PumpType parent, PumpCapability pumpCapability) - { + + PumpType(String description, PumpType parent, PumpCapability pumpCapability) { this.description = description; this.parent = parent; this.pumpCapability = pumpCapability; } - PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, // - DoseSettings extendedBolusSettings, // - PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, // - double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) - { - this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability); + + PumpType(String description, double bolusSize, + DoseStepSize specialBolusSize, // + DoseSettings extendedBolusSettings, // + PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, + PumpCapability specialBasalDurations, // + double baseBasalMinValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, + PumpCapability pumpCapability) { + this(description, bolusSize, specialBolusSize, extendedBolusSettings, pumpTempBasalType, tbrSettings, + specialBasalDurations, baseBasalMinValue, null, baseBasalStep, baseBasalSpecialSteps, pumpCapability); } - PumpType(String description, double bolusSize, DoseStepSize specialBolusSize, // - DoseSettings extendedBolusSettings, // - PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, PumpCapability specialBasalDurations, // - double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) - { + + PumpType(String description, double bolusSize, + DoseStepSize specialBolusSize, // + DoseSettings extendedBolusSettings, // + PumpTempBasalType pumpTempBasalType, DoseSettings tbrSettings, + PumpCapability specialBasalDurations, // + double baseBasalMinValue, Double baseBasalMaxValue, double baseBasalStep, + DoseStepSize baseBasalSpecialSteps, PumpCapability pumpCapability) { this.description = description; this.bolusSize = bolusSize; this.specialBolusSize = specialBolusSize; @@ -203,6 +198,7 @@ public enum PumpType { return description; } + public PumpCapability getPumpCapability() { if (isParentSet()) @@ -211,6 +207,7 @@ public enum PumpType { return this.pumpCapability; } + public double getBolusSize() { return isParentSet() ? parent.bolusSize : bolusSize; } @@ -261,20 +258,15 @@ public enum PumpType { } - private boolean isParentSet() - { - return this.parent!=null; + private boolean isParentSet() { + return this.parent != null; } - public static PumpType getByDescription(String desc) - { - if (mapByDescription.containsKey(desc)) - { + public static PumpType getByDescription(String desc) { + if (mapByDescription.containsKey(desc)) { return mapByDescription.get(desc); - } - else - { + } else { return PumpType.GenericAAPS; } } @@ -282,33 +274,33 @@ public enum PumpType { public String getFullDescription(String i18nTemplate, boolean hasExtendedBasals) { - String unit = getPumpTempBasalType()==PumpTempBasalType.Percent ? "%" : ""; + String unit = getPumpTempBasalType() == PumpTempBasalType.Percent ? "%" : ""; DoseSettings eb = getExtendedBolusSettings(); DoseSettings tbr = getTbrSettings(); String extendedNote = hasExtendedBasals ? MainApp.gs(R.string.virtualpump_pump_def_extended_note) : ""; - return String.format(i18nTemplate, // - getStep("" + getBolusSize(), getSpecialBolusSize()), // - eb.getStep(), eb.getDurationStep(), eb.getMaxDuration()/60, // - getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), // - tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit, - tbr.getDurationStep(), tbr.getMaxDuration()/60, extendedNote); + return String.format( + i18nTemplate, // + getStep("" + getBolusSize(), getSpecialBolusSize()), // + eb.getStep(), eb.getDurationStep(), + eb.getMaxDuration() / 60, // + getStep(getBaseBasalRange(), getBaseBasalSpecialSteps()), // + tbr.getMinDose() + unit + "-" + tbr.getMaxDose() + unit, tbr.getStep() + unit, tbr.getDurationStep(), + tbr.getMaxDuration() / 60, extendedNote); } - private String getBaseBasalRange() - { + private String getBaseBasalRange() { Double maxValue = getBaseBasalMaxValue(); - return maxValue==null ? "" + getBaseBasalMinValue() : getBaseBasalMinValue() + "-" + maxValue; + return maxValue == null ? "" + getBaseBasalMinValue() : getBaseBasalMinValue() + "-" + maxValue; } - private String getStep(String step, DoseStepSize stepSize) - { - if (stepSize!=null) + private String getStep(String step, DoseStepSize stepSize) { + if (stepSize != null) return step + " [" + stepSize.getDescription() + "] *"; else return "" + step; @@ -316,23 +308,22 @@ public enum PumpType { public boolean hasExtendedBasals() { - return ((getBaseBasalSpecialSteps() !=null) || (getSpecialBolusSize() != null)); + return ((getBaseBasalSpecialSteps() != null) || (getSpecialBolusSize() != null)); } public PumpCapability getSpecialBasalDurations() { - if (isParentSet()) - { + if (isParentSet()) { return parent.getSpecialBasalDurations(); - } - else - { + } else { return specialBasalDurations == null ? // - PumpCapability.BasalRate_Duration15and30minNotAllowed : specialBasalDurations; + PumpCapability.BasalRate_Duration15and30minNotAllowed + : specialBasalDurations; } } + public double determineCorrectBolusSize(double bolusAmount) { if (bolusAmount == 0.0d) { return bolusAmount; @@ -387,7 +378,7 @@ public enum PumpType { } else { DoseStepSize specialBolusSize = getBaseBasalSpecialSteps(); - basalStepSize = specialBolusSize.getStepSizeForAmount((double) basalAmount); + basalStepSize = specialBolusSize.getStepSizeForAmount((double)basalAmount); } if (basalAmount > getTbrSettings().getMaxDose()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java index 9ecb959259..c73e735db7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java @@ -632,11 +632,11 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder