improve calculation workflow behavior

This commit is contained in:
Milos Kozak 2023-08-16 13:54:23 +02:00
parent 551af710b6
commit 6ebec7935d
4 changed files with 7 additions and 4 deletions

View file

@ -198,23 +198,23 @@ class CalculationWorkflowImpl @Inject constructor(
.build()
)
.then(
job == MAIN_CALCULATION,
runIf = job == MAIN_CALCULATION,
OneTimeWorkRequest.Builder(UpdateGraphWorker::class.java)
.setInputData(Data.Builder().putString(JOB, job).putInt(PASS, CalculationWorkflow.ProgressData.DRAW_IOB.pass).build())
.build()
)
.then(
job == MAIN_CALCULATION,
runIf = job == MAIN_CALCULATION,
OneTimeWorkRequest.Builder(InvokeLoopWorker::class.java)
.setInputData(dataWorkerStorage.storeInputData(InvokeLoopWorker.InvokeLoopData(cause)))
.build()
)
.then(
job == MAIN_CALCULATION,
runIf = job == MAIN_CALCULATION,
OneTimeWorkRequest.Builder(UpdateWidgetWorker::class.java).build()
)
.then(
job == MAIN_CALCULATION,
runIf = job == MAIN_CALCULATION,
OneTimeWorkRequest.Builder(PreparePredictionsWorker::class.java)
.setInputData(dataWorkerStorage.storeInputData(PreparePredictionsWorker.PreparePredictionsData(overviewData)))
.build()

View file

@ -57,6 +57,7 @@ class PrepareBasalDataWorker(
val fromTime = data.overviewData.fromTime
var time = fromTime
while (time < endTime) {
if (isStopped) return Result.failure(workDataOf("Error" to "stopped"))
val progress = (time - fromTime).toDouble() / (endTime - fromTime) * 100.0
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_BASAL_DATA, progress.toInt(), null))
val profile = profileFunction.getProfile(time)

View file

@ -158,6 +158,7 @@ class PrepareIobAutosensGraphDataWorker(
val adsData = data.iobCobCalculator.ads.clone()
while (time <= endTime) {
if (isStopped) return Result.failure(workDataOf("Error" to "stopped"))
val progress = (time - fromTime).toDouble() / (endTime - fromTime) * 100.0
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_IOB_AUTOSENS_DATA, progress.toInt(), null))
val profile = profileFunction.getProfile(time)

View file

@ -58,6 +58,7 @@ class PrepareTemporaryTargetDataWorker(
loop.lastRun?.constraintsProcessed?.let { endTime = max(it.latestPredictionsTime, endTime) }
var time = fromTime
while (time < endTime) {
if (isStopped) return Result.failure(workDataOf("Error" to "stopped"))
val progress = (time - fromTime).toDouble() / (endTime - fromTime) * 100.0
rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_TEMPORARY_TARGET_DATA, progress.toInt(), null))
val tt = repository.getTemporaryTargetActiveAt(time).blockingGet()