diff --git a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Score.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Score.java index 9e5c1fd97..3272f0d28 100644 --- a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Score.java +++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Score.java @@ -63,6 +63,10 @@ public final class Score double previousScore, double checkmarkValue) { + + if (checkmarkValue < 0) + return previousScore; + double multiplier = pow(0.5, frequency / 13.0); double score = previousScore * multiplier; diff --git a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java index b3ba68370..236c394f3 100644 --- a/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java +++ b/uhabits-core/src/main/java/org/isoron/uhabits/core/models/ScoreList.java @@ -282,8 +282,8 @@ public abstract class ScoreList implements Iterable value /= habit.getTargetValue(); value = Math.min(1, value); } - - if (!habit.isNumerical() && value > 0) value = 1; + else if(value == 1.0) value = -1; + else if(value > 0) value = 1; previousValue = Score.compute(freq, previousValue, value); scores.add(new Score(from.plus(i), previousValue)); diff --git a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java index 3f2fd8783..32353edd0 100644 --- a/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java +++ b/uhabits-core/src/test/java/org/isoron/uhabits/core/models/ScoreListTest.java @@ -153,9 +153,9 @@ public class ScoreListTest extends BaseUnitTest habit.getScores().groupBy(DateUtils.TruncateField.MONTH); assertThat(list.size(), equalTo(5)); - assertThat(list.get(0).getValue(), closeTo(0.653659, E)); - assertThat(list.get(1).getValue(), closeTo(0.622715, E)); - assertThat(list.get(2).getValue(), closeTo(0.520997, E)); + assertThat(list.get(0).getValue(), closeTo(0.433317, E)); + assertThat(list.get(1).getValue(), closeTo(0.384690, E)); + assertThat(list.get(2).getValue(), closeTo(0.289305, E)); } @Test @@ -177,10 +177,10 @@ public class ScoreListTest extends BaseUnitTest { Habit habit = fixtures.createShortHabit(); - String expectedCSV = "2015-01-25,0.2654\n2015-01-24,0.2389\n" + - "2015-01-23,0.2475\n2015-01-22,0.2203\n" + - "2015-01-21,0.1921\n2015-01-20,0.1628\n" + - "2015-01-19,0.1325\n2015-01-18,0.1011\n" + + String expectedCSV = "2015-01-25,0.1866\n2015-01-24,0.1571\n" + + "2015-01-23,0.1628\n2015-01-22,0.1628\n" + + "2015-01-21,0.1325\n2015-01-20,0.1011\n" + + "2015-01-19,0.0686\n2015-01-18,0.0686\n" + "2015-01-17,0.0686\n2015-01-16,0.0349\n"; StringWriter writer = new StringWriter();