document.addEventListener('DOMContentLoaded', function() { // Initialize Chart const ctx = document.getElementById('hashrateChart').getContext('2d'); const hashrateChart = new Chart(ctx, { type: 'line', data: { labels: [], datasets: [{ label: 'Hashrate (MH/s)', data: [], borderColor: '#0d6efd', backgroundColor: 'rgba(13, 110, 253, 0.1)', borderWidth: 2, fill: true, tension: 0.4 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { x: { grid: { color: '#333' }, ticks: { color: '#aaa' } }, y: { grid: { color: '#333' }, ticks: { color: '#aaa' }, beginAtZero: true } } } }); // Helper to format large numbers function formatNumber(num) { return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'); } function updateDashboard() { fetch('/api/data') .then(response => response.json()) .then(data => { const summary = data.summary; const devs = data.devs; const pools = data.pools; // Update Top Stats if (summary) { // Cgminer returns MHS in different fields depending on version, usually "MHS 5s" or similar // The API returns dict keys. // Let's inspect typical cgminer summary keys: "MHS av", "MHS 5s", "Accepted", "Hardware Errors", "Utility" const mhs = summary['MHS 5s'] || summary['MHS av'] || 0; document.getElementById('stat-mhs').innerText = parseFloat(mhs).toFixed(2); document.getElementById('stat-accepted').innerText = formatNumber(summary['Accepted'] || 0); document.getElementById('stat-hw').innerText = formatNumber(summary['Hardware Errors'] || 0); } // Update Max Temp let maxTemp = 0; if (devs && devs.length > 0) { devs.forEach(dev => { if (dev['Temperature'] > maxTemp) maxTemp = dev['Temperature']; }); } 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 = `