Added a few more stats to the stats page

This commit is contained in:
Tiago Ribeiro
2023-09-05 16:31:32 +01:00
parent af994cfadb
commit 5211e92c65
2 changed files with 104 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ import {capitalize, groupBy} from "lodash";
import {convertCamelCaseToReadable} from "@/utils/string";
import {UserSolution} from "@/interfaces/exam";
import {Module} from "@/interfaces";
import {MODULES} from "@/constants/ielts";
export const totalExams = (stats: Stat[]): number => {
const moduleStats = formatModuleTotalStats(stats);
@@ -52,7 +53,7 @@ export const totalExamsByModule = (stats: Stat[], module: Module): number => {
return moduleSessions[module]?.length || 0;
};
export const formatModuleAverageScoreStats = (stats: Stat[]): {label: string; value: number}[] => {
export const calculateModuleAverageScoreStats = (stats: Stat[]): {module: Module; value: number}[] => {
const moduleScores: {[key: string]: {correct: number; total: number}} = {};
stats.forEach((stat) => {
@@ -66,16 +67,20 @@ export const formatModuleAverageScoreStats = (stats: Stat[]): {label: string; va
}
});
return ["reading", "listening", "writing", "speaking"].map((x) => {
return MODULES.map((x) => {
const score = moduleScores[x as keyof typeof moduleScores];
return {
label: capitalize(x),
module: x,
value: score ? parseFloat(((score.correct / score.total) * 100).toFixed(2)) : 0,
};
});
};
export const formatModuleAverageScoreStats = (stats: Stat[]): {label: string; value: number}[] => {
return calculateModuleAverageScoreStats(stats).map((x) => ({label: capitalize(x.module), value: x.value}));
};
export const formatExerciseTotalStats = (stats: Stat[]): {label: string; value: number}[] => {
const totalExercises = stats.map((stat) => ({
label: convertCamelCaseToReadable(stat.type),