Fix progressBar

This commit is contained in:
Milos Kozak 2023-01-07 23:35:24 +01:00
parent 82fb85c9e0
commit 9412f88672
7 changed files with 39 additions and 32 deletions

View file

@ -51,9 +51,11 @@ class PrepareBasalDataWorker(
var lastAbsoluteLineBasal = -1.0 var lastAbsoluteLineBasal = -1.0
var lastBaseBasal = 0.0 var lastBaseBasal = 0.0
var lastTempBasal = 0.0 var lastTempBasal = 0.0
var time = data.overviewData.fromTime val endTime = data.overviewData.endTime
while (time < data.overviewData.endTime) { val fromTime = data.overviewData.fromTime
val progress = (time - data.overviewData.endTime).toDouble() / (data.overviewData.endTime - data.overviewData.fromTime) * 100.0 var time = fromTime
while (time < endTime) {
val progress = (time - endTime).toDouble() / (endTime - fromTime) * 100.0
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_BASAL_DATA, progress.toInt(), null)) rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_BASAL_DATA, progress.toInt(), null))
val profile = profileFunction.getProfile(time) val profile = profileFunction.getProfile(time)
if (profile == null) { if (profile == null) {
@ -103,10 +105,10 @@ class PrepareBasalDataWorker(
} }
// final points // final points
basalLineArray.add(ScaledDataPoint(data.overviewData.endTime, lastLineBasal, data.overviewData.basalScale)) basalLineArray.add(ScaledDataPoint(endTime, lastLineBasal, data.overviewData.basalScale))
baseBasalArray.add(ScaledDataPoint(data.overviewData.endTime, lastBaseBasal, data.overviewData.basalScale)) baseBasalArray.add(ScaledDataPoint(endTime, lastBaseBasal, data.overviewData.basalScale))
tempBasalArray.add(ScaledDataPoint(data.overviewData.endTime, lastTempBasal, data.overviewData.basalScale)) tempBasalArray.add(ScaledDataPoint(endTime, lastTempBasal, data.overviewData.basalScale))
absoluteBasalLineArray.add(ScaledDataPoint(data.overviewData.endTime, lastAbsoluteLineBasal, data.overviewData.basalScale)) absoluteBasalLineArray.add(ScaledDataPoint(endTime, lastAbsoluteLineBasal, data.overviewData.basalScale))
// create series // create series
data.overviewData.baseBasalGraphSeries = LineGraphSeries(Array(baseBasalArray.size) { i -> baseBasalArray[i] }).also { data.overviewData.baseBasalGraphSeries = LineGraphSeries(Array(baseBasalArray.size) { i -> baseBasalArray[i] }).also {

View file

@ -40,11 +40,13 @@ class PrepareBgDataWorker(
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareBgData? val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareBgData?
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
val toTime = data.overviewData.toTime
val fromTime = data.overviewData.fromTime
data.overviewData.maxBgValue = Double.MIN_VALUE data.overviewData.maxBgValue = Double.MIN_VALUE
data.overviewData.bgReadingsArray = repository.compatGetBgReadingsDataFromTime(data.overviewData.fromTime, data.overviewData.toTime, false).blockingGet() data.overviewData.bgReadingsArray = repository.compatGetBgReadingsDataFromTime(data.overviewData.fromTime, data.overviewData.toTime, false).blockingGet()
val bgListArray: MutableList<DataPointWithLabelInterface> = ArrayList() val bgListArray: MutableList<DataPointWithLabelInterface> = ArrayList()
for (bg in data.overviewData.bgReadingsArray) { for (bg in data.overviewData.bgReadingsArray) {
if (bg.timestamp < data.overviewData.fromTime || bg.timestamp > data.overviewData.toTime) continue if (bg.timestamp < fromTime || bg.timestamp > toTime) continue
if (bg.value > data.overviewData.maxBgValue) data.overviewData.maxBgValue = bg.value if (bg.value > data.overviewData.maxBgValue) data.overviewData.maxBgValue = bg.value
bgListArray.add(GlucoseValueDataPoint(bg, defaultValueHelper, profileFunction, rh)) bgListArray.add(GlucoseValueDataPoint(bg, defaultValueHelper, profileFunction, rh))
} }

View file

@ -35,6 +35,8 @@ class PrepareBucketedDataWorker(
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareBucketedData? val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareBucketedData?
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
val toTime = data.overviewData.toTime
val fromTime = data.overviewData.fromTime
val bucketedData = data.iobCobCalculator.ads.getBucketedDataTableCopy() ?: return Result.success() val bucketedData = data.iobCobCalculator.ads.getBucketedDataTableCopy() ?: return Result.success()
if (bucketedData.isEmpty()) { if (bucketedData.isEmpty()) {
aapsLogger.debug("No bucketed data.") aapsLogger.debug("No bucketed data.")
@ -42,7 +44,7 @@ class PrepareBucketedDataWorker(
} }
val bucketedListArray: MutableList<DataPointWithLabelInterface> = ArrayList() val bucketedListArray: MutableList<DataPointWithLabelInterface> = ArrayList()
for (inMemoryGlucoseValue in bucketedData) { for (inMemoryGlucoseValue in bucketedData) {
if (inMemoryGlucoseValue.timestamp < data.overviewData.fromTime || inMemoryGlucoseValue.timestamp > data.overviewData.toTime) continue if (inMemoryGlucoseValue.timestamp < fromTime || inMemoryGlucoseValue.timestamp > toTime) continue
bucketedListArray.add(InMemoryGlucoseValueDataPoint(inMemoryGlucoseValue, defaultValueHelper , profileFunction, rh)) bucketedListArray.add(InMemoryGlucoseValueDataPoint(inMemoryGlucoseValue, defaultValueHelper , profileFunction, rh))
} }
bucketedListArray.sortWith { o1: DataPointWithLabelInterface, o2: DataPointWithLabelInterface -> o1.x.compareTo(o2.x) } bucketedListArray.sortWith { o1: DataPointWithLabelInterface, o2: DataPointWithLabelInterface -> o1.x.compareTo(o2.x) }

View file

@ -117,13 +117,16 @@ class PrepareIobAutosensGraphDataWorker(
override fun doWorkAndLog(): Result { override fun doWorkAndLog(): Result {
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareIobAutosensData? val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareIobAutosensData?
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
val endTime = data.overviewData.endTime
val fromTime = data.overviewData.fromTime
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_IOB_AUTOSENS_DATA, 0, null)) rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_IOB_AUTOSENS_DATA, 0, null))
val iobArray: MutableList<ScaledDataPoint> = ArrayList() val iobArray: MutableList<ScaledDataPoint> = ArrayList()
val absIobArray: MutableList<ScaledDataPoint> = ArrayList() val absIobArray: MutableList<ScaledDataPoint> = ArrayList()
data.overviewData.maxIobValueFound = Double.MIN_VALUE data.overviewData.maxIobValueFound = Double.MIN_VALUE
var lastIob = 0.0 var lastIob = 0.0
var absLastIob = 0.0 var absLastIob = 0.0
var time = data.overviewData.fromTime var time = fromTime
val minFailOverActiveList: MutableList<DataPointWithLabelInterface> = ArrayList() val minFailOverActiveList: MutableList<DataPointWithLabelInterface> = ArrayList()
val cobArray: MutableList<ScaledDataPoint> = ArrayList() val cobArray: MutableList<ScaledDataPoint> = ArrayList()
@ -153,8 +156,8 @@ class PrepareIobAutosensGraphDataWorker(
val adsData = data.iobCobCalculator.ads.clone() val adsData = data.iobCobCalculator.ads.clone()
while (time <= data.overviewData.endTime) { while (time <= endTime) {
val progress = (time - data.overviewData.endTime).toDouble() / (data.overviewData.endTime - data.overviewData.fromTime) * 100.0 val progress = (time - endTime).toDouble() / (endTime - fromTime) * 100.0
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_IOB_AUTOSENS_DATA, progress.toInt(), null)) rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_IOB_AUTOSENS_DATA, progress.toInt(), null))
val profile = profileFunction.getProfile(time) val profile = profileFunction.getProfile(time)
if (profile == null) { if (profile == null) {

View file

@ -49,13 +49,14 @@ class PrepareTemporaryTargetDataWorker(
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TEMPORARY_TARGET_DATA, 0, null)) rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TEMPORARY_TARGET_DATA, 0, null))
val profile = profileFunction.getProfile() ?: return Result.success(workDataOf("Error" to "missing profile")) val profile = profileFunction.getProfile() ?: return Result.success(workDataOf("Error" to "missing profile"))
val units = profileFunction.getUnits() val units = profileFunction.getUnits()
var toTime = data.overviewData.endTime var endTime = data.overviewData.endTime
val fromTime = data.overviewData.fromTime
val targetsSeriesArray: MutableList<DataPoint> = ArrayList() val targetsSeriesArray: MutableList<DataPoint> = ArrayList()
var lastTarget = -1.0 var lastTarget = -1.0
loop.lastRun?.constraintsProcessed?.let { toTime = max(it.latestPredictionsTime, toTime) } loop.lastRun?.constraintsProcessed?.let { endTime = max(it.latestPredictionsTime, endTime) }
var time = data.overviewData.fromTime var time = fromTime
while (time < toTime) { while (time < endTime) {
val progress = (time - data.overviewData.fromTime).toDouble() / (data.overviewData.toTime - data.overviewData.fromTime) * 100.0 val progress = (time - fromTime).toDouble() / (endTime - fromTime) * 100.0
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TEMPORARY_TARGET_DATA, progress.toInt(), null)) rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TEMPORARY_TARGET_DATA, progress.toInt(), null))
val tt = repository.getTemporaryTargetActiveAt(time).blockingGet() val tt = repository.getTemporaryTargetActiveAt(time).blockingGet()
val value: Double = if (tt is ValueWrapper.Existing) { val value: Double = if (tt is ValueWrapper.Existing) {
@ -71,7 +72,7 @@ class PrepareTemporaryTargetDataWorker(
time += 5 * 60 * 1000L time += 5 * 60 * 1000L
} }
// final point // final point
targetsSeriesArray.add(DataPoint(toTime.toDouble(), lastTarget)) targetsSeriesArray.add(DataPoint(endTime.toDouble(), lastTarget))
// create series // create series
data.overviewData.temporaryTargetSeries = LineGraphSeries(Array(targetsSeriesArray.size) { i -> targetsSeriesArray[i] }).also { data.overviewData.temporaryTargetSeries = LineGraphSeries(Array(targetsSeriesArray.size) { i -> targetsSeriesArray[i] }).also {
it.isDrawBackground = false it.isDrawBackground = false

View file

@ -53,6 +53,8 @@ class PrepareTreatmentsDataWorker(
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareTreatmentsData? val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareTreatmentsData?
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
val endTime = data.overviewData.endTime
val fromTime = data.overviewData.fromTime
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TREATMENTS_DATA, 0, null)) rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TREATMENTS_DATA, 0, null))
data.overviewData.maxTreatmentsValue = 0.0 data.overviewData.maxTreatmentsValue = 0.0
data.overviewData.maxEpsValue = 0.0 data.overviewData.maxEpsValue = 0.0
@ -60,14 +62,14 @@ class PrepareTreatmentsDataWorker(
val filteredTherapyEvents: MutableList<DataPointWithLabelInterface> = ArrayList() val filteredTherapyEvents: MutableList<DataPointWithLabelInterface> = ArrayList()
val filteredEps: MutableList<DataPointWithLabelInterface> = ArrayList() val filteredEps: MutableList<DataPointWithLabelInterface> = ArrayList()
repository.getBolusesDataFromTimeToTime(data.overviewData.fromTime, data.overviewData.endTime, true).blockingGet() repository.getBolusesDataFromTimeToTime(fromTime, endTime, true).blockingGet()
.map { BolusDataPoint(it, rh, activePlugin, defaultValueHelper) } .map { BolusDataPoint(it, rh, activePlugin, defaultValueHelper) }
.filter { it.data.type == Bolus.Type.NORMAL || it.data.type == Bolus.Type.SMB } .filter { it.data.type == Bolus.Type.NORMAL || it.data.type == Bolus.Type.SMB }
.forEach { .forEach {
it.y = getNearestBg(data.overviewData, it.x.toLong()) it.y = getNearestBg(data.overviewData, it.x.toLong())
filteredTreatments.add(it) filteredTreatments.add(it)
} }
repository.getCarbsDataFromTimeToTimeExpanded(data.overviewData.fromTime, data.overviewData.endTime, true).blockingGet() repository.getCarbsDataFromTimeToTimeExpanded(fromTime, endTime, true).blockingGet()
.map { CarbsDataPoint(it, rh) } .map { CarbsDataPoint(it, rh) }
.forEach { .forEach {
it.y = getNearestBg(data.overviewData, it.x.toLong()) it.y = getNearestBg(data.overviewData, it.x.toLong())
@ -75,7 +77,7 @@ class PrepareTreatmentsDataWorker(
} }
// ProfileSwitch // ProfileSwitch
repository.getEffectiveProfileSwitchDataFromTimeToTime(data.overviewData.fromTime, data.overviewData.endTime, true).blockingGet() repository.getEffectiveProfileSwitchDataFromTimeToTime(fromTime, endTime, true).blockingGet()
.map { EffectiveProfileSwitchDataPoint(it, rh, data.overviewData.epsScale) } .map { EffectiveProfileSwitchDataPoint(it, rh, data.overviewData.epsScale) }
.forEach { .forEach {
data.overviewData.maxEpsValue = maxOf(data.overviewData.maxEpsValue, it.data.originalPercentage.toDouble()) data.overviewData.maxEpsValue = maxOf(data.overviewData.maxEpsValue, it.data.originalPercentage.toDouble())
@ -96,7 +98,7 @@ class PrepareTreatmentsDataWorker(
// Extended bolus // Extended bolus
if (!activePlugin.activePump.isFakingTempsByExtendedBoluses) { if (!activePlugin.activePump.isFakingTempsByExtendedBoluses) {
repository.getExtendedBolusDataFromTimeToTime(data.overviewData.fromTime, data.overviewData.endTime, true).blockingGet() repository.getExtendedBolusDataFromTimeToTime(fromTime, endTime, true).blockingGet()
.map { ExtendedBolusDataPoint(it, rh) } .map { ExtendedBolusDataPoint(it, rh) }
.filter { it.duration != 0L } .filter { it.duration != 0L }
.forEach { .forEach {
@ -106,21 +108,19 @@ class PrepareTreatmentsDataWorker(
} }
// Careportal // Careportal
repository.compatGetTherapyEventDataFromToTime(data.overviewData.fromTime - T.hours(6).msecs(), data.overviewData.endTime).blockingGet() repository.compatGetTherapyEventDataFromToTime(fromTime - T.hours(6).msecs(), endTime).blockingGet()
.map { TherapyEventDataPoint(it, rh, profileFunction, translator) } .map { TherapyEventDataPoint(it, rh, profileFunction, translator) }
.filterTimeframe(data.overviewData.fromTime, data.overviewData.endTime) .filterTimeframe(fromTime, endTime)
.forEach { .forEach {
if (it.y == 0.0) it.y = getNearestBg(data.overviewData, it.x.toLong()) if (it.y == 0.0) it.y = getNearestBg(data.overviewData, it.x.toLong())
filteredTherapyEvents.add(it) filteredTherapyEvents.add(it)
} }
// increase maxY if a treatment forces it's own height that's higher than a BG value // increase maxY if a treatment forces it's own height that's higher than a BG value
filteredTreatments.map { it.y } filteredTreatments.maxOfOrNull { it.y }
.maxOrNull()
?.let(::addUpperChartMargin) ?.let(::addUpperChartMargin)
?.let { data.overviewData.maxTreatmentsValue = maxOf(data.overviewData.maxTreatmentsValue, it) } ?.let { data.overviewData.maxTreatmentsValue = maxOf(data.overviewData.maxTreatmentsValue, it) }
filteredTherapyEvents.map { it.y } filteredTherapyEvents.maxOfOrNull { it.y }
.maxOrNull()
?.let(::addUpperChartMargin) ?.let(::addUpperChartMargin)
?.let { data.overviewData.maxTherapyEventValue = maxOf(data.overviewData.maxTherapyEventValue, it) } ?.let { data.overviewData.maxTherapyEventValue = maxOf(data.overviewData.maxTherapyEventValue, it) }

View file

@ -6,7 +6,6 @@ import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.events.EventIobCalculationProgress
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.utils.receivers.DataWorkerStorage
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.core.workflow.CalculationWorkflow
@ -250,9 +249,7 @@ class IobCobOrefWorker @Inject internal constructor(
if (bgTime < dateUtil.now()) autosensDataTable.put(bgTime, autosensData) if (bgTime < dateUtil.now()) autosensDataTable.put(bgTime, autosensData)
aapsLogger.debug( aapsLogger.debug(
LTag.AUTOSENS, LTag.AUTOSENS,
"Running detectSensitivity from: " + dateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + dateUtil.dateAndTimeString(bgTime) + " lastDataTime:" + ads.lastDataTime( "Running detectSensitivity from: " + dateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + dateUtil.dateAndTimeString(bgTime) + " lastDataTime:" + ads.lastDataTime(dateUtil)
dateUtil
)
) )
val sensitivity = activePlugin.activeSensitivity.detectSensitivity(ads, oldestTimeWithData, bgTime) val sensitivity = activePlugin.activeSensitivity.detectSensitivity(ads, oldestTimeWithData, bgTime)
aapsLogger.debug(LTag.AUTOSENS, "Sensitivity result: $sensitivity") aapsLogger.debug(LTag.AUTOSENS, "Sensitivity result: $sensitivity")