CalculateAction
This commit is contained in:
79
public/calculateActions.js
Executable file
79
public/calculateActions.js
Executable file
@@ -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 };
|
||||
@@ -19,6 +19,7 @@
|
||||
<button data-cmd="STATUS">STATUS</button>
|
||||
<button data-cmd="RESET">RESET</button>
|
||||
<button data-cmd="PING">PING</button>
|
||||
<button onclick="calculate()">Calculate Actions</button>
|
||||
<input
|
||||
id="gcodePayload"
|
||||
type="text"
|
||||
@@ -34,6 +35,11 @@
|
||||
<textarea id="log" readonly></textarea>
|
||||
</section>
|
||||
|
||||
<section class="analysis">
|
||||
<label for="analysis">Analysis & Reasoning</label>
|
||||
<textarea id="analysis-log" readonly></textarea>
|
||||
</section>
|
||||
|
||||
<section class="snapshot">
|
||||
<label for="snapshot-content">Neuester Snapshot</label>
|
||||
<div id="snapshot-info"></div>
|
||||
@@ -46,5 +52,6 @@
|
||||
</footer>
|
||||
|
||||
<script src="/client.js"></script>
|
||||
<script src="/calculateActions.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user