@@ -12,6 +12,34 @@ class Scores {
1212
1313 const Scores ({this .mathTestScores = const []});
1414
15+ Iterable <MathTestResult > getResultsBySessionName (String name){
16+ return mathTestScores.where ((r) => r.type == name);
17+ }
18+
19+ int getProblemsSolvedBySessionName (String name){
20+ return mathTestScores
21+ .where ((r) => r.type == name)
22+ .fold (0 , (int sum, r) => sum + r.correct);
23+ }
24+
25+ double getAverageAccuracyBySessionName (String name) {
26+ var selectedScores = mathTestScores.where ((r) => r.type == name);
27+ var problemCount = selectedScores.fold (0 , (int sum, r) => sum + r.questions);
28+ var correct = selectedScores.fold (0 , (int sum, r) => sum + r.correct);
29+
30+ if (problemCount == 0 ) return 0 ;
31+ return correct / problemCount;
32+ }
33+
34+ double getAverageSpeedBySessionName (String name) {
35+ var selectedScores = mathTestScores.where ((r) => r.type == name);
36+ var totalProblems = selectedScores.fold (0 , (int sum, r) => sum + r.correct);
37+ var totalTime = selectedScores.fold (0 , (int sum, r) => sum + r.duration) / 60 ; // converting to minutes
38+
39+ if (totalTime == 0 ) return 0 ;
40+ return totalProblems / totalTime;
41+ }
42+
1543 static Scores fromJson (Map <String , dynamic > json){
1644 return _$ScoresFromJson (json);
1745 }
0 commit comments