},
},
'my-ranking': {
- props: ['players'],
- data: function() {
- return {
- sortMethod: "pdt",
- };
- },
+ props: ['players','sortByScore','rankPeople'],
template: `
<div id="ranking">
<table class="ranking">
<tr class="title">
<th>Rang</th>
<th>Joueur</th>
- <th @click="sortMethod='pdt'" class="scoring" :class="{active: sortMethod=='pdt'}">Points</th>
- <th @click="sortMethod='session'" class="scoring" :class="{active: sortMethod=='session'}">Mini-pts</th>
+ <th>Points</th>
+ <th>Mini-pts</th>
</tr>
- <tr v-for="p in sortedPlayers" v-if="p.nom!=''">
+ <tr v-for="p in sortedPlayers">
<td>{{ p.rank }}</td>
<td>{{ p.prenom }} {{ p.nom }}</td>
<td>{{ p.pdt }}</td>
</table>
</div>
`,
- 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<res.length; i++)
{
- if (i==0 || sortFunc(res[i],res[i-1]) == 0)
+ if (i==0 || this.sortByScore(res[i],res[i-1]) == 0)
res[i].rank = rank;
else //strictly lower scoring
res[i].rank = ++rank;
return res;
},
},
- methods: {
- sortByPdt: function(a,b) {
- return b.pdt - a.pdt;
- },
- sortBySession: function(a,b) {
- return b.session - a.session;
- },
- },
},
'my-pairings': {
- props: ['players'],
+ props: ['players','sortByScore'],
data: function() {
return {
unpaired: [],
// 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<ordering.length; i++)
{
if ( ! this.players[ordering[i]].available )
xhr.open("POST", "scripts/rw_players.php");
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
let orderedPlayers = this.players
- .slice(1) //discard "Toto"
+ .slice(1) //discard Toto
.map( p => { 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)));
},
},
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;
+ },
+ },
});
$players[$row] = array(
"prenom" => $data[0],
"nom" => $data[1],
- "score" => count($data)>=3 ? $data[2] : 0,
- "pdt" => count($data)>=4 ? $data[3] : 0,
+ "pdt" => count($data)>=3 ? $data[2] : 0,
+ "session" => count($data)>=4 ? $data[3] : 0,
"available" => count($data)>=5 ? $data[4] : 1,
);
$row++;
{
// Write header + all players
$handle = fopen("../joueurs.csv", "w");
- fputcsv($handle, ["prenom","nom","score","pdt","present"]);
+ fputcsv($handle, ["prenom","nom","pdt","session","present"]);
$players = json_decode($_POST["players"]);
foreach ($players as $p)
fputcsv($handle, (array)$p);