From bef8b38b76d27eb0d600d6f2f6e96f294f9ab5a2 Mon Sep 17 00:00:00 2001 From: Philoul Date: Thu, 28 May 2020 18:06:32 +0200 Subject: [PATCH] Fix Missing COB in history browser But more calculation and slower :( --- .../iob/iobCobCalculator/IobCobCalculatorPlugin.java | 4 ++-- .../iob/iobCobCalculator/IobCobOref1Thread.java | 10 ++++++---- .../plugins/iob/iobCobCalculator/IobCobThread.java | 8 +++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java index 01e8aa2ce2..2f49cd9971 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java @@ -814,9 +814,9 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat getAapsLogger().debug(LTag.AUTOSENS, "Starting calculation thread: " + from + " to " + dateUtil.dateAndTimeString(end)); if (thread == null || thread.getState() == Thread.State.TERMINATED) { if (sensitivityOref1Plugin.isEnabled()) - thread = new IobCobOref1Thread(injector, this, from, end, bgDataReload, limitDataToOldestAvailable, cause); + thread = new IobCobOref1Thread(injector, this, treatmentsPlugin, from, end, bgDataReload, limitDataToOldestAvailable, cause); else - thread = new IobCobThread(injector, this, from, end, bgDataReload, limitDataToOldestAvailable, cause); + thread = new IobCobThread(injector, this, treatmentsPlugin, from, end, bgDataReload, limitDataToOldestAvailable, cause); thread.start(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index ef891ff62c..ec8f711c99 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCa import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.FabricPrivacy; @@ -61,7 +62,6 @@ public class IobCobOref1Thread extends Thread { @Inject ResourceHelper resourceHelper; @Inject ProfileFunction profileFunction; @Inject Context context; - @Inject ActivePluginProvider activePluginProvider; @Inject SensitivityAAPSPlugin sensitivityAAPSPlugin; @Inject SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin; @Inject BuildHelper buildHelper; @@ -71,6 +71,7 @@ public class IobCobOref1Thread extends Thread { private final HasAndroidInjector injector; private final IobCobCalculatorPlugin iobCobCalculatorPlugin; // cannot be injected : HistoryBrowser uses different instance + private final TreatmentsPlugin treatmentsPlugin; // cannot be injected : HistoryBrowser uses different instance private boolean bgDataReload; private boolean limitDataToOldestAvailable; private String from; @@ -78,11 +79,12 @@ public class IobCobOref1Thread extends Thread { private PowerManager.WakeLock mWakeLock; - IobCobOref1Thread(HasAndroidInjector injector, IobCobCalculatorPlugin iobCobCalculatorPlugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { + IobCobOref1Thread(HasAndroidInjector injector, IobCobCalculatorPlugin iobCobCalculatorPlugin, TreatmentsPlugin treatmentsPlugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { super(); injector.androidInjector().inject(this); this.injector = injector; this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; + this.treatmentsPlugin = treatmentsPlugin; this.bgDataReload = bgDataReload; this.limitDataToOldestAvailable = limitDataToOldestAvailable; @@ -240,7 +242,7 @@ public class IobCobOref1Thread extends Thread { } } - List recentCarbTreatments = activePluginProvider.getActiveTreatments().getCarbTreatments5MinBackFromHistory(bgTime); + List recentCarbTreatments = treatmentsPlugin.getCarbTreatments5MinBackFromHistory(bgTime); for (Treatment recentCarbTreatment : recentCarbTreatments) { autosensData.carbsFromBolus += recentCarbTreatment.carbs; boolean isAAPSOrWeighted = sensitivityAAPSPlugin.isEnabled() || sensitivityWeightedAveragePlugin.isEnabled(); @@ -363,7 +365,7 @@ public class IobCobOref1Thread extends Thread { // add an extra negative deviation if a high temptarget is running and exercise mode is set // TODO AS-FIX if (false && sp.getBoolean(R.string.key_high_temptarget_raises_sensitivity, SMBDefaults.high_temptarget_raises_sensitivity)) { - TempTarget tempTarget = activePluginProvider.getActiveTreatments().getTempTargetFromHistory(bgTime); + TempTarget tempTarget = treatmentsPlugin.getTempTargetFromHistory(bgTime); if (tempTarget != null && tempTarget.target() >= 100) { autosensData.extraDeviation.add(-(tempTarget.target() - 100) / 20); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index d5af67e3b8..f78438772f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCa import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.db.Treatment; +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.FabricPrivacy; @@ -58,7 +59,6 @@ public class IobCobThread extends Thread { @Inject ResourceHelper resourceHelper; @Inject ProfileFunction profileFunction; @Inject Context context; - @Inject ActivePluginProvider activePluginProvider; @Inject SensitivityAAPSPlugin sensitivityAAPSPlugin; @Inject SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin; @Inject BuildHelper buildHelper; @@ -68,6 +68,7 @@ public class IobCobThread extends Thread { private final HasAndroidInjector injector; private final IobCobCalculatorPlugin iobCobCalculatorPlugin; // cannot be injected : HistoryBrowser uses different instance + private final TreatmentsPlugin treatmentsPlugin; // cannot be injected : HistoryBrowser uses different instance private boolean bgDataReload; private boolean limitDataToOldestAvailable; private String from; @@ -75,11 +76,12 @@ public class IobCobThread extends Thread { private PowerManager.WakeLock mWakeLock; - @Inject IobCobThread(HasAndroidInjector injector, IobCobCalculatorPlugin iobCobCalculatorPlugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { + @Inject IobCobThread(HasAndroidInjector injector, IobCobCalculatorPlugin iobCobCalculatorPlugin, TreatmentsPlugin treatmentsPlugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { super(); injector.androidInjector().inject(this); this.injector = injector; this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; + this.treatmentsPlugin = treatmentsPlugin; this.bgDataReload = bgDataReload; this.limitDataToOldestAvailable = limitDataToOldestAvailable; @@ -237,7 +239,7 @@ public class IobCobThread extends Thread { } } - List recentCarbTreatments = activePluginProvider.getActiveTreatments().getCarbTreatments5MinBackFromHistory(bgTime); + List recentCarbTreatments = treatmentsPlugin.getCarbTreatments5MinBackFromHistory(bgTime); for (Treatment recentCarbTreatment : recentCarbTreatments) { autosensData.carbsFromBolus += recentCarbTreatment.carbs; boolean isAAPSOrWeighted = sensitivityAAPSPlugin.isEnabled() || sensitivityWeightedAveragePlugin.isEnabled();