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