mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
ScoreList: Fix interaction between SKIP and rolling sum
This commit is contained in:
@@ -298,16 +298,18 @@ public abstract class ScoreList implements Iterable<Score>
|
||||
double percentageCompleted = Math.min(1, rollingSum / 1000 / habit.getTargetValue());
|
||||
previousValue = Score.compute(freq, previousValue, percentageCompleted);
|
||||
}
|
||||
else if (checkmarkValues[offset] != Checkmark.SKIP)
|
||||
else
|
||||
{
|
||||
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);
|
||||
if (checkmarkValues[offset] != SKIP)
|
||||
{
|
||||
double percentageCompleted = Math.min(1, rollingSum / numerator);
|
||||
previousValue = Score.compute(freq, previousValue, percentageCompleted);
|
||||
}
|
||||
}
|
||||
scores.add(new Score(from.plus(i), previousValue));
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package org.isoron.uhabits.core.models;
|
||||
|
||||
import org.isoron.uhabits.core.*;
|
||||
import org.isoron.uhabits.core.test.*;
|
||||
import org.isoron.uhabits.core.utils.*;
|
||||
import org.junit.*;
|
||||
|
||||
@@ -119,13 +118,7 @@ public class ScoreListTest extends BaseUnitTest
|
||||
0.000000
|
||||
};
|
||||
|
||||
ScoreList scores = habit.getScores();
|
||||
Timestamp current = DateUtils.getToday();
|
||||
for (double expectedValue : expectedValues)
|
||||
{
|
||||
assertThat(scores.getValue(current), closeTo(expectedValue, E));
|
||||
current = current.minus(1);
|
||||
}
|
||||
checkScoreValues(expectedValues);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,13 +155,26 @@ public class ScoreListTest extends BaseUnitTest
|
||||
0.000000
|
||||
};
|
||||
|
||||
ScoreList scores = habit.getScores();
|
||||
Timestamp current = DateUtils.getToday();
|
||||
for (double expectedValue : expectedValues)
|
||||
{
|
||||
assertThat(scores.getValue(current), closeTo(expectedValue, E));
|
||||
current = current.minus(1);
|
||||
}
|
||||
checkScoreValues(expectedValues);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getValueWithSkip2()
|
||||
{
|
||||
toggle(5);
|
||||
addSkip(4);
|
||||
|
||||
double[] expectedValues = {
|
||||
0.041949,
|
||||
0.044247,
|
||||
0.046670,
|
||||
0.049226,
|
||||
0.051922,
|
||||
0.051922,
|
||||
0.0
|
||||
};
|
||||
|
||||
checkScoreValues(expectedValues);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -349,4 +355,15 @@ public class ScoreListTest extends BaseUnitTest
|
||||
Timestamp today = DateUtils.getToday();
|
||||
reps.toggle(today.minus(day), Checkmark.SKIP);
|
||||
}
|
||||
|
||||
private void checkScoreValues(double[] expectedValues)
|
||||
{
|
||||
Timestamp current = DateUtils.getToday();
|
||||
ScoreList scores = habit.getScores();
|
||||
for (double expectedValue : expectedValues)
|
||||
{
|
||||
assertThat(scores.getValue(current), closeTo(expectedValue, E));
|
||||
current = current.minus(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user