mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
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:
parent
c5eaeaa91e
commit
cf090b8c60
3 changed files with 8 additions and 13 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue