From ea5275d04ec99fff210fe1212bf66e3a644b3a44 Mon Sep 17 00:00:00 2001 From: ChK Date: Tue, 17 Mar 2026 08:54:36 +0100 Subject: [PATCH] CalculateAction --- public/calculateActions.js | 79 ++++++++++++++++++++++++++++++++++++++ public/index.html | 7 ++++ public/styles.css | 2 + server/server.js | 4 +- 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100755 public/calculateActions.js diff --git a/public/calculateActions.js b/public/calculateActions.js new file mode 100755 index 0000000..1f3a3d1 --- /dev/null +++ b/public/calculateActions.js @@ -0,0 +1,79 @@ +// calculateActions.js +// Funktionen zum Berechnen von Vorschlägen basierend auf den neuesten CSV-Daten + +const analysisLogEl = document.getElementById('analysis-log'); + +function appendToAnalysis(line) { + const now = new Date().toISOString(); + analysisLogEl.value += `[${now}] ${line}\n`; + analysisLogEl.scrollTop = analysisLogEl.scrollHeight; +} + +async function fetchCSV() { + console.log('Lade und verarbeite CSV-Daten...'); + const res = await fetch('/api/latest-snapshot'); + if (!res.ok) throw new Error('Fehler beim Laden des Snapshots'); + + let data; + if (res.headers.get('content-type')?.includes('application/json')) { + data = await res.json(); + } else { + const csvData = await res.text(); + data = { filename: 'latest.csv', mtime: new Date().toISOString(), content: csvData }; + } + + // CSV parsen + const lines = data.content.trim().split('\n'); + if (lines.length < 2) { + throw new Error('Keine oder unvollständige Daten'); + } + + const headers = lines[0].split(',').map(h => h.trim()); + const rows = lines.slice(1).map(line => { + const cells = line.split(','); + let obj = {}; + headers.forEach((h, i) => { + const val = cells[i]?.trim(); + obj[h] = isNaN(val) ? val : parseFloat(val); + }); + return obj; + }); + + return { data, headers, rows }; +} + +async function readValues( data, headers, rows ){ + appendToAnalysis('Geladene Daten: ' + JSON.stringify(data, null, 2)); + appendToAnalysis('Headers: ' + JSON.stringify(headers)); + appendToAnalysis('Parsed rows: ' + JSON.stringify(rows, null, 2)); + + // Hier kannst du manuell mit den Daten arbeiten + // Beispiel: Finde die Position mit der höchsten x_mm + let maxX = -Infinity; + let bestRow = null; + rows.forEach(row => { + if (row.x_mm > maxX) { + maxX = row.x_mm; + bestRow = row; + } + }); + appendToAnalysis('Position mit höchster x_mm: ' + JSON.stringify(bestRow)); + + // Füge hier deine Logik für Vorschläge hinzu + // z.B. calculateSuggestions(rows); +} + +async function calculate() { + try { + appendToAnalysis('Starte Berechnung...'); + const { data, headers, rows } = await fetchCSV(); + await readValues( data, headers, rows ); + appendToAnalysis('Berechnung abgeschlossen.'); + } catch (err) { + appendToAnalysis('Fehler in calculate: ' + err.message); + } + // Schreibe den die Länge der CSV Datei und die vierte Zeile in das Analysis&Reasoning fenster. +} + +// Export für Module, falls benötigt +// export { fetchCSV, calculate }; \ No newline at end of file diff --git a/public/index.html b/public/index.html index 48ef3bc..b46205f 100755 --- a/public/index.html +++ b/public/index.html @@ -19,6 +19,7 @@ + +
+ + +
+
@@ -46,5 +52,6 @@ + diff --git a/public/styles.css b/public/styles.css index 55e9170..96177bf 100755 --- a/public/styles.css +++ b/public/styles.css @@ -13,6 +13,8 @@ main{ display:grid; grid-template-columns:1fr; gap:16px; padding:16px; max-width .controls button:hover{ border-color: var(--accent); } .log{ display:flex; flex-direction:column; gap:8px; } #log{ width:100%; height:360px; background:#0b1220; color:var(--fg); border:1px solid #1f2937; border-radius:8px; padding:8px; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size:12px; } +.analysis{ display:flex; flex-direction:column; gap:8px; } +#analysis-log{ width:100%; height:200px; background:#0b1220; color:var(--fg); border:1px solid #1f2937; border-radius:8px; padding:8px; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size:12px; } .snapshot{ display:flex; flex-direction:column; gap:8px; } #snapshot-info{ font-size:14px; color:var(--muted); } #snapshot-table{ width:100%; border-collapse:collapse; background:#0b1220; color:var(--fg); border:1px solid #1f2937; border-radius:8px; overflow:hidden; } diff --git a/server/server.js b/server/server.js index 3ff3e11..5711734 100755 --- a/server/server.js +++ b/server/server.js @@ -93,9 +93,7 @@ function connectWss() { function scheduleReconnect() { wsState.reconnectAttempts += 1; - const base = 1000; // 1s - const max = 30000; // 30s - const delay = Math.min(max, base * Math.pow(2, wsState.reconnectAttempts)); + const delay = 10000; // 10s logAndBroadcast('info', `Reconnecting in ${Math.round(delay/1000)}s...`); setTimeout(connectWss, delay); }