From cbf6cd07e62cbc53a5651e5afc14f0a67c2eeacf Mon Sep 17 00:00:00 2001 From: DeathByDenim Date: Sun, 23 Apr 2023 12:00:42 -0400 Subject: [PATCH] Automatic score updating for Xonotic tournament --- scripts/deploy_xonotic.sh | 6 ++- website/js/xonscore.js | 96 +++++++++++++++++++++++++++++++++++++++ website/tournament.html | 12 +++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 website/js/xonscore.js diff --git a/scripts/deploy_xonotic.sh b/scripts/deploy_xonotic.sh index 9758c0d..93f7ece 100755 --- a/scripts/deploy_xonotic.sh +++ b/scripts/deploy_xonotic.sh @@ -53,7 +53,7 @@ sv_vote_call 1 sv_weaponstats_file http://www.xonotic.org/weaponbalance/ sv_logscores_console 1 sv_logscores_file 1 -sv_logscores_filename xonotic-scores.log +sv_logscores_filename xonscore.txt EOF cat > /etc/systemd/system/xonotic.service < { + const fields = row.split(":"); + if(fields.length > 1) { + const verb = fields[1] + switch(verb) { + case "scores": + map_name = fields[2]; + duration_in_seconds = fields[3]; + break; + case "labels": + if(fields[2] === "player") { + labels = fields[3].split(","); + } + break; + case "player": + if(fields[2] === "see-labels") { + let split_fields = fields[3].split(","); + let player_stats = {name: fields[6]}; + for(let i = 0; i < labels.length; i++) { + if(labels[i] != "") { + player_stats[labels[i]] = split_fields[i] + } + } + round_stats.push(player_stats); + } + break; + case "end": + if(round_stats.length > 0) { + stats.push({ + map_name: map_name, + duration_in_seconds: duration_in_seconds, + stats: round_stats + }) + } + round_stats = []; + labels = []; + duration_in_seconds = 0; + map_name = ""; + break; + } + } + }) + + return stats; +} + +function xonoticScoreUpdate() { + xonoticGetScores().then((data) => { + let tables = d3.select("#xonotic-results") + .selectAll("table") + .data(data) + .join( + (enter) => { + let table = enter.append("table"); + let thead = table.append("thead"); + thead.append("tr") + .append("th") + .attr("colspan", 5) + .text((d) => "Map name: " + d.map_name); + let headerrows = thead.append("tr"); + + ["Name", "Score", "Kills", "Deaths", "Suicides"].forEach((col) => { + headerrows.append("th").text(col); + }) + + table.append("tbody"); + return table; + }, + (update) => { + let u = update; + u.select("th").text((d) => "Map name: " + d.map_name); + return u; + }, + (exit) => exit.remove() + ) + .classed("table", true); + + let tbodies = tables.select('tbody'); + tbodies.selectAll("tr") + .data((d) => d.stats) + .join("tr") + .selectAll("td") + .data((d) => ["name", "score!!", "kills", "deaths<", "suicides<"].map((col) => d[col])) + .join("td") + .text((d) => d); + }); +} diff --git a/website/tournament.html b/website/tournament.html index 8a17ca4..4b2df43 100644 --- a/website/tournament.html +++ b/website/tournament.html @@ -2,6 +2,7 @@ layout: default nav_pill: tournament --- +

Tournament

{% assign sitetime = site.time | date: "%FT%T" %} {% assign nextevent = site.data.events | where_exp: "item", "item.date >= sitetime" | last %} @@ -23,6 +24,17 @@ nav_pill: tournament {% endif %} {% endfor %} +
+ + {% else %}

No tournaments have been planned for the next event.

{% endif %}