X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=js%2Findex.js;h=649e44c359f421a16bb182682fa8c2bbb81ecfe2;hb=ade10194c01dcf4a71fc92f055d5dc53ac555e0e;hp=870be76d8b0429c2f1e8f6835d904c82a0b7fd10;hpb=fd4a69e4ea369afb39c01f1207d79b0ab2d4cc8e;p=westcastle.git diff --git a/js/index.js b/js/index.js index 870be76..649e44c 100644 --- a/js/index.js +++ b/js/index.js @@ -46,43 +46,33 @@ new Vue({ }, }, 'my-ranking': { - props: ['players'], - data: function() { - return { - sortMethod: "score", - }; - }, + props: ['players','sortByScore','rankPeople'], template: `
- - + + - + - +
Rang JoueurScorePdTPointsMini-pts
{{ p.rank }} {{ p.prenom }} {{ p.nom }}{{ p.score }} {{ p.pdt }}{{ p.session }}
`, - 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 == "score" - ? this.sortByScore - : this.sortByPdt; - 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
-

Table {{ index+1 }}

- +
{{ players[i].prenom }} {{ players[i].nom }}{{ pdts[index][j] }}{{ sessions[index][j] }}
@@ -137,7 +119,7 @@ new Vue({ {{ players[tables[currentIndex][i]].prenom }} {{ players[tables[currentIndex][i]].nom }} - +
@@ -152,7 +134,7 @@ new Vue({ // Simple case first: 4 by 4 let tables = []; let currentTable = []; - let ordering = _.shuffle(_.range(this.players.length)); //TODO: take scores into account? + let ordering = _.shuffle(_.range(this.players.length)); for (let i=0; i { return []; }); //empty scores this.pdts = tables.map( t => { return []; }); //empty pdts + this.sessions = tables.map( t => { return []; }); //empty sessions }, shuffle: function() { this.doPairings(); }, showScoreForm: function(table,index) { - if (this.scores[index].length > 0) + if (this.pdts[index].length > 0) return; //already scored - this.scores[index] = _.times(table.length, _.constant(0)); this.pdts[index] = _.times(table.length, _.constant(0)); + this.sessions[index] = _.times(table.length, _.constant(0)); this.currentIndex = index; }, setScore: function() { - let sortedPdts = this.pdts[this.currentIndex] + let sortedSessions = this.sessions[this.currentIndex] .map( (s,i) => { return {value:s, index:i}; }) .sort( (a,b) => { return parseInt(b.value) - parseInt(a.value); }); - let scores = [4, 2, 1, 0]; //TODO: ex-aequos ?! + let pdts = [4, 2, 1, 0]; //TODO: ex-aequos ?! for (let i=0; i { return Object.assign({}, p); }) //deep (enough) copy - .sort( (a,b) => { return b.score - a.score; }); + .sort(this.sortByScore); xhr.send("players="+encodeURIComponent(JSON.stringify(orderedPlayers))); }, }, @@ -244,15 +226,15 @@ new Vue({ { let players = JSON.parse(xhr.responseText); players.forEach( p => { - p.score = !!p.score ? parseInt(p.score) : 0; p.pdt = !!p.pdt ? parseInt(p.pdt) : 0; + p.session = !!p.session ? parseInt(p.session) : 0; p.available = !!p.available ? p.available : 1; //use integer for fputcsv PHP func }); players.unshift({ //add ghost 4th player for 3-players tables prenom: "Toto", nom: "", - score: 0, pdt: 0, + session: 0, available: 0, }); self.players = players; @@ -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; + }, + }, });