fix(sync): use frequency-based date column detection for Untersuchungen to find all exam rows

This commit is contained in:
Matthias Hochmeister
2026-04-20 08:04:44 +02:00
parent 84254a0b71
commit d5291360c9

View File

@@ -1032,17 +1032,25 @@ async function scrapeMemberUntersuchungen(
cells: r.cells.map(c => c.replace(/\u00A0/g, ' ').trim()),
}));
// Find date column
// Find date column dynamically: count date matches per column across ALL rows
// and pick the column with the MOST matches (avoids picking stray date in nav tables)
const datePattern = /^\d{2}\.\d{2}\.\d{4}$/;
let dateColIdx = -1;
const dateCountByCol: Record<number, number> = {};
for (const r of mapped) {
for (let ci = 0; ci < r.cells.length; ci++) {
if (datePattern.test(r.cells[ci] ?? '')) {
dateColIdx = ci;
break;
dateCountByCol[ci] = (dateCountByCol[ci] || 0) + 1;
}
}
if (dateColIdx >= 0) break;
}
let dateColIdx = -1;
let maxCount = 0;
for (const [col, count] of Object.entries(dateCountByCol)) {
const colNum = Number(col);
if (count > maxCount || (count === maxCount && (dateColIdx === -1 || colNum < dateColIdx))) {
dateColIdx = colNum;
maxCount = count;
}
}
const dataRows = dateColIdx >= 0