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 marker scaling in frequency display #1425

Merged
merged 6 commits into from
Jul 30, 2022

Conversation

eduebernal
Copy link
Contributor

@eduebernal eduebernal commented Jul 6, 2022

Fixes #1355

The marker scaling is now based on the ratio of (number of [Weekday] with habit observed in the month/number of [Weekday]), as proposed in the issue.

This screenshot shows weekdays with 100% completion:
Screenshot_20220705-213212_Habits

This screenshot shows weekdays with varying completion percentages:
Screenshot_20220705-213155_Habits

I have some concerns with the scaling percentages. On weekdays that appear 4 times in a month, the possible percentages are (0,25,50,75,100%), and on weekdays that appear 5 times, the percentages are (0,20,40,60,80,100%). So, for example if you missed the habit 1 time for each weekday, the percentage for some markers would be 75% and for others would be 80%. The difference is barely noticeable but I just wanted to point it out.

Another thing is that this frequency chart may be only meaningful with habits that are done everyday or on specific weekdays.

Tested with a samsung galaxy A71.

Let me know what you think.

Comment on lines 192 to 197
val extraWeekdays = YearMonth.of(year, month).lengthOfMonth() - 28

val freq = Array(7) { 4 }
for (day in weekday until weekday + extraWeekdays) {
freq[day % 7] = 5
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might more readable if you just iterate through all the days of the month and add +1 to the corresponding entry in the array at every iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I see what you mean, I went with this approach to reduce the time complexity of the algorithm, but I can see how it may be confusing to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to the method you described.

@eduebernal
Copy link
Contributor Author

eduebernal commented Jul 6, 2022

I fixed the test, I incorrectly assumed that Sunday was 0, but looking at the Timestamp class I noticed that Saturday is mapped to 0 instead.

I couldn't run the tests on my machine because of a mockito error, probably a misconfiguration on my end. But I ran the build & test workflow on my fork and the core tests seem to work fine now.

Also, the view test for the frequency display probably fails. I tried to follow the TEST.md documentation but it seems the ./build.sh fetch-image command described there doesn't exist.

*/
@JvmStatic
fun getWeekdaysInMonth(startOfMonth: Timestamp): Array<Int> {
val month = startOfMonth.toCalendar()[Calendar.MONTH] + 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why +1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Calendar class encodes the months with numbers from 0 to 11, but the YearMonth.of(year, month) method used below to get the length of the month expects an int from 1 to 12 for the month, so I just add 1 to use that method correctly.

@iSoron iSoron merged commit 2fc6c67 into iSoron:dev Jul 30, 2022
@iSoron
Copy link
Owner

iSoron commented Jul 30, 2022

Thank you for the PR, @eduebernal. I fixed the test screenshots and merged it. For the record, the commands were renamed to build.sh android-tests <API> and build.sh android-accept-images.

iSoron added a commit that referenced this pull request Aug 11, 2022
fix marker scaling in frequency display
@iSoron
Copy link
Owner

iSoron commented Sep 4, 2022

Hi @eduebernal, I just noticed that this PR breaks the frequency chart for numerical habits (see screenshot attached below). If you think you could fix this in the next few days please let me know, and I will wait for your fix before we release 2.1.0. Otherwise, I will revert the commits, and we can re-apply them later.

Screenshot_20220903_201436

@eduebernal
Copy link
Contributor Author

Sure, I submitted a new PR #1489, however if you're not satisfied with that fix, I cannot promise that I will have time to work on it outside of weekends.

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.

Frequency display does not normalize for the number of times a day of the week occurs in a month
3 participants