From 783174e2b97385ad87a5016999680b6410a0ec3d Mon Sep 17 00:00:00 2001 From: felix Date: Mon, 16 Nov 2020 19:07:55 +0100 Subject: [PATCH] Replace mean by median in final leaderboard --- game_full.py | 10 ++++++++-- static/script/main.js | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/game_full.py b/game_full.py index 338483d..cc94110 100644 --- a/game_full.py +++ b/game_full.py @@ -3,6 +3,7 @@ from collections import defaultdict, Counter import pandas as pd +import numpy as np from game import GameRun, load_cities from city_parser import GameMap, GROUPED # SPECIALS, COUNTRIES, GROUPED @@ -260,10 +261,15 @@ def get_final_results(self): # score=self.scores.get(player, 0) # ) + def summary(values): + if not values: + return "-" + return np.median(values) + results = [dict( player=player, - dist=sum(distances.get(player, []))/self.n_run, - delta=sum(durations.get(player, []))/self.n_run, + dist=summary(distances.get(player, [])), + delta=summary(durations.get(player, [])), score=self.scores.get(player, 0) ) for player in sorted(self.players, key=lambda p: -self.scores.get(p, 0))] diff --git a/static/script/main.js b/static/script/main.js index baed773..2a9cc74 100644 --- a/static/script/main.js +++ b/static/script/main.js @@ -210,14 +210,24 @@ document.addEventListener("DOMContentLoaded", () => { } function fullShowResults(results){ let table = ""; + function prettify(value, unit){ + if (value === "-") { + return "-"; + } else { + const roundingFactor = (unit === "s") ? 100 : 1; + let roundedValue = Math.round(value * roundingFactor) / roundingFactor; + roundedValue = String(roundedValue).replace(/(?!^)(?=(?:\d{3})+(?:\.|$))/gm, ' ').replace(".", ","); + return roundedValue + " " + unit; + } + } results.forEach((el, i) => { var crown = (i === 0) ? " " : ""; table += ` ${i+1} ${getPlayerName(el.player)}${crown} - ${Math.round(el.dist)}km - ${Math.round(100*el.delta)/100}s - ${el.score}pts + ${prettify(el.dist, "km")} + ${prettify(el.delta, "s")} + ${prettify(el.score, "pts")} ` }); $("final-results").innerHTML = table;