From f37e3ab4c2fc10a760f349984b97620846dc4a2f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 29 Mar 2021 09:43:25 +0200 Subject: [PATCH] Simplify IOB calculation call --- .../androidaps/dialogs/WizardDialog.kt | 2 -- .../dataBroadcaster/DataBroadcastPlugin.kt | 2 -- .../general/overview/OverviewFragment.kt | 2 -- .../PersistentNotificationPlugin.kt | 2 -- .../smsCommunicator/SmsCommunicatorPlugin.kt | 2 -- .../wearintegration/WatchUpdaterService.java | 2 -- .../xdripStatusline/StatusLinePlugin.kt | 2 -- .../plugins/treatments/TreatmentsPlugin.java | 19 ++----------------- .../androidaps/utils/wizard/BolusWizard.kt | 2 -- .../utils/wizard/QuickWizardEntry.kt | 2 -- .../interfaces/TreatmentsInterface.java | 4 ---- 11 files changed, 2 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index 043332aa4a..176136a67a 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -279,9 +279,7 @@ class WizardDialog : DaggerDialogFragment() { binding.ttcheckbox.isEnabled = repository.getTemporaryTargetActiveAt(dateUtil._now()).blockingGet() is ValueWrapper.Existing // IOB calculation - treatmentsPlugin.updateTotalIOBTreatments() val bolusIob = treatmentsPlugin.lastCalculationTreatments.round() - treatmentsPlugin.updateTotalIOBTempBasals() val basalIob = treatmentsPlugin.lastCalculationTempBasals.round() binding.bolusiobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, -bolusIob.iob) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt index 4ff7ce4d14..4d1665d19b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/dataBroadcaster/DataBroadcastPlugin.kt @@ -136,9 +136,7 @@ class DataBroadcastPlugin @Inject constructor( private fun iobCob(bundle: Bundle) { profileFunction.getProfile() ?: return - activePlugin.activeTreatments.updateTotalIOBTreatments() val bolusIob: IobTotal = activePlugin.activeTreatments.lastCalculationTreatments.round() - activePlugin.activeTreatments.updateTotalIOBTempBasals() val basalIob: IobTotal = activePlugin.activeTreatments.lastCalculationTempBasals.round() bundle.putDouble("bolusIob", bolusIob.iob) bundle.putDouble("basalIob", basalIob.basaliob) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 6c76c3f910..bc0187e98c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -749,8 +749,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList processButtonsVisibility() // iob - treatmentsPlugin.updateTotalIOBTreatments() - treatmentsPlugin.updateTotalIOBTempBasals() val bolusIob = treatmentsPlugin.lastCalculationTreatments.round() val basalIob = treatmentsPlugin.lastCalculationTempBasals.round() binding.infoLayout.iob.text = resourceHelper.gs(R.string.formatinsulinunits, bolusIob.iob + basalIob.basaliob) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt index 8c028c89be..b25d70f9b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt @@ -156,8 +156,6 @@ class PersistentNotificationPlugin @Inject constructor( line1aa += " " + activeTemp.toStringShort() + "." } //IOB - activePlugins.activeTreatments.updateTotalIOBTreatments() - activePlugins.activeTreatments.updateTotalIOBTempBasals() val bolusIob = activePlugins.activeTreatments.lastCalculationTreatments.round() val basalIob = activePlugins.activeTreatments.lastCalculationTempBasals.round() line2 = resourceHelper.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U " + resourceHelper.gs(R.string.cob) + ": " + iobCobCalculatorPlugin.getCobInfo(false, "PersistentNotificationPlugin").generateCOBString() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 981141cd83..5e5e557ffb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -325,9 +325,7 @@ class SmsCommunicatorPlugin @Inject constructor( } val glucoseStatus = glucoseStatusProvider.glucoseStatusData if (glucoseStatus != null) reply += resourceHelper.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", " - activePlugin.activeTreatments.updateTotalIOBTreatments() val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round() - activePlugin.activeTreatments.updateTotalIOBTempBasals() val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round() val cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "SMS COB") reply += (resourceHelper.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index db97d25b17..f9a90cfaa6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -685,9 +685,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog String iobSum, iobDetail, cobString, currentBasal, bgiString; iobSum = iobDetail = cobString = currentBasal = bgiString = ""; if (profile != null) { - treatmentsPlugin.updateTotalIOBTreatments(); IobTotal bolusIob = treatmentsPlugin.getLastCalculationTreatments().round(); - treatmentsPlugin.updateTotalIOBTempBasals(); IobTotal basalIob = treatmentsPlugin.getLastCalculationTempBasals().round(); iobSum = DecimalFormatter.INSTANCE.to2Decimal(bolusIob.iob + basalIob.basaliob); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt index a705394f59..38376b363a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatusLinePlugin.kt @@ -132,9 +132,7 @@ class StatusLinePlugin @Inject constructor( status += activeTemp.toStringShort() + " " } //IOB - activePlugin.activeTreatments.updateTotalIOBTreatments() val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round() - activePlugin.activeTreatments.updateTotalIOBTempBasals() val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round() status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U" if (sp.getBoolean(R.string.key_xdripstatus_detailediob, true)) { 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 8229320666..ea9f55d9b4 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 @@ -85,9 +85,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface protected TreatmentServiceInterface service; - private IobTotal lastTreatmentCalculation; - private IobTotal lastTempBasalsCalculation; - private final ArrayList treatments = new ArrayList<>(); private final Intervals tempBasals = new NonOverlappingIntervals<>(); private final Intervals extendedBoluses = new NonOverlappingIntervals<>(); @@ -149,7 +146,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTreatmentData"); initializeTreatmentData(range()); initializeExtendedBolusData(range()); - updateTotalIOBTreatments(); rxBus.send(event.getNext()); }, fabricPrivacy::logException @@ -166,7 +162,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface .subscribe(event -> { getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTempBasalData"); initializeTempBasalData(range()); - updateTotalIOBTempBasals(); }, fabricPrivacy::logException )); @@ -230,7 +225,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public IobTotal getLastCalculationTreatments() { - return lastTreatmentCalculation; + return getCalculationToTimeTreatments(System.currentTimeMillis()); } @Override @@ -278,11 +273,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface return total; } - @Override - public void updateTotalIOBTreatments() { - lastTreatmentCalculation = getCalculationToTimeTreatments(System.currentTimeMillis()); - } - @Override public List getTreatmentsFromHistory() { synchronized (treatments) { @@ -399,7 +389,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public IobTotal getLastCalculationTempBasals() { - return lastTempBasalsCalculation; + return getCalculationToTimeTempBasals(DateUtil.now()); } @Override @@ -537,11 +527,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface return total; } - @Override - public void updateTotalIOBTempBasals() { - lastTempBasalsCalculation = getCalculationToTimeTempBasals(DateUtil.now()); - } - @Nullable @Override public TemporaryBasal getTempBasalFromHistory(long time) { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index 56c02b213a..3f166ae4a4 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -205,9 +205,7 @@ class BolusWizard @Inject constructor( // Insulin from IOB // IOB calculation - activePlugin.activeTreatments.updateTotalIOBTreatments() val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round() - activePlugin.activeTreatments.updateTotalIOBTempBasals() val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round() insulinFromBolusIOB = if (includeBolusIOB) -bolusIob.iob else 0.0 diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt index efc2a371f3..2aff9f479f 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/QuickWizardEntry.kt @@ -9,7 +9,6 @@ import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin @@ -99,7 +98,6 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec bolusIOB = true } // Basal IOB - treatmentsPlugin.updateTotalIOBTempBasals() val basalIob = treatmentsPlugin.lastCalculationTempBasals.round() var basalIOB = false if (useBasalIOB() == YES) { diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index 89406a9992..a29a17884b 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -22,10 +22,6 @@ public interface TreatmentsInterface { TreatmentServiceInterface getService(); - void updateTotalIOBTreatments(); - - void updateTotalIOBTempBasals(); - IobTotal getLastCalculationTreatments(); IobTotal getCalculationToTimeTreatments(long time);