Updated part of the Selection screen to the new design

This commit is contained in:
Tiago Ribeiro
2023-06-13 15:43:26 +01:00
parent e055b84688
commit b41ee8e2ad
3 changed files with 95 additions and 70 deletions

View File

@@ -2,6 +2,7 @@ import {Stat} from "@/interfaces/user";
import {capitalize, groupBy} from "lodash";
import {convertCamelCaseToReadable} from "@/utils/string";
import {UserSolution} from "@/interfaces/exam";
import {Module} from "@/interfaces";
export const totalExams = (stats: Stat[]): number => {
const moduleStats = formatModuleTotalStats(stats);
@@ -35,6 +36,22 @@ export const formatModuleTotalStats = (stats: Stat[]): {label: string; value: nu
}));
};
export const totalExamsByModule = (stats: Stat[], module: Module): number => {
const moduleSessions: {[key: string]: string[]} = {};
stats.forEach((stat) => {
if (stat.module in moduleSessions) {
if (!moduleSessions[stat.module].includes(stat.session)) {
moduleSessions[stat.module] = [...moduleSessions[stat.module], stat.session];
}
} else {
moduleSessions[stat.module] = [stat.session];
}
});
return moduleSessions[module]?.length || 0;
};
export const formatModuleAverageScoreStats = (stats: Stat[]): {label: string; value: number}[] => {
const moduleScores: {[key: string]: {correct: number; total: number}} = {};