From 9549858c7525d3a330d49bd1f8e353d8a9d6eb96 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 13 Jun 2025 08:11:46 +0200 Subject: Add steps into words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a way to make more granular the accounting of successful runs, so we don't give a word for done until we have run it successfully at least MAX_STEPS times in a row. Signed-off-by: Miquel Sabaté Solà --- lib/mihi/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index e464549..0a3c2f7 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -222,6 +222,7 @@ pub struct Word { pub suffix: Option, pub translation: Value, pub succeeded: usize, + pub steps: usize, } pub fn select_enunciated(filter: Option) -> Result, String> { @@ -257,7 +258,8 @@ pub fn select_random_words(category: Category, number: usize) -> Result Result(12).unwrap()).unwrap(), succeeded: row.get(13).unwrap(), + steps: row.get(14).unwrap(), }); } Ok(res) } -pub fn update_success(word: &Word, success: usize) -> Result<(), String> { +pub fn update_success(word: &Word, success: usize, steps: usize) -> Result<(), String> { let conn = get_connection()?; match conn.execute( - "UPDATE words SET succeeded = ?1, updated_at = datetime('now') WHERE id = ?2", - params![success, word.id], + "UPDATE words \ + SET succeeded = ?1, steps = ?2, updated_at = datetime('now') \ + WHERE id = ?3", + params![success, steps, word.id], ) { Ok(_) => Ok(()), Err(e) => return Err(format!("could not update '{}': {}", word.enunciated, e)), -- cgit v1.2.3