Nouvelle ronde
+
@@ -173,48 +225,100 @@ new Vue({
t.push(0); //index of "Toto", ghost player
});
this.tables = tables;
- this.pdts = tables.map( t => { return []; }); //empty pdts
this.sessions = tables.map( t => { return []; }); //empty sessions
- },
- shuffle: function() {
- this.doPairings();
+ this.scored = tables.map( t => { return false; }); //nothing scored yet
+ this.currentIndex = -1; //required if reset while scoring
},
showScoreForm: function(table,index) {
- if (this.pdts[index].length > 0)
- return; //already scored
- this.pdts[index] = _.times(table.length, _.constant(0));
- this.sessions[index] = _.times(table.length, _.constant(0));
+ if (this.sessions[index].length == 0)
+ this.sessions[index] = _.times(table.length, _.constant(0));
this.currentIndex = index;
},
setScore: function() {
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 pdts = [4, 2, 1, 0]; //TODO: ex-aequos ?!
- for (let i=0; i
sortedSessions[i+1].value)
+ {
+ let pdt = curSum / curCount;
+ for (let j=start; j<=i; j++)
+ this.players[this.tables[this.currentIndex][sortedSessions[j].index]].pdt += pdt;
+ curSum = 0;
+ curCount = 0;
+ start = i+1;
+ }
+ // Update sessions:
this.players[this.tables[this.currentIndex][i]].session += parseInt(this.sessions[this.currentIndex][i]);
}
+ this.scored[this.currentIndex] = true;
this.currentIndex = -1;
this.writeScoreToDb();
},
- resetScore: function() {
- this.pdts[this.currentIndex] = [];
- this.sessions[this.currentIndex] = [];
- this.currentIndex = -1;
+ },
+ },
+ 'my-timer': {
+ data: function() {
+ return {
+ time: 0, //remaining time, in seconds
+ running: false,
+ };
+ },
+ template: `
+
+
+ {{ formattedTime }}
+
+
+
+ `,
+ computed: {
+ formattedTime: function() {
+ let seconds = this.time % 60;
+ let minutes = Math.floor(this.time / 60);
+ return this.padToZero(minutes) + ":" + this.padToZero(seconds);
},
- writeScoreToDb: function()
- {
- let xhr = new XMLHttpRequest();
- xhr.open("POST", "scripts/rw_players.php");
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- let orderedPlayers = this.players
- .slice(1) //discard Toto
- .map( p => { return Object.assign({}, p); }) //deep (enough) copy
- .sort(this.sortByScore);
- xhr.send("players="+encodeURIComponent(JSON.stringify(orderedPlayers)));
+ },
+ methods: {
+ padToZero: function(a) {
+ if (a < 10)
+ return "0" + a;
+ return a;
},
+ pauseResume: function() {
+ this.running = !this.running;
+ if (this.running)
+ this.start();
+ },
+ reset: function(e) {
+ this.running = false;
+ this.time = 10; //1:30
+ },
+ start: function() {
+ if (!this.running)
+ return;
+ if (this.time == 0)
+ {
+ new Audio("sounds/gong.mp3").play();
+ this.running = false;
+ return;
+ }
+ setTimeout(() => {
+ if (this.running)
+ this.time--;
+ this.start();
+ }, 1000);
+ },
+ },
+ created: function() {
+ this.reset();
},
},
},
@@ -226,7 +330,7 @@ new Vue({
{
let players = JSON.parse(xhr.responseText);
players.forEach( p => {
- p.pdt = !!p.pdt ? parseInt(p.pdt) : 0;
+ p.pdt = !!p.pdt ? parseFloat(p.pdt) : 0;
p.session = !!p.session ? parseInt(p.session) : 0;
p.available = !!p.available ? p.available : 1; //use integer for fputcsv PHP func
});
@@ -244,14 +348,19 @@ new Vue({
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);
- },
+ // Used both in ranking and pairings:
sortByScore: function(a,b) {
return b.pdt - a.pdt + (Math.atan(b.session - a.session) / (Math.PI/2)) / 2;
},
+ writeScoreToDb: function() {
+ let xhr = new XMLHttpRequest();
+ xhr.open("POST", "scripts/rw_players.php");
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+ let orderedPlayers = this.players
+ .slice(1) //discard Toto
+ .map( p => { return Object.assign({}, p); }) //deep (enough) copy
+ .sort(this.sortByScore);
+ xhr.send("players="+encodeURIComponent(JSON.stringify(orderedPlayers)));
+ },
},
});