From 2fffe4b7bace404b55ac291fdb30bd4cec837f78 Mon Sep 17 00:00:00 2001 From: Jarrett Ye Date: Tue, 30 Jan 2024 14:27:12 +0800 Subject: [PATCH] update FSRS to v0.2.0 (#2977) * update FSRS to v0.2.0 * update comments * ./ninja fix:minilints * 1000 -> 400 in translation (dae) --- Cargo.lock | 5 +++-- Cargo.toml | 5 +++-- cargo/licenses.json | 8 ++++---- ftl/core/deck-config.ftl | 4 ++-- rslib/src/error/mod.rs | 6 +++--- rslib/src/scheduler/fsrs/weights.rs | 10 +++++----- rslib/src/scheduler/service/mod.rs | 1 + ts/deck-options/FsrsOptions.svelte | 4 ++-- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd089f489..e043373de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1794,8 +1794,9 @@ dependencies = [ [[package]] name = "fsrs" -version = "0.1.0" -source = "git+https://github.com/open-spaced-repetition/fsrs-rs.git?rev=58ca25ed2bc4bb1dc376208bbcaed7f5a501b941#58ca25ed2bc4bb1dc376208bbcaed7f5a501b941" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4938928321ed55a54cd8b90f0aa9dad79ee223aed6462cc37e83eb80b8bddb5a" dependencies = [ "burn", "itertools 0.12.0", diff --git a/Cargo.toml b/Cargo.toml index af75a64ef..a6493141b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,8 +35,9 @@ git = "https://github.com/ankitects/linkcheck.git" rev = "184b2ca50ed39ca43da13f0b830a463861adb9ca" [workspace.dependencies.fsrs] -git = "https://github.com/open-spaced-repetition/fsrs-rs.git" -rev = "58ca25ed2bc4bb1dc376208bbcaed7f5a501b941" +version = "0.2.0" +# git = "https://github.com/open-spaced-repetition/fsrs-rs.git" +# rev = "58ca25ed2bc4bb1dc376208bbcaed7f5a501b941" # path = "../../../fsrs-rs" [workspace.dependencies] diff --git a/cargo/licenses.json b/cargo/licenses.json index a4e96afc7..a99dfcf59 100644 --- a/cargo/licenses.json +++ b/cargo/licenses.json @@ -1216,12 +1216,12 @@ }, { "name": "fsrs", - "version": "0.1.0", - "authors": null, - "repository": null, + "version": "0.2.0", + "authors": "Open Spaced Repetition", + "repository": "https://github.com/open-spaced-repetition/fsrs-rs", "license": "BSD-3-Clause", "license_file": null, - "description": null + "description": "FSRS for Rust, including Optimizer and Scheduler" }, { "name": "futf", diff --git a/ftl/core/deck-config.ftl b/ftl/core/deck-config.ftl index 340ff7c19..e0b76d56a 100644 --- a/ftl/core/deck-config.ftl +++ b/ftl/core/deck-config.ftl @@ -335,11 +335,11 @@ deck-config-invalid-weights = Parameters must be either left blank to use the de deck-config-not-enough-history = Insufficient review history to perform this operation. deck-config-unable-to-determine-desired-retention = Unable to determine an optimal retention. -deck-config-must-have-1000-reviews = +deck-config-must-have-400-reviews = { $count -> [one] Only { $count } review was found. *[other] Only { $count } reviews were found. - } You must have at least 1000 reviews for this operation. + } You must have at least 400 reviews for this operation. # Numbers that control how aggressively the FSRS algorithm schedules cards deck-config-weights = FSRS parameters deck-config-compute-optimal-weights = Optimize FSRS parameters diff --git a/rslib/src/error/mod.rs b/rslib/src/error/mod.rs index cde7a4304..40af3d3a8 100644 --- a/rslib/src/error/mod.rs +++ b/rslib/src/error/mod.rs @@ -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 400+ reviews FsrsInsufficientData, - /// Generated by our backend if count < 1000 + /// Generated by our backend if count < 400 FsrsInsufficientReviews { count: usize, }, @@ -175,7 +175,7 @@ impl AnkiError { AnkiError::NotFound { source } => source.message(tr), AnkiError::FsrsInsufficientData => tr.deck_config_not_enough_history().into(), AnkiError::FsrsInsufficientReviews { count } => { - tr.deck_config_must_have_1000_reviews(*count).into() + tr.deck_config_must_have_400_reviews(*count).into() } AnkiError::FsrsWeightsInvalid => tr.deck_config_invalid_weights().into(), AnkiError::SchedulerUpgradeRequired => { diff --git a/rslib/src/scheduler/fsrs/weights.rs b/rslib/src/scheduler/fsrs/weights.rs index e8049225b..e8e35d473 100644 --- a/rslib/src/scheduler/fsrs/weights.rs +++ b/rslib/src/scheduler/fsrs/weights.rs @@ -27,7 +27,7 @@ use crate::search::SortMode; pub(crate) type Weights = Vec; impl Collection { - /// Note this does not return an error if there are less than 1000 items - + /// Note this does not return an error if there are less than 400 items - /// the caller should instead check the fsrs_items count in the return /// value. pub fn compute_weights( @@ -39,12 +39,12 @@ impl Collection { let mut anki_progress = self.new_progress_handler::(); let timing = self.timing_today()?; let revlogs = self.revlog_for_srs(search)?; - if revlogs.len() < 1000 { + if revlogs.len() < 400 { return Err(AnkiError::FsrsInsufficientReviews { count: revlogs.len(), }); } - let items = fsrs_items_for_training(revlogs, timing.next_day_at); + let items = fsrs_items_for_training(revlogs.clone(), timing.next_day_at); let fsrs_items = items.len() as u32; anki_progress.update(false, |p| { p.fsrs_items = fsrs_items; @@ -70,7 +70,7 @@ impl Collection { } }); let fsrs = FSRS::new(None)?; - let weights = fsrs.compute_weights(items, Some(progress2))?; + let weights = fsrs.compute_weights(items, revlogs.len() < 1000, Some(progress2))?; Ok(ComputeFsrsWeightsResponse { weights, fsrs_items, @@ -123,7 +123,7 @@ impl Collection { .col .storage .get_revlog_entries_for_searched_cards_in_card_order()?; - if revlogs.len() < 1000 { + if revlogs.len() < 400 { return Err(AnkiError::FsrsInsufficientReviews { count: revlogs.len(), }); diff --git a/rslib/src/scheduler/service/mod.rs b/rslib/src/scheduler/service/mod.rs index 77e71f4a8..cdbaecde7 100644 --- a/rslib/src/scheduler/service/mod.rs +++ b/rslib/src/scheduler/service/mod.rs @@ -307,6 +307,7 @@ impl crate::services::BackendSchedulerService for Backend { let fsrs_items = req.items.len() as u32; let weights = fsrs.compute_weights( req.items.into_iter().map(fsrs_item_proto_to_fsrs).collect(), + false, None, )?; Ok(ComputeFsrsWeightsResponse { diff --git a/ts/deck-options/FsrsOptions.svelte b/ts/deck-options/FsrsOptions.svelte index 797542a99..306502c08 100644 --- a/ts/deck-options/FsrsOptions.svelte +++ b/ts/deck-options/FsrsOptions.svelte @@ -108,9 +108,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html if (computeWeightsProgress) { computeWeightsProgress.current = computeWeightsProgress.total; } - if (resp.fsrsItems < 1000) { + if (resp.fsrsItems < 400) { alert( - tr.deckConfigMustHave1000Reviews({ count: resp.fsrsItems }), + tr.deckConfigMustHave400Reviews({ count: resp.fsrsItems }), ); } else { $config.fsrsWeights = resp.weights;