Return worst mode
This commit is contained in:
+66
-53
@@ -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::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 chrono::{DateTime, Utc};
|
||||||
use rand::distr::weighted::WeightedIndex;
|
|
||||||
use rand::distr::Distribution;
|
use rand::distr::Distribution;
|
||||||
|
use rand::distr::weighted::WeightedIndex;
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
use rand::rng;
|
use rand::rng;
|
||||||
use rand::rngs::ThreadRng;
|
use rand::rngs::ThreadRng;
|
||||||
@@ -315,7 +317,7 @@ pub struct CardSet {
|
|||||||
current_word_index: Option<usize>,
|
current_word_index: Option<usize>,
|
||||||
state: Arc<Mutex<AppState>>,
|
state: Arc<Mutex<AppState>>,
|
||||||
order_module: OrderModule,
|
order_module: OrderModule,
|
||||||
settings: CardSetSettings
|
settings: CardSetSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CardSet {
|
impl CardSet {
|
||||||
@@ -337,7 +339,8 @@ impl CardSet {
|
|||||||
last_open: Utc::now(),
|
last_open: Utc::now(),
|
||||||
score: 1,
|
score: 1,
|
||||||
set_id: settings.id.clone(),
|
set_id: settings.id.clone(),
|
||||||
}).collect();
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
let time = Instant::now();
|
let time = Instant::now();
|
||||||
|
|
||||||
@@ -346,7 +349,11 @@ impl CardSet {
|
|||||||
current_set.append(new_stats);
|
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;
|
let mut index = 0;
|
||||||
for stat in current_set.clone() {
|
for stat in current_set.clone() {
|
||||||
if !word_ids.contains(&stat.word_id) {
|
if !word_ids.contains(&stat.word_id) {
|
||||||
@@ -364,9 +371,9 @@ impl CardSet {
|
|||||||
state: state_for,
|
state: state_for,
|
||||||
order_module: match settings.open_mode {
|
order_module: match settings.open_mode {
|
||||||
SetOrderMode::Default => OrderModule::SemiRandomSRS(SemiRandomSRSModule::new()),
|
SetOrderMode::Default => OrderModule::SemiRandomSRS(SemiRandomSRSModule::new()),
|
||||||
// SetOrderMode::TrainWorstFirst => {
|
SetOrderMode::TrainWorstFirst => {
|
||||||
// OrderModule::WorstWordsSRS(WorstWordsSRSModule::new())
|
OrderModule::WorstWordsSRS(WorstWordsSRSModule::new())
|
||||||
// }
|
}
|
||||||
SetOrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
SetOrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
||||||
},
|
},
|
||||||
settings: settings.clone(),
|
settings: settings.clone(),
|
||||||
@@ -391,14 +398,14 @@ impl CardSet {
|
|||||||
self.order_module = OrderModule::RandomSRS(module);
|
self.order_module = OrderModule::RandomSRS(module);
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
// OrderModule::WorstWordsSRS(mut module) => {
|
OrderModule::WorstWordsSRS(mut module) => {
|
||||||
// if module.initializated == false {
|
if module.initialized == false {
|
||||||
// module.init(self)
|
module.init(self)
|
||||||
// }
|
}
|
||||||
// let index = module.next(self);
|
let index = module.next(self);
|
||||||
// self.order_module = OrderModule::WorstWordsSRS(module);
|
self.order_module = OrderModule::WorstWordsSRS(module);
|
||||||
// index
|
index
|
||||||
// }
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.current_word_index = Some(index);
|
self.current_word_index = Some(index);
|
||||||
@@ -425,20 +432,22 @@ impl CardSet {
|
|||||||
module.open(status, index, word.clone());
|
module.open(status, index, word.clone());
|
||||||
self.order_module = OrderModule::RandomSRS(module);
|
self.order_module = OrderModule::RandomSRS(module);
|
||||||
}
|
}
|
||||||
// OrderModule::WorstWordsSRS(mut module) => {
|
OrderModule::WorstWordsSRS(mut module) => {
|
||||||
// module.open(status, index, word.clone());
|
module.open(status, index, word.clone());
|
||||||
// self.order_module = OrderModule::WorstWordsSRS(module);
|
self.order_module = OrderModule::WorstWordsSRS(module);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
update_stat_score(word, &self.state.lock().unwrap().connection);
|
update_stat_score(word, &self.state.lock().unwrap().connection);
|
||||||
push_note(self.settings.id, HistoryItem{
|
push_note(
|
||||||
|
self.settings.id,
|
||||||
|
HistoryItem {
|
||||||
timestamp: Utc::now(),
|
timestamp: Utc::now(),
|
||||||
word_id: word.word_id,
|
word_id: word.word_id,
|
||||||
mode: WordOpenMode::Easy,
|
mode: WordOpenMode::Easy,
|
||||||
before: old_score,
|
before: old_score,
|
||||||
after: new_score,
|
after: new_score,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
@@ -449,7 +458,7 @@ impl CardSet {
|
|||||||
#[derive(Clone, PartialEq, Copy, Eq)]
|
#[derive(Clone, PartialEq, Copy, Eq)]
|
||||||
pub enum SetOrderMode {
|
pub enum SetOrderMode {
|
||||||
Default,
|
Default,
|
||||||
// TrainWorstFirst,
|
TrainWorstFirst,
|
||||||
FullRandom,
|
FullRandom,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,7 +466,7 @@ pub enum SetOrderMode {
|
|||||||
enum OrderModule {
|
enum OrderModule {
|
||||||
SemiRandomSRS(SemiRandomSRSModule),
|
SemiRandomSRS(SemiRandomSRSModule),
|
||||||
RandomSRS(RandomSRSModule),
|
RandomSRS(RandomSRSModule),
|
||||||
// WorstWordsSRS(WorstWordsSRSModule),
|
WorstWordsSRS(WorstWordsSRSModule),
|
||||||
}
|
}
|
||||||
|
|
||||||
trait SRSModule {
|
trait SRSModule {
|
||||||
@@ -474,7 +483,7 @@ struct RandomSRSModule {
|
|||||||
|
|
||||||
impl RandomSRSModule {
|
impl RandomSRSModule {
|
||||||
fn new() -> RandomSRSModule {
|
fn new() -> RandomSRSModule {
|
||||||
Self{
|
Self {
|
||||||
basket: vec![],
|
basket: vec![],
|
||||||
initialized: false,
|
initialized: false,
|
||||||
}
|
}
|
||||||
@@ -562,29 +571,33 @@ impl SemiRandomSRSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Clone)]
|
#[derive(Clone)]
|
||||||
// struct WorstWordsSRSModule {
|
struct WorstWordsSRSModule {
|
||||||
// initializated: bool,
|
initialized: bool,
|
||||||
// }
|
rounds: u8,
|
||||||
|
pool: Vec<u32>
|
||||||
|
}
|
||||||
|
|
||||||
// impl SRSModule for WorstWordsSRSModule {
|
impl SRSModule for WorstWordsSRSModule {
|
||||||
// fn next(&mut self, _: &mut CardSet) -> usize {
|
fn next(&mut self, _: &mut CardSet) -> usize {
|
||||||
// todo!()
|
todo!()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {
|
fn open(&mut self, _: WordOpenMode, _: usize, _: CardStatistics) {
|
||||||
// todo!()
|
todo!()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// fn init(&mut self, _: &mut CardSet) {
|
fn init(&mut self, _: &mut CardSet) {
|
||||||
// todo!()
|
self.initialized = true;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// impl WorstWordsSRSModule {
|
impl WorstWordsSRSModule {
|
||||||
// fn new() -> WorstWordsSRSModule {
|
fn new() -> WorstWordsSRSModule {
|
||||||
// WorstWordsSRSModule {
|
WorstWordsSRSModule {
|
||||||
// initializated: false,
|
initialized: false,
|
||||||
// }
|
rounds: 0,
|
||||||
// }
|
pool: vec![],
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -202,7 +202,7 @@ impl RepetitionsState {
|
|||||||
column![
|
column![
|
||||||
text!("Худшие слова"),
|
text!("Худшие слова"),
|
||||||
container(scrollable(self.worst_words_list(&set)).height(200)).style(bordered_box),
|
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)
|
radio("Полностью случайно", SetOrderMode::FullRandom, Some(set.open_mode), RepetitionsMessage::SetOpenMode)
|
||||||
]
|
]
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
|
|||||||
Reference in New Issue
Block a user