Damien Elmes 2024-01-09 12:26:46 +10:00 committed by GitHub
parent cc81db0f9d
commit bf06020855
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 11 deletions

View file

@ -53,8 +53,8 @@ service SchedulerService {
returns (ComputeOptimalRetentionResponse); returns (ComputeOptimalRetentionResponse);
rpc EvaluateWeights(EvaluateWeightsRequest) returns (EvaluateWeightsResponse); rpc EvaluateWeights(EvaluateWeightsRequest) returns (EvaluateWeightsResponse);
rpc ComputeMemoryState(cards.CardId) returns (ComputeMemoryStateResponse); rpc ComputeMemoryState(cards.CardId) returns (ComputeMemoryStateResponse);
// The number of days the calculated interval will be fuzzed by. Utilized by // The number of days the calculated interval was fuzzed by on the previous
// the FSRS add-on. // review (if any). Utilized by the FSRS add-on.
rpc FuzzDelta(FuzzDeltaRequest) returns (FuzzDeltaResponse); rpc FuzzDelta(FuzzDeltaRequest) returns (FuzzDeltaResponse);
} }

View file

@ -114,9 +114,9 @@ pub enum AnkiError {
InvalidMethodIndex, InvalidMethodIndex,
InvalidServiceIndex, InvalidServiceIndex,
FsrsWeightsInvalid, FsrsWeightsInvalid,
// Returned by fsrs-rs; may happen even if 1000+ reviews /// Returned by fsrs-rs; may happen even if 1000+ reviews
FsrsInsufficientData, FsrsInsufficientData,
// Generated by our backend if count < 1000 /// Generated by our backend if count < 1000
FsrsInsufficientReviews { FsrsInsufficientReviews {
count: usize, count: usize,
}, },

View file

@ -398,7 +398,7 @@ impl Collection {
}; };
let desired_retention = fsrs_enabled.then_some(config.inner.desired_retention); let desired_retention = fsrs_enabled.then_some(config.inner.desired_retention);
Ok(CardStateUpdater { Ok(CardStateUpdater {
fuzz_seed: get_fuzz_seed(&card), fuzz_seed: get_fuzz_seed(&card, false),
card, card,
deck, deck,
config, config,
@ -519,14 +519,23 @@ pub mod test_helpers {
} }
impl Card { impl Card {
pub(crate) fn get_fuzz_factor(&self) -> Option<f32> { /// If for_reschedule is true, we use card.reps - 1 to match the previous
get_fuzz_factor(get_fuzz_seed(self)) /// 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. /// Return a consistent seed for a given card at a given number of reps.
fn get_fuzz_seed(card: &Card) -> Option<u64> { /// If for_reschedule is true, we use card.reps - 1 to match the previous
get_fuzz_seed_for_id_and_reps(card.id, card.reps) /// 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. /// If in test environment, disable fuzzing.

View file

@ -95,7 +95,7 @@ impl Collection {
) )
as f32; as f32;
card.interval = with_review_fuzz( card.interval = with_review_fuzz(
card.get_fuzz_factor(), card.get_fuzz_factor(true),
interval, interval,
1, 1,
req.max_interval, req.max_interval,

View file

@ -49,7 +49,7 @@ impl Collection {
.or_not_found(card.deck_id)?; .or_not_found(card.deck_id)?;
let config = self.home_deck_config(deck.config_id(), card.original_deck_id)?; let config = self.home_deck_config(deck.config_id(), card.original_deck_id)?;
let fuzzed = with_review_fuzz( let fuzzed = with_review_fuzz(
card.get_fuzz_factor(), card.get_fuzz_factor(true),
interval as f32, interval as f32,
1, 1,
config.inner.maximum_review_interval, config.inner.maximum_review_interval,