grading
Version:
Grading of student submissions, in particular programming tests.
74 lines • 2.69 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateGradingSchema = void 0;
const constants_1 = require("../constants");
const reportLoader_1 = require("./reportLoader");
async function generateGradingSchema(reportsDir, submitter) {
const unitCheck = await (0, reportLoader_1.loadUnitReport)(reportsDir, submitter.submissionId, "check");
if (!unitCheck) {
program.error(`No unit check report with ID ${submitter.submissionId} found in ${reportsDir}, cannot generate schema`);
}
const gradingSchema = {
$schema: constants_1.GRADING_SCHEMA_URL,
course: "Generated",
term: "WS/SS",
exam: "Exam",
points: 100,
tasks: []
};
gradingSchema.term = computeTerm();
const testSuites = unitCheck.testsuite instanceof Array ? unitCheck.testsuite : [unitCheck.testsuite];
const pointsPerTask = Math.round(100 / testSuites.length);
let totalPoints = 0;
for (let counter = 0; counter < testSuites.length; counter++) {
const testSuite = testSuites[counter];
const task = {
name: computeNameFromSuite(testSuite.name, counter),
suite: testSuite.name,
points: counter < testSuites.length - 1 ? pointsPerTask : 100 - totalPoints,
grading: [],
manual: false
};
gradingSchema.tasks.push(task);
totalPoints += task.points;
const testCases = testSuite.testcase;
const grading = {
points: task.points,
text: `Generated from test suite ${testSuite.name} with ${testCases.length} test cases.`,
tests: testCases.map(testCase => testCase.name)
};
task.grading.push(grading);
}
return gradingSchema;
}
exports.generateGradingSchema = generateGradingSchema;
function computeTerm() {
const now = new Date();
const month = now.getMonth();
let year = now.getFullYear();
const term = month < 3 || month > 9 ? "WS" : "SS";
if (term === 'WS') {
if (month < 3)
year--;
return term + " " + year + "/" + ((year + 1) % 2000);
}
else {
return term + " " + year;
}
}
function computeNameFromSuite(name, counter) {
if (!name) {
return "Task " + (1 + counter);
}
const parts = name.split(".");
for (let i = parts.length - 1; i >= 0; i--) {
if (["ts", "js", "test", "check", "spec", "jsx", "tsx"].includes(parts[i])) {
parts.splice(i, 1);
}
}
if (parts.length > 0) {
return parts.join(" ");
}
return parts[0] ?? ("Task " + (1 + counter));
}
//# sourceMappingURL=schemaGenerator.js.map
;