From fd62c572afdf61975a93467d9e683349a1c7a63b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 16 May 2017 09:46:09 +0200 Subject: [PATCH] more treatments plugin tweaking --- .../interfaces/TreatmentsInterface.java | 10 ++++++++-- .../ConfigBuilder/ConfigBuilderPlugin.java | 10 ++++++++++ .../plugins/PumpDanaR/DanaRFragment.java | 2 +- .../plugins/PumpDanaR/DanaRPlugin.java | 11 ++--------- .../PumpDanaRKorean/DanaRKoreanFragment.java | 2 +- .../plugins/Treatments/TreatmentsPlugin.java | 19 ++++++++++++++++--- .../TreatmentsFromHistoryPlugin.java | 10 ++++++++++ 7 files changed, 48 insertions(+), 16 deletions(-) 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 100ebf49d7..a063c9fa03 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -26,12 +26,18 @@ public interface TreatmentsInterface { List getTreatments(); List getTreatments5MinBack(long time); + // real basals on pump + boolean isRealTempBasalInProgress(); + TempBasal getRealTempBasal (long time); + + void tempBasalStart(TempBasal tempBasal); + void tempBasalStop(long time); + + // basal that can be faked by extended boluses boolean isTempBasalInProgress(); TempBasal getTempBasal (long time); double getTempBasalAbsoluteRate(); double getTempBasalRemainingMinutes(); - void tempBasalStart(TempBasal tempBasal); - void tempBasalStop(long time); boolean isExtendedBoluslInProgress(); TempBasal getExtendedBolus (long time); 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 8977277740..57ae8fdcc2 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 @@ -1178,6 +1178,16 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return activeTreatments.getTreatments5MinBack(time); } + @Override + public boolean isRealTempBasalInProgress() { + return activeTreatments.isRealTempBasalInProgress(); + } + + @Override + public TempBasal getRealTempBasal(long time) { + return activeTreatments.getRealTempBasal(time); + } + @Override public boolean isTempBasalInProgress() { return activeTreatments.isTempBasalInProgress(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index 2c54c1d9d5..0e8e156edd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -226,7 +226,7 @@ public class DanaRFragment extends Fragment { SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString()); + tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString()); } else { tempBasalView.setText(""); } 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 31649073c3..db65bec94a 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 @@ -35,6 +35,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.Overview.Notification; @@ -303,14 +304,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf return getDanaRPump().currentBasal; } - public TempBasal getTempBasal(long time) { - TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time); - if (temp != null) return temp; - if (useExtendedBoluses) - return MainApp.getConfigBuilder().getExtendedBolus(time); - return null; - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); @@ -678,7 +671,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf extended.put("PumpIOB", getDanaRPump().iob); extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); - TempBasal tb = getTempBasal(new Date().getTime()); + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); if (tb != null) { extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate()); extended.put("TempBasalStart", tb.timeStart.toLocaleString()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java index 3ec5a97164..4a76c8649f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java @@ -225,7 +225,7 @@ public class DanaRKoreanFragment extends Fragment { SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h"); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString()); + tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString()); } else { tempBasalView.setText(""); } 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 24ed705cd1..bed0cd1c43 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 @@ -312,14 +312,17 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { lastTempBasalsCalculation = total; } + public boolean isRealTempBasalInProgress() { + return getRealTempBasal(new Date().getTime()) != null; + } + @Override public boolean isTempBasalInProgress() { return getTempBasal(new Date().getTime()) != null; } @Nullable - @Override - public TempBasal getTempBasal(long time) { + public TempBasal getRealTempBasal(long time) { checkForExpired(tempBasals); for (TempBasal t : tempBasals) { if (t.isInProgress(time)) return t; @@ -327,6 +330,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { return null; } + @Nullable + @Override + public TempBasal getTempBasal(long time) { + if (isRealTempBasalInProgress()) + return getRealTempBasal(time); + if (isExtendedBoluslInProgress() && useExtendedBoluses) + return getExtendedBolus(time); + return null; + } + @Override public boolean isExtendedBoluslInProgress() { return getExtendedBolus(new Date().getTime()) != null; //TODO: crosscheck here @@ -344,7 +357,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public void extendedBolusStart(TempBasal extendedBolus) { - + MainApp.getDbHelper().create(extendedBolus); } @Override 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 d777fb41e2..45be4999d2 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 @@ -276,6 +276,16 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf return in5minback; } + @Override + public boolean isRealTempBasalInProgress() { + return false; + } + + @Override + public TempBasal getRealTempBasal(long time) { + return null; + } + @Override public boolean isTempBasalInProgress() { return getTempBasal(new Date().getTime()) != null;