diff --git a/static/js/dashboard.js b/static/js/dashboard.js index d482b93..fd7b679 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -61,6 +61,8 @@ document.addEventListener('DOMContentLoaded', function() { fetch('/api/data') .then(response => response.json()) .then(data => { + console.log("API Data:", data); // Debugging + const summary = data.summary; const devs = data.devs; const pools = data.pools; @@ -81,14 +83,27 @@ document.addEventListener('DOMContentLoaded', function() { val = parseFloat(mhs).toFixed(2); } - document.getElementById('stat-mhs').innerText = val; - // Note: HTML might still say MH/s in static part, need to update ID or text node of

- // But simplified: - const unitElem = document.querySelector('#stat-mhs').nextElementSibling; - if(unitElem) unitElem.innerText = unit; + const statMhs = document.getElementById('stat-mhs'); + if (statMhs) { + statMhs.innerText = val; + const unitElem = document.querySelector('#stat-mhs').nextElementSibling; + if(unitElem) unitElem.innerText = unit; + } document.getElementById('stat-accepted').innerText = formatNumber(summary['Accepted'] || 0); document.getElementById('stat-hw').innerText = formatNumber(summary['Hardware Errors'] || 0); + + // Update Chart + const now = new Date(); + const timeLabel = now.getHours() + ':' + String(now.getMinutes()).padStart(2, '0') + ':' + String(now.getSeconds()).padStart(2, '0'); + + if (hashrateChart.data.labels.length > 60) { + hashrateChart.data.labels.shift(); + hashrateChart.data.datasets[0].data.shift(); + } + hashrateChart.data.labels.push(timeLabel); + hashrateChart.data.datasets[0].data.push(mhs); + hashrateChart.update(); } // Update Device Count @@ -96,28 +111,15 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('stat-devices').innerText = devs.length; } - // Helper to find temp in stats if missing in devs - // Cgminer 'stats' command returns specific driver info. - // Structure: stats ->STATS -> list of dicts. usually one dict per device with ID keys like 'MM ID 0', etc. - // Or simplified list. - function getTempFallback(devId, statsData) { - // Try to find matching ID in stats - // This is heuristic as structure varies wildy between forks - return 0; - } - // Update Devs Table & Max Temp let maxTemp = 0; const tbody = document.getElementById('devs-table-body'); - tbody.innerHTML = ''; if (devs && devs.length > 0) { + tbody.innerHTML = ''; // Clear only if we have data devs.forEach(dev => { let temp = dev['Temperature'] || 0; - // Fallback logic could go here if we understood the STATS structure for this specific fork - // For now we rely on standard API. - if (temp > maxTemp) maxTemp = temp; const tr = document.createElement('tr'); @@ -136,50 +138,10 @@ document.addEventListener('DOMContentLoaded', function() { tbody.appendChild(tr); }); } else { - tbody.innerHTML = 'Keine Geräte gefunden...'; + tbody.innerHTML = 'Keine Geräte gefunden... (API Connected)'; } document.getElementById('stat-temp').innerText = maxTemp.toFixed(1); - // Update Chart - const now = new Date(); - const timeLabel = now.getHours() + ':' + String(now.getMinutes()).padStart(2, '0') + ':' + String(now.getSeconds()).padStart(2, '0'); - - if (summary) { - const currentMhs = summary['MHS 5s'] || summary['MHS av'] || 0; - - if (hashrateChart.data.labels.length > 60) { // Keep last 60 points - hashrateChart.data.labels.shift(); - hashrateChart.data.datasets[0].data.shift(); - } - hashrateChart.data.labels.push(timeLabel); - hashrateChart.data.datasets[0].data.push(currentMhs); - hashrateChart.update(); - } - - // Update Devs Table - const tbody = document.getElementById('devs-table-body'); - tbody.innerHTML = ''; - if (devs && devs.length > 0) { - devs.forEach(dev => { - const tr = document.createElement('tr'); - tr.innerHTML = ` - ${dev['ID']} - ${dev['Name'] || 'Gridseed'} - ${dev['Enabled']} - ${dev['Status']} - ${dev['Temperature']} - ${parseFloat(dev['MHS 5s'] || 0).toFixed(2)} - ${parseFloat(dev['MHS av'] || 0).toFixed(2)} - ${dev['Accepted']} - ${dev['Rejected']} - ${dev['Hardware Errors']} - `; - tbody.appendChild(tr); - }); - } else { - tbody.innerHTML = 'Keine Geräte gefunden...'; - } - // Update Pools const poolList = document.getElementById('pool-list'); poolList.innerHTML = ''; @@ -226,4 +188,4 @@ document.addEventListener('DOMContentLoaded', function() { setInterval(updateLog, 5000); updateDashboard(); // Initial call updateLog(); -}); +}); \ No newline at end of file