From: Benjamin Auder Date: Thu, 28 Dec 2017 13:50:03 +0000 (+0100) Subject: rename scoring: follow french Mahjong federation conventions X-Git-Url: https://git.auder.net/js/pieces/%7B%7B%20asset%28%27mixstore/doc/current/git-logo.png?a=commitdiff_plain;h=1d2d7593f3a9b1c78841040297c8c9b1752bd81c;p=westcastle.git rename scoring: follow french Mahjong federation conventions --- diff --git a/joueurs.csv.dist b/joueurs.csv.dist index 1a694b3..d78ed64 100644 --- a/joueurs.csv.dist +++ b/joueurs.csv.dist @@ -1 +1 @@ -prenom,nom,score,pdt,present +prenom,nom,pdt,session,present diff --git a/js/index.js b/js/index.js index 870be76..77287d8 100644 --- a/js/index.js +++ b/js/index.js @@ -49,7 +49,7 @@ new Vue({ props: ['players'], data: function() { return { - sortMethod: "score", + sortMethod: "pdt", }; }, template: ` @@ -58,23 +58,23 @@ new Vue({ Rang Joueur - Score - PdT + Points + Mini-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) sortedPlayers: function() { - let sortFunc = this.sortMethod == "score" - ? this.sortByScore - : this.sortByPdt; + 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); @@ -91,12 +91,12 @@ new Vue({ }, }, methods: { - sortByScore: function(a,b) { - return b.score - a.score; - }, sortByPdt: function(a,b) { return b.pdt - a.pdt; }, + sortBySession: function(a,b) { + return b.session - a.session; + }, }, }, 'my-pairings': { @@ -105,8 +105,8 @@ new Vue({ return { unpaired: [], tables: [], //array of arrays of players indices - scores: [], //scores for each table (3 or 4 players) - pdts: [], //"points de table" for each table (3 or 4 players) + pdts: [], //"points de table" for each table + sessions: [], //"mini-points" for each table currentIndex: -1, //table index for scoring }; }, @@ -114,13 +114,13 @@ new Vue({
-

Table {{ index+1 }}

- +
{{ players[i].prenom }} {{ players[i].nom }}{{ pdts[index][j] }}{{ sessions[index][j] }}
@@ -137,7 +137,7 @@ new Vue({ {{ players[tables[currentIndex][i]].prenom }} {{ players[tables[currentIndex][i]].nom }} - +
@@ -191,35 +191,35 @@ new Vue({ t.push(0); //index of "Toto", ghost player }); this.tables = tables; - this.scores = tables.map( t => { 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( (a,b) => { return b.pdt - a.pdt; }); //TODO: re-use sorting function in ranking component xhr.send("players="+encodeURIComponent(JSON.stringify(orderedPlayers))); }, }, @@ -244,15 +244,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;