Added a few more stats to the stats page
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user