Added 'correct' field to practice answer to make database queries easier

This commit is contained in:
BroodjeAap 2020-11-09 20:16:25 +01:00
parent 50f64ec4e8
commit d10f2ad861
6 changed files with 52 additions and 21 deletions

View file

@ -6,10 +6,11 @@ import 'package:ohthatsa/util/Months.dart';
class PracticeAnswer {
final int question;
final int answer;
final bool correct;
DateTime dateTime;
int sessionId = -1;
PracticeAnswer(this.question, this.answer){
PracticeAnswer(this.question, this.answer, this.correct){
dateTime = DateTime.now();
}
@ -19,6 +20,7 @@ class PracticeAnswer {
return <String, dynamic>{
"question": question,
"answer": answer,
"correct": correct,
"time": timeFormat,
"sessionId": sessionId
};

View file

@ -8,6 +8,7 @@ abstract class PracticeThing {
final random = Random();
final List<PracticeAnswer> answers = new List<PracticeAnswer>();
bool isCorrect(int answer);
bool answer(int answer);
void next();
List<bool> getBoolAnswers();

View file

@ -14,12 +14,18 @@ class PracticeThingCentury extends PracticeThing {
}
@override
bool answer(int answer) {
answers.add(PracticeAnswer(current, answer));
bool isCorrect(int answer){
final correctAnswer = DayCalculator.getCenturyValue(current);
return answer == correctAnswer;
}
@override
bool answer(int answer) {
bool isCorrect = this.isCorrect(answer);
answers.add(PracticeAnswer(current, answer, isCorrect));
return isCorrect;
}
@override
void next() {
current = 1700 + random.nextInt(500);
@ -27,7 +33,7 @@ class PracticeThingCentury extends PracticeThing {
List<bool> getBoolAnswers(){
return answers.map((answer) =>
answer.answer == DayCalculator.getCenturyValue(answer.question)
answer.correct
).toList();
}
@ -51,7 +57,7 @@ class PracticeThingCentury extends PracticeThing {
final answer = answers[answers.length - 1];
final correctAnswer = DayCalculator.getCenturyValue(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if(answer.answer == correctAnswer){
if(answer.correct){
color = Colors.green;
}
}
@ -70,7 +76,7 @@ class PracticeThingCentury extends PracticeThing {
final answer = answers[answers.length - 2];
final correctAnswer = DayCalculator.getCenturyValue(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if(answer.answer == correctAnswer){
if(answer.correct){
color = Colors.green;
}
}

View file

@ -13,12 +13,18 @@ class PracticeThingLeap extends PracticeThing {
}
@override
bool answer(int answer) {
answers.add(PracticeAnswer(current, answer));
bool isCorrect(int answer){
final correctAnswer = DayCalculator.isLeapYear(current);
return (answer != 0) == correctAnswer;
}
@override
bool answer(int answer) {
final isCorrect = this.isCorrect(answer);
answers.add(PracticeAnswer(current, answer, isCorrect));
return isCorrect;
}
@override
void next() {
current = random.nextInt(10000);
@ -26,7 +32,7 @@ class PracticeThingLeap extends PracticeThing {
List<bool> getBoolAnswers(){
return answers.map((answer) =>
(answer.answer != 0) == DayCalculator.isLeapYear(answer.question)
answer.correct
).toList();
}
@ -50,7 +56,7 @@ class PracticeThingLeap extends PracticeThing {
final answer = answers[answers.length - 1];
final correctAnswer = DayCalculator.isLeapYear(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if((answer.answer != 0) == correctAnswer){
if(answer.correct){
color = Colors.green;
}
}
@ -69,7 +75,7 @@ class PracticeThingLeap extends PracticeThing {
final answer = answers[answers.length - 2];
final correctAnswer = DayCalculator.isLeapYear(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if((answer.answer != 0) == correctAnswer){
if(answer.correct){
color = Colors.green;
}
}

View file

@ -11,12 +11,18 @@ class PracticeThingMod extends PracticeThing {
}
@override
bool answer(int answer) {
answers.add(PracticeAnswer(current, answer));
bool isCorrect(int answer){
final correctAnswer = current % 7;
return answer == correctAnswer;
}
@override
bool answer(int answer) {
final isCorrect = this.isCorrect(answer);
answers.add(PracticeAnswer(current, answer, isCorrect));
return isCorrect;
}
@override
void next() {
current = random.nextInt(141);
@ -30,7 +36,7 @@ class PracticeThingMod extends PracticeThing {
@override
List<bool> getBoolAnswers() {
return answers.map((answer) =>
answer.question % 7 == answer.answer
answer.correct
).toList();
}
@ -50,7 +56,7 @@ class PracticeThingMod extends PracticeThing {
final answer = answers[answers.length - 1];
final correctAnswer = answer.question % 7;
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if(answer.answer == correctAnswer){
if(answer.correct){
color = Colors.green;
}
}
@ -69,7 +75,7 @@ class PracticeThingMod extends PracticeThing {
final answer = answers[answers.length - 2];
final correctAnswer = answer.question % 7;
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if(answer.answer == correctAnswer){
if(answer.correct){
color = Colors.green;
}
}

View file

@ -13,10 +13,18 @@ class PracticeThingMonth extends PracticeThing {
PracticeThingMonth(){
next();
}
@override
bool isCorrect(int answer){
return current.value == answer;
}
@override
bool answer(int answer) {
answers.add(PracticeAnswer(current.i, answer));
return current.value == answer;
final isCorrect = this.isCorrect(answer);
answers.add(PracticeAnswer(current.i, answer, isCorrect));
return isCorrect;
}
@override
@ -25,7 +33,9 @@ class PracticeThingMonth extends PracticeThing {
}
List<bool> getBoolAnswers(){
return answers.map((answer) => Months.getFromInt(answer.question).value == answer.answer).toList();
return answers.map(
(answer) => answer.correct
).toList();
}
Text getAppBarTitleText(){
@ -48,7 +58,7 @@ class PracticeThingMonth extends PracticeThing {
final answer = answers[answers.length - 1];
final month = Months.getFromInt(answer.question);
text = month.toString() + (showCorrect ? ": ${month.value}" : "");
if(month.value == answer.answer){
if(answer.correct){
color = Colors.green;
}
}
@ -67,7 +77,7 @@ class PracticeThingMonth extends PracticeThing {
final answer = answers[answers.length - 2];
final month = Months.getFromInt(answer.question);
text = month.toString() + (showCorrect ? ": ${month.value}" : "");
if(month.value == answer.answer){
if(answer.correct){
color = Colors.green;
}
}