diff --git a/Cargo.lock b/Cargo.lock index e043373de..aa38db293 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1794,9 +1794,9 @@ dependencies = [ [[package]] name = "fsrs" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4938928321ed55a54cd8b90f0aa9dad79ee223aed6462cc37e83eb80b8bddb5a" +checksum = "eece5d2325704da8667c3a796e64a3c0b046100ff758ba88f91d0dee80d6deb9" dependencies = [ "burn", "itertools 0.12.0", diff --git a/Cargo.toml b/Cargo.toml index a6493141b..3136684ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ git = "https://github.com/ankitects/linkcheck.git" rev = "184b2ca50ed39ca43da13f0b830a463861adb9ca" [workspace.dependencies.fsrs] -version = "0.2.0" +version = "0.3.0" # git = "https://github.com/open-spaced-repetition/fsrs-rs.git" # rev = "58ca25ed2bc4bb1dc376208bbcaed7f5a501b941" # path = "../../../fsrs-rs" diff --git a/cargo/licenses.json b/cargo/licenses.json index a99dfcf59..3fe3fb01d 100644 --- a/cargo/licenses.json +++ b/cargo/licenses.json @@ -1216,7 +1216,7 @@ }, { "name": "fsrs", - "version": "0.2.0", + "version": "0.3.0", "authors": "Open Spaced Repetition", "repository": "https://github.com/open-spaced-repetition/fsrs-rs", "license": "BSD-3-Clause", diff --git a/proto/anki/scheduler.proto b/proto/anki/scheduler.proto index c80026a87..5def20e82 100644 --- a/proto/anki/scheduler.proto +++ b/proto/anki/scheduler.proto @@ -338,6 +338,7 @@ message RepositionDefaultsResponse { message ComputeFsrsWeightsRequest { /// The search used to gather cards for training string search = 1; + repeated float current_weights = 2; } message ComputeFsrsWeightsResponse { diff --git a/rslib/src/deckconfig/update.rs b/rslib/src/deckconfig/update.rs index 401c0aa30..bc6fe87be 100644 --- a/rslib/src/deckconfig/update.rs +++ b/rslib/src/deckconfig/update.rs @@ -332,7 +332,12 @@ impl Collection { } else { config.inner.weight_search.clone() }; - match self.compute_weights(&search, idx as u32 + 1, config_len) { + match self.compute_weights( + &search, + idx as u32 + 1, + config_len, + &config.inner.fsrs_weights, + ) { Ok(weights) => { if weights.fsrs_items >= 1000 { println!("{}: {:?}", config.name, weights.weights); diff --git a/rslib/src/scheduler/fsrs/weights.rs b/rslib/src/scheduler/fsrs/weights.rs index e8e35d473..70ccd6f4c 100644 --- a/rslib/src/scheduler/fsrs/weights.rs +++ b/rslib/src/scheduler/fsrs/weights.rs @@ -35,6 +35,7 @@ impl Collection { search: &str, current_preset: u32, total_presets: u32, + current_weights: &Weights, ) -> Result { let mut anki_progress = self.new_progress_handler::(); let timing = self.timing_today()?; @@ -69,8 +70,14 @@ impl Collection { } } }); - let fsrs = FSRS::new(None)?; - let weights = fsrs.compute_weights(items, revlogs.len() < 1000, Some(progress2))?; + let fsrs = FSRS::new(Some(current_weights))?; + let mut weights = + fsrs.compute_weights(items.clone(), revlogs.len() < 1000, Some(progress2))?; + let metrics = fsrs.universal_metrics(items, &weights, |_| true)?; + if metrics.0 < metrics.1 { + weights = current_weights.to_vec(); + } + Ok(ComputeFsrsWeightsResponse { weights, fsrs_items, diff --git a/rslib/src/scheduler/service/mod.rs b/rslib/src/scheduler/service/mod.rs index cdbaecde7..6a3d43cd8 100644 --- a/rslib/src/scheduler/service/mod.rs +++ b/rslib/src/scheduler/service/mod.rs @@ -254,7 +254,7 @@ impl crate::services::SchedulerService for Collection { &mut self, input: scheduler::ComputeFsrsWeightsRequest, ) -> Result { - self.compute_weights(&input.search, 1, 1) + self.compute_weights(&input.search, 1, 1, &input.current_weights) } fn compute_optimal_retention( diff --git a/ts/deck-options/FsrsOptions.svelte b/ts/deck-options/FsrsOptions.svelte index 306502c08..ccf498e58 100644 --- a/ts/deck-options/FsrsOptions.svelte +++ b/ts/deck-options/FsrsOptions.svelte @@ -104,6 +104,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html search: $config.weightSearch ? $config.weightSearch : defaultWeightSearch, + currentWeights: $config.fsrsWeights, }); if (computeWeightsProgress) { computeWeightsProgress.current = computeWeightsProgress.total;