mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Unify Checkmarks and Repetitions
This commit is contained in:
@@ -75,7 +75,7 @@ public class HabitFixtures
|
|||||||
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
|
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
|
||||||
|
|
||||||
for (int mark : marks)
|
for (int mark : marks)
|
||||||
habit.getRepetitions().setValue(today.minus(mark), YES_MANUAL);
|
habit.getOriginalCheckmarks().setValue(today.minus(mark), YES_MANUAL);
|
||||||
|
|
||||||
return habit;
|
return habit;
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ public class HabitFixtures
|
|||||||
582, 583, 584, 586, 589};
|
582, 583, 584, 586, 589};
|
||||||
|
|
||||||
for (int mark : marks)
|
for (int mark : marks)
|
||||||
habit.getRepetitions().setValue(today.minus(mark), YES_MANUAL);
|
habit.getOriginalCheckmarks().setValue(today.minus(mark), YES_MANUAL);
|
||||||
|
|
||||||
return habit;
|
return habit;
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ public class HabitFixtures
|
|||||||
Timestamp timestamp = DateUtils.getToday();
|
Timestamp timestamp = DateUtils.getToday();
|
||||||
for (int value : LONG_NUMERICAL_HABIT_CHECKS)
|
for (int value : LONG_NUMERICAL_HABIT_CHECKS)
|
||||||
{
|
{
|
||||||
habit.getRepetitions().setValue(timestamp, value);
|
habit.getOriginalCheckmarks().setValue(timestamp, value);
|
||||||
timestamp = timestamp.minus(1);
|
timestamp = timestamp.minus(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ public class HabitFixtures
|
|||||||
Timestamp timestamp = DateUtils.getToday();
|
Timestamp timestamp = DateUtils.getToday();
|
||||||
for (boolean c : LONG_HABIT_CHECKS)
|
for (boolean c : LONG_HABIT_CHECKS)
|
||||||
{
|
{
|
||||||
if (c) habit.getRepetitions().setValue(timestamp, YES_MANUAL);
|
if (c) habit.getOriginalCheckmarks().setValue(timestamp, YES_MANUAL);
|
||||||
timestamp = timestamp.minus(1);
|
timestamp = timestamp.minus(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class BarChartTest extends BaseViewTest
|
|||||||
Habit habit = fixtures.createLongNumericalHabit();
|
Habit habit = fixtures.createLongNumericalHabit();
|
||||||
view = new BarChart(targetContext);
|
view = new BarChart(targetContext);
|
||||||
Timestamp today = DateUtils.getToday();
|
Timestamp today = DateUtils.getToday();
|
||||||
CheckmarkList checkmarks = habit.getCheckmarks();
|
CheckmarkList checkmarks = habit.getComputedCheckmarks();
|
||||||
view.setCheckmarks(checkmarks.getByInterval(today.minus(20), today));
|
view.setCheckmarks(checkmarks.getByInterval(today.minus(20), today));
|
||||||
view.setColor(PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), targetContext));
|
view.setColor(PaletteUtilsKt.toThemedAndroidColor(habit.getColor(), targetContext));
|
||||||
view.setTarget(200.0);
|
view.setTarget(200.0);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class FrequencyChartTest extends BaseViewTest
|
|||||||
Habit habit = fixtures.createLongHabit();
|
Habit habit = fixtures.createLongHabit();
|
||||||
|
|
||||||
view = new FrequencyChart(targetContext);
|
view = new FrequencyChart(targetContext);
|
||||||
view.setFrequency(habit.getRepetitions().getWeekdayFrequency());
|
view.setFrequency(habit.getOriginalCheckmarks().getWeekdayFrequency());
|
||||||
view.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
|
view.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
|
||||||
measureView(view, dpToPixels(300), dpToPixels(100));
|
measureView(view, dpToPixels(300), dpToPixels(100));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class HistoryChartTest extends BaseViewTest
|
|||||||
|
|
||||||
chart = new HistoryChart(targetContext);
|
chart = new HistoryChart(targetContext);
|
||||||
chart.setSkipEnabled(true);
|
chart.setSkipEnabled(true);
|
||||||
chart.setCheckmarks(habit.getCheckmarks().getAllValues());
|
chart.setCheckmarks(habit.getComputedCheckmarks().getAllValues());
|
||||||
chart.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
|
chart.setColor(PaletteUtilsKt.toFixedAndroidColor(habit.getColor()));
|
||||||
measureView(chart, dpToPixels(400), dpToPixels(200));
|
measureView(chart, dpToPixels(400), dpToPixels(200));
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class HabitCardViewTest : BaseViewTest() {
|
|||||||
habit2 = fixtures.createLongNumericalHabit()
|
habit2 = fixtures.createLongNumericalHabit()
|
||||||
view = component.getHabitCardViewFactory().create().apply {
|
view = component.getHabitCardViewFactory().create().apply {
|
||||||
habit = habit1
|
habit = habit1
|
||||||
values = habit1.checkmarks.allValues
|
values = habit1.computedCheckmarks.allValues
|
||||||
score = habit1.scores.todayValue
|
score = habit1.scores.todayValue
|
||||||
isSelected = false
|
isSelected = false
|
||||||
buttonCount = 5
|
buttonCount = 5
|
||||||
@@ -70,7 +70,7 @@ class HabitCardViewTest : BaseViewTest() {
|
|||||||
fun testRender_numerical() {
|
fun testRender_numerical() {
|
||||||
view.apply {
|
view.apply {
|
||||||
habit = habit2
|
habit = habit2
|
||||||
values = habit2.checkmarks.allValues
|
values = habit2.computedCheckmarks.allValues
|
||||||
}
|
}
|
||||||
assertRenders(view, "$PATH/render_numerical.png")
|
assertRenders(view, "$PATH/render_numerical.png")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class PerformanceTest extends BaseAndroidTest
|
|||||||
for (int i = 0; i < 100000; i++)
|
for (int i = 0; i < 100000; i++)
|
||||||
{
|
{
|
||||||
habit.getScores().getTodayValue();
|
habit.getScores().getTodayValue();
|
||||||
habit.getCheckmarks().getTodayValue();
|
habit.getComputedCheckmarks().getTodayValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class CheckmarkWidgetTest extends BaseViewTest
|
|||||||
prefs.setSkipEnabled(true);
|
prefs.setSkipEnabled(true);
|
||||||
|
|
||||||
habit = fixtures.createVeryLongHabit();
|
habit = fixtures.createVeryLongHabit();
|
||||||
checkmarks = habit.getCheckmarks();
|
checkmarks = habit.getComputedCheckmarks();
|
||||||
CheckmarkWidget widget = new CheckmarkWidget(targetContext, 0, habit);
|
CheckmarkWidget widget = new CheckmarkWidget(targetContext, 0, habit);
|
||||||
view = convertToView(widget, 150, 200);
|
view = convertToView(widget, 150, 200);
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class CheckmarkWidgetViewTest extends BaseViewTest
|
|||||||
float percentage = (float) score;
|
float percentage = (float) score;
|
||||||
|
|
||||||
view.setActiveColor(PaletteUtils.getAndroidTestColor(0));
|
view.setActiveColor(PaletteUtils.getAndroidTestColor(0));
|
||||||
view.setCheckmarkState(habit.getCheckmarks().getTodayValue());
|
view.setCheckmarkState(habit.getComputedCheckmarks().getTodayValue());
|
||||||
view.setCheckmarkValue(habit.getCheckmarks().getTodayValue());
|
view.setCheckmarkValue(habit.getComputedCheckmarks().getTodayValue());
|
||||||
view.setPercentage(percentage);
|
view.setPercentage(percentage);
|
||||||
view.setName(habit.getName());
|
view.setName(habit.getName());
|
||||||
view.refresh();
|
view.refresh();
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onPause()
|
public void onPause()
|
||||||
{
|
{
|
||||||
habit.getCheckmarks().observable.removeListener(this);
|
habit.getComputedCheckmarks().observable.removeListener(this);
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
|
|||||||
getDialog().getWindow().setLayout(width, height);
|
getDialog().getWindow().setLayout(width, height);
|
||||||
|
|
||||||
refreshData();
|
refreshData();
|
||||||
habit.getCheckmarks().observable.addListener(this);
|
habit.getComputedCheckmarks().observable.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -175,7 +175,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
|
|||||||
@Override
|
@Override
|
||||||
public void doInBackground()
|
public void doInBackground()
|
||||||
{
|
{
|
||||||
checkmarks = habit.getCheckmarks().getAllValues();
|
checkmarks = habit.getComputedCheckmarks().getAllValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -96,9 +96,9 @@ class BarCardPresenter(
|
|||||||
boolBucketSizes[boolSpinnerPosition]
|
boolBucketSizes[boolSpinnerPosition]
|
||||||
}
|
}
|
||||||
val checkmarks = if (bucketSize == 1) {
|
val checkmarks = if (bucketSize == 1) {
|
||||||
habit.checkmarks.all
|
habit.computedCheckmarks.all
|
||||||
} else {
|
} else {
|
||||||
habit.checkmarks.groupBy(getTruncateField(bucketSize), firstWeekday)
|
habit.computedCheckmarks.groupBy(getTruncateField(bucketSize), firstWeekday)
|
||||||
}
|
}
|
||||||
return BarCardViewModel(
|
return BarCardViewModel(
|
||||||
checkmarks = checkmarks,
|
checkmarks = checkmarks,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class FrequencyCardPresenter(
|
|||||||
) {
|
) {
|
||||||
fun present() = FrequencyCardViewModel(
|
fun present() = FrequencyCardViewModel(
|
||||||
color = habit.color,
|
color = habit.color,
|
||||||
frequency = habit.repetitions.weekdayFrequency,
|
frequency = habit.originalCheckmarks.weekdayFrequency,
|
||||||
firstWeekday = firstWeekday,
|
firstWeekday = firstWeekday,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ class HistoryCardPresenter(
|
|||||||
val isSkipEnabled: Boolean,
|
val isSkipEnabled: Boolean,
|
||||||
) {
|
) {
|
||||||
fun present() = HistoryCardViewModel(
|
fun present() = HistoryCardViewModel(
|
||||||
checkmarks = habit.checkmarks.allValues,
|
checkmarks = habit.computedCheckmarks.allValues,
|
||||||
color = habit.color,
|
color = habit.color,
|
||||||
firstWeekday = firstWeekday,
|
firstWeekday = firstWeekday,
|
||||||
isNumerical = habit.isNumerical,
|
isNumerical = habit.isNumerical,
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class OverviewCardPresenter(val habit: Habit) {
|
|||||||
scoreToday = scoreToday,
|
scoreToday = scoreToday,
|
||||||
scoreMonthDiff = scoreToday - scoreLastMonth,
|
scoreMonthDiff = scoreToday - scoreLastMonth,
|
||||||
scoreYearDiff = scoreToday - scoreLastYear,
|
scoreYearDiff = scoreToday - scoreLastYear,
|
||||||
totalCount = habit.repetitions.totalCount,
|
totalCount = habit.originalCheckmarks.totalCount,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ class TargetCardPresenter(
|
|||||||
val resources: Resources,
|
val resources: Resources,
|
||||||
) {
|
) {
|
||||||
suspend fun present(): TargetCardViewModel = Dispatchers.IO {
|
suspend fun present(): TargetCardViewModel = Dispatchers.IO {
|
||||||
val checkmarks = habit.checkmarks
|
val checkmarks = habit.computedCheckmarks
|
||||||
val valueToday = checkmarks.todayValue / 1e3
|
val valueToday = checkmarks.todayValue / 1e3
|
||||||
val valueThisWeek = checkmarks.getThisWeekValue(firstWeekday) / 1e3
|
val valueThisWeek = checkmarks.getThisWeekValue(firstWeekday) / 1e3
|
||||||
val valueThisMonth = checkmarks.thisMonthValue / 1e3
|
val valueThisMonth = checkmarks.thisMonthValue / 1e3
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ open class CheckmarkWidget(
|
|||||||
|
|
||||||
setActiveColor(habit.color.toThemedAndroidColor(context))
|
setActiveColor(habit.color.toThemedAndroidColor(context))
|
||||||
setName(habit.name)
|
setName(habit.name)
|
||||||
setCheckmarkValue(habit.checkmarks.todayValue)
|
setCheckmarkValue(habit.computedCheckmarks.todayValue)
|
||||||
if (habit.isNumerical) {
|
if (habit.isNumerical) {
|
||||||
setNumerical(true)
|
setNumerical(true)
|
||||||
setCheckmarkState(getNumericalCheckmarkState())
|
setCheckmarkState(getNumericalCheckmarkState())
|
||||||
} else {
|
} else {
|
||||||
setCheckmarkState(habit.checkmarks.todayValue)
|
setCheckmarkState(habit.computedCheckmarks.todayValue)
|
||||||
}
|
}
|
||||||
setPercentage(habit.scores.todayValue.toFloat())
|
setPercentage(habit.scores.todayValue.toFloat())
|
||||||
refresh()
|
refresh()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class FrequencyWidget(
|
|||||||
(widgetView.dataView as FrequencyChart).apply {
|
(widgetView.dataView as FrequencyChart).apply {
|
||||||
setFirstWeekday(firstWeekday)
|
setFirstWeekday(firstWeekday)
|
||||||
setColor(habit.color.toThemedAndroidColor(context))
|
setColor(habit.color.toThemedAndroidColor(context))
|
||||||
setFrequency(habit.repetitions.weekdayFrequency)
|
setFrequency(habit.originalCheckmarks.weekdayFrequency)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class HistoryWidget(
|
|||||||
setFirstWeekday(firstWeekday)
|
setFirstWeekday(firstWeekday)
|
||||||
setSkipEnabled(prefs.isSkipEnabled)
|
setSkipEnabled(prefs.isSkipEnabled)
|
||||||
setColor(habit.color.toThemedAndroidColor(context))
|
setColor(habit.color.toThemedAndroidColor(context))
|
||||||
setCheckmarks(habit.checkmarks.allValues)
|
setCheckmarks(habit.computedCheckmarks.allValues)
|
||||||
setNumerical(habit.isNumerical)
|
setNumerical(habit.isNumerical)
|
||||||
setTarget(habit.targetValue / habit.frequency.denominator)
|
setTarget(habit.targetValue / habit.frequency.denominator)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class NumericalCheckmarkWidgetActivity : Activity(), ListHabitsBehavior.NumberPi
|
|||||||
val app = this.applicationContext as HabitsApplication
|
val app = this.applicationContext as HabitsApplication
|
||||||
AndroidThemeSwitcher(this, app.component.preferences).apply()
|
AndroidThemeSwitcher(this, app.component.preferences).apply()
|
||||||
val numberPickerFactory = NumberPickerFactory(context)
|
val numberPickerFactory = NumberPickerFactory(context)
|
||||||
numberPickerFactory.create(data.habit.checkmarks.today!!.value.toDouble() / 1000,
|
numberPickerFactory.create(data.habit.computedCheckmarks.today!!.value.toDouble() / 1000,
|
||||||
data.habit.unit,
|
data.habit.unit,
|
||||||
this).show()
|
this).show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ public class CreateRepetitionCommand implements Command
|
|||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
RepetitionList reps = habit.getRepetitions();
|
RepetitionList checks = habit.getOriginalCheckmarks();
|
||||||
reps.setValue(timestamp, value);
|
checks.setValue(timestamp, value);
|
||||||
habitList.resort();
|
habitList.resort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class HabitBullCSVImporter extends AbstractImporter
|
|||||||
map.put(name, h);
|
map.put(name, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
h.getRepetitions().setValue(timestamp, YES_MANUAL);
|
h.getOriginalCheckmarks().setValue(timestamp, YES_MANUAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public class HabitsCSVExporter
|
|||||||
generateDirs.add(habitDirName);
|
generateDirs.add(habitDirName);
|
||||||
|
|
||||||
writeScores(habitDirName, h.getScores());
|
writeScores(habitDirName, h.getScores());
|
||||||
writeCheckmarks(habitDirName, h.getCheckmarks());
|
writeCheckmarks(habitDirName, h.getComputedCheckmarks());
|
||||||
}
|
}
|
||||||
|
|
||||||
writeMultipleHabits();
|
writeMultipleHabits();
|
||||||
@@ -181,7 +181,7 @@ public class HabitsCSVExporter
|
|||||||
List<double[]> scores = new ArrayList<>();
|
List<double[]> scores = new ArrayList<>();
|
||||||
for (Habit h : selectedHabits)
|
for (Habit h : selectedHabits)
|
||||||
{
|
{
|
||||||
checkmarks.add(h.getCheckmarks().getValues(oldest, newest));
|
checkmarks.add(h.getComputedCheckmarks().getValues(oldest, newest));
|
||||||
scores.add(h.getScores().getValues(oldest, newest));
|
scores.add(h.getScores().getValues(oldest, newest));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,10 +244,10 @@ public class HabitsCSVExporter
|
|||||||
Timestamp newest = Timestamp.ZERO;
|
Timestamp newest = Timestamp.ZERO;
|
||||||
for (Habit h : selectedHabits)
|
for (Habit h : selectedHabits)
|
||||||
{
|
{
|
||||||
if(h.getRepetitions().getOldest() == null || h.getRepetitions().getNewest() == null)
|
if(h.getOriginalCheckmarks().getOldest() == null || h.getOriginalCheckmarks().getNewest() == null)
|
||||||
continue;
|
continue;
|
||||||
Timestamp currOld = h.getRepetitions().getOldest().getTimestamp();
|
Timestamp currOld = h.getOriginalCheckmarks().getOldest().getTimestamp();
|
||||||
Timestamp currNew = h.getRepetitions().getNewest().getTimestamp();
|
Timestamp currNew = h.getOriginalCheckmarks().getNewest().getTimestamp();
|
||||||
oldest = currOld.isOlderThan(oldest) ? currOld : oldest;
|
oldest = currOld.isOlderThan(oldest) ? currOld : oldest;
|
||||||
newest = currNew.isNewerThan(newest) ? currNew : newest;
|
newest = currNew.isNewerThan(newest) ? currNew : newest;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,8 +131,8 @@ public class LoopDBImporter extends AbstractImporter
|
|||||||
for (RepetitionRecord r : reps)
|
for (RepetitionRecord r : reps)
|
||||||
{
|
{
|
||||||
Timestamp t = new Timestamp(r.timestamp);
|
Timestamp t = new Timestamp(r.timestamp);
|
||||||
Repetition rep = habit.getRepetitions().getByTimestamp(t);
|
Checkmark check = habit.getOriginalCheckmarks().getByTimestamp(t);
|
||||||
if (rep == null || rep.getValue() != r.value)
|
if (check == null || check.getValue() != r.value)
|
||||||
new CreateRepetitionCommand(habitList, habit, t, r.value).execute();
|
new CreateRepetitionCommand(habitList, habit, t, r.value).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ public class RewireDBImporter extends AbstractImporter
|
|||||||
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
||||||
cal.set(year, month - 1, day);
|
cal.set(year, month - 1, day);
|
||||||
|
|
||||||
habit.getRepetitions().setValue(new Timestamp(cal), YES_MANUAL);
|
habit.getOriginalCheckmarks().setValue(new Timestamp(cal), YES_MANUAL);
|
||||||
} while (c.moveToNext());
|
} while (c.moveToNext());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class TickmateDBImporter extends AbstractImporter
|
|||||||
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
||||||
cal.set(year, month, day);
|
cal.set(year, month, day);
|
||||||
|
|
||||||
habit.getRepetitions().setValue(new Timestamp(cal), YES_MANUAL);
|
habit.getOriginalCheckmarks().setValue(new Timestamp(cal), YES_MANUAL);
|
||||||
} while (c.moveToNext());
|
} while (c.moveToNext());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ public abstract class CheckmarkList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
static List<Checkmark> buildCheckmarksFromIntervals(Repetition[] reps,
|
static List<Checkmark> buildCheckmarksFromIntervals(Checkmark[] original,
|
||||||
ArrayList<Interval> intervals)
|
ArrayList<Interval> intervals)
|
||||||
{
|
{
|
||||||
if (reps.length == 0) throw new IllegalArgumentException();
|
if (original.length == 0) throw new IllegalArgumentException();
|
||||||
|
|
||||||
Timestamp today = DateUtils.getTodayWithOffset();
|
Timestamp today = DateUtils.getTodayWithOffset();
|
||||||
Timestamp begin = reps[0].getTimestamp();
|
Timestamp begin = original[0].getTimestamp();
|
||||||
if (intervals.size() > 0) begin = Timestamp.oldest(begin, intervals.get(0).begin);
|
if (intervals.size() > 0) begin = Timestamp.oldest(begin, intervals.get(0).begin);
|
||||||
|
|
||||||
int nDays = begin.daysUntil(today) + 1;
|
int nDays = begin.daysUntil(today) + 1;
|
||||||
@@ -75,11 +75,11 @@ public abstract class CheckmarkList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Repetition rep : reps)
|
for (Checkmark c : original)
|
||||||
{
|
{
|
||||||
Timestamp date = rep.getTimestamp();
|
Timestamp date = c.getTimestamp();
|
||||||
int offset = date.daysUntil(today);
|
int offset = date.daysUntil(today);
|
||||||
int value = rep.getValue();
|
int value = c.getValue();
|
||||||
int prevValue = checkmarks.get(offset).getValue();
|
int prevValue = checkmarks.get(offset).getValue();
|
||||||
if (prevValue < value)
|
if (prevValue < value)
|
||||||
checkmarks.set(offset, new Checkmark(date, value));
|
checkmarks.set(offset, new Checkmark(date, value));
|
||||||
@@ -101,12 +101,12 @@ public abstract class CheckmarkList
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
static ArrayList<Interval> buildIntervals(@NonNull Frequency freq,
|
static ArrayList<Interval> buildIntervals(@NonNull Frequency freq,
|
||||||
@NonNull Repetition[] reps)
|
@NonNull Checkmark[] checks)
|
||||||
{
|
{
|
||||||
ArrayList<Repetition> filteredReps = new ArrayList<>();
|
ArrayList<Checkmark> filteredReps = new ArrayList<>();
|
||||||
for (Repetition r : reps)
|
for (Checkmark c : checks)
|
||||||
if (r.getValue() == YES_MANUAL)
|
if (c.getValue() == YES_MANUAL)
|
||||||
filteredReps.add(r);
|
filteredReps.add(c);
|
||||||
|
|
||||||
int num = freq.getNumerator();
|
int num = freq.getNumerator();
|
||||||
int den = freq.getDenominator();
|
int den = freq.getDenominator();
|
||||||
@@ -114,8 +114,8 @@ public abstract class CheckmarkList
|
|||||||
ArrayList<Interval> intervals = new ArrayList<>();
|
ArrayList<Interval> intervals = new ArrayList<>();
|
||||||
for (int i = 0; i < filteredReps.size() - num + 1; i++)
|
for (int i = 0; i < filteredReps.size() - num + 1; i++)
|
||||||
{
|
{
|
||||||
Repetition first = filteredReps.get(i);
|
Checkmark first = filteredReps.get(i);
|
||||||
Repetition last = filteredReps.get(i + num - 1);
|
Checkmark last = filteredReps.get(i + num - 1);
|
||||||
|
|
||||||
long distance = first.getTimestamp().daysUntil(last.getTimestamp());
|
long distance = first.getTimestamp().daysUntil(last.getTimestamp());
|
||||||
if (distance >= den) continue;
|
if (distance >= den) continue;
|
||||||
@@ -180,10 +180,10 @@ public abstract class CheckmarkList
|
|||||||
@NonNull
|
@NonNull
|
||||||
public synchronized final int[] getAllValues()
|
public synchronized final int[] getAllValues()
|
||||||
{
|
{
|
||||||
Repetition oldestRep = habit.getRepetitions().getOldest();
|
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
|
||||||
if (oldestRep == null) return new int[0];
|
if (oldestOriginal == null) return new int[0];
|
||||||
|
|
||||||
Timestamp fromTimestamp = oldestRep.getTimestamp();
|
Timestamp fromTimestamp = oldestOriginal.getTimestamp();
|
||||||
Timestamp toTimestamp = DateUtils.getTodayWithOffset();
|
Timestamp toTimestamp = DateUtils.getTodayWithOffset();
|
||||||
|
|
||||||
return getValues(fromTimestamp, toTimestamp);
|
return getValues(fromTimestamp, toTimestamp);
|
||||||
@@ -254,7 +254,7 @@ public abstract class CheckmarkList
|
|||||||
|
|
||||||
private int getThisIntervalValue(DateUtils.TruncateField truncateField, int firstWeekday)
|
private int getThisIntervalValue(DateUtils.TruncateField truncateField, int firstWeekday)
|
||||||
{
|
{
|
||||||
List<Checkmark> groups = habit.getCheckmarks().groupBy(truncateField, firstWeekday, 1);
|
List<Checkmark> groups = habit.getComputedCheckmarks().groupBy(truncateField, firstWeekday, 1);
|
||||||
if (groups.isEmpty()) return 0;
|
if (groups.isEmpty()) return 0;
|
||||||
return groups.get(0).getValue();
|
return groups.get(0).getValue();
|
||||||
}
|
}
|
||||||
@@ -334,16 +334,16 @@ public abstract class CheckmarkList
|
|||||||
if (newest != null && newest.getTimestamp().equals(today)) return;
|
if (newest != null && newest.getTimestamp().equals(today)) return;
|
||||||
invalidateNewerThan(Timestamp.ZERO);
|
invalidateNewerThan(Timestamp.ZERO);
|
||||||
|
|
||||||
Repetition oldestRep = habit.getRepetitions().getOldest();
|
Checkmark oldestRep = habit.getOriginalCheckmarks().getOldest();
|
||||||
if (oldestRep == null) return;
|
if (oldestRep == null) return;
|
||||||
final Timestamp from = oldestRep.getTimestamp();
|
final Timestamp from = oldestRep.getTimestamp();
|
||||||
|
|
||||||
if (from.isNewerThan(today)) return;
|
if (from.isNewerThan(today)) return;
|
||||||
|
|
||||||
Repetition reps[] = habit
|
Checkmark reps[] = habit
|
||||||
.getRepetitions()
|
.getOriginalCheckmarks()
|
||||||
.getByInterval(from, today)
|
.getByInterval(from, today)
|
||||||
.toArray(new Repetition[0]);
|
.toArray(new Checkmark[0]);
|
||||||
|
|
||||||
if (habit.isNumerical()) computeNumerical(reps);
|
if (habit.isNumerical()) computeNumerical(reps);
|
||||||
else computeYesNo(reps);
|
else computeYesNo(reps);
|
||||||
@@ -365,37 +365,37 @@ public abstract class CheckmarkList
|
|||||||
@Nullable
|
@Nullable
|
||||||
protected abstract Checkmark getOldestComputed();
|
protected abstract Checkmark getOldestComputed();
|
||||||
|
|
||||||
private void computeNumerical(Repetition[] reps)
|
private void computeNumerical(Checkmark[] original)
|
||||||
{
|
{
|
||||||
if (reps.length == 0) return;
|
if (original.length == 0) return;
|
||||||
|
|
||||||
Timestamp today = DateUtils.getTodayWithOffset();
|
Timestamp today = DateUtils.getTodayWithOffset();
|
||||||
Timestamp begin = reps[0].getTimestamp();
|
Timestamp begin = original[0].getTimestamp();
|
||||||
|
|
||||||
int nDays = begin.daysUntil(today) + 1;
|
int nDays = begin.daysUntil(today) + 1;
|
||||||
List<Checkmark> checkmarks = new ArrayList<>(nDays);
|
List<Checkmark> computed = new ArrayList<>(nDays);
|
||||||
for (int i = 0; i < nDays; i++)
|
for (int i = 0; i < nDays; i++)
|
||||||
checkmarks.add(new Checkmark(today.minus(i), 0));
|
computed.add(new Checkmark(today.minus(i), 0));
|
||||||
|
|
||||||
for (Repetition rep : reps)
|
for (Checkmark c : original)
|
||||||
{
|
{
|
||||||
int offset = rep.getTimestamp().daysUntil(today);
|
int offset = c.getTimestamp().daysUntil(today);
|
||||||
checkmarks.set(offset, new Checkmark(rep.getTimestamp(), rep.getValue()));
|
computed.set(offset, new Checkmark(c.getTimestamp(), c.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
add(checkmarks);
|
add(computed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void computeYesNo(Repetition[] reps)
|
private void computeYesNo(Checkmark[] original)
|
||||||
{
|
{
|
||||||
ArrayList<Interval> intervals;
|
ArrayList<Interval> intervals;
|
||||||
intervals = buildIntervals(habit.getFrequency(), reps);
|
intervals = buildIntervals(habit.getFrequency(), original);
|
||||||
snapIntervalsTogether(intervals);
|
snapIntervalsTogether(intervals);
|
||||||
add(buildCheckmarksFromIntervals(reps, intervals));
|
add(buildCheckmarksFromIntervals(original, intervals));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Checkmark> getAll() {
|
public List<Checkmark> getAll() {
|
||||||
Repetition oldest = habit.getRepetitions().getOldest();
|
Checkmark oldest = habit.getOriginalCheckmarks().getOldest();
|
||||||
if(oldest == null) return new ArrayList<>();
|
if(oldest == null) return new ArrayList<>();
|
||||||
return getByInterval(oldest.getTimestamp(), DateUtils.getTodayWithOffset());
|
return getByInterval(oldest.getTimestamp(), DateUtils.getTodayWithOffset());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,11 +114,8 @@ public class Habit
|
|||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* List of checkmarks belonging to this habit.
|
|
||||||
*/
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public synchronized CheckmarkList getCheckmarks()
|
public synchronized CheckmarkList getComputedCheckmarks()
|
||||||
{
|
{
|
||||||
return checkmarks;
|
return checkmarks;
|
||||||
}
|
}
|
||||||
@@ -206,8 +203,7 @@ public class Habit
|
|||||||
data.reminder = reminder;
|
data.reminder = reminder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
public RepetitionList getOriginalCheckmarks()
|
||||||
public RepetitionList getRepetitions()
|
|
||||||
{
|
{
|
||||||
return repetitions;
|
return repetitions;
|
||||||
}
|
}
|
||||||
@@ -300,7 +296,7 @@ public class Habit
|
|||||||
public void invalidateNewerThan(Timestamp timestamp)
|
public void invalidateNewerThan(Timestamp timestamp)
|
||||||
{
|
{
|
||||||
getScores().invalidateNewerThan(timestamp);
|
getScores().invalidateNewerThan(timestamp);
|
||||||
getCheckmarks().invalidateNewerThan(timestamp);
|
getComputedCheckmarks().invalidateNewerThan(timestamp);
|
||||||
getStreaks().invalidateNewerThan(timestamp);
|
getStreaks().invalidateNewerThan(timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,7 +312,7 @@ public class Habit
|
|||||||
|
|
||||||
public synchronized boolean isCompletedToday()
|
public synchronized boolean isCompletedToday()
|
||||||
{
|
{
|
||||||
int todayCheckmark = getCheckmarks().getTodayValue();
|
int todayCheckmark = getComputedCheckmarks().getTodayValue();
|
||||||
if (isNumerical())
|
if (isNumerical())
|
||||||
{
|
{
|
||||||
if(getTargetType() == AT_LEAST)
|
if(getTargetType() == AT_LEAST)
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import androidx.annotation.*;
|
|||||||
|
|
||||||
import com.opencsv.*;
|
import com.opencsv.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.core.utils.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -180,7 +178,7 @@ public abstract class HabitList implements Iterable<Habit>
|
|||||||
{
|
{
|
||||||
for (Habit h : this)
|
for (Habit h : this)
|
||||||
{
|
{
|
||||||
h.getCheckmarks().invalidateNewerThan(Timestamp.ZERO);
|
h.getComputedCheckmarks().invalidateNewerThan(Timestamp.ZERO);
|
||||||
h.getStreaks().invalidateNewerThan(Timestamp.ZERO);
|
h.getStreaks().invalidateNewerThan(Timestamp.ZERO);
|
||||||
h.getScores().invalidateNewerThan(Timestamp.ZERO);
|
h.getScores().invalidateNewerThan(Timestamp.ZERO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package org.isoron.uhabits.core.models
|
|
||||||
|
|
||||||
data class Repetition(
|
|
||||||
/**
|
|
||||||
* Time the repetition took place.
|
|
||||||
*/
|
|
||||||
val timestamp: Timestamp,
|
|
||||||
/**
|
|
||||||
* For boolean habits, [value] equals YES_MANUAL if performed or SKIP if skipped.
|
|
||||||
* For numerical habits, this number is stored in thousandths. That is, if the user enters
|
|
||||||
* value 1.50 on the app, it is here stored as 1500.
|
|
||||||
*/
|
|
||||||
val value: Int,
|
|
||||||
);
|
|
||||||
@@ -25,9 +25,6 @@ import org.isoron.uhabits.core.utils.*;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* The collection of {@link Repetition}s belonging to a habit.
|
|
||||||
*/
|
|
||||||
public abstract class RepetitionList
|
public abstract class RepetitionList
|
||||||
{
|
{
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -43,17 +40,17 @@ public abstract class RepetitionList
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a repetition to the list.
|
* Adds a checkmark to the list.
|
||||||
* <p>
|
* <p>
|
||||||
* Any implementation of this method must call observable.notifyListeners()
|
* Any implementation of this method must call observable.notifyListeners()
|
||||||
* after the repetition has been added.
|
* after the checkmark has been added.
|
||||||
*
|
*
|
||||||
* @param repetition the repetition to be added.
|
* @param checkmark the checkmark to be added.
|
||||||
*/
|
*/
|
||||||
public abstract void add(Repetition repetition);
|
public abstract void add(Checkmark checkmark);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of repetitions that happened within the given time
|
* Returns the list of checkmarks that happened within the given time
|
||||||
* interval.
|
* interval.
|
||||||
* <p>
|
* <p>
|
||||||
* The list is sorted by timestamp in increasing order. That is, the first
|
* The list is sorted by timestamp in increasing order. That is, the first
|
||||||
@@ -62,31 +59,31 @@ public abstract class RepetitionList
|
|||||||
*
|
*
|
||||||
* @param fromTimestamp timestamp of the beginning of the interval
|
* @param fromTimestamp timestamp of the beginning of the interval
|
||||||
* @param toTimestamp timestamp of the end of the interval
|
* @param toTimestamp timestamp of the end of the interval
|
||||||
* @return list of repetitions within given time interval
|
* @return list of checkmarks within given time interval
|
||||||
*/
|
*/
|
||||||
public abstract List<Repetition> getByInterval(Timestamp fromTimestamp,
|
public abstract List<Checkmark> getByInterval(Timestamp fromTimestamp,
|
||||||
Timestamp toTimestamp);
|
Timestamp toTimestamp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the repetition that has the given timestamp, or null if none
|
* Returns the checkmark that has the given timestamp, or null if none
|
||||||
* exists.
|
* exists.
|
||||||
*
|
*
|
||||||
* @param timestamp the repetition timestamp.
|
* @param timestamp the checkmark timestamp.
|
||||||
* @return the repetition that has the given timestamp.
|
* @return the checkmark that has the given timestamp.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract Repetition getByTimestamp(Timestamp timestamp);
|
public abstract Checkmark getByTimestamp(Timestamp timestamp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a repetition with the given timestamp exists, return its value. Otherwise, returns
|
* If a checkmark with the given timestamp exists, return its value. Otherwise, returns
|
||||||
* Checkmark.NO for boolean habits and zero for numerical habits.
|
* Checkmark.NO for boolean habits and zero for numerical habits.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public int getValue(Timestamp timestamp)
|
public int getValue(Timestamp timestamp)
|
||||||
{
|
{
|
||||||
Repetition rep = getByTimestamp(timestamp);
|
Checkmark check = getByTimestamp(timestamp);
|
||||||
if (rep == null) return Checkmark.UNKNOWN;
|
if (check == null) return Checkmark.UNKNOWN;
|
||||||
return rep.getValue();
|
return check.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -96,54 +93,54 @@ public abstract class RepetitionList
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the oldest repetition in the list.
|
* Returns the oldest checkmark in the list.
|
||||||
* <p>
|
* <p>
|
||||||
* If the list is empty, returns null. Repetitions in the future are
|
* If the list is empty, returns null. Repetitions in the future are
|
||||||
* discarded.
|
* discarded.
|
||||||
*
|
*
|
||||||
* @return oldest repetition in the list, or null if list is empty.
|
* @return oldest checkmark in the list, or null if list is empty.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract Repetition getOldest();
|
public abstract Checkmark getOldest();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
/**
|
/**
|
||||||
* Returns the newest repetition in the list.
|
* Returns the newest checkmark in the list.
|
||||||
* <p>
|
* <p>
|
||||||
* If the list is empty, returns null. Repetitions in the past are
|
* If the list is empty, returns null. Repetitions in the past are
|
||||||
* discarded.
|
* discarded.
|
||||||
*
|
*
|
||||||
* @return newest repetition in the list, or null if list is empty.
|
* @return newest checkmark in the list, or null if list is empty.
|
||||||
*/
|
*/
|
||||||
public abstract Repetition getNewest();
|
public abstract Checkmark getNewest();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total number of successful repetitions for each month, from the first
|
* Returns the total number of successful checkmarks for each month, from the first
|
||||||
* repetition until today, grouped by day of week.
|
* checkmark until today, grouped by day of week.
|
||||||
* <p>
|
* <p>
|
||||||
* The repetitions are returned in a HashMap. The key is the timestamp for
|
* The checkmarks are returned in a HashMap. The key is the timestamp for
|
||||||
* the first day of the month, at midnight (00:00). The value is an integer
|
* the first day of the month, at midnight (00:00). The value is an integer
|
||||||
* array with 7 entries. The first entry contains the total number of
|
* array with 7 entries. The first entry contains the total number of
|
||||||
* successful repetitions during the specified month that occurred on a Saturday. The
|
* successful checkmarks during the specified month that occurred on a Saturday. The
|
||||||
* second entry corresponds to Sunday, and so on. If there are no
|
* second entry corresponds to Sunday, and so on. If there are no
|
||||||
* successful repetitions during a certain month, the value is null.
|
* successful checkmarks during a certain month, the value is null.
|
||||||
*
|
*
|
||||||
* @return total number of repetitions by month versus day of week
|
* @return total number of checkmarks by month versus day of week
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public HashMap<Timestamp, Integer[]> getWeekdayFrequency()
|
public HashMap<Timestamp, Integer[]> getWeekdayFrequency()
|
||||||
{
|
{
|
||||||
List<Repetition> reps =
|
List<Checkmark> checks =
|
||||||
getByInterval(Timestamp.ZERO, DateUtils.getTodayWithOffset());
|
getByInterval(Timestamp.ZERO, DateUtils.getTodayWithOffset());
|
||||||
HashMap<Timestamp, Integer[]> map = new HashMap<>();
|
HashMap<Timestamp, Integer[]> map = new HashMap<>();
|
||||||
|
|
||||||
for (Repetition r : reps)
|
for (Checkmark c : checks)
|
||||||
{
|
{
|
||||||
if (!habit.isNumerical() && r.getValue() != Checkmark.YES_MANUAL)
|
if (!habit.isNumerical() && c.getValue() != Checkmark.YES_MANUAL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Calendar date = r.getTimestamp().toCalendar();
|
Calendar date = c.getTimestamp().toCalendar();
|
||||||
int weekday = r.getTimestamp().getWeekday();
|
int weekday = c.getTimestamp().getWeekday();
|
||||||
date.set(Calendar.DAY_OF_MONTH, 1);
|
date.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
|
||||||
Timestamp timestamp = new Timestamp(date.getTimeInMillis());
|
Timestamp timestamp = new Timestamp(date.getTimeInMillis());
|
||||||
@@ -163,24 +160,24 @@ public abstract class RepetitionList
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a given repetition from the list.
|
* Removes a given checkmark from the list.
|
||||||
* <p>
|
* <p>
|
||||||
* If the list does not contain the repetition, it is unchanged.
|
* If the list does not contain the checkmark, it is unchanged.
|
||||||
* <p>
|
* <p>
|
||||||
* Any implementation of this method must call observable.notifyListeners()
|
* Any implementation of this method must call observable.notifyListeners()
|
||||||
* after the repetition has been added.
|
* after the checkmark has been added.
|
||||||
*
|
*
|
||||||
* @param repetition the repetition to be removed
|
* @param checkmark the checkmark to be removed
|
||||||
*/
|
*/
|
||||||
public abstract void remove(@NonNull Repetition repetition);
|
public abstract void remove(@NonNull Checkmark checkmark);
|
||||||
|
|
||||||
public abstract long getTotalCount();
|
public abstract long getTotalCount();
|
||||||
|
|
||||||
public void setValue(Timestamp timestamp, int value)
|
public void setValue(Timestamp timestamp, int value)
|
||||||
{
|
{
|
||||||
Repetition rep = getByTimestamp(timestamp);
|
Checkmark check = getByTimestamp(timestamp);
|
||||||
if (rep != null) remove(rep);
|
if (check != null) remove(check);
|
||||||
add(new Repetition(timestamp, value));
|
add(new Checkmark(timestamp, value));
|
||||||
habit.invalidateNewerThan(timestamp);
|
habit.invalidateNewerThan(timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -196,22 +196,22 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
protected synchronized void compute(@NonNull Timestamp from,
|
protected synchronized void compute(@NonNull Timestamp from,
|
||||||
@NonNull Timestamp to)
|
@NonNull Timestamp to)
|
||||||
{
|
{
|
||||||
Score newest = getNewestComputed();
|
Score newestComputed = getNewestComputed();
|
||||||
Score oldest = getOldestComputed();
|
Score oldestComputed = getOldestComputed();
|
||||||
|
|
||||||
if (newest == null)
|
if (newestComputed == null)
|
||||||
{
|
{
|
||||||
Repetition oldestRep = habit.getRepetitions().getOldest();
|
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
|
||||||
if (oldestRep != null) from =
|
if (oldestOriginal != null) from =
|
||||||
Timestamp.oldest(from, oldestRep.getTimestamp());
|
Timestamp.oldest(from, oldestOriginal.getTimestamp());
|
||||||
forceRecompute(from, to, 0);
|
forceRecompute(from, to, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (oldest == null) throw new IllegalStateException();
|
if (oldestComputed == null) throw new IllegalStateException();
|
||||||
forceRecompute(from, oldest.getTimestamp().minus(1), 0);
|
forceRecompute(from, oldestComputed.getTimestamp().minus(1), 0);
|
||||||
forceRecompute(newest.getTimestamp().plus(1), to,
|
forceRecompute(newestComputed.getTimestamp().plus(1), to,
|
||||||
newest.getValue());
|
newestComputed.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
*/
|
*/
|
||||||
protected void computeAll()
|
protected void computeAll()
|
||||||
{
|
{
|
||||||
Repetition oldestRep = habit.getRepetitions().getOldest();
|
Checkmark oldestRep = habit.getOriginalCheckmarks().getOldest();
|
||||||
if (oldestRep == null) return;
|
if (oldestRep == null) return;
|
||||||
|
|
||||||
Timestamp today = DateUtils.getTodayWithOffset();
|
Timestamp today = DateUtils.getTodayWithOffset();
|
||||||
@@ -273,7 +273,7 @@ public abstract class ScoreList implements Iterable<Score>
|
|||||||
int numerator = habit.getFrequency().getNumerator();
|
int numerator = habit.getFrequency().getNumerator();
|
||||||
int denominator = habit.getFrequency().getDenominator();
|
int denominator = habit.getFrequency().getDenominator();
|
||||||
final double freq = habit.getFrequency().toDouble();
|
final double freq = habit.getFrequency().toDouble();
|
||||||
final int[] checkmarkValues = habit.getCheckmarks().getValues(from, to);
|
final int[] checkmarkValues = habit.getComputedCheckmarks().getValues(from, to);
|
||||||
|
|
||||||
// For non-daily boolean habits, we double the numerator and the denominator to smooth
|
// For non-daily boolean habits, we double the numerator and the denominator to smooth
|
||||||
// out irregular repetition schedules (for example, weekly habits performed on different
|
// out irregular repetition schedules (for example, weekly habits performed on different
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public abstract class StreakList
|
|||||||
Timestamp beginning = findBeginning();
|
Timestamp beginning = findBeginning();
|
||||||
if (beginning == null || beginning.isNewerThan(today)) return;
|
if (beginning == null || beginning.isNewerThan(today)) return;
|
||||||
|
|
||||||
int checks[] = habit.getCheckmarks().getValues(beginning, today);
|
int checks[] = habit.getComputedCheckmarks().getValues(beginning, today);
|
||||||
List<Streak> streaks = checkmarksToStreaks(beginning, checks);
|
List<Streak> streaks = checkmarksToStreaks(beginning, checks);
|
||||||
|
|
||||||
removeNewestComputed();
|
removeNewestComputed();
|
||||||
@@ -113,8 +113,8 @@ public abstract class StreakList
|
|||||||
Streak newestStreak = getNewestComputed();
|
Streak newestStreak = getNewestComputed();
|
||||||
if (newestStreak != null) return newestStreak.getStart();
|
if (newestStreak != null) return newestStreak.getStart();
|
||||||
|
|
||||||
Repetition oldestRep = habit.getRepetitions().getOldest();
|
Checkmark oldestOriginal = habit.getOriginalCheckmarks().getOldest();
|
||||||
if (oldestRep != null) return oldestRep.getTimestamp();
|
if (oldestOriginal != null) return oldestOriginal.getTimestamp();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,8 +186,8 @@ public class MemoryHabitList extends HabitList
|
|||||||
return h1.isNumerical() ? -1 : 1;
|
return h1.isNumerical() ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer v1 = Objects.requireNonNull(h1.getCheckmarks().getToday()).getValue();
|
Integer v1 = Objects.requireNonNull(h1.getComputedCheckmarks().getToday()).getValue();
|
||||||
Integer v2 = Objects.requireNonNull(h2.getCheckmarks().getToday()).getValue();
|
Integer v2 = Objects.requireNonNull(h2.getComputedCheckmarks().getToday()).getValue();
|
||||||
|
|
||||||
return v2.compareTo(v1);
|
return v2.compareTo(v1);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class MemoryRepetitionList extends RepetitionList
|
public class MemoryRepetitionList extends RepetitionList
|
||||||
{
|
{
|
||||||
ArrayList<Repetition> list;
|
ArrayList<Checkmark> list;
|
||||||
|
|
||||||
public MemoryRepetitionList(Habit habit)
|
public MemoryRepetitionList(Habit habit)
|
||||||
{
|
{
|
||||||
@@ -39,18 +39,18 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Repetition repetition)
|
public void add(Checkmark repetition)
|
||||||
{
|
{
|
||||||
list.add(repetition);
|
list.add(repetition);
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Repetition> getByInterval(Timestamp fromTimestamp, Timestamp toTimestamp)
|
public List<Checkmark> getByInterval(Timestamp fromTimestamp, Timestamp toTimestamp)
|
||||||
{
|
{
|
||||||
ArrayList<Repetition> filtered = new ArrayList<>();
|
ArrayList<Checkmark> filtered = new ArrayList<>();
|
||||||
|
|
||||||
for (Repetition r : list)
|
for (Checkmark r : list)
|
||||||
{
|
{
|
||||||
Timestamp t = r.getTimestamp();
|
Timestamp t = r.getTimestamp();
|
||||||
if (t.isOlderThan(fromTimestamp) || t.isNewerThan(toTimestamp)) continue;
|
if (t.isOlderThan(fromTimestamp) || t.isNewerThan(toTimestamp)) continue;
|
||||||
@@ -65,9 +65,9 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Repetition getByTimestamp(Timestamp timestamp)
|
public Checkmark getByTimestamp(Timestamp timestamp)
|
||||||
{
|
{
|
||||||
for (Repetition r : list)
|
for (Checkmark r : list)
|
||||||
if (r.getTimestamp().equals(timestamp)) return r;
|
if (r.getTimestamp().equals(timestamp)) return r;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -75,12 +75,12 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Repetition getOldest()
|
public Checkmark getOldest()
|
||||||
{
|
{
|
||||||
Timestamp oldestTimestamp = Timestamp.ZERO.plus(1000000);
|
Timestamp oldestTimestamp = Timestamp.ZERO.plus(1000000);
|
||||||
Repetition oldestRep = null;
|
Checkmark oldestRep = null;
|
||||||
|
|
||||||
for (Repetition rep : list)
|
for (Checkmark rep : list)
|
||||||
{
|
{
|
||||||
if (rep.getTimestamp().isOlderThan(oldestTimestamp))
|
if (rep.getTimestamp().isOlderThan(oldestTimestamp))
|
||||||
{
|
{
|
||||||
@@ -94,12 +94,12 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Repetition getNewest()
|
public Checkmark getNewest()
|
||||||
{
|
{
|
||||||
Timestamp newestTimestamp = Timestamp.ZERO;
|
Timestamp newestTimestamp = Timestamp.ZERO;
|
||||||
Repetition newestRep = null;
|
Checkmark newestRep = null;
|
||||||
|
|
||||||
for (Repetition rep : list)
|
for (Checkmark rep : list)
|
||||||
{
|
{
|
||||||
if (rep.getTimestamp().isNewerThan(newestTimestamp))
|
if (rep.getTimestamp().isNewerThan(newestTimestamp))
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,7 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(@NonNull Repetition repetition)
|
public void remove(@NonNull Checkmark repetition)
|
||||||
{
|
{
|
||||||
list.remove(repetition);
|
list.remove(repetition);
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
@@ -122,7 +122,7 @@ public class MemoryRepetitionList extends RepetitionList
|
|||||||
public long getTotalCount()
|
public long getTotalCount()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Repetition rep : list)
|
for (Checkmark rep : list)
|
||||||
if (rep.getValue() == Checkmark.YES_MANUAL)
|
if (rep.getValue() == Checkmark.YES_MANUAL)
|
||||||
count++;
|
count++;
|
||||||
return count;
|
return count;
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public Licenses along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides core models classes, such as {@link org.isoron.uhabits.core.models.Habit}
|
|
||||||
* and {@link org.isoron.uhabits.core.models.Repetition}.
|
|
||||||
*/
|
|
||||||
package org.isoron.uhabits.core.models;
|
|
||||||
@@ -201,7 +201,7 @@ public class SQLiteHabitList extends HabitList
|
|||||||
if (record == null) throw new RuntimeException("habit not in database");
|
if (record == null) throw new RuntimeException("habit not in database");
|
||||||
repository.executeAsTransaction(() ->
|
repository.executeAsTransaction(() ->
|
||||||
{
|
{
|
||||||
((SQLiteRepetitionList) habit.getRepetitions()).removeAll();
|
habit.getOriginalCheckmarks().removeAll();
|
||||||
repository.remove(record);
|
repository.remove(record);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -62,24 +62,24 @@ public class SQLiteRepetitionList extends RepetitionList
|
|||||||
habit.getId().toString());
|
habit.getId().toString());
|
||||||
|
|
||||||
for (RepetitionRecord rec : records)
|
for (RepetitionRecord rec : records)
|
||||||
list.add(rec.toRepetition());
|
list.add(rec.toCheckmark());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Repetition rep)
|
public void add(Checkmark check)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
list.add(rep);
|
list.add(check);
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
RepetitionRecord record = new RepetitionRecord();
|
RepetitionRecord record = new RepetitionRecord();
|
||||||
record.habit_id = habit.getId();
|
record.habit_id = habit.getId();
|
||||||
record.copyFrom(rep);
|
record.copyFrom(check);
|
||||||
repository.save(record);
|
repository.save(record);
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Repetition> getByInterval(Timestamp timeFrom, Timestamp timeTo)
|
public List<Checkmark> getByInterval(Timestamp timeFrom, Timestamp timeTo)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.getByInterval(timeFrom, timeTo);
|
return list.getByInterval(timeFrom, timeTo);
|
||||||
@@ -87,35 +87,35 @@ public class SQLiteRepetitionList extends RepetitionList
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Repetition getByTimestamp(Timestamp timestamp)
|
public Checkmark getByTimestamp(Timestamp timestamp)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.getByTimestamp(timestamp);
|
return list.getByTimestamp(timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Repetition getOldest()
|
public Checkmark getOldest()
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.getOldest();
|
return list.getOldest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Repetition getNewest()
|
public Checkmark getNewest()
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
return list.getNewest();
|
return list.getNewest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(@NonNull Repetition repetition)
|
public void remove(@NonNull Checkmark checkmark)
|
||||||
{
|
{
|
||||||
loadRecords();
|
loadRecords();
|
||||||
list.remove(repetition);
|
list.remove(checkmark);
|
||||||
check(habit.getId());
|
check(habit.getId());
|
||||||
repository.execSQL(
|
repository.execSQL(
|
||||||
"delete from repetitions where habit = ? and timestamp = ?",
|
"delete from repetitions where habit = ? and timestamp = ?",
|
||||||
habit.getId(), repetition.getTimestamp().getUnixTime());
|
habit.getId(), checkmark.getTimestamp().getUnixTime());
|
||||||
observable.notifyListeners();
|
observable.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.isoron.uhabits.core.database.*;
|
|||||||
import org.isoron.uhabits.core.models.*;
|
import org.isoron.uhabits.core.models.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SQLite database record corresponding to a {@link Repetition}.
|
* The SQLite database record corresponding to a {@link Checkmark}.
|
||||||
*/
|
*/
|
||||||
@Table(name = "Repetitions")
|
@Table(name = "Repetitions")
|
||||||
public class RepetitionRecord
|
public class RepetitionRecord
|
||||||
@@ -44,14 +44,14 @@ public class RepetitionRecord
|
|||||||
@Column
|
@Column
|
||||||
public Long id;
|
public Long id;
|
||||||
|
|
||||||
public void copyFrom(Repetition repetition)
|
public void copyFrom(Checkmark checkmark)
|
||||||
{
|
{
|
||||||
timestamp = repetition.getTimestamp().getUnixTime();
|
timestamp = checkmark.getTimestamp().getUnixTime();
|
||||||
value = repetition.getValue();
|
value = checkmark.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Repetition toRepetition()
|
public Checkmark toCheckmark()
|
||||||
{
|
{
|
||||||
return new Repetition(new Timestamp(timestamp), value);
|
return new Checkmark(new Timestamp(timestamp), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class HabitFixtures
|
|||||||
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
|
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
|
||||||
|
|
||||||
for (int mark : marks)
|
for (int mark : marks)
|
||||||
habit.getRepetitions().setValue(today.minus(mark), YES_MANUAL);
|
habit.getOriginalCheckmarks().setValue(today.minus(mark), YES_MANUAL);
|
||||||
|
|
||||||
return habit;
|
return habit;
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ public class HabitFixtures
|
|||||||
for (int i = 0; i < times.length; i++)
|
for (int i = 0; i < times.length; i++)
|
||||||
{
|
{
|
||||||
Timestamp timestamp = today.minus(times[i]);
|
Timestamp timestamp = today.minus(times[i]);
|
||||||
habit.getRepetitions().setValue(timestamp, values[i]);
|
habit.getOriginalCheckmarks().setValue(timestamp, values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return habit;
|
return habit;
|
||||||
@@ -125,7 +125,7 @@ public class HabitFixtures
|
|||||||
for (int i = 0; i < times.length; i++)
|
for (int i = 0; i < times.length; i++)
|
||||||
{
|
{
|
||||||
Timestamp timestamp = reference.minus(times[i]);
|
Timestamp timestamp = reference.minus(times[i]);
|
||||||
habit.getRepetitions().setValue(timestamp, values[i]);
|
habit.getOriginalCheckmarks().setValue(timestamp, values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return habit;
|
return habit;
|
||||||
@@ -144,7 +144,7 @@ public class HabitFixtures
|
|||||||
{
|
{
|
||||||
int value = NO;
|
int value = NO;
|
||||||
if (c) value = YES_MANUAL;
|
if (c) value = YES_MANUAL;
|
||||||
habit.getRepetitions().setValue(timestamp, value);
|
habit.getOriginalCheckmarks().setValue(timestamp, value);
|
||||||
timestamp = timestamp.minus(1);
|
timestamp = timestamp.minus(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ public class HabitFixtures
|
|||||||
|
|
||||||
private void saveIfSQLite(Habit habit)
|
private void saveIfSQLite(Habit habit)
|
||||||
{
|
{
|
||||||
if (!(habit.getRepetitions() instanceof SQLiteRepetitionList)) return;
|
if (!(habit.getOriginalCheckmarks() instanceof SQLiteRepetitionList)) return;
|
||||||
habitList.add(habit);
|
habitList.add(habit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ public class NotificationTray
|
|||||||
@Override
|
@Override
|
||||||
public void doInBackground()
|
public void doInBackground()
|
||||||
{
|
{
|
||||||
todayValue = habit.getCheckmarks().getTodayValue();
|
todayValue = habit.getComputedCheckmarks().getTodayValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ public class HabitCardListCache implements CommandRunner.Listener
|
|||||||
newData.scores.put(id, habit.getScores().getTodayValue());
|
newData.scores.put(id, habit.getScores().getTodayValue());
|
||||||
newData.checkmarks.put(
|
newData.checkmarks.put(
|
||||||
id,
|
id,
|
||||||
habit.getCheckmarks().getValues(dateFrom, dateTo));
|
habit.getComputedCheckmarks().getValues(dateFrom, dateTo));
|
||||||
|
|
||||||
runner.publishProgress(this, position);
|
runner.publishProgress(this, position);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class ListHabitsBehavior
|
|||||||
|
|
||||||
public void onEdit(@NonNull Habit habit, Timestamp timestamp)
|
public void onEdit(@NonNull Habit habit, Timestamp timestamp)
|
||||||
{
|
{
|
||||||
CheckmarkList checkmarks = habit.getCheckmarks();
|
CheckmarkList checkmarks = habit.getComputedCheckmarks();
|
||||||
double oldValue = checkmarks.getValues(timestamp, timestamp)[0];
|
double oldValue = checkmarks.getValues(timestamp, timestamp)[0];
|
||||||
|
|
||||||
screen.showNumberPicker(oldValue / 1000, habit.getUnit(), newValue ->
|
screen.showNumberPicker(oldValue / 1000, habit.getUnit(), newValue ->
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class ShowHabitBehavior(
|
|||||||
|
|
||||||
override fun onToggleCheckmark(timestamp: Timestamp, value: Int) {
|
override fun onToggleCheckmark(timestamp: Timestamp, value: Int) {
|
||||||
if (habit.isNumerical) {
|
if (habit.isNumerical) {
|
||||||
val checkmarks = habit.checkmarks
|
val checkmarks = habit.computedCheckmarks
|
||||||
val oldValue = checkmarks.getValues(timestamp, timestamp)[0].toDouble()
|
val oldValue = checkmarks.getValues(timestamp, timestamp)[0].toDouble()
|
||||||
screen.showNumberPicker(oldValue / 1000, habit.unit) { newValue: Double ->
|
screen.showNumberPicker(oldValue / 1000, habit.unit) { newValue: Double ->
|
||||||
val thousands = Math.round(newValue * 1000).toInt()
|
val thousands = Math.round(newValue * 1000).toInt()
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ class ShowHabitMenuBehavior(
|
|||||||
|
|
||||||
fun onRandomize() {
|
fun onRandomize() {
|
||||||
val random = Random()
|
val random = Random()
|
||||||
habit.repetitions.removeAll()
|
habit.originalCheckmarks.removeAll()
|
||||||
var strength = 50.0
|
var strength = 50.0
|
||||||
for (i in 0 until 365 * 5) {
|
for (i in 0 until 365 * 5) {
|
||||||
if (i % 7 == 0) strength = Math.max(0.0, Math.min(100.0, strength + 10 * random.nextGaussian()))
|
if (i % 7 == 0) strength = Math.max(0.0, Math.min(100.0, strength + 10 * random.nextGaussian()))
|
||||||
if (random.nextInt(100) > strength) continue
|
if (random.nextInt(100) > strength) continue
|
||||||
var value = Checkmark.YES_MANUAL
|
var value = Checkmark.YES_MANUAL
|
||||||
if (habit.isNumerical) value = (1000 + 250 * random.nextGaussian() * strength / 100).toInt() * 1000
|
if (habit.isNumerical) value = (1000 + 250 * random.nextGaussian() * strength / 100).toInt() * 1000
|
||||||
habit.repetitions.setValue(DateUtils.getToday().minus(i), value)
|
habit.originalCheckmarks.setValue(DateUtils.getToday().minus(i), value)
|
||||||
}
|
}
|
||||||
habit.invalidateNewerThan(Timestamp.ZERO)
|
habit.invalidateNewerThan(Timestamp.ZERO)
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class WidgetBehavior
|
|||||||
|
|
||||||
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
|
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
|
||||||
{
|
{
|
||||||
int currentValue = habit.getRepetitions().getValue(timestamp);
|
int currentValue = habit.getOriginalCheckmarks().getValue(timestamp);
|
||||||
int newValue;
|
int newValue;
|
||||||
if(preferences.isSkipEnabled())
|
if(preferences.isSkipEnabled())
|
||||||
newValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
|
newValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
|
||||||
@@ -81,13 +81,13 @@ public class WidgetBehavior
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onIncrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
|
public void onIncrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
|
||||||
int currentValue = habit.getCheckmarks().getValues(timestamp, timestamp)[0];
|
int currentValue = habit.getComputedCheckmarks().getValues(timestamp, timestamp)[0];
|
||||||
setValue(habit, timestamp, currentValue + amount);
|
setValue(habit, timestamp, currentValue + amount);
|
||||||
notificationTray.cancel(habit);
|
notificationTray.cancel(habit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDecrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
|
public void onDecrement(@NotNull Habit habit, @NotNull Timestamp timestamp, int amount) {
|
||||||
int currentValue = habit.getCheckmarks().getValues(timestamp, timestamp)[0];
|
int currentValue = habit.getComputedCheckmarks().getValues(timestamp, timestamp)[0];
|
||||||
setValue(habit, timestamp, currentValue - amount);
|
setValue(habit, timestamp, currentValue - amount);
|
||||||
notificationTray.cancel(habit);
|
notificationTray.cancel(habit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ public class CreateRepetitionCommandTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testExecute()
|
public void testExecute()
|
||||||
{
|
{
|
||||||
RepetitionList reps = habit.getRepetitions();
|
RepetitionList reps = habit.getOriginalCheckmarks();
|
||||||
Repetition rep = reps.getByTimestamp(today);
|
Checkmark check = reps.getByTimestamp(today);
|
||||||
assertNotNull(rep);
|
assertNotNull(check);
|
||||||
assertEquals(YES_MANUAL, rep.getValue());
|
assertEquals(YES_MANUAL, check.getValue());
|
||||||
command.execute();
|
command.execute();
|
||||||
rep = reps.getByTimestamp(today);
|
check = reps.getByTimestamp(today);
|
||||||
assertNotNull(rep);
|
assertNotNull(check);
|
||||||
assertEquals(100, rep.getValue());
|
assertEquals(100, check.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public class ImportTest extends BaseUnitTest
|
|||||||
GregorianCalendar date = DateUtils.getStartOfTodayCalendar();
|
GregorianCalendar date = DateUtils.getStartOfTodayCalendar();
|
||||||
date.set(year, month - 1, day);
|
date.set(year, month - 1, day);
|
||||||
Timestamp timestamp = new Timestamp(date);
|
Timestamp timestamp = new Timestamp(date);
|
||||||
return h.getRepetitions().getValue(timestamp) == YES_MANUAL;
|
return h.getOriginalCheckmarks().getValue(timestamp) == YES_MANUAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importFromFile(String assetFilename) throws IOException
|
private void importFromFile(String assetFilename) throws IOException
|
||||||
|
|||||||
@@ -67,11 +67,11 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void test_buildCheckmarksFromIntervals_1() throws Exception
|
public void test_buildCheckmarksFromIntervals_1() throws Exception
|
||||||
{
|
{
|
||||||
Repetition reps[] = new Repetition[]{
|
Checkmark checks[] = new Checkmark[]{
|
||||||
new Repetition(day(10), YES_MANUAL),
|
new Checkmark(day(10), YES_MANUAL),
|
||||||
new Repetition(day(5), YES_MANUAL),
|
new Checkmark(day(5), YES_MANUAL),
|
||||||
new Repetition(day(2), YES_MANUAL),
|
new Checkmark(day(2), YES_MANUAL),
|
||||||
new Repetition(day(1), YES_MANUAL),
|
new Checkmark(day(1), YES_MANUAL),
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
|
||||||
@@ -93,15 +93,15 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
expected.add(new Checkmark(day(10), YES_MANUAL));
|
expected.add(new Checkmark(day(10), YES_MANUAL));
|
||||||
|
|
||||||
List<Checkmark> actual =
|
List<Checkmark> actual =
|
||||||
CheckmarkList.buildCheckmarksFromIntervals(reps, intervals);
|
CheckmarkList.buildCheckmarksFromIntervals(checks, intervals);
|
||||||
assertThat(actual, equalTo(expected));
|
assertThat(actual, equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_buildCheckmarksFromIntervals_2() throws Exception
|
public void test_buildCheckmarksFromIntervals_2() throws Exception
|
||||||
{
|
{
|
||||||
Repetition reps[] = new Repetition[]{
|
Checkmark checks[] = new Checkmark[]{
|
||||||
new Repetition(day(0), YES_MANUAL),
|
new Checkmark(day(0), YES_MANUAL),
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
|
||||||
@@ -111,17 +111,17 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
expected.add(new Checkmark(day(0), YES_MANUAL));
|
expected.add(new Checkmark(day(0), YES_MANUAL));
|
||||||
|
|
||||||
List<Checkmark> actual =
|
List<Checkmark> actual =
|
||||||
CheckmarkList.buildCheckmarksFromIntervals(reps, intervals);
|
CheckmarkList.buildCheckmarksFromIntervals(checks, intervals);
|
||||||
assertThat(actual, equalTo(expected));
|
assertThat(actual, equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_buildIntervals_1() throws Exception
|
public void test_buildIntervals_1() throws Exception
|
||||||
{
|
{
|
||||||
Repetition reps[] = new Repetition[]{
|
Checkmark checks[] = new Checkmark[]{
|
||||||
new Repetition(day(23), YES_MANUAL),
|
new Checkmark(day(23), YES_MANUAL),
|
||||||
new Repetition(day(18), YES_MANUAL),
|
new Checkmark(day(18), YES_MANUAL),
|
||||||
new Repetition(day(8), YES_MANUAL),
|
new Checkmark(day(8), YES_MANUAL),
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||||
@@ -130,17 +130,17 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
expected.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
|
expected.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> actual;
|
ArrayList<CheckmarkList.Interval> actual;
|
||||||
actual = CheckmarkList.buildIntervals(Frequency.WEEKLY, reps);
|
actual = CheckmarkList.buildIntervals(Frequency.WEEKLY, checks);
|
||||||
assertThat(actual, equalTo(expected));
|
assertThat(actual, equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_buildIntervals_2() throws Exception
|
public void test_buildIntervals_2() throws Exception
|
||||||
{
|
{
|
||||||
Repetition reps[] = new Repetition[]{
|
Checkmark checks[] = new Checkmark[]{
|
||||||
new Repetition(day(23), YES_MANUAL),
|
new Checkmark(day(23), YES_MANUAL),
|
||||||
new Repetition(day(18), YES_MANUAL),
|
new Checkmark(day(18), YES_MANUAL),
|
||||||
new Repetition(day(8), YES_MANUAL),
|
new Checkmark(day(8), YES_MANUAL),
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||||
@@ -149,19 +149,19 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
expected.add(new CheckmarkList.Interval(day(8), day(8), day(8)));
|
expected.add(new CheckmarkList.Interval(day(8), day(8), day(8)));
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> actual;
|
ArrayList<CheckmarkList.Interval> actual;
|
||||||
actual = CheckmarkList.buildIntervals(Frequency.DAILY, reps);
|
actual = CheckmarkList.buildIntervals(Frequency.DAILY, checks);
|
||||||
assertThat(actual, equalTo(expected));
|
assertThat(actual, equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_buildIntervals_3() throws Exception
|
public void test_buildIntervals_3() throws Exception
|
||||||
{
|
{
|
||||||
Repetition reps[] = new Repetition[]{
|
Checkmark checks[] = new Checkmark[]{
|
||||||
new Repetition(day(23), YES_MANUAL),
|
new Checkmark(day(23), YES_MANUAL),
|
||||||
new Repetition(day(22), YES_MANUAL),
|
new Checkmark(day(22), YES_MANUAL),
|
||||||
new Repetition(day(18), YES_MANUAL),
|
new Checkmark(day(18), YES_MANUAL),
|
||||||
new Repetition(day(15), YES_MANUAL),
|
new Checkmark(day(15), YES_MANUAL),
|
||||||
new Repetition(day(8), YES_MANUAL),
|
new Checkmark(day(8), YES_MANUAL),
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||||
@@ -171,7 +171,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> actual;
|
ArrayList<CheckmarkList.Interval> actual;
|
||||||
actual =
|
actual =
|
||||||
CheckmarkList.buildIntervals(Frequency.TWO_TIMES_PER_WEEK, reps);
|
CheckmarkList.buildIntervals(Frequency.TWO_TIMES_PER_WEEK, checks);
|
||||||
assertThat(actual, equalTo(expected));
|
assertThat(actual, equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,10 +179,10 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void test_buildIntervals_4() throws Exception
|
public void test_buildIntervals_4() throws Exception
|
||||||
{
|
{
|
||||||
Repetition[] reps = new Repetition[]{
|
Checkmark[] checks = new Checkmark[]{
|
||||||
new Repetition(day(30), YES_MANUAL),
|
new Checkmark(day(30), YES_MANUAL),
|
||||||
new Repetition(day(20), SKIP),
|
new Checkmark(day(20), SKIP),
|
||||||
new Repetition(day(10), YES_MANUAL),
|
new Checkmark(day(10), YES_MANUAL),
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||||
@@ -190,7 +190,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
expected.add(new CheckmarkList.Interval(day(10), day(10), day(8)));
|
expected.add(new CheckmarkList.Interval(day(10), day(10), day(8)));
|
||||||
|
|
||||||
ArrayList<CheckmarkList.Interval> actual;
|
ArrayList<CheckmarkList.Interval> actual;
|
||||||
actual = CheckmarkList.buildIntervals(new Frequency(1, 3), reps);
|
actual = CheckmarkList.buildIntervals(new Frequency(1, 3), checks);
|
||||||
assertThat(actual, equalTo(expected));
|
assertThat(actual, equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
YES_MANUAL
|
YES_MANUAL
|
||||||
};
|
};
|
||||||
|
|
||||||
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
|
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
|
||||||
|
|
||||||
assertThat(actualValues, equalTo(expectedValues));
|
assertThat(actualValues, equalTo(expectedValues));
|
||||||
}
|
}
|
||||||
@@ -235,7 +235,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
YES_MANUAL
|
YES_MANUAL
|
||||||
};
|
};
|
||||||
|
|
||||||
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
|
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
|
||||||
|
|
||||||
assertThat(actualValues, equalTo(expectedValues));
|
assertThat(actualValues, equalTo(expectedValues));
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
public void test_getAllValues_withEmptyHabit()
|
public void test_getAllValues_withEmptyHabit()
|
||||||
{
|
{
|
||||||
int[] expectedValues = new int[0];
|
int[] expectedValues = new int[0];
|
||||||
int[] actualValues = emptyHabit.getCheckmarks().getAllValues();
|
int[] actualValues = emptyHabit.getComputedCheckmarks().getAllValues();
|
||||||
|
|
||||||
assertThat(actualValues, equalTo(expectedValues));
|
assertThat(actualValues, equalTo(expectedValues));
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
YES_MANUAL
|
YES_MANUAL
|
||||||
};
|
};
|
||||||
|
|
||||||
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
|
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getAllValues();
|
||||||
|
|
||||||
assertThat(actualValues, equalTo(expectedValues));
|
assertThat(actualValues, equalTo(expectedValues));
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void test_getByInterval_withNumericalHabits() throws Exception
|
public void test_getByInterval_withNumericalHabits() throws Exception
|
||||||
{
|
{
|
||||||
CheckmarkList checkmarks = numericalHabit.getCheckmarks();
|
CheckmarkList checkmarks = numericalHabit.getComputedCheckmarks();
|
||||||
|
|
||||||
List<Checkmark> expected =
|
List<Checkmark> expected =
|
||||||
Arrays.asList(new Checkmark(day(1), 200), new Checkmark(day(2), 0),
|
Arrays.asList(new Checkmark(day(1), 200), new Checkmark(day(2), 0),
|
||||||
@@ -287,7 +287,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void test_getTodayValue()
|
public void test_getTodayValue()
|
||||||
{
|
{
|
||||||
CheckmarkList checkmarks = nonDailyHabit.getCheckmarks();
|
CheckmarkList checkmarks = nonDailyHabit.getComputedCheckmarks();
|
||||||
|
|
||||||
travelInTime(-1);
|
travelInTime(-1);
|
||||||
assertThat(checkmarks.getTodayValue(), equalTo(NO));
|
assertThat(checkmarks.getTodayValue(), equalTo(NO));
|
||||||
@@ -303,7 +303,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
public void test_getValues_withInvalidInterval()
|
public void test_getValues_withInvalidInterval()
|
||||||
{
|
{
|
||||||
int values[] = nonDailyHabit
|
int values[] = nonDailyHabit
|
||||||
.getCheckmarks()
|
.getComputedCheckmarks()
|
||||||
.getValues(new Timestamp(0L).plus(100), new Timestamp(0L));
|
.getValues(new Timestamp(0L).plus(100), new Timestamp(0L));
|
||||||
assertThat(values, equalTo(new int[0]));
|
assertThat(values, equalTo(new int[0]));
|
||||||
}
|
}
|
||||||
@@ -328,7 +328,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
UNKNOWN
|
UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
int[] actualValues = nonDailyHabit.getCheckmarks().getValues(from, to);
|
int[] actualValues = nonDailyHabit.getComputedCheckmarks().getValues(from, to);
|
||||||
assertThat(actualValues, equalTo(expectedValues));
|
assertThat(actualValues, equalTo(expectedValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
|
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
nonDailyHabit.getCheckmarks().writeCSV(writer);
|
nonDailyHabit.getComputedCheckmarks().writeCSV(writer);
|
||||||
|
|
||||||
assertThat(writer.toString(), equalTo(expectedCSV));
|
assertThat(writer.toString(), equalTo(expectedCSV));
|
||||||
}
|
}
|
||||||
@@ -404,7 +404,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
public void testGroupBy() throws Exception
|
public void testGroupBy() throws Exception
|
||||||
{
|
{
|
||||||
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
|
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
|
||||||
CheckmarkList checkmarks = habit.getCheckmarks();
|
CheckmarkList checkmarks = habit.getComputedCheckmarks();
|
||||||
|
|
||||||
List<Checkmark> byMonth = checkmarks.groupBy(MONTH, Calendar.SATURDAY);
|
List<Checkmark> byMonth = checkmarks.groupBy(MONTH, Calendar.SATURDAY);
|
||||||
assertThat(byMonth.size(), equalTo(25)); // from 2013-01-01 to 2015-01-01
|
assertThat(byMonth.size(), equalTo(25)); // from 2013-01-01 to 2015-01-01
|
||||||
@@ -430,7 +430,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
public void testGetTodayValue() throws Exception
|
public void testGetTodayValue() throws Exception
|
||||||
{
|
{
|
||||||
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
|
Habit habit = fixtures.createLongNumericalHabit(timestamp(2014, JUNE, 1));
|
||||||
CheckmarkList checkmarks = habit.getCheckmarks();
|
CheckmarkList checkmarks = habit.getComputedCheckmarks();
|
||||||
|
|
||||||
DateUtils.setFixedLocalTime(unixTime(2050, MAY, 1));
|
DateUtils.setFixedLocalTime(unixTime(2050, MAY, 1));
|
||||||
assertThat(checkmarks.getTodayValue(), equalTo(0));
|
assertThat(checkmarks.getTodayValue(), equalTo(0));
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ public class HabitTest extends BaseUnitTest
|
|||||||
assertThat(habit.hasReminder(), is(false));
|
assertThat(habit.hasReminder(), is(false));
|
||||||
assertNotNull(habit.getStreaks());
|
assertNotNull(habit.getStreaks());
|
||||||
assertNotNull(habit.getScores());
|
assertNotNull(habit.getScores());
|
||||||
assertNotNull(habit.getRepetitions());
|
assertNotNull(habit.getOriginalCheckmarks());
|
||||||
assertNotNull(habit.getCheckmarks());
|
assertNotNull(habit.getComputedCheckmarks());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -89,7 +89,7 @@ public class HabitTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
Habit h = modelFactory.buildHabit();
|
Habit h = modelFactory.buildHabit();
|
||||||
assertFalse(h.isCompletedToday());
|
assertFalse(h.isCompletedToday());
|
||||||
h.getRepetitions().setValue(getToday(), Checkmark.YES_MANUAL);
|
h.getOriginalCheckmarks().setValue(getToday(), Checkmark.YES_MANUAL);
|
||||||
assertTrue(h.isCompletedToday());
|
assertTrue(h.isCompletedToday());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,19 +102,19 @@ public class HabitTest extends BaseUnitTest
|
|||||||
h.setTargetValue(100.0);
|
h.setTargetValue(100.0);
|
||||||
assertFalse(h.isCompletedToday());
|
assertFalse(h.isCompletedToday());
|
||||||
|
|
||||||
h.getRepetitions().setValue(getToday(), 200_000);
|
h.getOriginalCheckmarks().setValue(getToday(), 200_000);
|
||||||
assertTrue(h.isCompletedToday());
|
assertTrue(h.isCompletedToday());
|
||||||
h.getRepetitions().setValue(getToday(), 100_000);
|
h.getOriginalCheckmarks().setValue(getToday(), 100_000);
|
||||||
assertTrue(h.isCompletedToday());
|
assertTrue(h.isCompletedToday());
|
||||||
h.getRepetitions().setValue(getToday(), 50_000);
|
h.getOriginalCheckmarks().setValue(getToday(), 50_000);
|
||||||
assertFalse(h.isCompletedToday());
|
assertFalse(h.isCompletedToday());
|
||||||
|
|
||||||
h.setTargetType(Habit.AT_MOST);
|
h.setTargetType(Habit.AT_MOST);
|
||||||
h.getRepetitions().setValue(getToday(), 200_000);
|
h.getOriginalCheckmarks().setValue(getToday(), 200_000);
|
||||||
assertFalse(h.isCompletedToday());
|
assertFalse(h.isCompletedToday());
|
||||||
h.getRepetitions().setValue(getToday(), 100_000);
|
h.getOriginalCheckmarks().setValue(getToday(), 100_000);
|
||||||
assertTrue(h.isCompletedToday());
|
assertTrue(h.isCompletedToday());
|
||||||
h.getRepetitions().setValue(getToday(), 50_000);
|
h.getOriginalCheckmarks().setValue(getToday(), 50_000);
|
||||||
assertTrue(h.isCompletedToday());
|
assertTrue(h.isCompletedToday());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,6 @@ public class HabitTest extends BaseUnitTest
|
|||||||
.suppress(Warning.NONFINAL_FIELDS)
|
.suppress(Warning.NONFINAL_FIELDS)
|
||||||
.verify();
|
.verify();
|
||||||
|
|
||||||
EqualsVerifier.forClass(Repetition.class).verify();
|
|
||||||
EqualsVerifier.forClass(Score.class).verify();
|
EqualsVerifier.forClass(Score.class).verify();
|
||||||
EqualsVerifier.forClass(Streak.class).verify();
|
EqualsVerifier.forClass(Streak.class).verify();
|
||||||
EqualsVerifier.forClass(Reminder.class).verify();
|
EqualsVerifier.forClass(Reminder.class).verify();
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class RepetitionListTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
habit = fixtures.createEmptyHabit();
|
habit = fixtures.createEmptyHabit();
|
||||||
reps = habit.getRepetitions();
|
reps = habit.getOriginalCheckmarks();
|
||||||
|
|
||||||
today = DateUtils.getToday();
|
today = DateUtils.getToday();
|
||||||
|
|
||||||
@@ -79,15 +79,15 @@ public class RepetitionListTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void test_getOldest()
|
public void test_getOldest()
|
||||||
{
|
{
|
||||||
Repetition rep = reps.getOldest();
|
Checkmark check = reps.getOldest();
|
||||||
assertThat(rep.getTimestamp(), equalTo(today.minus(7)));
|
assertThat(check.getTimestamp(), equalTo(today.minus(7)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getWeekDayFrequency()
|
public void test_getWeekDayFrequency()
|
||||||
{
|
{
|
||||||
habit = fixtures.createEmptyHabit();
|
habit = fixtures.createEmptyHabit();
|
||||||
reps = habit.getRepetitions();
|
reps = habit.getOriginalCheckmarks();
|
||||||
|
|
||||||
Random random = new Random(123L);
|
Random random = new Random(123L);
|
||||||
Integer weekdayCount[][] = new Integer[12][7];
|
Integer weekdayCount[][] = new Integer[12][7];
|
||||||
|
|||||||
@@ -326,14 +326,14 @@ public class ScoreListTest extends BaseUnitTest
|
|||||||
|
|
||||||
private void check(final int offset)
|
private void check(final int offset)
|
||||||
{
|
{
|
||||||
RepetitionList reps = habit.getRepetitions();
|
RepetitionList reps = habit.getOriginalCheckmarks();
|
||||||
Timestamp today = DateUtils.getToday();
|
Timestamp today = DateUtils.getToday();
|
||||||
reps.setValue(today.minus(offset), YES_MANUAL);
|
reps.setValue(today.minus(offset), YES_MANUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void check(final int from, final int to)
|
private void check(final int from, final int to)
|
||||||
{
|
{
|
||||||
RepetitionList reps = habit.getRepetitions();
|
RepetitionList reps = habit.getOriginalCheckmarks();
|
||||||
Timestamp today = DateUtils.getToday();
|
Timestamp today = DateUtils.getToday();
|
||||||
|
|
||||||
for (int i = from; i < to; i++)
|
for (int i = from; i < to; i++)
|
||||||
@@ -342,7 +342,7 @@ public class ScoreListTest extends BaseUnitTest
|
|||||||
|
|
||||||
private void check(ArrayList<Integer> values)
|
private void check(ArrayList<Integer> values)
|
||||||
{
|
{
|
||||||
RepetitionList reps = habit.getRepetitions();
|
RepetitionList reps = habit.getOriginalCheckmarks();
|
||||||
Timestamp today = DateUtils.getToday();
|
Timestamp today = DateUtils.getToday();
|
||||||
for (int i = 0; i < values.size(); i++)
|
for (int i = 0; i < values.size(); i++)
|
||||||
if (values.get(i) == YES_MANUAL)
|
if (values.get(i) == YES_MANUAL)
|
||||||
@@ -351,7 +351,7 @@ public class ScoreListTest extends BaseUnitTest
|
|||||||
|
|
||||||
private void addSkip(final int day)
|
private void addSkip(final int day)
|
||||||
{
|
{
|
||||||
RepetitionList reps = habit.getRepetitions();
|
RepetitionList reps = habit.getOriginalCheckmarks();
|
||||||
Timestamp today = DateUtils.getToday();
|
Timestamp today = DateUtils.getToday();
|
||||||
reps.setValue(today.minus(day), Checkmark.SKIP);
|
reps.setValue(today.minus(day), Checkmark.SKIP);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
|
|||||||
|
|
||||||
private Timestamp today;
|
private Timestamp today;
|
||||||
|
|
||||||
private RepetitionList repetitions;
|
private RepetitionList originalCheckmarks;
|
||||||
|
|
||||||
private long day;
|
private long day;
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
|
|||||||
repository = new Repository<>(RepetitionRecord.class, db);
|
repository = new Repository<>(RepetitionRecord.class, db);
|
||||||
habit = fixtures.createLongHabit();
|
habit = fixtures.createLongHabit();
|
||||||
|
|
||||||
repetitions = habit.getRepetitions();
|
originalCheckmarks = habit.getOriginalCheckmarks();
|
||||||
today = DateUtils.getToday();
|
today = DateUtils.getToday();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +70,8 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
|
|||||||
RepetitionRecord record = getByTimestamp(today.plus(1));
|
RepetitionRecord record = getByTimestamp(today.plus(1));
|
||||||
assertNull(record);
|
assertNull(record);
|
||||||
|
|
||||||
Repetition rep = new Repetition(today.plus(1), YES_MANUAL);
|
Checkmark rep = new Checkmark(today.plus(1), YES_MANUAL);
|
||||||
habit.getRepetitions().add(rep);
|
habit.getOriginalCheckmarks().add(rep);
|
||||||
|
|
||||||
record = getByTimestamp(today.plus(1));
|
record = getByTimestamp(today.plus(1));
|
||||||
assertNotNull(record);
|
assertNotNull(record);
|
||||||
@@ -81,30 +81,30 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testGetByInterval()
|
public void testGetByInterval()
|
||||||
{
|
{
|
||||||
List<Repetition> reps =
|
List<Checkmark> checks =
|
||||||
repetitions.getByInterval(today.minus(10), today);
|
originalCheckmarks.getByInterval(today.minus(10), today);
|
||||||
|
|
||||||
assertThat(reps.size(), equalTo(8));
|
assertThat(checks.size(), equalTo(8));
|
||||||
assertThat(reps.get(0).getTimestamp(), equalTo(today.minus(10)));
|
assertThat(checks.get(0).getTimestamp(), equalTo(today.minus(10)));
|
||||||
assertThat(reps.get(4).getTimestamp(), equalTo(today.minus(5)));
|
assertThat(checks.get(4).getTimestamp(), equalTo(today.minus(5)));
|
||||||
assertThat(reps.get(5).getTimestamp(), equalTo(today.minus(3)));
|
assertThat(checks.get(5).getTimestamp(), equalTo(today.minus(3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetByTimestamp()
|
public void testGetByTimestamp()
|
||||||
{
|
{
|
||||||
Repetition rep = repetitions.getByTimestamp(today);
|
Checkmark rep = originalCheckmarks.getByTimestamp(today);
|
||||||
assertNotNull(rep);
|
assertNotNull(rep);
|
||||||
assertThat(rep.getTimestamp(), equalTo(today));
|
assertThat(rep.getTimestamp(), equalTo(today));
|
||||||
|
|
||||||
rep = repetitions.getByTimestamp(today.minus(2));
|
rep = originalCheckmarks.getByTimestamp(today.minus(2));
|
||||||
assertNull(rep);
|
assertNull(rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetOldest()
|
public void testGetOldest()
|
||||||
{
|
{
|
||||||
Repetition rep = repetitions.getOldest();
|
Checkmark rep = originalCheckmarks.getOldest();
|
||||||
assertNotNull(rep);
|
assertNotNull(rep);
|
||||||
assertThat(rep.getTimestamp(), equalTo(today.minus(120)));
|
assertThat(rep.getTimestamp(), equalTo(today.minus(120)));
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
|
|||||||
public void testGetOldest_withEmptyHabit()
|
public void testGetOldest_withEmptyHabit()
|
||||||
{
|
{
|
||||||
Habit empty = fixtures.createEmptyHabit();
|
Habit empty = fixtures.createEmptyHabit();
|
||||||
Repetition rep = empty.getRepetitions().getOldest();
|
Checkmark rep = empty.getOriginalCheckmarks().getOldest();
|
||||||
assertNull(rep);
|
assertNull(rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +123,8 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
|
|||||||
RepetitionRecord record = getByTimestamp(today);
|
RepetitionRecord record = getByTimestamp(today);
|
||||||
assertNotNull(record);
|
assertNotNull(record);
|
||||||
|
|
||||||
Repetition rep = record.toRepetition();
|
Checkmark rep = record.toCheckmark();
|
||||||
repetitions.remove(rep);
|
originalCheckmarks.remove(rep);
|
||||||
|
|
||||||
record = getByTimestamp(today);
|
record = getByTimestamp(today);
|
||||||
assertNull(record);
|
assertNull(record);
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ public class RepetitionRecordTest extends BaseUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testRecord() throws Exception
|
public void testRecord() throws Exception
|
||||||
{
|
{
|
||||||
Repetition rep = new Repetition(Timestamp.ZERO.plus(100), 50);
|
Checkmark check = new Checkmark(Timestamp.ZERO.plus(100), 50);
|
||||||
RepetitionRecord record = new RepetitionRecord();
|
RepetitionRecord record = new RepetitionRecord();
|
||||||
record.copyFrom(rep);
|
record.copyFrom(check);
|
||||||
assertThat(rep, equalTo(record.toRepetition()));
|
assertThat(check, equalTo(record.toCheckmark()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
|
|||||||
Timestamp today = DateUtils.getToday();
|
Timestamp today = DateUtils.getToday();
|
||||||
int[] actualCheckmarks = cache.getCheckmarks(h.getId());
|
int[] actualCheckmarks = cache.getCheckmarks(h.getId());
|
||||||
int[] expectedCheckmarks =
|
int[] expectedCheckmarks =
|
||||||
h.getCheckmarks().getValues(today.minus(9), today);
|
h.getComputedCheckmarks().getValues(today.minus(9), today);
|
||||||
|
|
||||||
assertThat(actualCheckmarks, equalTo(expectedCheckmarks));
|
assertThat(actualCheckmarks, equalTo(expectedCheckmarks));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class ListHabitsBehaviorTest extends BaseUnitTest
|
|||||||
behavior.onEdit(habit2, DateUtils.getToday());
|
behavior.onEdit(habit2, DateUtils.getToday());
|
||||||
verify(screen).showNumberPicker(eq(0.1), eq("miles"), picker.capture());
|
verify(screen).showNumberPicker(eq(0.1), eq("miles"), picker.capture());
|
||||||
picker.getValue().onNumberPicked(100);
|
picker.getValue().onNumberPicked(100);
|
||||||
assertThat(habit2.getCheckmarks().getTodayValue(), equalTo(100000));
|
assertThat(habit2.getComputedCheckmarks().getTodayValue(), equalTo(100000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class WidgetBehaviorTest extends BaseUnitTest
|
|||||||
if(skipEnabled) nextValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
|
if(skipEnabled) nextValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue);
|
||||||
else nextValue = Checkmark.Companion.nextToggleValueWithoutSkip(currentValue);
|
else nextValue = Checkmark.Companion.nextToggleValueWithoutSkip(currentValue);
|
||||||
|
|
||||||
habit.getRepetitions().setValue(timestamp, currentValue);
|
habit.getOriginalCheckmarks().setValue(timestamp, currentValue);
|
||||||
behavior.onToggleRepetition(habit, timestamp);
|
behavior.onToggleRepetition(habit, timestamp);
|
||||||
verify(preferences).isSkipEnabled();
|
verify(preferences).isSkipEnabled();
|
||||||
verify(commandRunner).execute(
|
verify(commandRunner).execute(
|
||||||
@@ -106,7 +106,7 @@ public class WidgetBehaviorTest extends BaseUnitTest
|
|||||||
public void testOnIncrement()
|
public void testOnIncrement()
|
||||||
{
|
{
|
||||||
habit = fixtures.createNumericalHabit();
|
habit = fixtures.createNumericalHabit();
|
||||||
habit.getRepetitions().setValue(timestamp, 500);
|
habit.getOriginalCheckmarks().setValue(timestamp, 500);
|
||||||
|
|
||||||
behavior.onIncrement(habit, timestamp, 100);
|
behavior.onIncrement(habit, timestamp, 100);
|
||||||
verify(commandRunner).execute(
|
verify(commandRunner).execute(
|
||||||
@@ -120,7 +120,7 @@ public class WidgetBehaviorTest extends BaseUnitTest
|
|||||||
public void testOnDecrement()
|
public void testOnDecrement()
|
||||||
{
|
{
|
||||||
habit = fixtures.createNumericalHabit();
|
habit = fixtures.createNumericalHabit();
|
||||||
habit.getRepetitions().setValue(timestamp, 500);
|
habit.getOriginalCheckmarks().setValue(timestamp, 500);
|
||||||
|
|
||||||
behavior.onDecrement(habit, timestamp, 100);
|
behavior.onDecrement(habit, timestamp, 100);
|
||||||
verify(commandRunner).execute(
|
verify(commandRunner).execute(
|
||||||
|
|||||||
Reference in New Issue
Block a user