document.addEventListener('DOMContentLoaded', async () => {
const tbody = document.getElementById('historyTableBody');
if(!tbody) return;
async function fetchHistory() {
try {
const res = await fetch('/api/history');
const historyData = await res.json();
tbody.innerHTML = '';
if (historyData.length === 0) {
tbody.innerHTML = '
The AI Engine has booted up. Waiting for live match data to process before generating history records... |
';
return;
}
historyData.forEach(item => {
const tr = document.createElement('tr');
tr.innerHTML = `
${item.time} |
${item.match} |
${item.over} Overs |
${item.score} |
${item.prediction} |
${item.acc ? '✓ Correct Prediction' : '✗ Model Inaccuracy'} |
`;
tbody.appendChild(tr);
});
} catch(e) {
console.error("History fetch error", e);
}
}
fetchHistory();
// Refresh history grid every 15 seconds automatically
setInterval(fetchHistory, 15000);
});