From d4b2efe048df16a1efa72babbb32b484185c4789 Mon Sep 17 00:00:00 2001 From: magmaus3 Date: Sat, 19 Nov 2022 15:54:01 +0100 Subject: [PATCH] Fix leaderboard sorting --- customiwmserver/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/customiwmserver/main.py b/customiwmserver/main.py index e1fd344..0b99bd2 100644 --- a/customiwmserver/main.py +++ b/customiwmserver/main.py @@ -339,7 +339,7 @@ async def getMapLeaderboard(mapID, maxEntries): del query["_id"] leaderboard = query["Leaderboard"] - return leaderboard + return sorted(leaderboard, key=lambda sort: sort["BestPlaytime"])[0:5] @app.get("/api/v1/map/{mapID}/userbesttime/{userID}") @@ -353,11 +353,11 @@ async def getPlayerRecord(mapID, userID): # Find user replayIndex = None + BestTime = None for i in range(len(leaderboard)): print(f"DBG: {i}, {leaderboard[i]}\t{leaderboard[i]['UserID'] == int(userID):}") - if leaderboard[i]["UserID"] == int(userID): + if leaderboard[i]["UserID"] == int(userID) and (BestTime is None or leaderboard[i]["BestPlaytime"] < BestTime): replayIndex = i - break print(leaderboard[replayIndex]) if replayIndex is not None: