start charting results

This commit is contained in:
2024-09-23 16:46:39 +01:00
parent 885a44be11
commit a9bd47b6bd
3 changed files with 117 additions and 2 deletions

48
index.html Normal file
View File

@ -0,0 +1,48 @@
<html>
<head>
</head>
<body>
<div id="chart">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" integrity="sha512-ZwR1/gSZM3ai6vCdI+LVF1zSq/5HznD3ZSTk7kajkaj4D292NLuduDCO1c/NT8Id+jE58KYLKT7hXnbtryGmMg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
async function letsGo() {
const req = await fetch("./runs.csv");
const data = await req.text();
let lines = data.split("\n").map((l) => l.trim()).filter((l) => l !== "");
const keys = lines.splice(0, 1)[0].split(",");
lines = lines.map((l) => l.split(","));
console.log(lines[0]);
const d = lines.map((line) => {
const datum = {};
line.forEach((cell, index) => datum[keys[index]] = cell);
return datum;
});
const table = document.createElement("table");
const thead = document.createElement("thead");
table.appendChild(thead);
const tr = document.createElement("tr");
for (const key of keys) {
const th = document.createElement("th");
th.innerText = key;
tr.appendChild(th);
}
thead.appendChild(tr);
const tbody = document.createElement("tbody");
for (const row of d) {
const tr = document.createElement("tr");
tr.innerHTML = `<td>${row.laps}</td><td>${row.p1_sp}</td><td>${row.p1_lead}</td><td>${row.p2_sp}</td><td>${row.p2_lead}</td><td>${row.winner}</td>`;
tbody.appendChild(tr);
}
table.appendChild(tbody);
document.getElementById("chart").appendChild(table);
}
letsGo();
</script>
</body>
</html>