X-Git-Url: https://git.auder.net/game/current/gitweb.js?a=blobdiff_plain;f=js%2Findex.js;h=649e44c359f421a16bb182682fa8c2bbb81ecfe2;hb=ade10194c01dcf4a71fc92f055d5dc53ac555e0e;hp=77287d8bcc9ad13c86cd49fad4cf85b712a31645;hpb=1d2d7593f3a9b1c78841040297c8c9b1752bd81c;p=westcastle.git
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: `
Rang |
Joueur |
- Points |
- Mini-pts |
+ Points |
+ Mini-pts |
-
+
{{ p.rank }} |
{{ p.prenom }} {{ p.nom }} |
{{ p.pdt }} |
@@ -70,19 +65,14 @@ new Vue({
`,
- 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;
+ },
+ },
});