fix calculation progress

This commit is contained in:
Milos Kozak 2022-09-22 21:21:23 +02:00
parent 8fb5c5a984
commit cc4feb610c
4 changed files with 14 additions and 11 deletions

View file

@ -31,31 +31,31 @@ class CompatDBHelper @Inject constructor(
* *
*/ */
var newestGlucoseValue: GlucoseValue? = null var newestGlucoseValue: GlucoseValue? = null
it.filterIsInstance<GlucoseValue>().lastOrNull()?.let { gv -> it.filterIsInstance<GlucoseValue>().maxByOrNull { gv -> gv.timestamp }?.let { gv ->
aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv") aapsLogger.debug(LTag.DATABASE, "Firing EventNewBg $gv")
rxBus.send(EventNewBG(gv)) rxBus.send(EventNewBG(gv))
newestGlucoseValue = gv newestGlucoseValue = gv
} }
it.filterIsInstance<GlucoseValue>().map { gv -> gv.timestamp }.minOrNull()?.let { timestamp -> it.filterIsInstance<GlucoseValue>().minOfOrNull { gv -> gv.timestamp }?.let { timestamp ->
aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData $newestGlucoseValue") aapsLogger.debug(LTag.DATABASE, "Firing EventNewHistoryData $timestamp $newestGlucoseValue")
rxBus.send(EventNewHistoryData(timestamp, true, newestGlucoseValue)) rxBus.send(EventNewHistoryData(timestamp, true, newestGlucoseValue))
} }
it.filterIsInstance<Carbs>().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> it.filterIsInstance<Carbs>().minOfOrNull { t -> t.timestamp }?.let { timestamp ->
aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp") aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp")
rxBus.send(EventTreatmentChange()) rxBus.send(EventTreatmentChange())
rxBus.send(EventNewHistoryData(timestamp, false)) rxBus.send(EventNewHistoryData(timestamp, false))
} }
it.filterIsInstance<Bolus>().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> it.filterIsInstance<Bolus>().minOfOrNull { t -> t.timestamp }?.let { timestamp ->
aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp") aapsLogger.debug(LTag.DATABASE, "Firing EventTreatmentChange $timestamp")
rxBus.send(EventTreatmentChange()) rxBus.send(EventTreatmentChange())
rxBus.send(EventNewHistoryData(timestamp, false)) rxBus.send(EventNewHistoryData(timestamp, false))
} }
it.filterIsInstance<TemporaryBasal>().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> it.filterIsInstance<TemporaryBasal>().minOfOrNull { t -> t.timestamp }?.let { timestamp ->
aapsLogger.debug(LTag.DATABASE, "Firing EventTempBasalChange $timestamp") aapsLogger.debug(LTag.DATABASE, "Firing EventTempBasalChange $timestamp")
rxBus.send(EventTempBasalChange()) rxBus.send(EventTempBasalChange())
rxBus.send(EventNewHistoryData(timestamp, false)) rxBus.send(EventNewHistoryData(timestamp, false))
} }
it.filterIsInstance<ExtendedBolus>().map { t -> t.timestamp }.minOrNull()?.let { timestamp -> it.filterIsInstance<ExtendedBolus>().minOfOrNull { t -> t.timestamp }?.let { timestamp ->
aapsLogger.debug(LTag.DATABASE, "Firing EventExtendedBolusChange $timestamp") aapsLogger.debug(LTag.DATABASE, "Firing EventExtendedBolusChange $timestamp")
rxBus.send(EventExtendedBolusChange()) rxBus.send(EventExtendedBolusChange())
rxBus.send(EventNewHistoryData(timestamp, false)) rxBus.send(EventNewHistoryData(timestamp, false))

View file

@ -369,7 +369,7 @@ class IobCobCalculatorPlugin @Inject constructor(
@Synchronized @Synchronized
private fun scheduleHistoryDataChange(event: EventNewHistoryData) { private fun scheduleHistoryDataChange(event: EventNewHistoryData) {
// if there is nothing scheduled or asking reload deeper to the past // 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 // cancel waiting task to prevent sending multiple posts
scheduledHistoryPost?.cancel(false) scheduledHistoryPost?.cancel(false)
// prepare task for execution in 1 sec // prepare task for execution in 1 sec

View file

@ -60,12 +60,13 @@ class CalculationWorkflow @Inject constructor(
private val overviewData: OverviewData private val overviewData: OverviewData
get() = (iobCobCalculator as IobCobCalculatorPlugin).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_BASAL_DATA(0, 5),
PREPARE_TEMPORARY_TARGET_DATA(1, 5), PREPARE_TEMPORARY_TARGET_DATA(1, 5),
PREPARE_TREATMENTS_DATA(2, 5), PREPARE_TREATMENTS_DATA(2, 5),
IOB_COB_OREF(3, 75), IOB_COB_OREF(3, 74),
PREPARE_IOB_AUTOSENS_DATA(4, 10); PREPARE_IOB_AUTOSENS_DATA(4, 10),
DRAW(5, 1);
fun finalPercent(progress: Int): Int { fun finalPercent(progress: Int): Int {
var total = 0 var total = 0

View file

@ -7,6 +7,7 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin
import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewGraph
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress
import javax.inject.Inject import javax.inject.Inject
class UpdateGraphWorker( class UpdateGraphWorker(
@ -26,6 +27,7 @@ class UpdateGraphWorker(
overviewPlugin.overviewBus.send(EventUpdateOverviewGraph("UpdateGraphWorker")) overviewPlugin.overviewBus.send(EventUpdateOverviewGraph("UpdateGraphWorker"))
else else
rxBus.send(EventUpdateOverviewGraph("UpdateGraphWorker")) rxBus.send(EventUpdateOverviewGraph("UpdateGraphWorker"))
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.DRAW, 100, null))
return Result.success() return Result.success()
} }
} }