From 52d309e7f488344a5749315901a358877d10c24e Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sat, 17 Feb 2024 10:43:55 +0000 Subject: [PATCH 1/3] Fixed NaN display on level progress --- src/dashboards/Student.tsx | 56 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/dashboards/Student.tsx b/src/dashboards/Student.tsx index 28c0385c..c22915c0 100644 --- a/src/dashboards/Student.tsx +++ b/src/dashboards/Student.tsx @@ -227,35 +227,39 @@ export default function StudentDashboard({user}: Props) {
Score History
- {MODULE_ARRAY.map((module) => ( -
-
-
- {module === "reading" && } - {module === "listening" && } - {module === "writing" && } - {module === "speaking" && } - {module === "level" && } + {MODULE_ARRAY.map((module) => { + const desiredLevel = user.desiredLevels[module] || 9; + const level = user.levels[module] || 0; + return ( +
+
+
+ {module === "reading" && } + {module === "listening" && } + {module === "writing" && } + {module === "speaking" && } + {module === "level" && } +
+
+ {capitalize(module)} + + Level {level} / Level 9 (Desired Level: {desiredLevel}) + +
-
- {capitalize(module)} - - Level {user.levels[module] || 0} / Level 9 (Desired Level: {user.desiredLevels[module] || 9}) - +
+
-
- -
-
- ))} + ); + })}
From 04f97b62c38407c65911ba994d1b020c806c691b Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sat, 17 Feb 2024 14:22:46 +0000 Subject: [PATCH 2/3] Filtered out level from students history display --- src/dashboards/Student.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dashboards/Student.tsx b/src/dashboards/Student.tsx index c22915c0..d84f35d2 100644 --- a/src/dashboards/Student.tsx +++ b/src/dashboards/Student.tsx @@ -227,7 +227,12 @@ export default function StudentDashboard({user}: Props) {
Score History
- {MODULE_ARRAY.map((module) => { + {MODULE_ARRAY + // filtered out level as the questions for a level test are registed as the other modules + // therefore there are no stats to display on the level section + // for future reference, this data is registered on /api/stats/update.ts:90 + .filter((module) => module !== 'level') + .map((module) => { const desiredLevel = user.desiredLevels[module] || 9; const level = user.levels[module] || 0; return ( From 29cae5c3d259a15847cd5fb0158b8eda71330732 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Sun, 18 Feb 2024 11:09:25 +0000 Subject: [PATCH 3/3] Stats for Level exam are now being properly calculated --- src/dashboards/Student.tsx | 4 ---- src/pages/api/stats/update.ts | 10 +++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dashboards/Student.tsx b/src/dashboards/Student.tsx index d84f35d2..f3c6eca4 100644 --- a/src/dashboards/Student.tsx +++ b/src/dashboards/Student.tsx @@ -228,10 +228,6 @@ export default function StudentDashboard({user}: Props) { Score History
{MODULE_ARRAY - // filtered out level as the questions for a level test are registed as the other modules - // therefore there are no stats to display on the level section - // for future reference, this data is registered on /api/stats/update.ts:90 - .filter((module) => module !== 'level') .map((module) => { const desiredLevel = user.desiredLevels[module] || 9; const level = user.levels[module] || 0; diff --git a/src/pages/api/stats/update.ts b/src/pages/api/stats/update.ts index c1c01674..7d089445 100644 --- a/src/pages/api/stats/update.ts +++ b/src/pages/api/stats/update.ts @@ -5,6 +5,7 @@ import {Stat, User} from "@/interfaces/user"; import {sessionOptions} from "@/lib/session"; import {calculateBandScore} from "@/utils/score"; import {groupByModule, groupBySession} from "@/utils/stats"; +import { MODULE_ARRAY } from "@/utils/moduleUtils"; import {getAuth} from "firebase/auth"; import {collection, doc, getDoc, getDocs, getFirestore, query, updateDoc, where} from "firebase/firestore"; import {withIronSessionApiRoute} from "iron-session/next"; @@ -55,7 +56,7 @@ async function update(req: NextApiRequest, res: NextApiResponse) { }, }; - MODULES.forEach((module: Module) => { + MODULE_ARRAY.forEach((module: Module) => { const moduleStats = sessionStats.filter((x) => x.module === module); if (moduleStats.length === 0) return; @@ -87,11 +88,18 @@ async function update(req: NextApiRequest, res: NextApiResponse) { .filter((x) => x.total > 0) .reduce((acc, cur) => ({total: acc.total + cur.total, correct: acc.correct + cur.correct}), {total: 0, correct: 0}); + const levelLevel = sessionLevels + .map((x) => x.level) + .filter((x) => x.total > 0) + .reduce((acc, cur) => ({total: acc.total + cur.total, correct: acc.correct + cur.correct}), {total: 0, correct: 0}); + + const levels = { reading: calculateBandScore(readingLevel.correct, readingLevel.total, "reading", req.session.user.focus), listening: calculateBandScore(listeningLevel.correct, listeningLevel.total, "listening", req.session.user.focus), writing: calculateBandScore(writingLevel.correct, writingLevel.total, "writing", req.session.user.focus), speaking: calculateBandScore(speakingLevel.correct, speakingLevel.total, "speaking", req.session.user.focus), + level: calculateBandScore(levelLevel.correct, levelLevel.total, "level", req.session.user.focus), }; const userDoc = doc(db, "users", req.session.user.id);