From 021a6c67ea7b611678058de1032f250bcb298b70 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 18 May 2024 02:01:48 +0300 Subject: [PATCH] add percentage in cards game --- src/ui/cards/edit/imp.rs | 28 ++++++++++++++-------------- src/ui/cards/game/mod.rs | 5 +++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/ui/cards/edit/imp.rs b/src/ui/cards/edit/imp.rs index 4ef4712..7948c78 100644 --- a/src/ui/cards/edit/imp.rs +++ b/src/ui/cards/edit/imp.rs @@ -297,20 +297,20 @@ async fn new_card_setup>(window: Rc) { let conn = Connection::open(get_db_path()).unwrap(); conn.execute("INSERT OR REPLACE INTO cards ( id, - imagename, - hieroglyph, - reading, - translation, - is_learning - ) VALUES ( - (SELECT id FROM cards WHERE hieroglyph = ?2), - ?1, - ?2, - ?3, - ?4, - (SELECT is_learning FROM cards WHERE hieroglyph = ?2 OR TRUE - ) - )", (&new_filename, &hieroglyph, &reading, &translation)).unwrap(); + imagename, + hieroglyph, + reading, + translation, + is_learning + ) VALUES ( + (SELECT id FROM cards WHERE hieroglyph = ?2), + ?1, + ?2, + ?3, + ?4, + (SELECT is_learning FROM cards WHERE hieroglyph = ?2 OR TRUE + ) + )", (&new_filename, &hieroglyph, &reading, &translation)).unwrap(); w.close(); }), ); diff --git a/src/ui/cards/game/mod.rs b/src/ui/cards/game/mod.rs index 9c3b54f..925107f 100644 --- a/src/ui/cards/game/mod.rs +++ b/src/ui/cards/game/mod.rs @@ -22,9 +22,10 @@ impl MemoryCardsGameScene { pub fn update_stats(&self) { self.imp().stats_label.set_text(&format!( - "Correct|Incorrect: {}|{}", + "Correct|Incorrect: {}|{} ({:.2}%)", self.imp().correct.borrow(), - self.imp().incorrect.borrow() + self.imp().incorrect.borrow(), + 100.0 * f64::from(*self.imp().correct.borrow() as i32) / f64::from((*self.imp().incorrect.borrow() + *self.imp().correct.borrow()) as i32) )); }