45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
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 p1 = d.filter((d) => d.winner === "Player 1").length;
|
|
document.getElementById("p1").innerHTML = p1;
|
|
const p2 = d.filter((d) => d.winner === "Player 2").length;
|
|
document.getElementById("p2").innerHTML = p2;
|
|
const draw = d.filter((d) => d.winner === "draw").length;
|
|
document.getElementById("draw").innerHTML = draw;
|
|
|
|
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);
|
|
sorttable.makeSortable(table);
|
|
}
|
|
letsGo();
|
|
|