import Round from './Round';
export const calculateScores = tournament => {
- const scores = getRunners(tournament).map(participant => ({ participant, score: 0 }));
+ const runners = getRunners(tournament);
+ const scores = runners.map(participant => ({ participant, score: 0 }));
+ if (!scores.length) return scores;
if (!tournament.rounds || !tournament.rounds.length) return scores;
tournament.rounds.forEach(round => {
const filtered = Participant
- .sortByResult(tournament.participants, round)
+ .sortByResult(runners, round)
.map(p => ({ participant: p, result: Participant.findResult(p, round) }))
.filter(r => r.result && (r.result.time || r.result.forfeit))
.reverse();
}
}
});
- return scores.sort(compareScore).reverse();
+ const sorted = scores.sort(compareScore);
+ let placement = scores.length;
+ let skipped = 0;
+ let lastScore = sorted[0].score;
+ for (let i = 0; i < sorted.length; ++i) {
+ if (sorted[i].score > lastScore) {
+ placement -= skipped;
+ skipped = 1;
+ lastScore = sorted[i].score;
+ } else {
+ ++skipped;
+ }
+ sorted[i].placement = placement;
+ }
+ return sorted.reverse();
};
export const compareScore = (a, b) => {