Refactor PDF upload and CSV parsing logic in 'spielplaene' and 'mannschaften' components; implement automatic delimiter detection for CSV files and enhance hall information extraction for improved data handling. Update UI to remove PDF upload section and streamline CSV upload process.

This commit is contained in:
Torsten Schulz (local)
2025-10-24 01:23:57 +02:00
parent 7660f7cf7b
commit f80a1e5ea9
4 changed files with 233 additions and 240 deletions

View File

@@ -35,9 +35,19 @@ export default defineEventHandler(async (event) => {
})
}
const headers = lines[0].split(';')
// Automatische Erkennung des Trennzeichens
const firstLine = lines[0]
const tabCount = (firstLine.match(/\t/g) || []).length
const semicolonCount = (firstLine.match(/;/g) || []).length
const delimiter = tabCount > semicolonCount ? '\t' : ';'
console.log(`Verwendetes Trennzeichen: ${delimiter === '\t' ? 'Tab' : 'Semikolon'}`)
const headers = firstLine.split(delimiter)
console.log('CSV-Header:', headers)
const dataRows = lines.slice(1).map(line => {
const values = line.split(';')
const values = line.split(delimiter)
const row = {}
headers.forEach((header, index) => {
row[header] = values[index] || ''
@@ -45,6 +55,9 @@ export default defineEventHandler(async (event) => {
return row
})
console.log('Anzahl Datenzeilen:', dataRows.length)
console.log('Erste Datenzeile:', dataRows[0])
// Filtere Daten basierend auf Team
let filteredData = dataRows
@@ -183,6 +196,45 @@ export default defineEventHandler(async (event) => {
}
})
// Sammle Halle-Informationen für die jeweilige Mannschaft
const hallenMap = new Map()
// Debug: Zeige verfügbare Spalten
console.log('Verfügbare Spalten in gefilterten Daten:', Object.keys(filteredData[0] || {}))
filteredData.forEach((row, index) => {
// Suche Halle-Spalten mit verschiedenen möglichen Namen
const halleName = row.HalleName || row.halleName || row.Halle || row.halle || ''
const halleStrasse = row.HalleStrasse || row.halleStrasse || row.HalleStrasse || row.halleStrasse || ''
const hallePLZ = row.HallePLZ || row.hallePLZ || row.HallePLZ || row.hallePLZ || ''
const halleOrt = row.HalleOrt || row.halleOrt || row.HalleOrt || row.halleOrt || ''
const heimMannschaft = row.HeimMannschaft || ''
// Debug: Zeige Halle-Daten für erste paar Zeilen
if (index < 3) {
console.log(`Zeile ${index}: HalleName="${halleName}", HalleStrasse="${halleStrasse}", HallePLZ="${hallePLZ}", HalleOrt="${halleOrt}", HeimMannschaft="${heimMannschaft}"`)
}
if (halleName && halleStrasse && hallePLZ && halleOrt) {
const halleKey = `${halleName}|${halleStrasse}|${hallePLZ}|${halleOrt}`
if (!hallenMap.has(halleKey)) {
hallenMap.set(halleKey, {
name: halleName,
strasse: halleStrasse,
plz: hallePLZ,
ort: halleOrt,
mannschaften: new Set()
})
}
// Füge Heimmannschaft hinzu (unabhängig von Harheimer TC)
hallenMap.get(halleKey).mannschaften.add(heimMannschaft)
}
})
const hallenListe = Array.from(hallenMap.values())
console.log('Gefundene Hallen:', hallenListe.length, hallenListe)
// Generiere LaTeX-Code für PDF
const teamName = team.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase())
const currentDate = new Date().toLocaleDateString('de-DE')
@@ -256,6 +308,27 @@ ${filteredData.map(row => {
\\end{center}
`}
${hallenListe.length > 0 ? `
\\newpage
\\section*{Spielstätten}
\\vspace{0.5cm}
\\begin{longtable}{|p{5cm}|p{4cm}|p{8cm}|}
\\hline
\\textbf{Heimmannschaft} & \\textbf{Halle} & \\textbf{Adresse} \\\\
\\hline
\\endhead
${hallenListe.map(halle => {
const halleName = halle.name.replace(/&/g, '\\&')
const adresse = `${halle.strasse.replace(/&/g, '\\&')}, ${halle.plz} ${halle.ort.replace(/&/g, '\\&')}`
const mannschaften = Array.from(halle.mannschaften).map(m => m.replace(/&/g, '\\&')).join(', ')
return `${mannschaften} & ${halleName} & ${adresse} \\\\ \\hline`
}).join('\n')}
\\end{longtable}
` : ''}
\\vfill
\\begin{center}
\\small Generiert am ${currentDate} | Harheimer TC