Fix leaderboard sorting

This commit is contained in:
magmaus3 2022-11-19 15:54:01 +01:00
parent 5360b128e0
commit d4b2efe048
Signed by: magmaus3
GPG key ID: 966755D3F4A9B251

View file

@ -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: