From 9dd9799994ed9bef6794aaa89b0d1cf37cd5174f Mon Sep 17 00:00:00 2001 From: Finn Brewer Date: Tue, 16 Jul 2024 11:23:37 -0700 Subject: [PATCH] feat: keep track of the number of words seen --- src-tauri/src/language_parsing.rs | 19 +++++++++++++++---- src-tauri/src/main.rs | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/language_parsing.rs b/src-tauri/src/language_parsing.rs index 773a913..dddd603 100644 --- a/src-tauri/src/language_parsing.rs +++ b/src-tauri/src/language_parsing.rs @@ -30,12 +30,23 @@ pub async fn parse_text( .expect("Language to have already been chosen"); let interpreter = load_spyglys(&mut state)?; - if state.language_parser.is_some() { + let words = if state.language_parser.is_some() { log::trace!("Sending to stanza parser"); - stanza_parser(sent, &mut state, language, &interpreter) + stanza_parser(sent, &mut state, language.clone(), &interpreter) } else { - default_tokenizer(sent, language, &mut state, &interpreter) - } + default_tokenizer(sent, language.clone(), &mut state, &interpreter) + }?; + state + .to_save + .language_specific + .get_mut(&language) + .expect("language to have state") + .words_seen + .push(( + chrono::Utc::now(), + words.iter().filter(|v| v.clickable).count(), + )); + Ok(words) } #[derive(serde::Deserialize, Clone)] struct StanzaToken { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 78135cf..dde4e53 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -92,6 +92,7 @@ struct LanguageSpecficToSave { cached_defs: HashMap>>, previous_file: Option, previous_amount: usize, + words_seen: Vec<(DateTime, usize)>, } impl Default for SharedInfo {