Merged in ENCOA-131_MasterStatistical (pull request #94)
Added level part display on excel and a pseudo sorting Approved-by: Tiago Ribeiro
This commit is contained in:
@@ -29,7 +29,13 @@ interface TableData {
|
|||||||
date: moment.Moment;
|
date: moment.Moment;
|
||||||
assignment: string;
|
assignment: string;
|
||||||
corporateId: string;
|
corporateId: string;
|
||||||
|
score: number;
|
||||||
level: string;
|
level: string;
|
||||||
|
part1?: string;
|
||||||
|
part2?: string;
|
||||||
|
part3?: string;
|
||||||
|
part4?: string;
|
||||||
|
part5?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
@@ -94,11 +100,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
"level",
|
"level",
|
||||||
user.focus
|
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(
|
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 corporateUser = users.find((u) => u.id === a.assigner);
|
||||||
const correct = userStats.reduce((n, e) => n + e.score.correct, 0);
|
const correct = userStats.reduce((n, e) => n + e.score.correct, 0);
|
||||||
const total = userStats.reduce((n, e) => n + e.score.total, 0);
|
const total = userStats.reduce((n, e) => n + e.score.total, 0);
|
||||||
const level = getGradingSystemHelper(
|
const { label: level, score } = getGradingSystemHelper(
|
||||||
a.exams,
|
a.exams,
|
||||||
a.assigner,
|
a.assigner,
|
||||||
userData!,
|
userData!,
|
||||||
correct,
|
correct,
|
||||||
total
|
total
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
console.log("Level", level);
|
console.log("Level", level);
|
||||||
const commonData = {
|
const commonData = {
|
||||||
user: userData?.name || "",
|
user: userData?.name || "",
|
||||||
@@ -126,6 +134,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
corporate: corporateUser?.name || "",
|
corporate: corporateUser?.name || "",
|
||||||
assignment: a.name,
|
assignment: a.name,
|
||||||
level,
|
level,
|
||||||
|
score,
|
||||||
};
|
};
|
||||||
if (userStats.length === 0) {
|
if (userStats.length === 0) {
|
||||||
return {
|
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 {
|
return {
|
||||||
...commonData,
|
...commonData,
|
||||||
correct,
|
correct,
|
||||||
submitted: true,
|
submitted: true,
|
||||||
date: moment.max(userStats.map((e) => moment(e.date))),
|
date: moment.max(userStats.map((e) => moment(e.date))),
|
||||||
|
...partsData,
|
||||||
};
|
};
|
||||||
}) as TableData[];
|
}) as TableData[];
|
||||||
|
|
||||||
return [...accmA, ...userResults];
|
return [...accmA, ...userResults];
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
).sort((a,b) => b.score - a.score);
|
||||||
|
|
||||||
// Create a new workbook and add a worksheet
|
// Create a new workbook and add a worksheet
|
||||||
const workbook = new ExcelJS.Workbook();
|
const workbook = new ExcelJS.Workbook();
|
||||||
@@ -185,7 +202,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
{
|
{
|
||||||
label: "Level",
|
label: "Level",
|
||||||
value: (entry: TableData) => entry.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
|
const filteredSearch = searchText
|
||||||
|
|||||||
Reference in New Issue
Block a user