1
0

feat: v2
All checks were successful
Remote Deploy / deploy (push) Successful in 1m11s

Support of teacher absence format: "za Vn zastupuje Jk"
This commit is contained in:
2026-01-04 14:02:10 +01:00
parent 0325ce1815
commit 6b383b1af4
7 changed files with 95 additions and 12 deletions

View File

@@ -12,8 +12,8 @@
* GNU General Public License for more details.
*/
import parseV1 from "./parse/v1.js";
import parseV1V2 from "./parse/v1_v2.js";
export default async function parseThisShit(downloadedFilePath) {
await parseV1(downloadedFilePath)
await parseV1V2(downloadedFilePath)
}

View File

@@ -17,7 +17,7 @@ import fs from "fs"
import parseAbsence from "../utils/parseAbsence.js"
import parseTeachers from "../utils/parseTeachers.js"
export default async function parseV1(downloadedFilePath) {
export default async function parseV1V2(downloadedFilePath) {
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(downloadedFilePath);
const teacherMap = await parseTeachers();
@@ -216,7 +216,29 @@ export default async function parseV1(downloadedFilePath) {
}
}
fs.writeFileSync("db/v1.json", JSON.stringify(data, null, 2));
fs.writeFileSync("db/v2.json", JSON.stringify(data, null, 2));
// Modify the data for v1
const copy = JSON.parse(JSON.stringify(data));
copy.schedule.forEach(day => {
if (!Array.isArray(day.ABSENCE)) return;
day.ABSENCE = day.ABSENCE.map(old => {
if (old.type === "zastoupen") {
console.log("pepa")
return {
teacher: old.teacher,
teacherCode: old.teacherCode,
type: "wholeDay",
hours: null
};
}
return old;
});
});
fs.writeFileSync("db/v1.json", JSON.stringify(copy, null, 2))
}
//parseThisShit("downloads/table.xlsx")
parseV1V2("db/current.xlsx")

View File

@@ -67,7 +67,7 @@ async function handleError(page, err) {
let browser, page;
try {
browser = await puppeteer.launch({
headless: 'new',
headless: false,
userDataDir: VOLUME_PATH,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});

View File

@@ -98,6 +98,7 @@ export default function parseAbsence(input, teacherMap = {}) {
const markConsumed = (start, end) => consumed.push([start, end]);
const isConsumed = (i) => consumed.some(([a, b]) => i >= a && i < b);
// 1. Teachers with specific hours (e.g. "Ab 1-4")
const teacherListThenSpecRe =
/([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\+|-\d+|,\d+)?)(?![A-Za-z])/g;
@@ -115,6 +116,7 @@ export default function parseAbsence(input, teacherMap = {}) {
markConsumed(matchStart, matchEnd);
}
// 2. Teachers with "-exk" suffix
const teacherExkRe = /([A-Za-z]+)-exk/gi;
while ((m = teacherExkRe.exec(s)) !== null) {
const matchStart = m.index;
@@ -132,7 +134,34 @@ export default function parseAbsence(input, teacherMap = {}) {
markConsumed(matchStart, matchEnd);
}
// Standalone teachers → whole day
// ---------------------------------------------------------
// 3. Substitution Pattern: "za Vn zastupuje Jk"
// ---------------------------------------------------------
const substitutionRe = /za\s+([A-Za-z]+)\s+zastupuje\s+([A-Za-z]+)/gi;
while ((m = substitutionRe.exec(s)) !== null) {
const matchStart = m.index;
const matchEnd = substitutionRe.lastIndex;
if (isConsumed(matchStart)) continue;
const missingCode = m[1];
const substituteCode = m[2];
const missingResolved = resolveTeacher(missingCode, teacherMap);
const subResolved = resolveTeacher(substituteCode, teacherMap);
results.push({
teacher: missingResolved.name,
teacherCode: missingResolved.code.toLowerCase(),
type: "zastoupen",
zastupuje: {
teacher: subResolved.name,
teacherCode: subResolved.code.toLowerCase()
}
});
markConsumed(matchStart, matchEnd);
}
const teacherOnlyRe = /([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)/g;
while ((m = teacherOnlyRe.exec(s)) !== null) {
const matchStart = m.index;
@@ -141,6 +170,9 @@ export default function parseAbsence(input, teacherMap = {}) {
const tList = m[1].split(/[,;]\s*/).filter(Boolean);
tList.forEach((t) => {
const lowerT = t.toLowerCase();
if (lowerT === 'za' || lowerT === 'zastupuje') return;
if (isTeacherToken(t)) results.push(makeResult(t, null, teacherMap));
else
results.push({
@@ -154,12 +186,12 @@ export default function parseAbsence(input, teacherMap = {}) {
markConsumed(matchStart, matchEnd);
}
// Bare specs without teacher → invalid
// 5. Bare specs without teacher → invalid
const specOnlyRe = /\b(\d+(?:\+|-\d+|,\d+)?)\b/g;
while ((m = specOnlyRe.exec(s)) !== null) {
const matchStart = m.index;
if (isConsumed(matchStart)) continue;
if (m[1].trim() == "exk") continue; // Exkurze, will be implemented later
if (m[1].trim() == "exk") continue;
results.push({
type: "invalid",