Simplify IOB calculation call

This commit is contained in:
Milos Kozak 2021-03-29 09:43:25 +02:00
parent e3ac451f8d
commit f37e3ab4c2
11 changed files with 2 additions and 39 deletions

View file

@ -279,9 +279,7 @@ class WizardDialog : DaggerDialogFragment() {
binding.ttcheckbox.isEnabled = repository.getTemporaryTargetActiveAt(dateUtil._now()).blockingGet() is ValueWrapper.Existing binding.ttcheckbox.isEnabled = repository.getTemporaryTargetActiveAt(dateUtil._now()).blockingGet() is ValueWrapper.Existing
// IOB calculation // IOB calculation
treatmentsPlugin.updateTotalIOBTreatments()
val bolusIob = treatmentsPlugin.lastCalculationTreatments.round() val bolusIob = treatmentsPlugin.lastCalculationTreatments.round()
treatmentsPlugin.updateTotalIOBTempBasals()
val basalIob = treatmentsPlugin.lastCalculationTempBasals.round() val basalIob = treatmentsPlugin.lastCalculationTempBasals.round()
binding.bolusiobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, -bolusIob.iob) binding.bolusiobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, -bolusIob.iob)

View file

@ -136,9 +136,7 @@ class DataBroadcastPlugin @Inject constructor(
private fun iobCob(bundle: Bundle) { private fun iobCob(bundle: Bundle) {
profileFunction.getProfile() ?: return profileFunction.getProfile() ?: return
activePlugin.activeTreatments.updateTotalIOBTreatments()
val bolusIob: IobTotal = activePlugin.activeTreatments.lastCalculationTreatments.round() val bolusIob: IobTotal = activePlugin.activeTreatments.lastCalculationTreatments.round()
activePlugin.activeTreatments.updateTotalIOBTempBasals()
val basalIob: IobTotal = activePlugin.activeTreatments.lastCalculationTempBasals.round() val basalIob: IobTotal = activePlugin.activeTreatments.lastCalculationTempBasals.round()
bundle.putDouble("bolusIob", bolusIob.iob) bundle.putDouble("bolusIob", bolusIob.iob)
bundle.putDouble("basalIob", basalIob.basaliob) bundle.putDouble("basalIob", basalIob.basaliob)

View file

@ -749,8 +749,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
processButtonsVisibility() processButtonsVisibility()
// iob // iob
treatmentsPlugin.updateTotalIOBTreatments()
treatmentsPlugin.updateTotalIOBTempBasals()
val bolusIob = treatmentsPlugin.lastCalculationTreatments.round() val bolusIob = treatmentsPlugin.lastCalculationTreatments.round()
val basalIob = treatmentsPlugin.lastCalculationTempBasals.round() val basalIob = treatmentsPlugin.lastCalculationTempBasals.round()
binding.infoLayout.iob.text = resourceHelper.gs(R.string.formatinsulinunits, bolusIob.iob + basalIob.basaliob) binding.infoLayout.iob.text = resourceHelper.gs(R.string.formatinsulinunits, bolusIob.iob + basalIob.basaliob)

View file

@ -156,8 +156,6 @@ class PersistentNotificationPlugin @Inject constructor(
line1aa += " " + activeTemp.toStringShort() + "." line1aa += " " + activeTemp.toStringShort() + "."
} }
//IOB //IOB
activePlugins.activeTreatments.updateTotalIOBTreatments()
activePlugins.activeTreatments.updateTotalIOBTempBasals()
val bolusIob = activePlugins.activeTreatments.lastCalculationTreatments.round() val bolusIob = activePlugins.activeTreatments.lastCalculationTreatments.round()
val basalIob = activePlugins.activeTreatments.lastCalculationTempBasals.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() 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()

View file

@ -325,9 +325,7 @@ class SmsCommunicatorPlugin @Inject constructor(
} }
val glucoseStatus = glucoseStatusProvider.glucoseStatusData 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 + ", " 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() val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round()
activePlugin.activeTreatments.updateTotalIOBTempBasals()
val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round() val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round()
val cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "SMS COB") val cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "SMS COB")
reply += (resourceHelper.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" reply += (resourceHelper.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("

View file

@ -685,9 +685,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
String iobSum, iobDetail, cobString, currentBasal, bgiString; String iobSum, iobDetail, cobString, currentBasal, bgiString;
iobSum = iobDetail = cobString = currentBasal = bgiString = ""; iobSum = iobDetail = cobString = currentBasal = bgiString = "";
if (profile != null) { if (profile != null) {
treatmentsPlugin.updateTotalIOBTreatments();
IobTotal bolusIob = treatmentsPlugin.getLastCalculationTreatments().round(); IobTotal bolusIob = treatmentsPlugin.getLastCalculationTreatments().round();
treatmentsPlugin.updateTotalIOBTempBasals();
IobTotal basalIob = treatmentsPlugin.getLastCalculationTempBasals().round(); IobTotal basalIob = treatmentsPlugin.getLastCalculationTempBasals().round();
iobSum = DecimalFormatter.INSTANCE.to2Decimal(bolusIob.iob + basalIob.basaliob); iobSum = DecimalFormatter.INSTANCE.to2Decimal(bolusIob.iob + basalIob.basaliob);

View file

@ -132,9 +132,7 @@ class StatusLinePlugin @Inject constructor(
status += activeTemp.toStringShort() + " " status += activeTemp.toStringShort() + " "
} }
//IOB //IOB
activePlugin.activeTreatments.updateTotalIOBTreatments()
val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round() val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round()
activePlugin.activeTreatments.updateTotalIOBTempBasals()
val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round() val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round()
status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U" status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U"
if (sp.getBoolean(R.string.key_xdripstatus_detailediob, true)) { if (sp.getBoolean(R.string.key_xdripstatus_detailediob, true)) {

View file

@ -85,9 +85,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
protected TreatmentServiceInterface service; protected TreatmentServiceInterface service;
private IobTotal lastTreatmentCalculation;
private IobTotal lastTempBasalsCalculation;
private final ArrayList<Treatment> treatments = new ArrayList<>(); private final ArrayList<Treatment> treatments = new ArrayList<>();
private final Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<>(); private final Intervals<TemporaryBasal> tempBasals = new NonOverlappingIntervals<>();
private final Intervals<ExtendedBolus> extendedBoluses = new NonOverlappingIntervals<>(); private final Intervals<ExtendedBolus> extendedBoluses = new NonOverlappingIntervals<>();
@ -149,7 +146,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTreatmentData"); getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTreatmentData");
initializeTreatmentData(range()); initializeTreatmentData(range());
initializeExtendedBolusData(range()); initializeExtendedBolusData(range());
updateTotalIOBTreatments();
rxBus.send(event.getNext()); rxBus.send(event.getNext());
}, },
fabricPrivacy::logException fabricPrivacy::logException
@ -166,7 +162,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
.subscribe(event -> { .subscribe(event -> {
getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTempBasalData"); getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTempBasalData");
initializeTempBasalData(range()); initializeTempBasalData(range());
updateTotalIOBTempBasals();
}, },
fabricPrivacy::logException fabricPrivacy::logException
)); ));
@ -230,7 +225,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
@Override @Override
public IobTotal getLastCalculationTreatments() { public IobTotal getLastCalculationTreatments() {
return lastTreatmentCalculation; return getCalculationToTimeTreatments(System.currentTimeMillis());
} }
@Override @Override
@ -278,11 +273,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
return total; return total;
} }
@Override
public void updateTotalIOBTreatments() {
lastTreatmentCalculation = getCalculationToTimeTreatments(System.currentTimeMillis());
}
@Override @Override
public List<Treatment> getTreatmentsFromHistory() { public List<Treatment> getTreatmentsFromHistory() {
synchronized (treatments) { synchronized (treatments) {
@ -399,7 +389,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
@Override @Override
public IobTotal getLastCalculationTempBasals() { public IobTotal getLastCalculationTempBasals() {
return lastTempBasalsCalculation; return getCalculationToTimeTempBasals(DateUtil.now());
} }
@Override @Override
@ -537,11 +527,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
return total; return total;
} }
@Override
public void updateTotalIOBTempBasals() {
lastTempBasalsCalculation = getCalculationToTimeTempBasals(DateUtil.now());
}
@Nullable @Nullable
@Override @Override
public TemporaryBasal getTempBasalFromHistory(long time) { public TemporaryBasal getTempBasalFromHistory(long time) {

View file

@ -205,9 +205,7 @@ class BolusWizard @Inject constructor(
// Insulin from IOB // Insulin from IOB
// IOB calculation // IOB calculation
activePlugin.activeTreatments.updateTotalIOBTreatments()
val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round() val bolusIob = activePlugin.activeTreatments.lastCalculationTreatments.round()
activePlugin.activeTreatments.updateTotalIOBTempBasals()
val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round() val basalIob = activePlugin.activeTreatments.lastCalculationTempBasals.round()
insulinFromBolusIOB = if (includeBolusIOB) -bolusIob.iob else 0.0 insulinFromBolusIOB = if (includeBolusIOB) -bolusIob.iob else 0.0

View file

@ -9,7 +9,6 @@ import info.nightscout.androidaps.database.entities.GlucoseValue
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin 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.GlucoseStatusProvider
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
@ -99,7 +98,6 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
bolusIOB = true bolusIOB = true
} }
// Basal IOB // Basal IOB
treatmentsPlugin.updateTotalIOBTempBasals()
val basalIob = treatmentsPlugin.lastCalculationTempBasals.round() val basalIob = treatmentsPlugin.lastCalculationTempBasals.round()
var basalIOB = false var basalIOB = false
if (useBasalIOB() == YES) { if (useBasalIOB() == YES) {

View file

@ -22,10 +22,6 @@ public interface TreatmentsInterface {
TreatmentServiceInterface getService(); TreatmentServiceInterface getService();
void updateTotalIOBTreatments();
void updateTotalIOBTempBasals();
IobTotal getLastCalculationTreatments(); IobTotal getLastCalculationTreatments();
IobTotal getCalculationToTimeTreatments(long time); IobTotal getCalculationToTimeTreatments(long time);