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"] del query["_id"]
leaderboard = query["Leaderboard"] leaderboard = query["Leaderboard"]
return leaderboard return sorted(leaderboard, key=lambda sort: sort["BestPlaytime"])[0:5]
@app.get("/api/v1/map/{mapID}/userbesttime/{userID}") @app.get("/api/v1/map/{mapID}/userbesttime/{userID}")
@ -353,11 +353,11 @@ async def getPlayerRecord(mapID, userID):
# Find user # Find user
replayIndex = None replayIndex = None
BestTime = None
for i in range(len(leaderboard)): for i in range(len(leaderboard)):
print(f"DBG: {i}, {leaderboard[i]}\t{leaderboard[i]['UserID'] == int(userID):}") 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 replayIndex = i
break
print(leaderboard[replayIndex]) print(leaderboard[replayIndex])
if replayIndex is not None: if replayIndex is not None: