mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
ScoreList: Use rolling sum for non-daily numerical habits
This commit is contained in:
@@ -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];
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user