Fixing bugs
This commit is contained in:
@@ -9,6 +9,7 @@ pub fn create_db() {
|
|||||||
if !db_file.exists() {
|
if !db_file.exists() {
|
||||||
std::fs::File::create(&db_file).unwrap();
|
std::fs::File::create(&db_file).unwrap();
|
||||||
let connection = Connection::open(&db_file).unwrap();
|
let connection = Connection::open(&db_file).unwrap();
|
||||||
|
connection.execute("PRAGMA foreign_keys = ON;", []).unwrap();
|
||||||
create_words_table(&connection);
|
create_words_table(&connection);
|
||||||
create_card_stat_table(&connection);
|
create_card_stat_table(&connection);
|
||||||
create_card_set_table(&connection);
|
create_card_set_table(&connection);
|
||||||
@@ -120,7 +121,7 @@ fn create_card_stat_table(conn: &Connection) {
|
|||||||
score INTEGER NOT NULL DEFAULT 1,
|
score INTEGER NOT NULL DEFAULT 1,
|
||||||
last_opened INTEGER NOT NULL,
|
last_opened INTEGER NOT NULL,
|
||||||
FOREIGN KEY (word_id) REFERENCES words (id) ON DELETE CASCADE,
|
FOREIGN KEY (word_id) REFERENCES words (id) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (set_id) REFERENCES sets (id) ON DELETE CASCADE
|
FOREIGN KEY (set_id) REFERENCES card_set (id) ON DELETE CASCADE
|
||||||
)",
|
)",
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
|||||||
+9
-9
@@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
const MAX_SCORE: u8 = 25_u8;
|
const MAX_SCORE: i32 = 25;
|
||||||
const FADE_PER_DAY: f32 = 0.95;
|
const FADE_PER_DAY: f32 = 0.95;
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct KanaSet {
|
pub struct KanaSet {
|
||||||
@@ -252,7 +252,7 @@ pub struct CardStatistics {
|
|||||||
pub word_id: u32,
|
pub word_id: u32,
|
||||||
pub set_id: u32,
|
pub set_id: u32,
|
||||||
pub last_open: DateTime<Utc>,
|
pub last_open: DateTime<Utc>,
|
||||||
pub score: u8,
|
pub score: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CardStatistics {
|
impl CardStatistics {
|
||||||
@@ -260,16 +260,16 @@ impl CardStatistics {
|
|||||||
self.last_open = Utc::now();
|
self.last_open = Utc::now();
|
||||||
match status {
|
match status {
|
||||||
WordOpenMode::Easy => {
|
WordOpenMode::Easy => {
|
||||||
self.score = self.calculated_score().round() as u8 + 5;
|
self.score = (self.calculated_score() + 5.0).round() as i32;
|
||||||
}
|
}
|
||||||
WordOpenMode::Ok => {
|
WordOpenMode::Ok => {
|
||||||
self.score += self.calculated_score().round() as u8 + 3;
|
self.score = (self.calculated_score() + 3.0).round() as i32
|
||||||
}
|
}
|
||||||
WordOpenMode::Hard => {
|
WordOpenMode::Hard => {
|
||||||
self.score = self.calculated_score().round() as u8 - 1;
|
self.score = (self.calculated_score() - 1.0).round() as i32;
|
||||||
}
|
}
|
||||||
WordOpenMode::None => {
|
WordOpenMode::None => {
|
||||||
self.score = (self.calculated_score() * 0.5) as u8;
|
self.score = (self.calculated_score() * 0.5) as i32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ impl CardStatistics {
|
|||||||
let time = Utc::now() - self.last_open;
|
let time = Utc::now() - self.last_open;
|
||||||
let days = time.num_days();
|
let days = time.num_days();
|
||||||
let multiplier = FADE_PER_DAY.powi(days as i32);
|
let multiplier = FADE_PER_DAY.powi(days as i32);
|
||||||
(1.0 / self.score as f32) * multiplier
|
self.score as f32 * multiplier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +330,7 @@ impl CardSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let indexes = WeightedIndex::new(current_set.iter().map(|s| 1.0 / s.score as f32)).unwrap();
|
let indexes = WeightedIndex::new(current_set.iter().map(|s| 1.0 / s.calculated_score())).unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
set: current_set,
|
set: current_set,
|
||||||
@@ -355,7 +355,7 @@ impl CardSet {
|
|||||||
|
|
||||||
let word = &mut self.set[self.current_word_index.unwrap()];
|
let word = &mut self.set[self.current_word_index.unwrap()];
|
||||||
word.update(status);
|
word.update(status);
|
||||||
let new_weight = word.calculated_score();
|
let new_weight = 1.0 / word.calculated_score();
|
||||||
self.last_weights.update_weights(&[(self.current_word_index.unwrap(), &new_weight)]).unwrap();
|
self.last_weights.update_weights(&[(self.current_word_index.unwrap(), &new_weight)]).unwrap();
|
||||||
{
|
{
|
||||||
update_stat_score(word, &self.state.lock().unwrap().connection)
|
update_stat_score(word, &self.state.lock().unwrap().connection)
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ impl Default for ScreenState {
|
|||||||
let path = app_data_dir();
|
let path = app_data_dir();
|
||||||
let db_file = path.join("data.db");
|
let db_file = path.join("data.db");
|
||||||
let connection = Connection::open(db_file).unwrap();
|
let connection = Connection::open(db_file).unwrap();
|
||||||
|
connection.execute("PRAGMA foreign_keys = ON;", []).unwrap();
|
||||||
let list: Vec<DictionaryElement> = load_words(&connection);
|
let list: Vec<DictionaryElement> = load_words(&connection);
|
||||||
let sets: Vec<CardSetSettings> = load_sets(&connection);
|
let sets: Vec<CardSetSettings> = load_sets(&connection);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user