Implement ranking logic for players with identical scores in TournamentsView
Updated the ranking assignment logic in TournamentsView to ensure players with identical points, set differences, and sets won receive the same position. This change enhances the accuracy of player rankings and improves the user experience by reflecting true standings in tournament scenarios. Additionally, adjusted the position retrieval for players in live stats to accommodate the new ranking logic.
This commit is contained in:
@@ -789,9 +789,23 @@ export default {
|
||||
if (b.setsWon !== a.setsWon) return b.setsWon - a.setsWon;
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
rankings[gid] = arr.map((p, i) => ({
|
||||
...p, position: i + 1
|
||||
}));
|
||||
// Weise Positionen zu, wobei Spieler mit identischen Werten den gleichen Platz bekommen
|
||||
let currentPosition = 1;
|
||||
rankings[gid] = arr.map((p, i) => {
|
||||
// Wenn nicht der erste Spieler und die Werte identisch sind, verwende die gleiche Position
|
||||
if (i > 0) {
|
||||
const prev = arr[i - 1];
|
||||
if (prev.points === p.points &&
|
||||
prev.setDiff === p.setDiff &&
|
||||
prev.setsWon === p.setsWon) {
|
||||
// Gleicher Platz wie Vorgänger
|
||||
return { ...p, position: currentPosition };
|
||||
}
|
||||
}
|
||||
// Neuer Platz
|
||||
currentPosition = i + 1;
|
||||
return { ...p, position: currentPosition };
|
||||
});
|
||||
});
|
||||
return rankings;
|
||||
},
|
||||
@@ -1701,9 +1715,27 @@ export default {
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
// Weise Positionen zu, wobei Spieler mit identischen Werten den gleichen Platz bekommen
|
||||
let currentPosition = 1;
|
||||
const positions = liveStats.map((p, i) => {
|
||||
// Wenn nicht der erste Spieler und die Werte identisch sind, verwende die gleiche Position
|
||||
if (i > 0) {
|
||||
const prev = liveStats[i - 1];
|
||||
if (prev.livePoints === p.livePoints &&
|
||||
prev.liveSetDiff === p.liveSetDiff &&
|
||||
prev.liveSetsWon === p.liveSetsWon) {
|
||||
// Gleicher Platz wie Vorgänger
|
||||
return currentPosition;
|
||||
}
|
||||
}
|
||||
// Neuer Platz
|
||||
currentPosition = i + 1;
|
||||
return currentPosition;
|
||||
});
|
||||
|
||||
// Finde Position des Spielers
|
||||
const position = liveStats.findIndex(p => p.id === playerId) + 1;
|
||||
return position;
|
||||
const playerIndex = liveStats.findIndex(p => p.id === playerId);
|
||||
return playerIndex >= 0 ? positions[playerIndex] : liveStats.length + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user