ScoreList: Use rolling sum method also for boolean habits

See #641
This commit is contained in:
2020-09-15 21:02:04 -05:00
parent a4ef657897
commit 8b847ae9fa
3 changed files with 58 additions and 10 deletions

View File

@@ -162,6 +162,7 @@ public class Habit
public synchronized void setFrequency(@NonNull Frequency frequency)
{
data.frequency = frequency;
invalidateNewerThan(Timestamp.ZERO);
}
@Nullable

View File

@@ -27,6 +27,8 @@ import java.io.*;
import java.text.*;
import java.util.*;
import static org.isoron.uhabits.core.models.Checkmark.*;
public abstract class ScoreList implements Iterable<Score>
{
protected final Habit habit;
@@ -268,6 +270,7 @@ public abstract class ScoreList implements Iterable<Score>
if (from.isNewerThan(to)) return;
double rollingSum = 0.0;
int numerator = habit.getFrequency().getNumerator();
int denominator = habit.getFrequency().getDenominator();
final double freq = habit.getFrequency().toDouble();
final int[] checkmarkValues = habit.getCheckmarks().getValues(from, to);
@@ -288,8 +291,14 @@ public abstract class ScoreList implements Iterable<Score>
}
else if (checkmarkValues[offset] != Checkmark.SKIP)
{
double value = Math.min(1, checkmarkValues[offset]);
previousValue = Score.compute(freq, previousValue, value);
if (checkmarkValues[offset] == YES_MANUAL)
rollingSum += 1.0;
if (offset + denominator < checkmarkValues.length)
if (checkmarkValues[offset + denominator] == YES_MANUAL)
rollingSum -= 1.0;
double percentageCompleted = Math.min(1, rollingSum / numerator);
previousValue = Score.compute(freq, previousValue, percentageCompleted);
}
scores.add(new Score(from.plus(i), previousValue));
}