ENCOA-90: Updated the instances of Level test to use the Grading System

This commit is contained in:
Tiago Ribeiro
2024-08-27 00:18:01 +01:00
parent a0b8521f0a
commit 0aba6355ed
6 changed files with 360 additions and 350 deletions

View File

@@ -1,5 +1,4 @@
import {Module} from "@/interfaces";
import {LevelScore} from "@/constants/ielts";
import {Module, Step} from "@/interfaces";
import {Stat, User} from "@/interfaces/user";
type Type = "academic" | "general";
@@ -135,6 +134,8 @@ export const calculateBandScore = (correct: number, total: number, module: Modul
const marking = moduleMarkings[module][type];
const percentage = (correct * 100) / total;
if (module === "level") return percentage;
for (const value of Object.keys(marking)
.map((x) => parseFloat(x))
.sort((a, b) => b - a)) {
@@ -147,7 +148,11 @@ export const calculateBandScore = (correct: number, total: number, module: Modul
};
export const calculateAverageLevel = (levels: {[key in Module]: number}) => {
return Object.keys(levels).reduce((accumulator, current) => levels[current as Module] + accumulator, 0) / 5;
return (
Object.keys(levels)
.filter((x) => x !== "level")
.reduce((accumulator, current) => levels[current as Module] + accumulator, 0) / 4
);
};
export const getLevelScore = (level: number) => {
@@ -180,6 +185,14 @@ export const getLevelLabel = (level: number) => {
return ["Proficiency", "C2"];
};
export const getGradingLabel = (score: number, grading: Step[]) => {
for (const step of grading) {
if (score >= step.min && score <= step.max) return step.label;
}
return "N/A";
};
export const averageLevelCalculator = (users: User[], studentStats: Stat[]) => {
const formattedStats = studentStats
.map((s) => ({