From 3b650d63b4b9dfd17cdbd267f2150c0c19e175b2 Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Sun, 20 Mar 2022 16:58:49 +0100 Subject: [PATCH] Got the score chart to work --- .../isoron/uhabits/core/models/ScoreList.kt | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/ScoreList.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/ScoreList.kt index 23bd88fd1..74a66342e 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/ScoreList.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/ScoreList.kt @@ -100,20 +100,25 @@ class ScoreList { } val normalizedRollingSum = rollingSum / 1000 - val percentageCompleted = if (!isAtMost) { - if (targetValue > 0) - min(1.0, normalizedRollingSum / targetValue) - else - 1.0 - } else { - if (targetValue > 0) { - (1 - ((normalizedRollingSum - targetValue) / targetValue)).coerceIn(0.0, 1.0) + if(values[offset] != Entry.SKIP) { + val percentageCompleted = if (!isAtMost) { + if (targetValue > 0) + min(1.0, normalizedRollingSum / targetValue) + else + 1.0 } else { - if (normalizedRollingSum > 0) 0.0 else 1.0 + if (targetValue > 0) { + (1 - ((normalizedRollingSum - targetValue) / targetValue)).coerceIn( + 0.0, + 1.0 + ) + } else { + if (normalizedRollingSum > 0) 0.0 else 1.0 + } } - } - previousValue = compute(freq, previousValue, percentageCompleted) + previousValue = compute(freq, previousValue, percentageCompleted) + } } else { if (values[offset] == Entry.YES_MANUAL) { rollingSum += 1.0