mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Make score take target value into account
This commit is contained in:
@@ -42,6 +42,8 @@ public class EditHabitCommand extends Command
|
||||
|
||||
private boolean hasFrequencyChanged;
|
||||
|
||||
private final boolean hasTargetChanged;
|
||||
|
||||
public EditHabitCommand(@Provided @NonNull ModelFactory modelFactory,
|
||||
@NonNull HabitList habitList,
|
||||
@NonNull Habit original,
|
||||
@@ -58,6 +60,9 @@ public class EditHabitCommand extends Command
|
||||
Frequency originalFreq = this.original.getFrequency();
|
||||
Frequency modifiedFreq = this.modified.getFrequency();
|
||||
hasFrequencyChanged = (!originalFreq.equals(modifiedFreq));
|
||||
hasTargetChanged =
|
||||
(original.getTargetType() != modified.getTargetType() ||
|
||||
original.getTargetValue() != modified.getTargetValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,11 +102,7 @@ public class EditHabitCommand extends Command
|
||||
|
||||
private void invalidateIfNeeded(Habit habit)
|
||||
{
|
||||
if (hasFrequencyChanged)
|
||||
{
|
||||
habit.getCheckmarks().invalidateNewerThan(0);
|
||||
habit.getStreaks().invalidateNewerThan(0);
|
||||
habit.getScores().invalidateNewerThan(0);
|
||||
}
|
||||
if (hasFrequencyChanged || hasTargetChanged)
|
||||
habit.invalidateNewerThan(0);
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class Habit
|
||||
this.name = "";
|
||||
this.description = "";
|
||||
this.targetType = AT_LEAST;
|
||||
this.targetValue = 0;
|
||||
this.targetValue = 1;
|
||||
this.unit = "";
|
||||
|
||||
checkmarks = factory.buildCheckmarkList(this);
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class Score
|
||||
*/
|
||||
public static double compute(double frequency,
|
||||
double previousScore,
|
||||
int checkmarkValue)
|
||||
double checkmarkValue)
|
||||
{
|
||||
double multiplier = pow(0.5, frequency / 13.0);
|
||||
|
||||
|
||||
@@ -276,8 +276,16 @@ public abstract class ScoreList implements Iterable<Score>
|
||||
|
||||
for (int i = 0; i < checkmarkValues.length; i++)
|
||||
{
|
||||
int value = checkmarkValues[checkmarkValues.length - i - 1];
|
||||
if(!habit.isNumerical() && value > 0) value = 1;
|
||||
double value = checkmarkValues[checkmarkValues.length - i - 1];
|
||||
|
||||
if(habit.isNumerical())
|
||||
{
|
||||
value /= habit.getTargetValue();
|
||||
value = Math.min(1, value);
|
||||
}
|
||||
|
||||
if(!habit.isNumerical() && value > 0)
|
||||
value = 1;
|
||||
|
||||
previousValue = Score.compute(freq, previousValue, value);
|
||||
scores.add(new Score(from + day * i, previousValue));
|
||||
|
||||
Reference in New Issue
Block a user