diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java index 748e8f2cc..f37a4b095 100644 --- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java +++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java @@ -267,21 +267,30 @@ public abstract class ScoreList implements Iterable { if (from.isNewerThan(to)) return; + double rollingSum = 0.0; + int denominator = habit.getFrequency().getDenominator(); final double freq = habit.getFrequency().toDouble(); - final int checkmarkValues[] = habit.getCheckmarks().getValues(from, to); + final int[] checkmarkValues = habit.getCheckmarks().getValues(from, to); List scores = new LinkedList<>(); for (int i = 0; i < checkmarkValues.length; i++) { - double value = checkmarkValues[checkmarkValues.length - i - 1]; + int offset = checkmarkValues.length - i - 1; if (habit.isNumerical()) { - value /= 1000; - value /= habit.getTargetValue(); + rollingSum += checkmarkValues[offset]; + if (offset + denominator < checkmarkValues.length) { + rollingSum -= checkmarkValues[offset + denominator]; + } + double percentageCompleted = Math.min(1, rollingSum / 1000 / habit.getTargetValue()); + previousValue = Score.compute(1.0, previousValue, percentageCompleted); + } + else + { + double value = Math.min(1, checkmarkValues[offset]); + previousValue = Score.compute(freq, previousValue, value); } - value = Math.min(1, value); - previousValue = Score.compute(freq, previousValue, value); scores.add(new Score(from.plus(i), previousValue)); }