From c26ff48b601898371dec74c2bd5585d8fd4bf205 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Wed, 17 Jan 2024 11:32:20 +0000 Subject: [PATCH 1/3] Solved some issues with the Student Dashboard --- src/dashboards/Student.tsx | 4 ++-- src/dashboards/Teacher.tsx | 2 +- src/pages/(admin)/BatchCodeGenerator.tsx | 2 +- src/utils/groups.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dashboards/Student.tsx b/src/dashboards/Student.tsx index 97acd6d1..f55bf16e 100644 --- a/src/dashboards/Student.tsx +++ b/src/dashboards/Student.tsx @@ -42,7 +42,7 @@ export default function StudentDashboard({user}: Props) { const setAssignment = useExamStore((state) => state.setAssignment); useEffect(() => { - getUserCorporate(user.id).then(setCorporateUserToShow); + getUserCorporate("IXdh9EQziAVXXh0jOiC5cPVlgS82").then(setCorporateUserToShow); }, [user]); const startAssignment = (assignment: Assignment) => { @@ -70,7 +70,7 @@ export default function StudentDashboard({user}: Props) { <> {corporateUserToShow && (
- Linked to: {corporateUserToShow?.corporateInformation.companyInformation.name || corporateUserToShow.name} + Linked to: {corporateUserToShow?.corporateInformation?.companyInformation.name || corporateUserToShow.name}
)} {corporateUserToShow && (
- Linked to: {corporateUserToShow?.corporateInformation.companyInformation.name || corporateUserToShow.name} + Linked to: {corporateUserToShow?.corporateInformation?.companyInformation.name || corporateUserToShow.name}
)}
u.email).includes(email) ? { email: email.toString(), - name: `${firstName} ${lastName}`, + name: `${firstName ?? ""} ${lastName ?? ""}`.trim(), passport_id: passport_id.toString(), } : undefined; diff --git a/src/utils/groups.ts b/src/utils/groups.ts index 0d0dec55..44f63fe7 100644 --- a/src/utils/groups.ts +++ b/src/utils/groups.ts @@ -14,5 +14,5 @@ export const getUserCorporate = async (userID: string) => { const users = (await axios.get("/api/users/list")).data; const admins = groups.map((g) => users.find((u) => u.id === g.admin)); - return admins.map((x) => x?.type).includes("corporate") ? (admins[0] as CorporateUser) : undefined; + return admins.filter((x) => x?.type === "admin") ? (admins[0] as CorporateUser) : undefined; }; From 7a577a7ca2549e1f76cbc1f22be514ceb5f15625 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Wed, 17 Jan 2024 11:50:50 +0000 Subject: [PATCH 2/3] Solved another stupid bug --- src/utils/groups.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/groups.ts b/src/utils/groups.ts index 44f63fe7..5b7c894d 100644 --- a/src/utils/groups.ts +++ b/src/utils/groups.ts @@ -13,6 +13,6 @@ export const getUserCorporate = async (userID: string) => { const groups = (await axios.get(`/api/groups?participant=${userID}`)).data; const users = (await axios.get("/api/users/list")).data; - const admins = groups.map((g) => users.find((u) => u.id === g.admin)); - return admins.filter((x) => x?.type === "admin") ? (admins[0] as CorporateUser) : undefined; + const admins = groups.map((g) => users.find((u) => u.id === g.admin)).filter((x) => x?.type === "corporate"); + return admins.length > 0 ? (admins[0] as CorporateUser) : undefined; }; From a646955493d6aaff2f0c6532b58927408c93ae01 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Wed, 17 Jan 2024 11:59:40 +0000 Subject: [PATCH 3/3] Solved a bug with calculations of the stats page --- src/pages/stats.tsx | 231 +++++++++----------------------------------- src/utils/score.ts | 25 ++--- 2 files changed, 60 insertions(+), 196 deletions(-) diff --git a/src/pages/stats.tsx b/src/pages/stats.tsx index a6abe9ef..21661251 100644 --- a/src/pages/stats.tsx +++ b/src/pages/stats.tsx @@ -139,9 +139,9 @@ export default function Stats() { } }, [startDate, endDate]); - const calculateTotalScore = (stats: Stat[]) => { + const calculateTotalScore = (stats: Stat[], divisionFactor: number) => { const moduleScores = calculateModuleScore(stats); - return moduleScores.reduce((acc, curr) => acc + curr.score, 0) / 4; + return moduleScores.reduce((acc, curr) => acc + curr.score, 0) / divisionFactor; }; const calculateScorePerModule = (stats: Stat[], module: Module) => { @@ -278,7 +278,10 @@ export default function Stats() { Level{" "} - {calculateTotalScore(stats.filter((s) => timestampToMoment(s).isBefore(date))).toFixed(1)} + {calculateTotalScore( + stats.filter((s) => timestampToMoment(s).isBefore(date)), + 5, + ).toFixed(1)} ) : null; @@ -364,6 +367,7 @@ export default function Stats() { return date.isValid() ? calculateTotalScore( stats.filter((s) => timestampToMoment(s).isBefore(date)), + 5, ).toFixed(1) : undefined; }) @@ -599,188 +603,47 @@ export default function Stats() { }} />
- {/* Reading Score Band in Interval */} -
- Reading Score Band in Interval - ( +
+ {capitalize(module)} Score Band in Interval + moment(date).format("DD/MM/YYYY")), - datasets: [ - { - type: "line", - label: "Reading", - fill: false, - borderColor: COLORS[0], - backgroundColor: COLORS[0], - borderWidth: 2, - spanGaps: true, - data: intervalDates.map((date) => { - return calculateTotalScore( - stats.filter( - (s) => timestampToMoment(s).isBefore(date) && s.module === "reading", - ), - ).toFixed(1); - }), - }, - ], - }} - /> -
- - {/* Listening Score Band in Interval */} -
- Listening Score Band in Interval - moment(date).format("DD/MM/YYYY")), - datasets: [ - { - type: "line", - label: "Listening", - fill: false, - borderColor: COLORS[1], - backgroundColor: COLORS[1], - borderWidth: 2, - spanGaps: true, - data: intervalDates.map((date) => { - return calculateTotalScore( - stats.filter( - (s) => timestampToMoment(s).isBefore(date) && s.module === "listening", - ), - ).toFixed(1); - }), - }, - ], - }} - /> -
- - {/* Writing Score Band in Interval */} -
- Writing Score Band in Interval - moment(date).format("DD/MM/YYYY")), - datasets: [ - { - type: "line", - label: "Writing", - fill: false, - borderColor: COLORS[2], - backgroundColor: COLORS[2], - borderWidth: 2, - spanGaps: true, - data: intervalDates.map((date) => { - return calculateTotalScore( - stats.filter( - (s) => timestampToMoment(s).isBefore(date) && s.module === "writing", - ), - ).toFixed(1); - }), - }, - ], - }} - /> -
- - {/* Speaking Score Band in Interval */} -
- Speaking Score Band in Interval - moment(date).format("DD/MM/YYYY")), - datasets: [ - { - type: "line", - label: "Speaking", - fill: false, - borderColor: COLORS[3], - backgroundColor: COLORS[3], - borderWidth: 2, - spanGaps: true, - data: intervalDates.map((date) => { - return calculateTotalScore( - stats.filter( - (s) => timestampToMoment(s).isBefore(date) && s.module === "speaking", - ), - ).toFixed(1); - }), - }, - ], - }} - /> -
- - {/* Level Score Band in Interval */} -
- Level Score Band in Interval - moment(date).format("DD/MM/YYYY")), - datasets: [ - { - type: "line", - label: "Level", - fill: false, - borderColor: COLORS[4], - backgroundColor: COLORS[4], - borderWidth: 2, - spanGaps: true, - data: intervalDates.map((date) => { - return calculateTotalScore( - stats.filter((s) => timestampToMoment(s).isBefore(date) && s.module === "level"), - ).toFixed(1); - }), - }, - ], - }} - /> -
+ }} + type="line" + data={{ + labels: intervalDates.map((date) => moment(date).format("DD/MM/YYYY")), + datasets: [ + { + type: "line", + label: capitalize(module), + fill: false, + borderColor: COLORS[index], + backgroundColor: COLORS[index], + borderWidth: 2, + spanGaps: true, + data: intervalDates.map((date) => { + return calculateTotalScore( + stats.filter( + (s) => timestampToMoment(s).isBefore(date) && s.module === module, + ), + 1, + ).toFixed(1); + }), + }, + ], + }} + /> +
+ ))}
diff --git a/src/utils/score.ts b/src/utils/score.ts index 08707312..2e191025 100644 --- a/src/utils/score.ts +++ b/src/utils/score.ts @@ -1,5 +1,5 @@ import {Module} from "@/interfaces"; -import { LevelScore } from "@/constants/ielts"; +import {LevelScore} from "@/constants/ielts"; type Type = "academic" | "general"; @@ -96,7 +96,7 @@ const academicMarking: {[key: number]: number} = { const levelMarking: {[key: number]: number} = { 88: 9, // Advanced - 64: 8 , // Upper-Intermediate + 64: 8, // Upper-Intermediate 52: 6, // Intermediate 32: 4, // Pre-Intermediate 16: 2, // Elementary @@ -142,23 +142,24 @@ 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) / 4; + return Object.keys(levels).reduce((accumulator, current) => levels[current as Module] + accumulator, 0) / 5; }; export const getLevelScore = (level: number) => { - switch(level) { + switch (level) { case 0: - return ['Beginner', 'Low A1']; + return ["Beginner", "Low A1"]; case 2: - return ['Elementary', 'High A1/Low A2']; + return ["Elementary", "High A1/Low A2"]; case 4: - return ['Pre-Intermediate', 'High A2/Low B1']; + return ["Pre-Intermediate", "High A2/Low B1"]; case 6: - return ['Intermediate', 'High B1/Low B2']; + return ["Intermediate", "High B1/Low B2"]; case 8: - return ['Upper-Intermediate', 'High B2/Low C1']; + return ["Upper-Intermediate", "High B2/Low C1"]; case 9: - return ['Advanced', 'C1']; - default: return []; + return ["Advanced", "C1"]; + default: + return []; } -} \ No newline at end of file +};