From 34fe028233ec17ba25aded7e6d69e40d19aefde2 Mon Sep 17 00:00:00 2001 From: razeeman Date: Fri, 22 Dec 2023 18:54:16 +0300 Subject: [PATCH] fix category goals not calculating correctly --- .../interactor/NotificationGoalTimeInteractorImpl.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/goalTime/interactor/NotificationGoalTimeInteractorImpl.kt b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/goalTime/interactor/NotificationGoalTimeInteractorImpl.kt index 5125ee5c..02c9709b 100644 --- a/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/goalTime/interactor/NotificationGoalTimeInteractorImpl.kt +++ b/features/feature_notification/src/main/java/com/example/util/simpletimetracker/feature_notification/goalTime/interactor/NotificationGoalTimeInteractorImpl.kt @@ -250,6 +250,12 @@ class NotificationGoalTimeInteractorImpl @Inject constructor( .toList() categoryId to currents.sum() }.toMap() + val thisRangeRunningCounts = categoriesWithThisTypes.mapNotNull { (categoryId, typeIds) -> + val counts = runningRecords + .filter { it.id in typeIds } + .size + categoryId to counts + }.toMap() rangeGoals.forEach { goal -> val categoryId = (goal.idData as? RecordTypeGoal.IdData.Category)?.value @@ -257,9 +263,8 @@ class NotificationGoalTimeInteractorImpl @Inject constructor( val current = thisRangeCurrents[categoryId].orZero() val goalValue = goal.value * 1000 if (goalValue > current) { - val count = categoriesWithThisTypes[categoryId] - ?.sum() - .takeUnless { it == 0L } ?: return@forEach + val count = thisRangeRunningCounts[categoryId].orZero() + .takeUnless { it == 0 } ?: return@forEach scheduler.schedule( durationMillisFromNow = (goalValue - current) / count, idData = RecordTypeGoal.IdData.Category(categoryId), -- 2.51.2