Refactor rating logic in RevlogEntry and update related scheduling functions

This commit introduces a new `has_rating` method in the `RevlogEntry` struct to encapsulate the logic for checking if an entry has a rating. The scheduling logic in `params.rs` and the calculation of normal answer counts in `card.rs` have been updated to use this new method, enhancing code clarity and maintainability.
This commit is contained in:
Jarrett Ye 2025-07-31 18:52:55 +08:00
parent c5eaeaa91e
commit cf090b8c60
No known key found for this signature in database
GPG key ID: EBFC55E0C1A352BB
3 changed files with 8 additions and 13 deletions

View file

@ -102,12 +102,16 @@ impl RevlogEntry {
self.review_kind == RevlogReviewKind::Filtered && self.ease_factor == 0
}
pub(crate) fn has_rating(&self) -> bool {
self.button_chosen > 0
}
/// Returns true if the review entry is not manually rescheduled and not
/// cramming. Used to filter out entries that shouldn't be considered
/// for statistics and scheduling.
pub(crate) fn has_rating_and_affects_scheduling(&self) -> bool {
// not rescheduled/set due date/reset
self.button_chosen > 0
self.has_rating()
// not cramming
&& !self.is_cramming()
}

View file

@ -400,7 +400,7 @@ pub(crate) fn reviews_for_fsrs(
// For incomplete review histories, initial memory state is based on the first
// user-graded review after the cutoff date with interval >= 1d.
let within_cutoff = entry.id.0 > ignore_revlogs_before.0;
let user_graded = matches!(entry.button_chosen, 1..=4);
let user_graded = entry.has_rating();
let interday = entry.interval >= 1 || entry.interval <= -86400;
if user_graded && within_cutoff && interday {
first_user_grade_idx = Some(index);
@ -469,16 +469,7 @@ pub(crate) fn reviews_for_fsrs(
}
// Filter out unwanted entries
entries.retain(|entry| {
!(
// set due date, reset or rescheduled
(entry.review_kind == RevlogReviewKind::Manual || entry.button_chosen == 0)
|| // cram
entry.is_cramming()
|| // rescheduled
(entry.review_kind == RevlogReviewKind::Rescheduled)
)
});
entries.retain(|entry| entry.has_rating_and_affects_scheduling());
// Compute delta_t for each entry
let delta_ts = iter::once(0)

View file

@ -187,7 +187,7 @@ impl Collection {
}
fn average_and_total_secs_strings(revlog: &[RevlogEntry]) -> (f32, f32) {
let normal_answer_count = revlog.iter().filter(|r| r.button_chosen > 0).count();
let normal_answer_count = revlog.iter().filter(|r| r.has_rating()).count();
let total_secs: f32 = revlog
.iter()
.map(|entry| (entry.taken_millis as f32) / 1000.0)