From: Benjamin Auder Date: Thu, 28 Dec 2017 13:53:19 +0000 (+0100) Subject: improve / simplify ranking. Fix forgotten renaming X-Git-Url: https://git.auder.net/variants/img/current/assets/css/doc/R.css?a=commitdiff_plain;h=ade10194c01dcf4a71fc92f055d5dc53ac555e0e;p=westcastle.git improve / simplify ranking. Fix forgotten renaming --- diff --git a/css/index.css b/css/index.css index 54022f6..d92ca1c 100644 --- a/css/index.css +++ b/css/index.css @@ -148,14 +148,6 @@ table.ranking tr:not(.title):hover, table.ranking tr:not(.title):nth-child(even) background-color: lightyellow; } -table.ranking th.scoring { - cursor: pointer; -} - -.active { - background-color: yellow; -} - /* pairings div */ button.block { diff --git a/index.html b/index.html index 1392bfe..1360c13 100644 --- a/index.html +++ b/index.html @@ -19,8 +19,8 @@
- - + +
diff --git a/js/index.js b/js/index.js index 77287d8..649e44c 100644 --- a/js/index.js +++ b/js/index.js @@ -46,22 +46,17 @@ new Vue({ }, }, 'my-ranking': { - props: ['players'], - data: function() { - return { - sortMethod: "pdt", - }; - }, + props: ['players','sortByScore','rankPeople'], template: `
- - + + - + @@ -70,19 +65,14 @@ new Vue({
Rang JoueurPointsMini-ptsPointsMini-pts
{{ p.rank }} {{ p.prenom }} {{ p.nom }} {{ p.pdt }}
`, - computed: { //TODO: first sort on score, then on Pdt (and reciprocally) --> function add fraction relative Pdt / score (compute min max first, take care of 0 case) + computed: { sortedPlayers: function() { - let sortFunc = this.sortMethod == "pdt" - ? this.sortByPdt - : this.sortBySession; - let res = this.players - .map( p => { return Object.assign({}, p); }) //to not alter original array - .sort(sortFunc); + let res = this.rankPeople(); // Add rank information (taking care of ex-aequos) let rank = 1; for (let i=0; i { return Object.assign({}, p); }) //deep (enough) copy - .sort( (a,b) => { return b.pdt - a.pdt; }); //TODO: re-use sorting function in ranking component + .sort(this.sortByScore); xhr.send("players="+encodeURIComponent(JSON.stringify(orderedPlayers))); }, }, @@ -261,4 +243,15 @@ new Vue({ xhr.open("GET", "scripts/rw_players.php", true); xhr.send(null); }, + methods: { + rankPeople: function() { + return this.players + .slice(1) //discard Toto + .map( p => { return Object.assign({}, p); }) //to not alter original array + .sort(this.sortByScore); + }, + sortByScore: function(a,b) { + return b.pdt - a.pdt + (Math.atan(b.session - a.session) / (Math.PI/2)) / 2; + }, + }, }); diff --git a/scripts/rw_players.php b/scripts/rw_players.php index 3f641c2..b5bdabc 100644 --- a/scripts/rw_players.php +++ b/scripts/rw_players.php @@ -12,8 +12,8 @@ if (!isset($_POST["players"])) $players[$row] = array( "prenom" => $data[0], "nom" => $data[1], - "score" => count($data)>=3 ? $data[2] : 0, - "pdt" => count($data)>=4 ? $data[3] : 0, + "pdt" => count($data)>=3 ? $data[2] : 0, + "session" => count($data)>=4 ? $data[3] : 0, "available" => count($data)>=5 ? $data[4] : 1, ); $row++; @@ -25,7 +25,7 @@ else { // Write header + all players $handle = fopen("../joueurs.csv", "w"); - fputcsv($handle, ["prenom","nom","score","pdt","present"]); + fputcsv($handle, ["prenom","nom","pdt","session","present"]); $players = json_decode($_POST["players"]); foreach ($players as $p) fputcsv($handle, (array)$p);