+ methods: {
+ // 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)));
+ },
+ },