Show map rankings for player personal records
This commit is contained in:
@@ -36,10 +36,31 @@ export function getPlayerProfile(guid: string, requestedOffset = 0,
|
||||
const mapStats = handle.prepare(`SELECT m.game, m.map_key AS key, m.map_name AS name,
|
||||
MAX(mp.last_seen_at) AS lastSeen, ${totals} ${scope}
|
||||
GROUP BY m.game, m.map_key ORDER BY highestRound DESC, kills DESC, name COLLATE NOCASE, m.game, key`)
|
||||
.all(guid) as Array<Omit<PlayerMapRecord, 'records'>>;
|
||||
.all(guid) as Array<Omit<PlayerMapRecord, 'records' | 'ranks'>>;
|
||||
const [records, ...mapRecords] = getPersonalBestRecords(handle, [{ guid, ...stats },
|
||||
...mapStats.map(map => ({ guid, ...map, map: map.key }))]);
|
||||
const maps = mapStats.map((map, index) => ({ ...map, records: mapRecords[index] }));
|
||||
// Rank all three bests in one pass over this player's maps. Filter the GUID
|
||||
// only after ranking competitors so ties and skipped ranks match the leaderboard.
|
||||
const mapRanks = handle.prepare(`WITH totals AS (
|
||||
SELECT requested.key AS requestId, mp.guid,
|
||||
MAX(mp.highest_round) AS highestRound, MAX(mp.kills) AS bestKills, MAX(mp.best_score) AS bestScore
|
||||
FROM json_each(?) requested
|
||||
JOIN leaderboard_matches m ON m.game = json_extract(requested.value, '$.game')
|
||||
AND m.map_key = json_extract(requested.value, '$.key')
|
||||
JOIN leaderboard_match_players mp ON mp.match_id = m.id
|
||||
WHERE m.game IN ('t5', 't6') AND m.status = 'completed' AND mp.has_stats = 1
|
||||
AND m.highest_round >= ${MIN_RECORDED_ROUND} AND mp.highest_round >= ${MIN_RECORDED_ROUND}
|
||||
AND EXISTS (SELECT 1 FROM leaderboard_players p WHERE p.guid = mp.guid AND p.game IN ('t5', 't6'))
|
||||
GROUP BY requested.key, mp.guid
|
||||
), ranked AS (
|
||||
SELECT requestId, guid,
|
||||
RANK() OVER (PARTITION BY requestId ORDER BY highestRound DESC) AS highestRound,
|
||||
RANK() OVER (PARTITION BY requestId ORDER BY bestKills DESC) AS bestKills,
|
||||
RANK() OVER (PARTITION BY requestId ORDER BY bestScore DESC) AS bestScore
|
||||
FROM totals
|
||||
) SELECT highestRound, bestKills, bestScore FROM ranked WHERE guid = ? ORDER BY requestId`)
|
||||
.all(JSON.stringify(mapStats.map(({ game, key }) => ({ game, key }))), guid) as PlayerMapRecord['ranks'][];
|
||||
const maps = mapStats.map((map, index) => ({ ...map, records: mapRecords[index], ranks: mapRanks[index] }));
|
||||
const matches = handle.prepare(`SELECT m.id, m.game, m.server, m.server_deleted_at, m.map_name AS mapName,
|
||||
m.started_at AS startedAt, mp.last_seen_at AS lastSeen, m.status, mp.completed,
|
||||
mp.highest_round AS highestRound, mp.rounds_survived AS roundsSurvived,
|
||||
|
||||
Reference in New Issue
Block a user