ScoreList: Use rolling sum for non-daily numerical habits

pull/630/head
Alinson S. Xavier 5 years ago
parent 8a895b2d20
commit f44556e281

@ -267,21 +267,30 @@ public abstract class ScoreList implements Iterable<Score>
{
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<Score> 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];
}
value = Math.min(1, value);
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);
}
scores.add(new Score(from.plus(i), previousValue));
}

Loading…
Cancel
Save