mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -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;
|
if (from.isNewerThan(to)) return;
|
||||||
|
|
||||||
|
double rollingSum = 0.0;
|
||||||
|
int denominator = habit.getFrequency().getDenominator();
|
||||||
final double freq = habit.getFrequency().toDouble();
|
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<>();
|
List<Score> scores = new LinkedList<>();
|
||||||
|
|
||||||
for (int i = 0; i < checkmarkValues.length; i++)
|
for (int i = 0; i < checkmarkValues.length; i++)
|
||||||
{
|
{
|
||||||
double value = checkmarkValues[checkmarkValues.length - i - 1];
|
int offset = checkmarkValues.length - i - 1;
|
||||||
if (habit.isNumerical())
|
if (habit.isNumerical())
|
||||||
{
|
{
|
||||||
value /= 1000;
|
rollingSum += checkmarkValues[offset];
|
||||||
value /= habit.getTargetValue();
|
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);
|
previousValue = Score.compute(freq, previousValue, value);
|
||||||
|
}
|
||||||
scores.add(new Score(from.plus(i), previousValue));
|
scores.add(new Score(from.plus(i), previousValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user