Stats for Level exam are now being properly calculated
This commit is contained in:
@@ -228,10 +228,6 @@ export default function StudentDashboard({user}: Props) {
|
||||
<span className="text-lg font-bold">Score History</span>
|
||||
<div className="-md:grid-rows-4 grid gap-6 md:grid-cols-2">
|
||||
{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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user