From 432c890166aa52aab1d065977945a7eb47909baf Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Wed, 29 Jul 2026 14:24:40 +0300 Subject: [PATCH] Return worst mode --- src/lang.rs | 129 +++++++++++++++++++++++++-------------------- src/repetitions.rs | 2 +- 2 files changed, 72 insertions(+), 59 deletions(-) diff --git a/src/lang.rs b/src/lang.rs index b9734c6..861e10a 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -1,10 +1,12 @@ -use crate::data_provider::card_stats::{add_stat_list, delete_stat, load_stats_of_set, update_stat_score}; -use crate::data_provider::history::{push_note, HistoryItem}; -use crate::repetitions::CardSetSettings; use crate::AppState; +use crate::data_provider::card_stats::{ + add_stat_list, delete_stat, load_stats_of_set, update_stat_score, +}; +use crate::data_provider::history::{HistoryItem, push_note}; +use crate::repetitions::CardSetSettings; use chrono::{DateTime, Utc}; -use rand::distr::weighted::WeightedIndex; use rand::distr::Distribution; +use rand::distr::weighted::WeightedIndex; use rand::prelude::SliceRandom; use rand::rng; use rand::rngs::ThreadRng; @@ -315,7 +317,7 @@ pub struct CardSet { current_word_index: Option, state: Arc>, order_module: OrderModule, - settings: CardSetSettings + settings: CardSetSettings, } impl CardSet { @@ -337,7 +339,8 @@ impl CardSet { last_open: Utc::now(), score: 1, set_id: settings.id.clone(), - }).collect(); + }) + .collect(); let time = Instant::now(); @@ -346,7 +349,11 @@ impl CardSet { current_set.append(new_stats); } - println!("Added {} stats: {}", new_stats.len(), time.elapsed().as_millis()); + println!( + "Added {} stats: {}", + new_stats.len(), + time.elapsed().as_millis() + ); let mut index = 0; for stat in current_set.clone() { if !word_ids.contains(&stat.word_id) { @@ -364,9 +371,9 @@ impl CardSet { state: state_for, order_module: match settings.open_mode { SetOrderMode::Default => OrderModule::SemiRandomSRS(SemiRandomSRSModule::new()), - // SetOrderMode::TrainWorstFirst => { - // OrderModule::WorstWordsSRS(WorstWordsSRSModule::new()) - // } + SetOrderMode::TrainWorstFirst => { + OrderModule::WorstWordsSRS(WorstWordsSRSModule::new()) + } SetOrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()), }, settings: settings.clone(), @@ -391,14 +398,14 @@ impl CardSet { self.order_module = OrderModule::RandomSRS(module); index } - // OrderModule::WorstWordsSRS(mut module) => { - // if module.initializated == false { - // module.init(self) - // } - // let index = module.next(self); - // self.order_module = OrderModule::WorstWordsSRS(module); - // index - // } + OrderModule::WorstWordsSRS(mut module) => { + if module.initialized == false { + module.init(self) + } + let index = module.next(self); + self.order_module = OrderModule::WorstWordsSRS(module); + index + } }; self.current_word_index = Some(index); @@ -425,20 +432,22 @@ impl CardSet { module.open(status, index, word.clone()); self.order_module = OrderModule::RandomSRS(module); } - // OrderModule::WorstWordsSRS(mut module) => { - // module.open(status, index, word.clone()); - // self.order_module = OrderModule::WorstWordsSRS(module); - // } + OrderModule::WorstWordsSRS(mut module) => { + module.open(status, index, word.clone()); + self.order_module = OrderModule::WorstWordsSRS(module); + } } update_stat_score(word, &self.state.lock().unwrap().connection); - push_note(self.settings.id, HistoryItem{ - timestamp: Utc::now(), - word_id: word.word_id, - mode: WordOpenMode::Easy, - before: old_score, - after: new_score, - }) - + push_note( + self.settings.id, + HistoryItem { + timestamp: Utc::now(), + word_id: word.word_id, + mode: WordOpenMode::Easy, + before: old_score, + after: new_score, + }, + ) } pub fn len(&self) -> usize { @@ -449,7 +458,7 @@ impl CardSet { #[derive(Clone, PartialEq, Copy, Eq)] pub enum SetOrderMode { Default, - // TrainWorstFirst, + TrainWorstFirst, FullRandom, } @@ -457,7 +466,7 @@ pub enum SetOrderMode { enum OrderModule { SemiRandomSRS(SemiRandomSRSModule), RandomSRS(RandomSRSModule), - // WorstWordsSRS(WorstWordsSRSModule), + WorstWordsSRS(WorstWordsSRSModule), } trait SRSModule { @@ -474,7 +483,7 @@ struct RandomSRSModule { impl RandomSRSModule { fn new() -> RandomSRSModule { - Self{ + Self { basket: vec![], initialized: false, } @@ -562,29 +571,33 @@ impl SemiRandomSRSModule { } } -// #[derive(Clone)] -// struct WorstWordsSRSModule { -// initializated: bool, -// } +#[derive(Clone)] +struct WorstWordsSRSModule { + initialized: bool, + rounds: u8, + pool: Vec +} -// impl SRSModule for WorstWordsSRSModule { -// fn next(&mut self, _: &mut CardSet) -> usize { -// todo!() -// } -// -// fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) { -// todo!() -// } -// -// fn init(&mut self, _: &mut CardSet) { -// todo!() -// } -// } -// -// impl WorstWordsSRSModule { -// fn new() -> WorstWordsSRSModule { -// WorstWordsSRSModule { -// initializated: false, -// } -// } -// } +impl SRSModule for WorstWordsSRSModule { + fn next(&mut self, _: &mut CardSet) -> usize { + todo!() + } + + fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) { + todo!() + } + + fn init(&mut self, _: &mut CardSet) { + self.initialized = true; + } +} + +impl WorstWordsSRSModule { + fn new() -> WorstWordsSRSModule { + WorstWordsSRSModule { + initialized: false, + rounds: 0, + pool: vec![], + } + } +} diff --git a/src/repetitions.rs b/src/repetitions.rs index 2450e65..4cc268e 100644 --- a/src/repetitions.rs +++ b/src/repetitions.rs @@ -202,7 +202,7 @@ impl RepetitionsState { column![ text!("Худшие слова"), container(scrollable(self.worst_words_list(&set)).height(200)).style(bordered_box), - // radio("Начать с плохих слов", SetOrderMode::TrainWorstFirst, Some(set.open_mode), RepetitionsMessage::SetOpenMode), + radio("Начать с плохих слов", SetOrderMode::TrainWorstFirst, Some(set.open_mode), RepetitionsMessage::SetOpenMode), radio("Полностью случайно", SetOrderMode::FullRandom, Some(set.open_mode), RepetitionsMessage::SetOpenMode) ] .spacing(DEFAULT_SPACING)