Skip to content

Commit 53e58ad

Browse files
rmarkermateusz-bak
authored andcommitted
fix: Books without readings being spuriously included in statistics.
It was the case that books without recorded readings would be included in some of the statistics for a specific year. Specifically the shortest/longest, and average pages statistics. It now will only include these books in overall statistics where a specific year isn't provided.
1 parent 0c905bb commit 53e58ad

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

lib/logic/bloc/stats_bloc/stats_bloc.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ class StatsBloc extends Bloc<StatsEvent, StatsState> {
279279
if (book.pages == null || book.pages! == 0) continue;
280280

281281
if (book.readings.isEmpty) {
282+
if (year != null) {
283+
continue;
284+
}
285+
282286
if (shortestBookPages == null || book.pages! < shortestBookPages) {
283287
shortestBookPages = book.pages!;
284288
shortestBookString = '${book.title} - ${book.author}';
@@ -343,6 +347,10 @@ class StatsBloc extends Bloc<StatsEvent, StatsState> {
343347
if (book.pages == null || book.pages! == 0) continue;
344348

345349
if (book.readings.isEmpty) {
350+
if (year != null) {
351+
continue;
352+
}
353+
346354
if (longestBookPages == null || book.pages! > longestBookPages) {
347355
longestBookPages = book.pages!;
348356
longestBookString = '${book.title} - ${book.author}';
@@ -472,6 +480,10 @@ class StatsBloc extends Bloc<StatsEvent, StatsState> {
472480
if (book.pages == null) continue;
473481

474482
if (book.readings.isEmpty) {
483+
if (year != null) {
484+
continue;
485+
}
486+
475487
finishedPages += book.pages!;
476488
countedBooks += 1;
477489
} else {

0 commit comments

Comments
 (0)