Skip to content

Commit

Permalink
Fix SKIP behavior in YES_AUTO and score
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristian Tashkov committed Jan 5, 2024
1 parent 800f92f commit 82d8db4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ open class EntryList {
entries: List<Entry>
): ArrayList<Interval> {
val filtered = entries.filter { it.value == YES_MANUAL }
val skips = entries.filter { it.value == SKIP }
val num = freq.numerator
val den = freq.denominator
val intervals = arrayListOf<Interval>()
for (i in num - 1 until filtered.size) {
val (begin, _) = filtered[i]
val (center, _) = filtered[i - num + 1]
val skipCounts = skips.filter { it.timestamp in begin..center }.size
var size = den
if (den == 30 || den == 31) {
val beginDate = begin.toLocalDate()
Expand All @@ -264,8 +266,8 @@ open class EntryList {
beginDate.monthLength
}
}
if (begin.daysUntil(center) < size) {
val end = begin.plus(size - 1)
if (begin.daysUntil(center) - skipCounts < size) {
val end = begin.plus(size - 1 + skipCounts)
intervals.add(Interval(begin, center, end))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ScoreList {
) {
map.clear()
var rollingSum = 0.0
var skipDays = 0
var numerator = frequency.numerator
var denominator = frequency.denominator
val freq = frequency.toDouble()
Expand All @@ -93,14 +94,19 @@ class ScoreList {
var previousValue = if (isNumerical && isAtMost) 1.0 else 0.0
for (i in values.indices) {
val offset = values.size - i - 1
var outsideRangeIndex = offset + denominator + skipDays
if (isNumerical) {
rollingSum += max(0, values[offset])
if (offset + denominator < values.size) {
rollingSum -= max(0, values[offset + denominator])
}

val normalizedRollingSum = rollingSum / 1000
if (values[offset] != Entry.SKIP) {
if (outsideRangeIndex < values.size) {
while (values[outsideRangeIndex] == Entry.SKIP) {
skipDays -= 1
outsideRangeIndex -= 1
}
rollingSum -= max(0, values[outsideRangeIndex])
}

val normalizedRollingSum = rollingSum / 1000
val percentageCompleted = if (!isAtMost) {
if (targetValue > 0) {
min(1.0, normalizedRollingSum / targetValue)
Expand All @@ -119,19 +125,27 @@ class ScoreList {
}

previousValue = compute(freq, previousValue, percentageCompleted)
} else {
skipDays += 1
}
} else {
if (values[offset] == Entry.YES_MANUAL) {
rollingSum += 1.0
}
if (offset + denominator < values.size) {
if (values[offset + denominator] == Entry.YES_MANUAL) {
rollingSum -= 1.0
}
}
if (values[offset] != Entry.SKIP) {
if (outsideRangeIndex < values.size) {
while (values[outsideRangeIndex] == Entry.SKIP) {
skipDays -= 1
outsideRangeIndex -= 1
}
if (values[outsideRangeIndex] == Entry.YES_MANUAL) {
rollingSum -= 1.0
}
}
val percentageCompleted = min(1.0, rollingSum / numerator)
previousValue = compute(freq, previousValue, percentageCompleted)
} else {
skipDays += 1
}
}
val timestamp = from.plus(i)
Expand Down

0 comments on commit 82d8db4

Please sign in to comment.