Added Streaks info for numeric habits

This commit is contained in:
Abdul Majeed
2024-10-24 00:16:04 +05:30
committed by Alinson S. Xavier
parent 2296a49999
commit 13ecc2a386
3 changed files with 20 additions and 7 deletions

View File

@@ -100,7 +100,10 @@ data class Habit(
streaks.recompute(
computedEntries,
from,
to
to,
isNumerical,
targetValue,
targetType
)
}

View File

@@ -37,12 +37,25 @@ class StreakList {
fun recompute(
computedEntries: EntryList,
from: Timestamp,
to: Timestamp
to: Timestamp,
isNumerical: Boolean,
targetValue: Double,
targetType: NumericalHabitType
) {
list.clear()
val timestamps = computedEntries
.getByInterval(from, to)
.filter { it.value > 0 }
.filter {
val value = it.value
if (isNumerical) {
when (targetType) {
NumericalHabitType.AT_LEAST -> value / 1000.0 >= targetValue
NumericalHabitType.AT_MOST -> value != Entry.UNKNOWN && value / 1000.0 <= targetValue
}
} else {
value > 0
}
}
.map { it.timestamp }
.toTypedArray()