diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index 2e4bcc0a34..4a919044c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -30,8 +30,6 @@ public interface PumpInterface { void refreshDataFromPump(String reason); double getBaseBasalRate(); // base basal rate, not temp basal - double getTempBasalAbsoluteRate(); - double getTempBasalRemainingMinutes(); PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context); void stopBolusDelivering(); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index 322941179c..0f2337c670 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -27,9 +27,11 @@ public interface TreatmentsInterface { List getTreatments5MinBack(long time); boolean isTempBasalInProgress(); - boolean isExtendedBoluslInProgress(); - TempBasal getTempBasal (long time); + double getTempBasalAbsoluteRate(); + double getTempBasalRemainingMinutes(); + + boolean isExtendedBoluslInProgress(); TempBasal getExtendedBolus (long time); long oldestDataAvaialable(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 4cd1015cfb..60f2925dbb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -259,7 +259,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } } - // PluginBase.PROFILE + // PluginBase.PROFILE pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class); activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PROFILE); if (Config.logConfigBuilder) @@ -414,18 +414,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain @Override public double getTempBasalAbsoluteRate() { - if (activePump != null) - return activePump.getTempBasalAbsoluteRate(); - else - return 0d; + return activeTreatments.getTempBasalAbsoluteRate(); } @Override public double getTempBasalRemainingMinutes() { - if (activePump != null) - return activePump.getTempBasalRemainingMinutes(); - else - return 0d; + return activeTreatments.getTempBasalRemainingMinutes(); } public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 2518dcffbe..75cf7fabfc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -228,8 +228,8 @@ public class DetermineBasalAdapterAMAJS { mCurrentTemp = new V8Object(mV8rt); mCurrentTemp.add("temp", "absolute"); - mCurrentTemp.add("duration", pump.getTempBasalRemainingMinutes()); - mCurrentTemp.add("rate", pump.getTempBasalAbsoluteRate()); + mCurrentTemp.add("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutes()); + mCurrentTemp.add("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate()); // as we have non default temps longer than 30 mintues TempBasal tempBasal = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index ee0a00b802..38ce184cad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; @@ -45,8 +46,8 @@ public class DetermineBasalAdapterMAJS { private String storedProfile = null; private String storedMeal_data = null; - /** - * Main code + /** + * Main code */ public DetermineBasalAdapterMAJS(ScriptReader scriptReader) throws IOException { @@ -106,10 +107,10 @@ public class DetermineBasalAdapterMAJS { mV8rt.executeVoidScript( "console.error(\"determine_basal(\"+\n" + "JSON.stringify(" + PARAM_glucoseStatus + ")+ \", \" +\n" + - "JSON.stringify(" + PARAM_currentTemp + ")+ \", \" +\n" + - "JSON.stringify(" + PARAM_iobData + ")+ \", \" +\n" + - "JSON.stringify(" + PARAM_profile + ")+ \", \" +\n" + - "JSON.stringify(" + PARAM_meal_data + ")+ \") \");" + "JSON.stringify(" + PARAM_currentTemp + ")+ \", \" +\n" + + "JSON.stringify(" + PARAM_iobData + ")+ \", \" +\n" + + "JSON.stringify(" + PARAM_profile + ")+ \", \" +\n" + + "JSON.stringify(" + PARAM_meal_data + ")+ \") \");" ); mV8rt.executeVoidScript( "var rT = determine_basal(" + @@ -241,8 +242,8 @@ public class DetermineBasalAdapterMAJS { mProfile.add("sens", NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()).doubleValue(), units)); mProfile.add("current_basal", pump.getBaseBasalRate()); - mCurrentTemp.add("duration", pump.getTempBasalRemainingMinutes()); - mCurrentTemp.add("rate", pump.getTempBasalAbsoluteRate()); + mCurrentTemp.add("duration", MainApp.getConfigBuilder().getTempBasalRemainingMinutes()); + mCurrentTemp.add("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate()); mIobData.add("iob", iobData.iob); //netIob mIobData.add("activity", iobData.activity); //netActivity @@ -252,7 +253,7 @@ public class DetermineBasalAdapterMAJS { mIobData.add("hightempinsulin", iobData.hightempinsulin); mGlucoseStatus.add("glucose", glucoseStatus.glucose); - if(SP.getBoolean("always_use_shortavg", false)){ + if (SP.getBoolean("always_use_shortavg", false)) { mGlucoseStatus.add("delta", glucoseStatus.short_avgdelta); } else { mGlucoseStatus.add("delta", glucoseStatus.delta); @@ -264,7 +265,7 @@ public class DetermineBasalAdapterMAJS { } - public void release() { + public void release() { mProfile.release(); mCurrentTemp.release(); mIobData.release(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 863daee656..31649073c3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -303,34 +303,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf return getDanaRPump().currentBasal; } - @Override - public double getTempBasalAbsoluteRate() { - TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); - if (tb != null) { - if (tb.isAbsolute) { - return tb.absolute; - } else { - Double baseRate = getBaseBasalRate(); - Double tempRate = baseRate * (tb.percent / 100d); - return tempRate; - } - } - TempBasal eb = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()); - if (eb != null && useExtendedBoluses) { - return getBaseBasalRate() + eb.absolute; - } - return 0; - } - - @Override - public double getTempBasalRemainingMinutes() { - if (MainApp.getConfigBuilder().isTempBasalInProgress()) - return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); - if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) - return MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).getPlannedRemainingMinutes(); - return 0; - } - public TempBasal getTempBasal(long time) { TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time); if (temp != null) return temp; @@ -439,9 +411,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) { result.success = true; result.percent = percentRate; - result.absolute = getTempBasalAbsoluteRate(); + result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRate(); result.enacted = false; - result.duration = ((Double) getTempBasalRemainingMinutes()).intValue(); + result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutes()).intValue(); result.isPercent = true; result.isTempCancel = false; if (Config.logPumpActions) @@ -708,7 +680,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); TempBasal tb = getTempBasal(new Date().getTime()); if (tb != null) { - extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); + extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate()); extended.put("TempBasalStart", tb.timeStart.toLocaleString()); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); extended.put("IsExtended", tb.isExtended); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 0f2b4972d6..6324d69425 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -310,34 +310,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints return getDanaRPump().currentBasal; } - @Override - public double getTempBasalAbsoluteRate() { - TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); - if (tb != null) { - if (tb.isAbsolute) { - return tb.absolute; - } else { - Double baseRate = getBaseBasalRate(); - Double tempRate = baseRate * (tb.percent / 100d); - return tempRate; - } - } - TempBasal eb = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()); - if (eb != null && useExtendedBoluses) { - return getBaseBasalRate() + eb.absolute; - } - return 0; - } - - @Override - public double getTempBasalRemainingMinutes() { - if (MainApp.getConfigBuilder().isTempBasalInProgress()) - return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); - if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) - return MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).getPlannedRemainingMinutes(); - return 0; - } - public TempBasal getTempBasal(long time) { TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time); if (temp != null) return temp; @@ -446,9 +418,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) { result.success = true; result.percent = percentRate; - result.absolute = getTempBasalAbsoluteRate(); + result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRate(); result.enacted = false; - result.duration = ((Double) getTempBasalRemainingMinutes()).intValue(); + result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutes()).intValue(); result.isPercent = true; result.isTempCancel = false; if (Config.logPumpActions) @@ -715,7 +687,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints // extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); TempBasal tb = getTempBasal(new Date().getTime()); if (tb != null) { - extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); + extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate()); extended.put("TempBasalStart", tb.timeStart.toLocaleString()); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); extended.put("IsExtended", tb.isExtended); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 3daadafd2e..86247368ca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -286,24 +286,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte return getDanaRPump().currentBasal; } - @Override - public double getTempBasalAbsoluteRate() { - TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); - if (tb != null) { - Double baseRate = getBaseBasalRate(); - Double tempRate = baseRate * (tb.percent / 100d); - return tempRate; - } - return 0; - } - - @Override - public double getTempBasalRemainingMinutes() { - if (MainApp.getConfigBuilder().isTempBasalInProgress()) - return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); - return 0; - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); @@ -386,9 +368,9 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) { result.success = true; result.percent = percentRate; - result.absolute = getTempBasalAbsoluteRate(); + result.absolute = MainApp.getConfigBuilder().getTempBasalAbsoluteRate(); result.enacted = false; - result.duration = ((Double) getTempBasalRemainingMinutes()).intValue(); + result.duration = ((Double) MainApp.getConfigBuilder().getTempBasalRemainingMinutes()).intValue(); result.isPercent = true; result.isTempCancel = false; if (Config.logPumpActions) @@ -611,7 +593,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); if (tb != null) { - extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); + extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate()); extended.put("TempBasalStart", tb.timeStart.toLocaleString()); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); extended.put("IsExtended", tb.isExtended); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index a609c66fd3..b95b8f20a4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -164,16 +164,6 @@ public class MDIPlugin implements PluginBase, PumpInterface { return 0d; } - @Override - public double getTempBasalAbsoluteRate() { - return 0; - } - - @Override - public double getTempBasalRemainingMinutes() { - return 0d; - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { PumpEnactResult result = new PumpEnactResult(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index c86eee0d08..fa12430ab9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -187,29 +187,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { return profile.getBasal(profile.secondsFromMidnight()); } - @Override - public double getTempBasalAbsoluteRate() { - if (!MainApp.getConfigBuilder().isTempBasalInProgress()) - return 0; - if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).isAbsolute) { - return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).absolute; - } else { - NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); - if (profile == null) - return defaultBasalValue; - Double baseRate = profile.getBasal(profile.secondsFromMidnight()); - Double tempRate = baseRate * (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent / 100d); - return baseRate + tempRate; - } - } - - @Override - public double getTempBasalRemainingMinutes() { - if (!MainApp.getConfigBuilder().isTempBasalInProgress()) - return 0; - return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { PumpEnactResult result = new PumpEnactResult(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 10d0bb794d..634d6c808a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -29,6 +29,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; @@ -345,6 +346,36 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { return null; } + @Override + public double getTempBasalAbsoluteRate() { + PumpInterface pump = MainApp.getConfigBuilder(); + + TempBasal tb = getTempBasal(new Date().getTime()); + if (tb != null) { + if (tb.isAbsolute) { + return tb.absolute; + } else { + Double baseRate = pump.getBaseBasalRate(); + Double tempRate = baseRate * (tb.percent / 100d); + return tempRate; + } + } + TempBasal eb = getExtendedBolus(new Date().getTime()); + if (eb != null && useExtendedBoluses) { + return pump.getBaseBasalRate() + eb.absolute; + } + return 0; + } + + @Override + public double getTempBasalRemainingMinutes() { + if (isTempBasalInProgress()) + return getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); + if (isExtendedBoluslInProgress() && useExtendedBoluses) + return getExtendedBolus(new Date().getTime()).getPlannedRemainingMinutes(); + return 0; + } + @Override public long oldestDataAvaialable() { long oldestTemp = new Date().getTime(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java index eff04d6a4b..b528fe1570 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java @@ -29,6 +29,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; @@ -341,6 +342,30 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf return null; } + @Override + public double getTempBasalAbsoluteRate() { + PumpInterface pump = MainApp.getConfigBuilder(); + + TempBasal tb = getTempBasal(new Date().getTime()); + if (tb != null) { + if (tb.isAbsolute) { + return tb.absolute; + } else { + Double baseRate = pump.getBaseBasalRate(); + Double tempRate = baseRate * (tb.percent / 100d); + return tempRate; + } + } + return 0; + } + + @Override + public double getTempBasalRemainingMinutes() { + if (isTempBasalInProgress()) + return getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); + return 0; + } + @Override public long oldestDataAvaialable() { long oldestTemp = new Date().getTime();