Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SKIP behavior in YES_AUTO and score #1916

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading