Add ranking to Xonotic scripts and clean up names
This commit is contained in:
parent
75b55979ac
commit
e4f91b4b5a
|
@ -1,8 +1,14 @@
|
||||||
|
// Parse the Xonotic score log format and return a JSON
|
||||||
|
// The returned data contains data for the individual
|
||||||
|
// rounds as well as totals
|
||||||
async function xonoticGetScores() {
|
async function xonoticGetScores() {
|
||||||
const data = await fetch("xonscore.txt");
|
const data = await fetch("xonscore.txt");
|
||||||
const text = await data.text();
|
const text = await data.text();
|
||||||
|
|
||||||
let stats = [];
|
let stats = {
|
||||||
|
rounds: [],
|
||||||
|
totals: []
|
||||||
|
};
|
||||||
let map_name = "[unknown]";
|
let map_name = "[unknown]";
|
||||||
let duration_in_seconds = 0;
|
let duration_in_seconds = 0;
|
||||||
let labels = [];
|
let labels = [];
|
||||||
|
@ -23,8 +29,14 @@ async function xonoticGetScores() {
|
||||||
break;
|
break;
|
||||||
case "player":
|
case "player":
|
||||||
if(fields[2] === "see-labels") {
|
if(fields[2] === "see-labels") {
|
||||||
|
if(fields[5] === "spectator") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let split_fields = fields[3].split(",");
|
let split_fields = fields[3].split(",");
|
||||||
let player_stats = {name: fields[6]};
|
let player_name = fields[6]
|
||||||
|
.replace(/\^.../g, "")
|
||||||
|
.replaceAll("^7", "");
|
||||||
|
let player_stats = {name: player_name};
|
||||||
for(let i = 0; i < labels.length; i++) {
|
for(let i = 0; i < labels.length; i++) {
|
||||||
if(labels[i] != "") {
|
if(labels[i] != "") {
|
||||||
player_stats[labels[i]] = split_fields[i]
|
player_stats[labels[i]] = split_fields[i]
|
||||||
|
@ -36,7 +48,7 @@ async function xonoticGetScores() {
|
||||||
case "end":
|
case "end":
|
||||||
if(round_stats.length > 0) {
|
if(round_stats.length > 0) {
|
||||||
round_stats = round_stats.sort((a,b) => +a["score!!"] < +b["score!!"]);
|
round_stats = round_stats.sort((a,b) => +a["score!!"] < +b["score!!"]);
|
||||||
stats.push({
|
stats.rounds.push({
|
||||||
map_name: map_name,
|
map_name: map_name,
|
||||||
duration_in_seconds: duration_in_seconds,
|
duration_in_seconds: duration_in_seconds,
|
||||||
stats: round_stats
|
stats: round_stats
|
||||||
|
@ -51,14 +63,40 @@ async function xonoticGetScores() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let final = {};
|
||||||
|
stats.rounds.forEach((map) => {
|
||||||
|
map.stats.forEach((stat) => {
|
||||||
|
if(stat.name in final) {
|
||||||
|
final[stat.name] += +stat["score!!"]
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final[stat.name] = +stat["score!!"]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.keys(final).forEach(name => {
|
||||||
|
stats.totals.push({
|
||||||
|
name: name,
|
||||||
|
score: final[name]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
stats.totals = stats.totals.sort((a,b) => a.score < b.score);
|
||||||
|
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xonoticScoreUpdate() {
|
function xonoticScoreUpdate() {
|
||||||
xonoticGetScores().then((data) => {
|
xonoticGetScores().then((data) => {
|
||||||
|
d3.select("#xonotic-ranking")
|
||||||
|
.selectAll("li")
|
||||||
|
.data(data.totals)
|
||||||
|
.join("li")
|
||||||
|
.text(d => d.name + " (" + d.score + ")");
|
||||||
|
|
||||||
let tables = d3.select("#xonotic-results")
|
let tables = d3.select("#xonotic-results")
|
||||||
.selectAll("table")
|
.selectAll("table")
|
||||||
.data(data)
|
.data(data.rounds)
|
||||||
.join(
|
.join(
|
||||||
(enter) => {
|
(enter) => {
|
||||||
let table = enter.append("table");
|
let table = enter.append("table");
|
||||||
|
|
|
@ -24,6 +24,9 @@ nav_pill: tournament
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
<h2>Ranking</h2>
|
||||||
|
<ol id="xonotic-ranking"></ol>
|
||||||
|
<h2>Rounds</h2>
|
||||||
<div id="xonotic-results"></div>
|
<div id="xonotic-results"></div>
|
||||||
<script>
|
<script>
|
||||||
if(typeof d3 === 'undefined') {
|
if(typeof d3 === 'undefined') {
|
||||||
|
|
Reference in New Issue