From cc4feb610c8a4fc6312aab491b16ad1a3aa5cc29 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 22 Sep 2022 21:21:23 +0200 Subject: [PATCH] fix calculation progress --- .../nightscout/androidaps/db/CompatDBHelper.kt | 14 +++++++------- .../iob/iobCobCalculator/IobCobCalculatorPlugin.kt | 2 +- .../androidaps/workflow/CalculationWorkflow.kt | 7 ++++--- .../androidaps/workflow/UpdateGraphWorker.kt | 2 ++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/CompatDBHelper.kt b/app/src/main/java/info/nightscout/androidaps/db/CompatDBHelper.kt index 2dcfac933e..7d223be028 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CompatDBHelper.kt +++ b/app/src/main/java/info/nightscout/androidaps/db/CompatDBHelper.kt @@ -31,31 +31,31 @@ class CompatDBHelper @Inject constructor( * */ var newestGlucoseValue: GlucoseValue? = null - it.filterIsInstance().lastOrNull()?.let { gv -> + it.filterIsInstance().maxByOrNull { gv -> gv.timestamp }?.let { gv -> aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv") rxBus.send(EventNewBG(gv)) newestGlucoseValue = gv } - it.filterIsInstance().map { gv -> gv.timestamp }.minOrNull()?.let { timestamp -> - aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData $newestGlucoseValue") + it.filterIsInstance().minOfOrNull { gv -> gv.timestamp }?.let { timestamp -> + aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData $timestamp $newestGlucoseValue") rxBus.send(EventNewHistoryData(timestamp, true, newestGlucoseValue)) } - it.filterIsInstance().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> + it.filterIsInstance().minOfOrNull { t -> t.timestamp }?.let { timestamp -> aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp") rxBus.send(EventTreatmentChange()) rxBus.send(EventNewHistoryData(timestamp, false)) } - it.filterIsInstance().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> + it.filterIsInstance().minOfOrNull { t -> t.timestamp }?.let { timestamp -> aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp") rxBus.send(EventTreatmentChange()) rxBus.send(EventNewHistoryData(timestamp, false)) } - it.filterIsInstance().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> + it.filterIsInstance().minOfOrNull { t -> t.timestamp }?.let { timestamp -> aapsLogger.debug(LTag.DATABASE, "Firing EventTempBasalChange $timestamp") rxBus.send(EventTempBasalChange()) rxBus.send(EventNewHistoryData(timestamp, false)) } - it.filterIsInstance().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> + it.filterIsInstance().minOfOrNull { t -> t.timestamp }?.let { timestamp -> aapsLogger.debug(LTag.DATABASE, "Firing EventExtendedBolusChange $timestamp") rxBus.send(EventExtendedBolusChange()) rxBus.send(EventNewHistoryData(timestamp, false)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt index 30c05b1f32..c048c7133a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.kt @@ -369,7 +369,7 @@ class IobCobCalculatorPlugin @Inject constructor( @Synchronized private fun scheduleHistoryDataChange(event: EventNewHistoryData) { // if there is nothing scheduled or asking reload deeper to the past - if (scheduledEvent == null || event.oldDataTimestamp < (scheduledEvent?.oldDataTimestamp) ?: 0L) { + if (scheduledEvent == null || event.oldDataTimestamp < (scheduledEvent?.oldDataTimestamp ?: 0L)) { // cancel waiting task to prevent sending multiple posts scheduledHistoryPost?.cancel(false) // prepare task for execution in 1 sec diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflow.kt b/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflow.kt index ddae280577..60efbbcd1c 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflow.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/CalculationWorkflow.kt @@ -60,12 +60,13 @@ class CalculationWorkflow @Inject constructor( private val overviewData: OverviewData get() = (iobCobCalculator as IobCobCalculatorPlugin).overviewData - enum class ProgressData(val pass: Int, val percentOfTotal: Int) { + enum class ProgressData(private val pass: Int, val percentOfTotal: Int) { PREPARE_BASAL_DATA(0, 5), PREPARE_TEMPORARY_TARGET_DATA(1, 5), PREPARE_TREATMENTS_DATA(2, 5), - IOB_COB_OREF(3, 75), - PREPARE_IOB_AUTOSENS_DATA(4, 10); + IOB_COB_OREF(3, 74), + PREPARE_IOB_AUTOSENS_DATA(4, 10), + DRAW(5, 1); fun finalPercent(progress: Int): Int { var total = 0 diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt b/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt index 3038afcd6b..f5294d6d7f 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/UpdateGraphWorker.kt @@ -7,6 +7,7 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress import javax.inject.Inject class UpdateGraphWorker( @@ -26,6 +27,7 @@ class UpdateGraphWorker( overviewPlugin.overviewBus.send(EventUpdateOverviewGraph("UpdateGraphWorker")) else rxBus.send(EventUpdateOverviewGraph("UpdateGraphWorker")) + rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.DRAW, 100, null)) return Result.success() } } \ No newline at end of file