Return worst mode
This commit is contained in:
+71
-58
@@ -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<usize>,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
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<u32>
|
||||
}
|
||||
|
||||
// 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![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user