Added level part display on excel and a pseudo sorting
This commit is contained in:
@@ -29,7 +29,13 @@ interface TableData {
|
||||
date: moment.Moment;
|
||||
assignment: string;
|
||||
corporateId: string;
|
||||
score: number;
|
||||
level: string;
|
||||
part1?: string;
|
||||
part2?: string;
|
||||
part3?: string;
|
||||
part4?: string;
|
||||
part5?: string;
|
||||
}
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -94,11 +100,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
"level",
|
||||
user.focus
|
||||
);
|
||||
return getGradingLabel(bandScore, gradingSystem?.steps || []);
|
||||
return { label: getGradingLabel(bandScore, gradingSystem?.steps || []), score: bandScore };
|
||||
}
|
||||
}
|
||||
|
||||
return "N/A";
|
||||
return { score: -1, label: "N/A" };
|
||||
};
|
||||
|
||||
const tableResults = assignments.reduce(
|
||||
@@ -110,13 +116,15 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const corporateUser = users.find((u) => u.id === a.assigner);
|
||||
const correct = userStats.reduce((n, e) => n + e.score.correct, 0);
|
||||
const total = userStats.reduce((n, e) => n + e.score.total, 0);
|
||||
const level = getGradingSystemHelper(
|
||||
const { label: level, score } = getGradingSystemHelper(
|
||||
a.exams,
|
||||
a.assigner,
|
||||
userData!,
|
||||
correct,
|
||||
total
|
||||
);
|
||||
|
||||
|
||||
console.log("Level", level);
|
||||
const commonData = {
|
||||
user: userData?.name || "",
|
||||
@@ -126,6 +134,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
corporate: corporateUser?.name || "",
|
||||
assignment: a.name,
|
||||
level,
|
||||
score,
|
||||
};
|
||||
if (userStats.length === 0) {
|
||||
return {
|
||||
@@ -136,18 +145,26 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
};
|
||||
}
|
||||
|
||||
const partsData = userStats.every((e) => e.module === "level") ? userStats.reduce((acc, e, index) => {
|
||||
return {
|
||||
...acc,
|
||||
[`part${index}`]: `${e.score.correct}/${e.score.total}`
|
||||
}
|
||||
}, {}) : {};
|
||||
|
||||
return {
|
||||
...commonData,
|
||||
correct,
|
||||
submitted: true,
|
||||
date: moment.max(userStats.map((e) => moment(e.date))),
|
||||
...partsData,
|
||||
};
|
||||
}) as TableData[];
|
||||
|
||||
return [...accmA, ...userResults];
|
||||
},
|
||||
[]
|
||||
);
|
||||
).sort((a,b) => b.score - a.score);
|
||||
|
||||
// Create a new workbook and add a worksheet
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
@@ -185,7 +202,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
{
|
||||
label: "Level",
|
||||
value: (entry: TableData) => entry.level,
|
||||
}
|
||||
},
|
||||
...new Array(5).fill(0).map((_, index) => ({
|
||||
label: `Part ${index + 1}`,
|
||||
value: (entry: TableData) => {
|
||||
const key = `part${index}` as keyof TableData;
|
||||
return entry[key] || "";
|
||||
},
|
||||
})),
|
||||
];
|
||||
|
||||
const filteredSearch = searchText
|
||||
|
||||
Reference in New Issue
Block a user