Fixed parser
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 53s

This commit is contained in:
Torsten Schulz (local)
2026-08-10 15:26:51 +02:00
parent 5f2de5e671
commit cfe2cbeec0

View File

@@ -157,9 +157,14 @@ class PDFParserService {
let guestFromColumns = null;
let codeFromColumns = null;
if (columnSegments && columnSegments.length >= 3) {
homeFromColumns = columnSegments[1]?.trim() || null;
guestFromColumns = columnSegments[2]?.trim() || null;
if (columnSegments && columnSegments.length >= 4) {
// In the nuLiga code table the two team columns follow the time.
// Do not rely on fixed offsets: the weekday is a separate PDF item.
const timeColumnIndex = columnSegments.findIndex((segment) => /\b\d{1,2}:\d{2}\b/.test(segment));
if (timeColumnIndex >= 0) {
homeFromColumns = columnSegments[timeColumnIndex + 1]?.trim() || null;
guestFromColumns = columnSegments[timeColumnIndex + 2]?.trim() || null;
}
const lastSegment = columnSegments[columnSegments.length - 1];
if (lastSegment) {
const candidateCode = lastSegment.replace(/\s+/g, '').trim();
@@ -255,6 +260,25 @@ class PDFParserService {
teamsPart = teamsPart.replace(new RegExp(`${code}$`), '').trim();
}
// A layout-aware extraction has already identified the team
// columns unambiguously. Use them directly instead of trying
// to reconstruct column boundaries from the flattened text.
// This also preserves names with characters such as "ä".
if (code && homeFromColumns && guestFromColumns) {
matches.push({
date: date,
time: time,
homeTeamName: homeFromColumns,
guestTeamName: guestFromColumns,
code: code,
homePin: null,
guestPin: null,
clubId: clubId,
rawLine: line
});
continue;
}
if (code || pinMatch) {
@@ -831,8 +855,10 @@ class PDFParserService {
return;
}
const [scaleX, , , , x, y] = item.transform;
const width = (item.width || 0) * (scaleX || 1);
const [, , , , x, y] = item.transform;
// PDF.js already reports item.width in page coordinates. Applying
// the text scale again turns separate table columns into one line.
const width = item.width || 0;
let targetLine = pageLines.find((line) => Math.abs(line.y - y) < lineTolerance);
if (!targetLine) {