diff --git a/Cargo.lock b/Cargo.lock index 86787124a..fce546a9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,6 +131,7 @@ dependencies = [ "prost-reflect", "pulldown-cmark 0.13.0", "rand 0.9.1", + "rayon", "regex", "reqwest 0.12.20", "rusqlite", diff --git a/Cargo.toml b/Cargo.toml index 2ff29cd1a..3ef2df9bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,6 +110,7 @@ prost-types = "0.13" pulldown-cmark = "0.13.0" pyo3 = { version = "0.25.1", features = ["extension-module", "abi3", "abi3-py39"] } rand = "0.9.1" +rayon = "1.10.0" regex = "1.11.1" reqwest = { version = "0.12.20", default-features = false, features = ["json", "socks", "stream", "multipart"] } rusqlite = { version = "0.36.0", features = ["trace", "functions", "collation", "bundled"] } diff --git a/ftl/core/deck-config.ftl b/ftl/core/deck-config.ftl index 01eac3369..2ca45fcd8 100644 --- a/ftl/core/deck-config.ftl +++ b/ftl/core/deck-config.ftl @@ -505,7 +505,9 @@ deck-config-desired-retention-below-optimal = Your desired retention is below op # Description of the y axis in the FSRS simulation # diagram (Deck options -> FSRS) showing the total number of # cards that can be recalled or retrieved on a specific date. -deck-config-fsrs-simulator-experimental = FSRS simulator (experimental) +deck-config-fsrs-simulator-experimental = FSRS Simulator (Experimental) +deck-config-fsrs-simulate-desired-retention-experimental = FSRS Desired Retention Simulator (Experimental) +deck-config-fsrs-desired-retention-help-me-decide-experimental = Help Me Decide (Experimental) deck-config-additional-new-cards-to-simulate = Additional new cards to simulate deck-config-simulate = Simulate deck-config-clear-last-simulate = Clear Last Simulation @@ -515,10 +517,14 @@ deck-config-smooth-graph = Smooth graph deck-config-suspend-leeches = Suspend leeches deck-config-save-options-to-preset = Save Changes to Preset deck-config-save-options-to-preset-confirm = Overwrite the options in your current preset with the options that are currently set in the simulator? +deck-config-plotted-on-x-axis = (Plotted on the X-axis) # Radio button in the FSRS simulation diagram (Deck options -> FSRS) selecting # to show the total number of cards that can be recalled or retrieved on a # specific date. deck-config-fsrs-simulator-radio-memorized = Memorized +deck-config-fsrs-simulator-radio-ratio = Time / Memorized Ratio +# $time here is pre-formatted e.g. "10 Seconds" +deck-config-fsrs-simulator-ratio-tooltip = { $time } per memorized card ## Messages related to the FSRS scheduler’s health check. The health check determines whether the correlation between FSRS predictions and your memory is good or bad. It can be optionally triggered as part of the "Optimize" function. diff --git a/proto/anki/scheduler.proto b/proto/anki/scheduler.proto index 1294b4543..a88cd468c 100644 --- a/proto/anki/scheduler.proto +++ b/proto/anki/scheduler.proto @@ -55,6 +55,8 @@ service SchedulerService { returns (ComputeOptimalRetentionResponse); rpc SimulateFsrsReview(SimulateFsrsReviewRequest) returns (SimulateFsrsReviewResponse); + rpc SimulateFsrsWorkload(SimulateFsrsReviewRequest) + returns (SimulateFsrsWorkloadResponse); rpc EvaluateParams(EvaluateParamsRequest) returns (EvaluateParamsResponse); rpc EvaluateParamsLegacy(EvaluateParamsLegacyRequest) returns (EvaluateParamsResponse); @@ -414,6 +416,12 @@ message SimulateFsrsReviewResponse { repeated float daily_time_cost = 4; } +message SimulateFsrsWorkloadResponse { + map cost = 1; + map memorized = 2; + map review_count = 3; +} + message ComputeOptimalRetentionResponse { float optimal_retention = 1; } diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index f08be4cef..d1d55e232 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -654,6 +654,7 @@ exposed_backend_list = [ "evaluate_params_legacy", "get_optimal_retention_parameters", "simulate_fsrs_review", + "simulate_fsrs_workload", # DeckConfigService "get_ignored_before_count", "get_retention_workload", diff --git a/rslib/Cargo.toml b/rslib/Cargo.toml index a1d24cc87..9be9e8d87 100644 --- a/rslib/Cargo.toml +++ b/rslib/Cargo.toml @@ -81,6 +81,7 @@ pin-project.workspace = true prost.workspace = true pulldown-cmark.workspace = true rand.workspace = true +rayon.workspace = true regex.workspace = true reqwest.workspace = true rusqlite.workspace = true diff --git a/rslib/src/scheduler/fsrs/simulator.rs b/rslib/src/scheduler/fsrs/simulator.rs index e032ecaf3..3b173939b 100644 --- a/rslib/src/scheduler/fsrs/simulator.rs +++ b/rslib/src/scheduler/fsrs/simulator.rs @@ -1,11 +1,13 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +use std::collections::HashMap; use std::sync::Arc; use anki_proto::deck_config::deck_config::config::ReviewCardOrder; use anki_proto::deck_config::deck_config::config::ReviewCardOrder::*; use anki_proto::scheduler::SimulateFsrsReviewRequest; use anki_proto::scheduler::SimulateFsrsReviewResponse; +use anki_proto::scheduler::SimulateFsrsWorkloadResponse; use fsrs::simulate; use fsrs::PostSchedulingFn; use fsrs::ReviewPriorityFn; @@ -14,6 +16,8 @@ use fsrs::FSRS; use itertools::Itertools; use rand::rngs::StdRng; use rand::Rng; +use rayon::iter::IntoParallelIterator; +use rayon::iter::ParallelIterator; use crate::card::CardQueue; use crate::card::CardType; @@ -267,6 +271,38 @@ impl Collection { daily_time_cost: result.cost_per_day, }) } + + pub fn simulate_workload( + &mut self, + req: SimulateFsrsReviewRequest, + ) -> Result { + let (config, cards) = self.simulate_request_to_config(&req)?; + let dr_workload = (70u32..=99u32) + .into_par_iter() + .map(|dr| { + let result = simulate( + &config, + &req.params, + dr as f32 / 100., + None, + Some(cards.clone()), + )?; + Ok(( + dr, + ( + *result.memorized_cnt_per_day.last().unwrap_or(&0.), + result.cost_per_day.iter().sum::(), + result.review_cnt_per_day.iter().sum::() as u32, + ), + )) + }) + .collect::>>()?; + Ok(SimulateFsrsWorkloadResponse { + memorized: dr_workload.iter().map(|(k, v)| (*k, v.0)).collect(), + cost: dr_workload.iter().map(|(k, v)| (*k, v.1)).collect(), + review_count: dr_workload.iter().map(|(k, v)| (*k, v.2)).collect(), + }) + } } impl Card { diff --git a/rslib/src/scheduler/service/mod.rs b/rslib/src/scheduler/service/mod.rs index 43d694e4f..9f42a79f7 100644 --- a/rslib/src/scheduler/service/mod.rs +++ b/rslib/src/scheduler/service/mod.rs @@ -16,6 +16,7 @@ use anki_proto::scheduler::FuzzDeltaResponse; use anki_proto::scheduler::GetOptimalRetentionParametersResponse; use anki_proto::scheduler::SimulateFsrsReviewRequest; use anki_proto::scheduler::SimulateFsrsReviewResponse; +use anki_proto::scheduler::SimulateFsrsWorkloadResponse; use fsrs::ComputeParametersInput; use fsrs::FSRSItem; use fsrs::FSRSReview; @@ -283,6 +284,13 @@ impl crate::services::SchedulerService for Collection { self.simulate_review(input) } + fn simulate_fsrs_workload( + &mut self, + input: SimulateFsrsReviewRequest, + ) -> Result { + self.simulate_workload(input) + } + fn compute_optimal_retention( &mut self, input: SimulateFsrsReviewRequest, diff --git a/rslib/src/timestamp.rs b/rslib/src/timestamp.rs index a020d706d..8a6ac4eb7 100644 --- a/rslib/src/timestamp.rs +++ b/rslib/src/timestamp.rs @@ -93,6 +93,10 @@ impl TimestampMillis { pub fn adding_secs(self, secs: i64) -> Self { Self(self.0 + secs * 1000) } + + pub fn elapsed_millis(self) -> u64 { + (Self::now().0 - self.0).max(0) as u64 + } } fn elapsed() -> time::Duration { diff --git a/ts/routes/deck-options/FsrsOptions.svelte b/ts/routes/deck-options/FsrsOptions.svelte index 9b7bb218e..526c3aa99 100644 --- a/ts/routes/deck-options/FsrsOptions.svelte +++ b/ts/routes/deck-options/FsrsOptions.svelte @@ -325,6 +325,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } let simulatorModal: Modal; + let workloadModal: Modal; @@ -349,6 +350,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + + @@ -444,6 +455,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html {onPresetChange} /> + +