From 663fa377b196543f19e4b00e2b4ece423adb8f52 Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Fri, 28 Aug 2026 17:44:14 +0300 Subject: [PATCH] Add history table and modify card_stats --- Cargo.lock | 124 ++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +- sql/card_stats.sql | 6 +- sql/history.sql | 11 ++++ src/data_provider/history.rs | 7 +- src/data_provider/sqlite.rs | 7 ++ 6 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 sql/history.sql diff --git a/Cargo.lock b/Cargo.lock index f86de79..d59a4c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1003,7 +1003,7 @@ dependencies = [ "ciborium", "clap", "criterion-plot", - "itertools", + "itertools 0.13.0", "num-traits", "oorandom", "page_size", @@ -1023,7 +1023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea" dependencies = [ "cast", - "itertools", + "itertools 0.13.0", ] [[package]] @@ -1529,6 +1529,23 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +[[package]] +name = "fsrs" +version = "6.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a99ea3dec9af37c9ed3835463ff6820a578a0026a8e370b4c1c0db48dfab3f" +dependencies = [ + "itertools 0.14.0", + "log", + "ndarray", + "priority-queue", + "rand", + "rayon", + "serde", + "snafu", + "strum", +] + [[package]] name = "futures" version = "0.3.31" @@ -2411,6 +2428,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.17" @@ -2425,6 +2451,7 @@ dependencies = [ "criterion", "dirs", "env_logger", + "fsrs", "hashbrown 0.17.1", "hex", "iced", @@ -2775,6 +2802,16 @@ dependencies = [ "libc", ] +[[package]] +name = "matrixmultiply" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f607c237553f086e7043417a51df26b2eb899d3caff94e6a67592ff992fedc7" +dependencies = [ + "autocfg", + "rawpointer", +] + [[package]] name = "memchr" version = "2.8.0" @@ -2911,6 +2948,21 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "ndarray" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d" +dependencies = [ + "matrixmultiply", + "num-complex", + "num-integer", + "num-traits", + "portable-atomic", + "portable-atomic-util", + "rawpointer", +] + [[package]] name = "ndk" version = "0.9.0" @@ -2960,6 +3012,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + [[package]] name = "num-conv" version = "0.2.2" @@ -3772,6 +3833,17 @@ dependencies = [ "syn 2.0.114", ] +[[package]] +name = "priority-queue" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93980406f12d9f8140ed5abe7155acb10bb1e69ea55c88960b9c2f117445ef96" +dependencies = [ + "equivalent", + "indexmap", + "serde", +] + [[package]] name = "proc-macro-crate" version = "3.4.0" @@ -3950,6 +4022,12 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + [[package]] name = "rayon" version = "1.12.0" @@ -4715,6 +4793,27 @@ dependencies = [ "serde", ] +[[package]] +name = "snafu" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e45cb604038abb7b926b679887b3226d8d0f23874b66623625a0454be425a4b7" +dependencies = [ + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287f59010008f0d7cf5e3b03196d666c1acc46c8d3e9cf34c28a1a7157601e72" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.114", +] + [[package]] name = "socket2" version = "0.6.3" @@ -4804,6 +4903,27 @@ dependencies = [ "float-cmp", ] +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.114", +] + [[package]] name = "subtle" version = "2.6.1" diff --git a/Cargo.toml b/Cargo.toml index 06ba459..9e481a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,13 +26,14 @@ rayon = "1.12.0" parking_lot = "0.12.5" env_logger = "0.11.11" log = "0.4.34" +fsrs = "6.6.1" [profile.super-release] inherits = "release" codegen-units = 1 lto = true opt-level = 3 -strip = true +#strip = true panic = "abort" [dev-dependencies] diff --git a/sql/card_stats.sql b/sql/card_stats.sql index fb2b675..4c6c6b4 100644 --- a/sql/card_stats.sql +++ b/sql/card_stats.sql @@ -9,5 +9,9 @@ create table card_stats references card_set on delete cascade, score INTEGER default 1 not null, - last_opened INTEGER not null + last_opened INTEGER not null, + added INTEGER not null, + fsrs_opened INTEGER, + fsrs_memory INTEGER, + fsrs_open_time INTEGER ); \ No newline at end of file diff --git a/sql/history.sql b/sql/history.sql new file mode 100644 index 0000000..cfeff01 --- /dev/null +++ b/sql/history.sql @@ -0,0 +1,11 @@ +create table history +( + id INTEGER + primary key autoincrement, + set_id INTEGER not null references card_set on delete cascade, + stat_id INTEGER not null references card_stats on delete cascade, + timestamp INTEGER not null, + answer INTEGER not null, + before INTEGER not null, + after INTEGER not null +); diff --git a/src/data_provider/history.rs b/src/data_provider/history.rs index 023d6b7..1c78cd6 100644 --- a/src/data_provider/history.rs +++ b/src/data_provider/history.rs @@ -4,11 +4,16 @@ use crate::data::entities::HistoryItem; use crate::fs::*; use crate::notification::NotificationData::PermissionDenied; use crate::notification::{MaybeError, NotificationData}; -use chrono::DateTime; +use chrono::{DateTime, NaiveDate}; use std::fs::{File, OpenOptions}; use std::io::Write; use std::io::{BufRead, BufReader}; use std::path::PathBuf; +use rusqlite::Connection; + +pub fn get_open_count_of_set(id: Id, connection: &Connection) -> Result, NotificationData>{ + todo!() +} pub fn get_history_of_set(id: Id) -> Result, NotificationData> { let app_dir = history_dir()?; diff --git a/src/data_provider/sqlite.rs b/src/data_provider/sqlite.rs index cbe539d..be04f07 100644 --- a/src/data_provider/sqlite.rs +++ b/src/data_provider/sqlite.rs @@ -20,6 +20,7 @@ fn create_tables(conn: &Connection) { make_word_group(conn).expect("Failed to init table"); make_words(conn).expect("Failed to init table"); make_card_stats(conn).expect("Failed to init table"); + make_history(conn).expect("Failed to init table"); } fn make_settings(conn: &Connection) -> Result<(), rusqlite::Error> { @@ -51,6 +52,12 @@ fn make_card_stats(conn: &Connection) -> Result<(), rusqlite::Error> { Ok(()) } +fn make_history(conn: &Connection) -> Result<(), rusqlite::Error> { + let query = include_str!("../../sql/history.sql"); + conn.execute(query, ())?; + Ok(()) +} + pub fn default_connection() -> Connection { let db_file = db_path(); let connection = Connection::open(db_file).expect("Failed to open database");