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

Fixed score when using skips on non-daily habit #1713

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

Maxet1000
Copy link

This fixes the problems with the score raised in issue #1695 where a skip affects the score in non-daily habits, when it shouldn't.

To fix the issue, the part of the recompute function that calculates the rolling sum of completed habits in the last period was changed to take skips into account. A new function that calculates amount of skips in an interval is used to expand the length of that period.

Six tests where added, three to test the new helper function and three for testing the score.

Copy link
Collaborator

@hiqua hiqua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change needed in the numerical habit case?

* sum of the denominator and the number of skips within the interval.
*/
@Synchronized
fun getNumberOfSkipsByInterval(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really knowledgeable about this, but if you want to make it recursive, might as well follow https://kotlinlang.org/docs/functions.html#tail-recursive-functions, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't work here as the 'tailrec' modifier requires that the function calling itself is the last operation that function performs, which isn't the case here. I'm not really knowledgeable about this either, so I might be missing something.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but you can rewrite so that's the case, i.e. you can change the function so that it's tail-recursive. I think that'd be preferable here.

rollingSum -= 1.0
val nbOfSkips =
getNumberOfSkipsByInterval(values, offset, offset + denominator)
if (offset + denominator + nbOfSkips < values.size) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a variable for offset + denominator + nbOfSkips to make it easier to read?

fun getNumberOfSkipsByInterval(
values: IntArray,
firstIndexToCheck: Int,
lastIndexToCheck: Int
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter name is misleading, because in practice it's not necessarily the last index checked. Can you try to make it clearer for the reader what this does in which cases?

* the percentage of completed days.
*
* If skips are found in the interval, it is expanded until the interval has the size of the
* sum of the denominator and the number of skips within the interval.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no denominator in this function so this doc could be improved to make it understandable on its own, can you try to do that?

@@ -145,6 +146,93 @@ class YesNoScoreListTest : BaseScoreListTest() {
checkScoreValues(expectedValues)
}

@Test
fun test_getNumberOfSkipsByInterval_NoSkips() {
val vars = intArrayOf(-1, -1, -1, -1, 3, 2, 2, -1, 2, 2, -1, 2, 2, -1, 3, 2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: can you hide the integer behind the enum, i.e. use SKIP etc. instead?

@Maxet1000
Copy link
Author

@hiqua
I've tried to resolve the issues you raised. As for the numerical case, I don't think it has the same problem. It seems to account for skips and after some functional testing it seems to work fine.
My apologies for the late reply, please let me know if I need to do anything else!

@Maxet1000
Copy link
Author

Does anything else need to be changed or can this be integrated? @hiqua @iSoron

@Thaer-Jleilati
Copy link

Requesting this fix @iSoron please. I want to properly skip a workout day for my 3 days a week workout habit but it broke my streak!

@hiqua
Copy link
Collaborator

hiqua commented Jul 13, 2024

Does anything else need to be changed or can this be integrated? @hiqua @iSoron

I think we should fix the potential stack overflow with the recursive function before merging this, either by making the function tail recursive as commented, or just switch to an imperative style.

@Maxet1000
Copy link
Author

@hiqua I've now made the function tail recursive like requested

@hiqua
Copy link
Collaborator

hiqua commented Jul 20, 2024

Could you also rebase on top of the current dev, to make it possible to run the GH actions? Thanks!

@Maxet1000
Copy link
Author

I've rebased it! I'm not very familiar with rebasing, so I hope I did it correctly. Please let me know if I should make any more changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants