mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00

* Pack FSRS data into card.data * Update FSRS card data when preset or weights change + Show FSRS stats in card stats * Show a warning when there's a limited review history * Add some translations; tweak UI * Fix default requested retention * Add browser columns, fix calculation of R * Property searches eg prop:d>0.1 * Integrate FSRS into reviewer * Warn about long learning steps * Hide minimum interval when FSRS is on * Don't apply interval multiplier to FSRS intervals * Expose memory state to Python * Don't set memory state on new cards * Port Jarret's new tests; add some helpers to make tests more compact https://github.com/open-spaced-repetition/fsrs-rs/pull/64 * Fix learning cards not being given memory state * Require update to v3 scheduler * Don't exclude single learning step when calculating memory state * Use relearning step when learning steps unavailable * Update docstring * fix single_card_revlog_to_items (#2656) * not need check the review_kind for unique_dates * add email address to CONTRIBUTORS * fix last first learn & keep early review * cargo fmt * cargo clippy --fix * Add Jarrett to about screen * Fix fsrs_memory_state being initialized to default in get_card() * Set initial memory state on graduate * Update to latest FSRS * Fix experiment.log being empty * Fix broken colpkg imports Introduced by "Update FSRS card data when preset or weights change" * Update memory state during (re)learning; use FSRS for graduating intervals * Reset memory state when cards are manually rescheduled as new * Add difficulty graph; hide eases when FSRS enabled * Add retrievability graph * Derive memory_state from revlog when it's missing and shouldn't be --------- Co-authored-by: Jarrett Ye <jarrett.ye@outlook.com>
80 lines
2.7 KiB
Rust
80 lines
2.7 KiB
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
use rand::prelude::*;
|
|
use rand::rngs::StdRng;
|
|
|
|
use super::CardStateUpdater;
|
|
use super::RevlogEntryPartial;
|
|
use crate::card::CardQueue;
|
|
use crate::card::CardType;
|
|
use crate::prelude::*;
|
|
use crate::scheduler::states::CardState;
|
|
use crate::scheduler::states::IntervalKind;
|
|
use crate::scheduler::states::LearnState;
|
|
use crate::scheduler::states::NewState;
|
|
|
|
impl CardStateUpdater {
|
|
pub(super) fn apply_new_state(
|
|
&mut self,
|
|
current: CardState,
|
|
next: NewState,
|
|
) -> RevlogEntryPartial {
|
|
self.card.ctype = CardType::New;
|
|
self.card.queue = CardQueue::New;
|
|
self.card.due = next.position as i32;
|
|
self.card.original_position = None;
|
|
self.card.fsrs_memory_state = None;
|
|
|
|
RevlogEntryPartial::new(current, next.into(), 0.0, self.secs_until_rollover())
|
|
}
|
|
|
|
pub(super) fn apply_learning_state(
|
|
&mut self,
|
|
current: CardState,
|
|
next: LearnState,
|
|
) -> RevlogEntryPartial {
|
|
self.card.remaining_steps = next.remaining_steps;
|
|
self.card.ctype = CardType::Learn;
|
|
if let Some(position) = current.new_position() {
|
|
self.card.original_position = Some(position)
|
|
}
|
|
self.card.fsrs_memory_state = next.fsrs_memory_state;
|
|
|
|
let interval = next
|
|
.interval_kind()
|
|
.maybe_as_days(self.secs_until_rollover());
|
|
match interval {
|
|
IntervalKind::InSecs(secs) => {
|
|
self.card.queue = CardQueue::Learn;
|
|
self.card.due = self.fuzzed_next_learning_timestamp(secs);
|
|
}
|
|
IntervalKind::InDays(days) => {
|
|
self.card.queue = CardQueue::DayLearn;
|
|
self.card.due = (self.timing.days_elapsed + days) as i32;
|
|
}
|
|
}
|
|
|
|
RevlogEntryPartial::new(current, next.into(), 0.0, self.secs_until_rollover())
|
|
}
|
|
|
|
/// Adds secs + fuzz to current time
|
|
pub(super) fn fuzzed_next_learning_timestamp(&self, secs: u32) -> i32 {
|
|
TimestampSecs::now().0 as i32 + self.with_learning_fuzz(secs) as i32
|
|
}
|
|
|
|
/// Add up to 25% increase to seconds, but no more than 5 minutes.
|
|
fn with_learning_fuzz(&self, secs: u32) -> u32 {
|
|
if let Some(seed) = self.fuzz_seed {
|
|
let mut rng = StdRng::seed_from_u64(seed);
|
|
let upper_exclusive = secs + ((secs as f32) * 0.25).min(300.0).floor() as u32;
|
|
if secs >= upper_exclusive {
|
|
secs
|
|
} else {
|
|
rng.gen_range(secs..upper_exclusive)
|
|
}
|
|
} else {
|
|
secs
|
|
}
|
|
}
|
|
}
|