Adding words by parts
This commit is contained in:
+46
-36
@@ -1,14 +1,13 @@
|
||||
use crate::data_provider::card_stats::{
|
||||
delete_stat, load_stats_of_set, update_stat_score,
|
||||
};
|
||||
use crate::data_provider::history::{push_note, HistoryItem};
|
||||
use crate::AppState;
|
||||
use crate::data_provider::card_stats::{delete_stat, load_stats_of_set, update_stat_score};
|
||||
use crate::data_provider::history::{HistoryItem, push_note};
|
||||
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;
|
||||
use rayon::iter::IndexedParallelIterator;
|
||||
use rayon::iter::IntoParallelRefIterator;
|
||||
use rayon::iter::ParallelIterator;
|
||||
use rhai::{Engine, Scope};
|
||||
@@ -316,7 +315,12 @@ impl CardSet {
|
||||
let state_locked = state.lock().unwrap();
|
||||
|
||||
let mut current_set = load_stats_of_set(settings, &state_locked.connection);
|
||||
let last_list = settings.get_word_list(&state_locked);
|
||||
let last_list: Vec<_> = settings
|
||||
.get_word_list(&state_locked)
|
||||
.iter()
|
||||
.map(|w| state_locked.dictionary.get(*w).unwrap())
|
||||
.cloned()
|
||||
.collect();
|
||||
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<u32>>();
|
||||
|
||||
// let new_stats: &mut Vec<CardStatistics> = &mut last_list
|
||||
@@ -452,9 +456,9 @@ pub enum OrderMode {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
pub enum AppendMode{
|
||||
pub enum AppendMode {
|
||||
Full,
|
||||
Manual
|
||||
Manual,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -637,7 +641,7 @@ pub struct CardSetSettings {
|
||||
pub count: Option<usize>,
|
||||
pub worst_words_list: Option<Vec<WordData>>,
|
||||
pub open_mode: OrderMode,
|
||||
pub append_mode: AppendMode
|
||||
pub append_mode: AppendMode,
|
||||
}
|
||||
|
||||
impl CardSetSettings {
|
||||
@@ -651,7 +655,7 @@ impl CardSetSettings {
|
||||
count: None,
|
||||
worst_words_list: None,
|
||||
open_mode: OrderMode::Default,
|
||||
append_mode: AppendMode::Full
|
||||
append_mode: AppendMode::Full,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,7 +665,7 @@ impl CardSetSettings {
|
||||
ast.is_ok()
|
||||
}
|
||||
|
||||
pub fn get_word_list(&self, state: &AppState) -> Vec<WordData> {
|
||||
pub fn get_word_list(&self, state: &AppState) -> Vec<usize> {
|
||||
let time = Instant::now();
|
||||
let mut list = vec![];
|
||||
let engine = Engine::new();
|
||||
@@ -675,31 +679,37 @@ impl CardSetSettings {
|
||||
|
||||
let groups = &state.word_groups;
|
||||
|
||||
list = state.dictionary.par_iter().filter(|word| {
|
||||
let mut more = rhai::Map::new();
|
||||
for iced in &word.additional {
|
||||
more.insert(iced.0.clone().into(), iced.1.clone().into());
|
||||
}
|
||||
let mut scope = Scope::new();
|
||||
scope
|
||||
.push_constant("id", word.id)
|
||||
.push_constant("key", word.key.clone())
|
||||
.push_constant("value", word.value.clone())
|
||||
.push_constant("tags", word.tags.clone())
|
||||
.push_constant("more", more)
|
||||
.push_constant(
|
||||
"group",
|
||||
groups
|
||||
.iter()
|
||||
.find(|g| g.id == word.group_id)
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.name,
|
||||
);
|
||||
list = state
|
||||
.dictionary
|
||||
.par_iter()
|
||||
.enumerate()
|
||||
.filter(|(_, word)| {
|
||||
let mut more = rhai::Map::new();
|
||||
for iced in &word.additional {
|
||||
more.insert(iced.0.clone().into(), iced.1.clone().into());
|
||||
}
|
||||
let mut scope = Scope::new();
|
||||
scope
|
||||
.push_constant("id", word.id)
|
||||
.push_constant("key", word.key.clone())
|
||||
.push_constant("value", word.value.clone())
|
||||
.push_constant("tags", word.tags.clone())
|
||||
.push_constant("more", more)
|
||||
.push_constant(
|
||||
"group",
|
||||
groups
|
||||
.iter()
|
||||
.find(|g| g.id == word.group_id)
|
||||
.cloned()
|
||||
.unwrap()
|
||||
.name,
|
||||
);
|
||||
|
||||
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||
result.is_ok() && result.unwrap()
|
||||
}).cloned().collect();
|
||||
let result = engine.eval_ast_with_scope::<bool>(&mut scope, &ast);
|
||||
result.is_ok() && result.unwrap()
|
||||
})
|
||||
.map(|(index, _)| index)
|
||||
.collect();
|
||||
|
||||
println!("Collecting available words is {:?}", time.elapsed());
|
||||
|
||||
@@ -728,7 +738,7 @@ impl CardSetSettings {
|
||||
.dictionary
|
||||
.binary_search_by_key(&stat.word_id, |x| x.id)
|
||||
.unwrap()]
|
||||
.clone()
|
||||
.clone()
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user