From 0d672a8016bf6ac569d7eb076f0a8f3af1b849d5 Mon Sep 17 00:00:00 2001 From: Jarrett Ye Date: Sun, 29 Sep 2024 10:31:58 +0800 Subject: [PATCH] Fix/filter rating_stability to match rating_count keys Prevents processing non-existent rating data, improving data consistency and avoiding potential errors when working with unmatched ratings. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/pre_training.rs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 263317a4..80fa2fd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1077,7 +1077,7 @@ dependencies = [ [[package]] name = "fsrs" -version = "1.2.3" +version = "1.2.4" dependencies = [ "burn", "chrono", diff --git a/Cargo.toml b/Cargo.toml index d193930f..b7ef898c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fsrs" -version = "1.2.3" +version = "1.2.4" authors = ["Open Spaced Repetition"] categories = ["algorithms", "science"] edition = "2021" diff --git a/src/pre_training.rs b/src/pre_training.rs index c5e32d30..8dc78b9e 100644 --- a/src/pre_training.rs +++ b/src/pre_training.rs @@ -168,6 +168,7 @@ pub(crate) fn smooth_and_fill( rating_stability: &mut HashMap, rating_count: &HashMap, ) -> Result<[f32; 4]> { + rating_stability.retain(|&key, _| rating_count.contains_key(&key)); for (small_rating, big_rating) in [(1, 2), (2, 3), (3, 4), (1, 3), (2, 4), (1, 4)] { if let (Some(&small_value), Some(&big_value)) = ( rating_stability.get(&small_rating),