X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FTournament.js;h=7dffebbd07d96c1c189d6f51bdef61b62a524365;hb=6c3125ca01833f7cec3659353840dbe1ddfb0fc6;hp=792b593091b70ba62a24414325420e8645100786;hpb=d1f28ea443b090c7593791eba9631796ccaeafe1;p=alttp.git diff --git a/resources/js/helpers/Tournament.js b/resources/js/helpers/Tournament.js index 792b593..7dffebb 100644 --- a/resources/js/helpers/Tournament.js +++ b/resources/js/helpers/Tournament.js @@ -2,11 +2,13 @@ import Participant from './Participant'; 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(); @@ -30,7 +32,21 @@ export const calculateScores = tournament => { } } }); - 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) => {