Handle numerical habits with target value of zero

Fixes #903
This commit is contained in:
2021-05-15 20:08:04 -05:00
parent 89e3dd7655
commit fcadbe7c38
6 changed files with 30 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ import org.isoron.uhabits.core.models.Score.Companion.compute
import java.util.ArrayList
import java.util.HashMap
import javax.annotation.concurrent.ThreadSafe
import kotlin.math.max
import kotlin.math.min
@ThreadSafe
@@ -93,11 +94,15 @@ class ScoreList {
for (i in values.indices) {
val offset = values.size - i - 1
if (isNumerical) {
rollingSum += values[offset]
rollingSum += max(0, values[offset])
if (offset + denominator < values.size) {
rollingSum -= values[offset + denominator]
}
val percentageCompleted = min(1.0, rollingSum / 1000 / targetValue)
val percentageCompleted = if (targetValue > 0) {
min(1.0, rollingSum / 1000 / targetValue)
} else {
1.0
}
previousValue = compute(freq, previousValue, percentageCompleted)
} else {
if (values[offset] == Entry.YES_MANUAL) {