From e445b121e39ae49e66c8dcc514dd58e407197987 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 9 Nov 2020 20:33:15 +0100 Subject: [PATCH] working basic percentage of correct 'all' answers --- lib/pages/practice/PracticeDatabase.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/pages/practice/PracticeDatabase.dart b/lib/pages/practice/PracticeDatabase.dart index a56b8ec..164912d 100644 --- a/lib/pages/practice/PracticeDatabase.dart +++ b/lib/pages/practice/PracticeDatabase.dart @@ -71,7 +71,20 @@ class PracticeDatabase { static Future> getStats() async { var db = await getDatabase(); - List> answers = await db.rawQuery('''SELECT * FROM AnswersView;'''); + List> answers = await db.rawQuery(''' + SELECT + type, + SUM(correct = 1) AS correct, + SUM(correct = 0) AS incorrect, + ( + (SUM(correct = 1)*1.0) / + (SUM(correct = 0) + SUM(correct = 1)) + ) as ratio + FROM + AnswersView + GROUP BY + type; + '''); print(answers); var first = answers.first; print(first["practice_id"]);