From 80c5f2d4916a239b5b1ae09a57641c7e62aa06fb Mon Sep 17 00:00:00 2001 From: Jarrett Ye Date: Tue, 5 Dec 2023 11:08:34 +0800 Subject: [PATCH] skip revlog with time = 0 when calc recall cost (#2870) * skip revlog with time = 0 when calc recall cost * Update retention.rs --- rslib/src/scheduler/fsrs/retention.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/rslib/src/scheduler/fsrs/retention.rs b/rslib/src/scheduler/fsrs/retention.rs index 444cb1201..db866822d 100644 --- a/rslib/src/scheduler/fsrs/retention.rs +++ b/rslib/src/scheduler/fsrs/retention.rs @@ -121,7 +121,11 @@ impl Collection { let mut arr = default; revlogs .iter() - .filter(|r| r.review_kind == RevlogReviewKind::Review && r.button_chosen > 0) + .filter(|r| { + r.review_kind == RevlogReviewKind::Review + && r.button_chosen > 0 + && r.taken_millis > 0 + }) .sorted_by(|a, b| a.button_chosen.cmp(&b.button_chosen)) .group_by(|r| r.button_chosen) .into_iter() @@ -139,10 +143,15 @@ impl Collection { let learn_cost = { let revlogs_filter = revlogs .iter() - .filter(|r| r.review_kind == RevlogReviewKind::Learning && r.button_chosen >= 1) + .filter(|r| { + r.review_kind == RevlogReviewKind::Learning + && r.button_chosen >= 1 + && r.taken_millis > 0 + }) .map(|r| r.taken_millis); - if total_first > 0.0 { - revlogs_filter.sum::() as f64 / total_first / 1000.0 + let length = revlogs_filter.clone().count() as f64; + if length > 0.0 { + revlogs_filter.sum::() as f64 / length / 1000.0 } else { return Err(AnkiError::FsrsInsufficientData); }