Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use card.reps - 1 when calculating fuzz #2933

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions proto/anki/scheduler.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ service SchedulerService {
returns (ComputeOptimalRetentionResponse);
rpc EvaluateWeights(EvaluateWeightsRequest) returns (EvaluateWeightsResponse);
rpc ComputeMemoryState(cards.CardId) returns (ComputeMemoryStateResponse);
// The number of days the calculated interval will be fuzzed by. Utilized by
// the FSRS add-on.
// The number of days the calculated interval was fuzzed by on the previous
// review (if any). Utilized by the FSRS add-on.
rpc FuzzDelta(FuzzDeltaRequest) returns (FuzzDeltaResponse);
}

Expand Down
4 changes: 2 additions & 2 deletions rslib/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ pub enum AnkiError {
InvalidMethodIndex,
InvalidServiceIndex,
FsrsWeightsInvalid,
// Returned by fsrs-rs; may happen even if 1000+ reviews
/// Returned by fsrs-rs; may happen even if 1000+ reviews
FsrsInsufficientData,
// Generated by our backend if count < 1000
/// Generated by our backend if count < 1000
FsrsInsufficientReviews {
count: usize,
},
Expand Down
19 changes: 14 additions & 5 deletions rslib/src/scheduler/answering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl Collection {
};
let desired_retention = fsrs_enabled.then_some(config.inner.desired_retention);
Ok(CardStateUpdater {
fuzz_seed: get_fuzz_seed(&card),
fuzz_seed: get_fuzz_seed(&card, false),
card,
deck,
config,
Expand Down Expand Up @@ -519,14 +519,23 @@ pub mod test_helpers {
}

impl Card {
pub(crate) fn get_fuzz_factor(&self) -> Option<f32> {
get_fuzz_factor(get_fuzz_seed(self))
/// If for_reschedule is true, we use card.reps - 1 to match the previous
/// review.
pub(crate) fn get_fuzz_factor(&self, for_reschedule: bool) -> Option<f32> {
get_fuzz_factor(get_fuzz_seed(self, for_reschedule))
}
}

/// Return a consistent seed for a given card at a given number of reps.
fn get_fuzz_seed(card: &Card) -> Option<u64> {
get_fuzz_seed_for_id_and_reps(card.id, card.reps)
/// If for_reschedule is true, we use card.reps - 1 to match the previous
/// review.
fn get_fuzz_seed(card: &Card, for_reschedule: bool) -> Option<u64> {
let reps = if for_reschedule {
card.reps.saturating_sub(1)
} else {
card.reps
};
get_fuzz_seed_for_id_and_reps(card.id, reps)
}

/// If in test environment, disable fuzzing.
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/scheduler/fsrs/memory_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Collection {
)
as f32;
card.interval = with_review_fuzz(
card.get_fuzz_factor(),
card.get_fuzz_factor(true),
interval,
1,
req.max_interval,
Expand Down
2 changes: 1 addition & 1 deletion rslib/src/scheduler/states/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Collection {
.or_not_found(card.deck_id)?;
let config = self.home_deck_config(deck.config_id(), card.original_deck_id)?;
let fuzzed = with_review_fuzz(
card.get_fuzz_factor(),
card.get_fuzz_factor(true),
interval as f32,
1,
config.inner.maximum_review_interval,
Expand Down