-
-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Describe the bug
When calculating average pages per book (and possibly other stats), the app counts each reading of a book as a separate instance. This inflates the statistics for books that have been read more than once, since a book with multiple readings in the same year (or overall) is counted multiple times for pages and book count.
To Reproduce
Steps to reproduce the behavior:
- Add a book with a set number of pages.
- Add multiple readings for that book (with finish dates in the same year).
- Check the statistics for average pages per book.
- Observe that the book is counted more than once in the stats.
Expected behavior
Each book should only be counted once per year (or overall) regardless of how many readings it has, unless the statistic is specifically meant to count readings in which case we should add reads stats instead of the whole book stats.
Screenshots
Additional info(please complete the following information):
I haven't tested this issue in the app, just found it in code and discussed with copilot.
Additional context
Relevant code lines:
openreads/lib/logic/bloc/stats_bloc/stats_bloc.dart
Lines 490 to 497 in 536469c
| for (final reading in book.readings) { | |
| if (year != null && reading.finishDate?.year != year) { | |
| continue; | |
| } | |
| finishedPages += book.pages!; | |
| countedBooks += 1; | |
| } |
Logic in these lines loops over all readings for a book and counts each, which may not be the intended behavior for certain statistics.