mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Added Streaks info for numeric habits
This commit is contained in:
@@ -100,7 +100,10 @@ data class Habit(
|
||||
streaks.recompute(
|
||||
computedEntries,
|
||||
from,
|
||||
to
|
||||
to,
|
||||
isNumerical,
|
||||
targetValue,
|
||||
targetType
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user