in between commit to save some possibly useful views
This commit is contained in:
parent
e445b121e3
commit
df3e6b8e51
1 changed files with 28 additions and 9 deletions
|
@ -40,6 +40,29 @@ class PracticeDatabase {
|
||||||
FROM PracticeSession
|
FROM PracticeSession
|
||||||
INNER JOIN PracticeAnswer on PracticeSession.id = PracticeAnswer.sessionId;
|
INNER JOIN PracticeAnswer on PracticeSession.id = PracticeAnswer.sessionId;
|
||||||
''');
|
''');
|
||||||
|
await database.execute('''
|
||||||
|
CREATE VIEW AnswersCorrectByTypeView AS
|
||||||
|
SELECT
|
||||||
|
type,
|
||||||
|
SUM(correct = 1)*1.0 AS correct,
|
||||||
|
SUM(correct = 0)*1.0 AS incorrect,
|
||||||
|
COUNT(*) AS total
|
||||||
|
FROM
|
||||||
|
AnswersView
|
||||||
|
GROUP BY
|
||||||
|
type;
|
||||||
|
''');
|
||||||
|
await database.execute('''
|
||||||
|
CREATE VIEW AnswersRatioByTypeView AS
|
||||||
|
SELECT
|
||||||
|
type,
|
||||||
|
correct,
|
||||||
|
incorrect,
|
||||||
|
total,
|
||||||
|
correct / total AS ratio
|
||||||
|
FROM
|
||||||
|
AnswersCorrectByTypeView
|
||||||
|
''');
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Database> getDatabase() async {
|
static Future<Database> getDatabase() async {
|
||||||
|
@ -74,16 +97,12 @@ class PracticeDatabase {
|
||||||
List<Map<String, dynamic>> answers = await db.rawQuery('''
|
List<Map<String, dynamic>> answers = await db.rawQuery('''
|
||||||
SELECT
|
SELECT
|
||||||
type,
|
type,
|
||||||
SUM(correct = 1) AS correct,
|
correct,
|
||||||
SUM(correct = 0) AS incorrect,
|
incorrect,
|
||||||
(
|
total,
|
||||||
(SUM(correct = 1)*1.0) /
|
ratio
|
||||||
(SUM(correct = 0) + SUM(correct = 1))
|
|
||||||
) as ratio
|
|
||||||
FROM
|
FROM
|
||||||
AnswersView
|
AnswersRatioByTypeView
|
||||||
GROUP BY
|
|
||||||
type;
|
|
||||||
''');
|
''');
|
||||||
print(answers);
|
print(answers);
|
||||||
var first = answers.first;
|
var first = answers.first;
|
||||||
|
|
Loading…
Add table
Reference in a new issue