Skip to content

Commit

Permalink
Replace mean by median in final leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-martel committed Nov 16, 2020
1 parent 73526ed commit 783174e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 8 additions & 2 deletions game_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))]

Expand Down
16 changes: 13 additions & 3 deletions static/script/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ? " <i class='fas fa-crown first-place'></i>" : "";
table += `<tr>
<td class="rank">${i+1}</td>
<td class="player-name">${getPlayerName(el.player)}${crown}</td>
<td class="player-score-deets"><i class="fas fa-ruler"></i>${Math.round(el.dist)}km</td>
<td class="player-score-deets"><i class="fas fa-clock"></i>${Math.round(100*el.delta)/100}s</td>
<td class="player-score">${el.score}pts</td>
<td class="player-score-deets"><i class="fas fa-ruler"></i>${prettify(el.dist, "km")}</td>
<td class="player-score-deets"><i class="fas fa-clock"></i>${prettify(el.delta, "s")}</td>
<td class="player-score">${prettify(el.score, "pts")}</td>
</tr>`
});
$("final-results").innerHTML = table;
Expand Down

0 comments on commit 783174e

Please sign in to comment.