Create new UNKNOWN checkmark state

This commit is contained in:
2020-11-26 15:08:49 -06:00
parent 9ca1c8e459
commit 2228dbf0f4
15 changed files with 49 additions and 34 deletions

View File

@@ -43,27 +43,32 @@ import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
public final class Checkmark
{
/**
* Indicates that there was an explicit skip at the timestamp.
* Checkmark value indicating that the habit is not applicable for this timestamp.
*/
public static final int SKIP = 3;
/**
* Indicates that there was a repetition at the timestamp.
* Checkmark value indicating that the user has performed the habit at this timestamp.
*/
public static final int YES_MANUAL = 2;
/**
* Indicates that there was no repetition at the timestamp, but one was not
* expected in any case, due to the frequency of the habit.
* Checkmark value indicating that the user did not perform the habit, but they were not
* expected to, because of the frequency of the habit.
*/
public static final int YES_AUTO = 1;
/**
* Indicates that there was no repetition at the timestamp, even though a
* repetition was expected.
* Checkmark value indicating that the user did not perform the habit, even though they were
* expected to perform it.
*/
public static final int NO = 0;
/**
* Checkmark value indicating that no data is available for the given timestamp.
*/
public static final int UNKNOWN = -1;
private final Timestamp timestamp;
/**

View File

@@ -62,7 +62,7 @@ public abstract class CheckmarkList
int nDays = begin.daysUntil(today) + 1;
List<Checkmark> checkmarks = new ArrayList<>(nDays);
for (int i = 0; i < nDays; i++)
checkmarks.add(new Checkmark(today.minus(i), NO));
checkmarks.add(new Checkmark(today.minus(i), UNKNOWN));
for (Interval interval : intervals)
{
@@ -79,7 +79,10 @@ public abstract class CheckmarkList
{
Timestamp date = rep.getTimestamp();
int offset = date.daysUntil(today);
checkmarks.set(offset, new Checkmark(date, rep.getValue()));
int value = rep.getValue();
int prevValue = checkmarks.get(offset).getValue();
if (prevValue < value)
checkmarks.set(offset, new Checkmark(date, value));
}
return checkmarks;
@@ -224,7 +227,7 @@ public abstract class CheckmarkList
{
Checkmark today = getToday();
if (today != null) return today.getValue();
else return NO;
else return UNKNOWN;
}
public synchronized int getThisWeekValue(int firstWeekday)

View File

@@ -332,7 +332,7 @@ public class Habit
else
return todayCheckmark / 1000.0 <= data.targetValue;
}
else return (todayCheckmark != NO);
else return (todayCheckmark != NO && todayCheckmark != UNKNOWN);
}
public synchronized boolean isNumerical()

View File

@@ -60,6 +60,7 @@ public final class Repetition
{
switch(value) {
case NO:
case UNKNOWN:
case YES_AUTO:
return YES_MANUAL;
case YES_MANUAL:
@@ -74,6 +75,7 @@ public final class Repetition
{
switch(value) {
case NO:
case UNKNOWN:
case YES_AUTO:
return YES_MANUAL;
default:

View File

@@ -85,7 +85,7 @@ public abstract class RepetitionList
public int getValue(Timestamp timestamp)
{
Repetition rep = getByTimestamp(timestamp);
if (rep == null) return Checkmark.NO;
if (rep == null) return Checkmark.UNKNOWN;
return rep.getValue();
}

View File

@@ -138,8 +138,8 @@ public abstract class StreakList
current = current.plus(1);
int j = checks.length - i - 1;
if ((checks[j + 1] == 0 && checks[j] > 0)) list.add(current);
if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current.minus(1));
if ((checks[j + 1] <= 0 && checks[j] > 0)) list.add(current);
if ((checks[j + 1] > 0 && checks[j] <= 0)) list.add(current.minus(1));
}
if (list.size() % 2 == 1) list.add(current);

View File

@@ -68,7 +68,7 @@ public class MemoryCheckmarkList extends CheckmarkList
{
Timestamp t = to.minus(i);
if(t.isNewerThan(newestComputed) || t.isOlderThan(oldestComputed))
filtered.add(new Checkmark(t, Checkmark.NO));
filtered.add(new Checkmark(t, Checkmark.UNKNOWN));
else
filtered.add(list.get(t.daysUntil(newestComputed)));
}

View File

@@ -142,7 +142,9 @@ public class HabitFixtures
Timestamp timestamp = DateUtils.getToday();
for (boolean c : NON_DAILY_HABIT_CHECKS)
{
if (c) habit.getRepetitions().setValue(timestamp, YES_MANUAL);
int value = NO;
if (c) value = YES_MANUAL;
habit.getRepetitions().setValue(timestamp, value);
timestamp = timestamp.minus(1);
}

View File

@@ -186,7 +186,7 @@ public class NotificationTray
{
systemTray.log("Showing notification for habit=" + habit.id);
if (todayValue != Checkmark.NO) {
if (todayValue != Checkmark.UNKNOWN) {
systemTray.log(String.format(
Locale.US,
"Habit %d already checked. Skipping.",

View File

@@ -80,14 +80,14 @@ public class CheckmarkListTest extends BaseUnitTest
intervals.add(new CheckmarkList.Interval(day(2), day(2), day(1)));
List<Checkmark> expected = new ArrayList<>();
expected.add(new Checkmark(day(0), NO));
expected.add(new Checkmark(day(0), UNKNOWN));
expected.add(new Checkmark(day(1), YES_MANUAL));
expected.add(new Checkmark(day(2), YES_MANUAL));
expected.add(new Checkmark(day(3), NO));
expected.add(new Checkmark(day(3), UNKNOWN));
expected.add(new Checkmark(day(4), YES_AUTO));
expected.add(new Checkmark(day(5), YES_MANUAL));
expected.add(new Checkmark(day(6), YES_AUTO));
expected.add(new Checkmark(day(7), NO));
expected.add(new Checkmark(day(7), UNKNOWN));
expected.add(new Checkmark(day(8), YES_AUTO));
expected.add(new Checkmark(day(9), YES_AUTO));
expected.add(new Checkmark(day(10), YES_MANUAL));
@@ -220,9 +220,9 @@ public class CheckmarkListTest extends BaseUnitTest
travelInTime(3);
int[] expectedValues = {
NO,
NO,
NO,
UNKNOWN,
UNKNOWN,
UNKNOWN,
YES_MANUAL,
NO,
YES_AUTO,
@@ -296,7 +296,7 @@ public class CheckmarkListTest extends BaseUnitTest
assertThat(checkmarks.getTodayValue(), equalTo(YES_MANUAL));
travelInTime(1);
assertThat(checkmarks.getTodayValue(), equalTo(NO));
assertThat(checkmarks.getTodayValue(), equalTo(UNKNOWN));
}
@Test
@@ -320,12 +320,12 @@ public class CheckmarkListTest extends BaseUnitTest
YES_AUTO,
YES_MANUAL,
YES_MANUAL,
NO,
NO,
NO,
NO,
NO,
NO
UNKNOWN,
UNKNOWN,
UNKNOWN,
UNKNOWN,
UNKNOWN,
UNKNOWN
};
int[] actualValues = nonDailyHabit.getCheckmarks().getValues(from, to);
@@ -475,7 +475,7 @@ public class CheckmarkListTest extends BaseUnitTest
assertThat(checkmarks.getThisMonthValue(), equalTo(1006));
DateUtils.setFixedLocalTime(unixTime(2000, MAY, 1));
assertThat(checkmarks.getTodayValue(), equalTo(0));
assertThat(checkmarks.getTodayValue(), equalTo(UNKNOWN));
assertThat(checkmarks.getThisWeekValue(SATURDAY), equalTo(0));
assertThat(checkmarks.getThisMonthValue(), equalTo(0));
}