Updated the grading system to work based on entities
This commit is contained in:
@@ -16,6 +16,8 @@ import { findBy, mapBy } from "@/utils";
|
||||
import ExcelJS from "exceljs";
|
||||
import moment from "moment";
|
||||
import { Session } from "@/hooks/useSessions";
|
||||
import { getGradingSystemByEntity } from "@/utils/grading.be";
|
||||
import { getGradingLabel } from "@/utils/score";
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -81,14 +83,16 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const worksheet = workbook.addWorksheet("Statistical");
|
||||
|
||||
entityInformations.forEach((e) => addEntityInformationToWorksheet(worksheet, e))
|
||||
for (const e of entityInformations) {
|
||||
await addEntityInformationToWorksheet(worksheet, e)
|
||||
}
|
||||
|
||||
const buffer = await workbook.xlsx.writeBuffer()
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
||||
res.status(200).send(buffer);
|
||||
}
|
||||
|
||||
const addEntityInformationToWorksheet = (worksheet: ExcelJS.Worksheet, entityInformation: EntityInformation) => {
|
||||
const addEntityInformationToWorksheet = async (worksheet: ExcelJS.Worksheet, entityInformation: EntityInformation) => {
|
||||
const data = [
|
||||
['Entity', undefined, undefined, entityInformation.entity.label],
|
||||
['Assignment', undefined, undefined, entityInformation.assignment.name],
|
||||
@@ -108,6 +112,7 @@ const addEntityInformationToWorksheet = (worksheet: ExcelJS.Worksheet, entityInf
|
||||
dataRows.forEach(row => worksheet.mergeCells(`${row.getCell(4).address}:${row.getCell(7).address}`))
|
||||
|
||||
worksheet.addRows([[], []]);
|
||||
const gradingSystem = await getGradingSystemByEntity(entityInformation.entity.id)
|
||||
|
||||
for (const exam of entityInformation.exams) {
|
||||
const examRow = worksheet.addRow([`${capitalize(exam.module)} Exam`, undefined, exam.id])
|
||||
@@ -127,7 +132,9 @@ const addEntityInformationToWorksheet = (worksheet: ExcelJS.Worksheet, entityInf
|
||||
"Student ID",
|
||||
"Passport/ID",
|
||||
"Gender",
|
||||
"Finished at",
|
||||
"Score",
|
||||
...(exam.module === "level" ? ["Grade"] : []),
|
||||
...parts.map((_, i) => `Part ${i + 1}`)
|
||||
])
|
||||
header.font = { bold: true, color: { argb: "FFFFFFFF" } }
|
||||
@@ -152,6 +159,11 @@ const addEntityInformationToWorksheet = (worksheet: ExcelJS.Worksheet, entityInf
|
||||
const { total, correct } = calculateScore(item.result.stats)
|
||||
const score = `${correct} / ${total}`
|
||||
|
||||
const finishTimestamp = [...item.result.stats].sort((a, b) => b.date - a.date).shift()?.date || -1
|
||||
const finishDate = finishTimestamp === -1 ? "N/A" : moment(new Date(finishTimestamp)).format("DD/MM/YYYY HH:mm")
|
||||
|
||||
const grade = getGradingLabel(correct, gradingSystem.steps)
|
||||
|
||||
return [
|
||||
index + 1,
|
||||
item.student.name,
|
||||
@@ -159,7 +171,9 @@ const addEntityInformationToWorksheet = (worksheet: ExcelJS.Worksheet, entityInf
|
||||
item.student.studentID || "N/A",
|
||||
item.student.demographicInformation?.passport_id || "N/A",
|
||||
item.student.demographicInformation?.gender || "N/A",
|
||||
finishDate,
|
||||
score,
|
||||
...(exam.module === "level" ? [grade] : []),
|
||||
...parts.map((part) => {
|
||||
const exerciseIDs = mapBy(part.exercises, 'id')
|
||||
const { total, correct } = calculateScore(item.result.stats.filter(s => exerciseIDs.includes(s.exercise)))
|
||||
|
||||
Reference in New Issue
Block a user