Final code cleanup
This commit is contained in:
+45
-47
@@ -1,9 +1,10 @@
|
||||
use crate::AppState;
|
||||
use crate::data_provider::card_stats::{delete_stat, load_stats_of_deck, update_stat_score};
|
||||
use crate::data_provider::history::{HistoryItem, push_note};
|
||||
use crate::data_provider::history::{push_note, HistoryItem};
|
||||
use crate::AppState;
|
||||
use chrono::{DateTime, Utc};
|
||||
use rand::distr::Distribution;
|
||||
use parking_lot::Mutex;
|
||||
use rand::distr::weighted::WeightedIndex;
|
||||
use rand::distr::Distribution;
|
||||
use rand::prelude::SliceRandom;
|
||||
use rand::rng;
|
||||
use rand::rngs::ThreadRng;
|
||||
@@ -11,15 +12,14 @@ use rayon::iter::IndexedParallelIterator;
|
||||
use rayon::iter::IntoParallelRefIterator;
|
||||
use rayon::iter::ParallelIterator;
|
||||
use rhai::{Engine, Scope};
|
||||
use rusqlite::ToSql;
|
||||
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
|
||||
use rusqlite::ToSql;
|
||||
use std::cmp::PartialEq;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use parking_lot::Mutex;
|
||||
use std::time::Instant;
|
||||
|
||||
const MAX_HISTORY_LEN: usize = 20;
|
||||
@@ -668,49 +668,47 @@ impl DeckSettings {
|
||||
let engine = Engine::new();
|
||||
|
||||
let ast = engine.compile(&self.filter);
|
||||
if ast.is_err() {
|
||||
return list;
|
||||
if let Ok(ast) = ast {
|
||||
let groups = &state.word_groups;
|
||||
|
||||
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.0)
|
||||
.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()
|
||||
})
|
||||
.map(|(index, _)| index)
|
||||
.collect();
|
||||
|
||||
println!("Collecting available words is {:?}", time.elapsed());
|
||||
|
||||
list
|
||||
} else {
|
||||
list
|
||||
}
|
||||
|
||||
let ast = ast.unwrap();
|
||||
|
||||
let groups = &state.word_groups;
|
||||
|
||||
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.0)
|
||||
.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()
|
||||
})
|
||||
.map(|(index, _)| index)
|
||||
.collect();
|
||||
|
||||
println!("Collecting available words is {:?}", time.elapsed());
|
||||
|
||||
list
|
||||
}
|
||||
pub fn require_speech(&self) -> bool {
|
||||
self.forward == "speech" || self.backward == "speech"
|
||||
|
||||
@@ -56,6 +56,7 @@ fn main() -> iced::Result {
|
||||
.run()
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
fn window_settings() -> window::Settings {
|
||||
let mut settings = window::Settings {
|
||||
position: Position::Centered,
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ impl ScreenState {
|
||||
Ok(v) => v,
|
||||
};
|
||||
|
||||
let id: Id = history_file_name[4..history_file_name.len() - 12]
|
||||
let id = history_file_name[4..history_file_name.len() - 12]
|
||||
.parse::<Id>()
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user