add percentage in cards game

This commit is contained in:
leca 2024-05-18 02:01:48 +03:00
parent c67ae2834d
commit 021a6c67ea
2 changed files with 17 additions and 16 deletions

View File

@ -297,20 +297,20 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
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();
}),
);

View File

@ -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)
));
}