should be fine

This commit is contained in:
Alicia 2018-12-24 07:14:06 +00:00
parent d03f68e4e9
commit bb4c8541c9

View File

@ -59,6 +59,31 @@ def getUserStatsRx(userID, gameMode):
# Return stats + game rank # Return stats + game rank
return stats return stats
def getUserStatsAp(userID, gameMode):
"""
Get all user stats relative to `gameMode`
:param userID:
:param gameMode: game mode number
:return: dictionary with result
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
# Get stats
stats = glob.db.fetch("""SELECT
ranked_score_{gm} AS rankedScore,
avg_accuracy_{gm} AS accuracy,
playcount_{gm} AS playcount,
total_score_{gm} AS totalScore,
pp_{gm}_rx AS pp
FROM users_stats WHERE id = %s LIMIT 1""".format(gm=modeForDB), [userID])
# Get game rank
stats["gameRank"] = getGameRankAp(userID, gameMode)
# Return stats + game rank
return stats
def getIDSafe(_safeUsername): def getIDSafe(_safeUsername):
""" """
Get user ID from a safe username Get user ID from a safe username
@ -314,6 +339,31 @@ def calculatePPRelax(userID, gameMode):
totalPP += new totalPP += new
k += 1 k += 1
return totalPP
def calculatePPAuto(userID, gameMode):
"""
Calculate userID's total PP for gameMode
:param userID: user id
:param gameMode: game mode number
:return: total PP
"""
# Get best pp scores
bestPPScores = glob.db.fetchAll(
"SELECT pp FROM scores_auto WHERE userid = %s AND play_mode = %s AND completed = 3 ORDER BY pp DESC LIMIT 500",
[userID, gameMode])
# Calculate weighted PP
totalPP = 0
if bestPPScores is not None:
k = 0
for i in bestPPScores:
new = round(round(i["pp"]) * 0.95 ** k)
totalPP += new
k += 1
return totalPP return totalPP
def updateAccuracy(userID, gameMode): def updateAccuracy(userID, gameMode):
""" """
@ -361,6 +411,22 @@ def updatePPRelax(userID, gameMode):
mode = scoreUtils.readableGameMode(gameMode) mode = scoreUtils.readableGameMode(gameMode)
glob.db.execute("UPDATE users_stats SET pp_{}_rx=%s WHERE id = %s LIMIT 1".format(mode), [newPP, userID]) glob.db.execute("UPDATE users_stats SET pp_{}_rx=%s WHERE id = %s LIMIT 1".format(mode), [newPP, userID])
def updatePPAuto(userID, gameMode):
"""
Update userID's pp with new value
:param userID: user id
:param gameMode: game mode number
"""
# Make sure the user exists
# if not exists(userID):
# return
# Get new total PP and update db
newPP = calculatePPAuto(userID, gameMode)
mode = scoreUtils.readableGameMode(gameMode)
glob.db.execute("UPDATE users_stats SET pp_{}_auto=%s WHERE id = %s LIMIT 1".format(mode), [newPP, userID])
def updateStats(userID, __score): def updateStats(userID, __score):
""" """
Update stats (playcount, total score, ranked score, level bla bla) Update stats (playcount, total score, ranked score, level bla bla)
@ -785,6 +851,19 @@ def getGameRankRx(userID, gameMode):
else: else:
return int(position) + 1 return int(position) + 1
def getGameRankAp(userID, gameMode):
"""
Get `userID`'s **in-game rank** (eg: #1337) relative to gameMode
:param userID: user id
:param gameMode: game mode number
:return: game rank
"""
position = glob.redis.zrevrank("ripple:leaderboard_auto:{}".format(gameModes.getGameModeForDB(gameMode)), userID)
if position is None:
return 0
else:
return int(position) + 1
def getPlaycount(userID, gameMode): def getPlaycount(userID, gameMode):
""" """
Get `userID`'s playcount relative to `gameMode` Get `userID`'s playcount relative to `gameMode`