// Linux BenchTools - Dashboard Logic const { formatDate, formatRelativeTime, createScoreBadge, getScoreBadgeText, escapeHtml, showError, showEmptyState, copyToClipboard, showToast } = window.BenchUtils; const api = window.BenchAPI; // Load dashboard data async function loadDashboard() { try { await Promise.all([ loadStats(), loadTopDevices() ]); } catch (error) { console.error('Failed to load dashboard:', error); } } // Load statistics async function loadStats() { try { const devices = await api.getDevices({ page_size: 1000 }); const totalDevices = devices.total || 0; let totalBenchmarks = 0; let scoreSum = 0; let scoreCount = 0; let lastBenchDate = null; // Calculate stats from devices devices.items.forEach(device => { if (device.last_benchmark) { totalBenchmarks++; if (device.last_benchmark.global_score !== null) { scoreSum += device.last_benchmark.global_score; scoreCount++; } const benchDate = new Date(device.last_benchmark.run_at); if (!lastBenchDate || benchDate > lastBenchDate) { lastBenchDate = benchDate; } } }); const avgScore = scoreCount > 0 ? Math.round(scoreSum / scoreCount) : 0; // Update UI document.getElementById('totalDevices').textContent = totalDevices; document.getElementById('totalBenchmarks').textContent = totalBenchmarks; document.getElementById('avgScore').textContent = avgScore; document.getElementById('lastBench').textContent = lastBenchDate ? formatRelativeTime(lastBenchDate.toISOString()) : 'Aucun'; } catch (error) { console.error('Failed to load stats:', error); // Set default values on error document.getElementById('totalDevices').textContent = '0'; document.getElementById('totalBenchmarks').textContent = '0'; document.getElementById('avgScore').textContent = '0'; document.getElementById('lastBench').textContent = 'N/A'; } } // Load top devices async function loadTopDevices() { const container = document.getElementById('devicesTable'); try { const data = await api.getDevices({ page_size: 50 }); if (!data.items || data.items.length === 0) { showEmptyState(container, 'Aucun device trouvé. Exécutez un benchmark sur une machine pour commencer.', '📊'); return; } // Sort by global_score descending const sortedDevices = data.items.sort((a, b) => { const scoreA = a.last_benchmark?.global_score ?? -1; const scoreB = b.last_benchmark?.global_score ?? -1; return scoreB - scoreA; }); // Generate table HTML container.innerHTML = `
| # | Hostname | Description | Score Global | CPU | MEM | DISK | NET | GPU | Dernier Bench | Action |
|---|