feat(match-service): update ranking logic for league table based on balance and previous tie-breakers
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 58s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 58s
This commit is contained in:
@@ -652,11 +652,23 @@ class MatchService {
|
||||
'id', 'name', 'matchesPlayed', 'matchesWon', 'matchesLost', 'matchesTied',
|
||||
'setsWon', 'setsLost', 'pointsWon', 'pointsLost', 'tablePoints', 'tablePointsWon', 'tablePointsLost'
|
||||
],
|
||||
order: [
|
||||
['tablePointsWon', 'DESC'], // Highest table points first
|
||||
['matchesWon', 'DESC'], // Then by matches won
|
||||
['setsWon', 'DESC'] // Then by sets won
|
||||
]
|
||||
order: [['id', 'ASC']]
|
||||
});
|
||||
|
||||
// A table-points result is ranked by its balance, not just by the
|
||||
// number of points won: 0:0 (0) must therefore rank ahead of 0:2
|
||||
// (-2), which in turn ranks ahead of 0:4 (-4).
|
||||
teams.sort((left, right) => {
|
||||
const leftBalance = left.tablePointsWon - left.tablePointsLost;
|
||||
const rightBalance = right.tablePointsWon - right.tablePointsLost;
|
||||
if (rightBalance !== leftBalance) return rightBalance - leftBalance;
|
||||
|
||||
// Retain the previous tie-breakers for teams with the same balance.
|
||||
if (right.tablePointsWon !== left.tablePointsWon) {
|
||||
return right.tablePointsWon - left.tablePointsWon;
|
||||
}
|
||||
if (right.matchesWon !== left.matchesWon) return right.matchesWon - left.matchesWon;
|
||||
return right.setsWon - left.setsWon;
|
||||
});
|
||||
|
||||
// Format table data
|
||||
|
||||
Reference in New Issue
Block a user