History page drawing
This commit is contained in:
+20
-7
@@ -13,10 +13,11 @@ use serde::{Deserialize, Serialize};
|
||||
use std::cmp::min;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use crate::data_provider::history::{push_note, HistoryItem};
|
||||
|
||||
const MAX_HISTORY_LEN: usize = 20;
|
||||
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
||||
const MAX_SCORE: i32 = 25;
|
||||
const MAX_SCORE: u8 = 25;
|
||||
const FADE_PER_DAY: f32 = 0.95;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct KanaSet {
|
||||
@@ -266,21 +267,21 @@ pub struct CardStatistics {
|
||||
pub word_id: u32,
|
||||
pub set_id: u32,
|
||||
pub last_open: DateTime<Utc>,
|
||||
pub score: i32,
|
||||
pub score: u8,
|
||||
}
|
||||
|
||||
impl CardStatistics {
|
||||
pub fn update(&mut self, status: WordOpenMode) {
|
||||
match status {
|
||||
WordOpenMode::Easy => {
|
||||
self.score = (self.calculated_score() + 5.0).round() as i32;
|
||||
self.score = (self.calculated_score() + 5.0).round() as u8;
|
||||
}
|
||||
WordOpenMode::Ok => self.score = (self.calculated_score() + 2.0).round() as i32,
|
||||
WordOpenMode::Ok => self.score = (self.calculated_score() + 2.0).round() as u8,
|
||||
WordOpenMode::Hard => {
|
||||
self.score = (self.calculated_score() * 0.75).round() as i32;
|
||||
self.score = (self.calculated_score() * 0.75).round() as u8;
|
||||
}
|
||||
WordOpenMode::None => {
|
||||
self.score = (self.calculated_score() * 0.4) as i32;
|
||||
self.score = (self.calculated_score() * 0.4) as u8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +316,7 @@ pub struct CardSet {
|
||||
current_word_index: Option<usize>,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
order_module: OrderModule,
|
||||
settings: CardSetSettings
|
||||
}
|
||||
|
||||
impl CardSet {
|
||||
@@ -364,6 +366,7 @@ impl CardSet {
|
||||
// }
|
||||
SetOrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
||||
},
|
||||
settings: settings.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +409,9 @@ impl CardSet {
|
||||
let index = self.current_word_index.unwrap();
|
||||
|
||||
let word = &mut self.set[index];
|
||||
let old_score = word.score;
|
||||
word.update(status);
|
||||
let new_score = word.score;
|
||||
|
||||
match self.order_module.clone() {
|
||||
OrderModule::SemiRandomSRS(mut module) => {
|
||||
@@ -422,7 +427,15 @@ impl CardSet {
|
||||
// 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{
|
||||
timestamp: Utc::now(),
|
||||
word_id: word.word_id,
|
||||
mode: WordOpenMode::Easy,
|
||||
before: old_score,
|
||||
after: new_score,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user