From d5291360c94ce5ab5c49b9dcbba9c0f6673ef24a Mon Sep 17 00:00:00 2001 From: Matthias Hochmeister Date: Mon, 20 Apr 2026 08:04:44 +0200 Subject: [PATCH] fix(sync): use frequency-based date column detection for Untersuchungen to find all exam rows --- sync/src/scraper.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sync/src/scraper.ts b/sync/src/scraper.ts index a61246f..71998f0 100644 --- a/sync/src/scraper.ts +++ b/sync/src/scraper.ts @@ -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 = {}; 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