grading
Version:
Grading of student submissions, in particular programming tests.
111 lines • 3.6 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeExcel = exports.asNumber = exports.toCol = exports.forEachCellInRow = exports.headerRow = exports.bgLightRed = exports.bgLightYellow = exports.bgLightGreen = exports.bgVeryLightGray = exports.bgLightGray = exports.bgHeader = void 0;
const ExcelJS = __importStar(require("exceljs"));
exports.bgHeader = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FFD0CECE' },
};
exports.bgLightGray = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FFE7E6E6' },
};
exports.bgVeryLightGray = {
type: 'pattern',
pattern: 'solid',
bgColor: { argb: 'FFF2F2F2' },
fgColor: { argb: 'FFF2F2F2' },
};
exports.bgLightGreen = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FFCEEED0' },
bgColor: { argb: 'FFCEEED0' },
};
exports.bgLightYellow = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FFFFF4CC' },
bgColor: { argb: 'FFFFF4CC' },
};
exports.bgLightRed = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FFFFC7CE' },
bgColor: { argb: 'FFFFC7CE' },
};
function headerRow(ws, row) {
for (let col = 0; col < ws.columnCount; col++) {
const cell = ws.getCell(row, col + 1);
cell.fill = exports.bgHeader;
cell.font = { bold: true };
}
}
exports.headerRow = headerRow;
function forEachCellInRow(ws, col, startRow, callback) {
for (let row = startRow; row <= ws.rowCount; row++) {
const cell = ws.getCell(row, col);
callback(cell);
}
}
exports.forEachCellInRow = forEachCellInRow;
function toCol(idx) {
let col = "";
do {
col = String.fromCharCode('A'.charCodeAt(0) + (idx - 1) % 26) + col;
idx = Math.floor((idx - 1) / 26);
} while (idx > 0);
return col;
}
exports.toCol = toCol;
function asNumber(value) {
if (value.match(/^-?\d+(?:\,\d+)?$/)) {
return parseFloat(value.replace(',', '.'));
}
if (value === '') { // empty strings lead to problems in Excel
return undefined;
}
return value;
}
exports.asNumber = asNumber;
async function writeExcel(table, fileName, formatter) {
const wb = new ExcelJS.Workbook();
const ws = wb.addWorksheet('Sheet1');
table.rawArray.forEach((row) => {
ws.addRow(row.map((val) => asNumber(val)));
});
if (!formatter) {
headerRow(ws, 1);
}
else {
formatter(ws);
}
await wb.xlsx.writeFile(fileName);
}
exports.writeExcel = writeExcel;
//# sourceMappingURL=excel.js.map
;