Code cleanup

This commit is contained in:
micialware committed 2026-09-09 15:00:52 +03:00
1 parent 1ad991667b
commit f66bf69ef5
32 files changed
+234 -899

No files matched your search

+5 -3
View File
@@ -33,7 +33,9 @@ impl DeckData {
.map(|card_state| EntityHandle::from_id(card_state.word_id))
.collect();
let states = query.handles().collect::<Vec<EntityHandle<CardState>>>();
let fsrs = Fsrs(FsrsModule::new(Self::set_links(states.as_slice(), &states_repo).as_slice()));
let fsrs = Fsrs(FsrsModule::new(
Self::set_links(states.as_slice(), &states_repo).as_slice(),
));
drop(states_repo);
Self {
states,
@@ -61,7 +63,7 @@ impl DeckData {
};
self.current_word_index = Some(index);
(self.words[index].clone(), self.states[index].clone())
(self.words[index], self.states[index])
}
fn set_links<'a>(
@@ -108,7 +110,7 @@ impl DeckData {
timestamp: Utc::now(),
deck_id: self.settings.id,
word_id,
answer: status.clone(),
answer: status,
before: old_score,
after: new_score,
fsrs,
+7 -8
View File
@@ -44,9 +44,7 @@ impl SRSModule for RandomSRSModule {
fn new(set: &[&CardState]) -> Self {
let mut basket = (0..set.len()).collect::<Vec<usize>>();
basket.shuffle(&mut rand::rng());
Self{
basket,
}
Self { basket }
}
fn next(&mut self, set: &[&CardState]) -> usize {
@@ -90,16 +88,15 @@ impl SRSModule for SemiRandomSRSModule {
.expect("update weights error");
}
fn new(set: &[&CardState]) -> Self {
let weights = set
.iter()
.map(|s| (100.0 / s.calculated_score()).powf(2.0) * 2.0)
.collect::<Vec<f32>>();
Self{
Self {
generator: rng(),
last_weights: WeightedIndex::new(weights).expect("Incorrect weights update"),
history: vec![]
last_weights: WeightedIndex::new(weights).expect("Incorrect weights update"),
history: vec![],
}
}
}
@@ -233,7 +230,9 @@ impl SRSModule for FsrsModule {
updated_word.fsrs_open_day = next_day;
updated_word.fsrs_opened = updated_word.last_open.date_naive();
if (updated_word.fsrs_open_day != today && !first_time) || (first_time && status == WordOpenMode::Easy) {
if (updated_word.fsrs_open_day != today && !first_time)
|| (first_time && status == WordOpenMode::Easy)
{
info!("For today word on index {} solved", index);
self.solved.push(index);
let index = self.current_group.iter().position(|x| *x == index).unwrap();