This commit is contained in:
depreciate 2019-02-03 22:50:33 +10:30
parent 25963a8eb7
commit df83b9f25a

View File

@ -70,10 +70,10 @@ def getUserStatsRx(userID, gameMode):
# Get stats # Get stats
stats = glob.db.fetch("""SELECT stats = glob.db.fetch("""SELECT
ranked_score_{gm} AS rankedScore, ranked_score_{gm}_rx AS rankedScore,
avg_accuracy_{gm} AS accuracy, avg_accuracy_{gm}_rx AS accuracy,
playcount_{gm} AS playcount, playcount_{gm}_rx AS playcount,
total_score_{gm} AS totalScore, total_score_{gm}_rx AS totalScore,
pp_{gm}_rx AS pp pp_{gm}_rx AS pp
FROM users_stats WHERE id = %s LIMIT 1""".format(gm=modeForDB), [userID]) FROM users_stats WHERE id = %s LIMIT 1""".format(gm=modeForDB), [userID])
@ -95,10 +95,10 @@ def getUserStatsAp(userID, gameMode):
# Get stats # Get stats
stats = glob.db.fetch("""SELECT stats = glob.db.fetch("""SELECT
ranked_score_{gm} AS rankedScore, ranked_score_{gm}_ap AS rankedScore,
avg_accuracy_{gm} AS accuracy, avg_accuracy_{gm}_ap AS accuracy,
playcount_{gm} AS playcount, playcount_{gm}_ap AS playcount,
total_score_{gm} AS totalScore, total_score_{gm}_ap AS totalScore,
pp_{gm}_auto AS pp pp_{gm}_auto AS pp
FROM users_stats WHERE id = %s LIMIT 1""".format(gm=modeForDB), [userID]) FROM users_stats WHERE id = %s LIMIT 1""".format(gm=modeForDB), [userID])
@ -281,6 +281,60 @@ def updateLevel(userID, gameMode=0, totalScore=0):
# Save new level # Save new level
glob.db.execute("UPDATE users_stats SET level_{m} = %s WHERE id = %s LIMIT 1".format(m=mode), [level, userID]) glob.db.execute("UPDATE users_stats SET level_{m} = %s WHERE id = %s LIMIT 1".format(m=mode), [level, userID])
def updateLevelRX(userID, gameMode=0, totalScore=0):
"""
Update level in DB for userID relative to gameMode
:param userID: user id
:param gameMode: game mode number
:param totalScore: new total score
:return:
"""
# Make sure the user exists
# if not exists(userID):
# return
# Get total score from db if not passed
mode = scoreUtils.readableGameMode(gameMode)
if totalScore == 0:
totalScore = glob.db.fetch(
"SELECT total_score_{m}_rx as total_score FROM users_stats WHERE id = %s LIMIT 1".format(m=mode), [userID])
if totalScore:
totalScore = totalScore["total_score"]
# Calculate level from totalScore
level = getLevel(totalScore)
# Save new level
glob.db.execute("UPDATE users_stats SET level_{m}_rx = %s WHERE id = %s LIMIT 1".format(m=mode), [level, userID])
def updateLevelAP(userID, gameMode=0, totalScore=0):
"""
Update level in DB for userID relative to gameMode
:param userID: user id
:param gameMode: game mode number
:param totalScore: new total score
:return:
"""
# Make sure the user exists
# if not exists(userID):
# return
# Get total score from db if not passed
mode = scoreUtils.readableGameMode(gameMode)
if totalScore == 0:
totalScore = glob.db.fetch(
"SELECT total_score_{m}_ap as total_score FROM users_stats WHERE id = %s LIMIT 1".format(m=mode), [userID])
if totalScore:
totalScore = totalScore["total_score"]
# Calculate level from totalScore
level = getLevel(totalScore)
# Save new level
glob.db.execute("UPDATE users_stats SET level_{m}_ap = %s WHERE id = %s LIMIT 1".format(m=mode), [level, userID])
def calculateAccuracy(userID, gameMode): def calculateAccuracy(userID, gameMode):
""" """
Calculate accuracy value for userID relative to gameMode Calculate accuracy value for userID relative to gameMode
@ -402,6 +456,32 @@ def updateAccuracy(userID, gameMode):
glob.db.execute("UPDATE users_stats SET avg_accuracy_{m} = %s WHERE id = %s LIMIT 1".format(m=mode), glob.db.execute("UPDATE users_stats SET avg_accuracy_{m} = %s WHERE id = %s LIMIT 1".format(m=mode),
[newAcc, userID]) [newAcc, userID])
def updateAccuracyRX(userID, gameMode):
"""
Update accuracy value for userID relative to gameMode in DB
:param userID: user id
:param gameMode: gameMode number
:return:
"""
newAcc = calculateAccuracy(userID, gameMode)
mode = scoreUtils.readableGameMode(gameMode)
glob.db.execute("UPDATE users_stats SET avg_accuracy_{m}_rx = %s WHERE id = %s LIMIT 1".format(m=mode),
[newAcc, userID])
def updateAccuracyAP(userID, gameMode):
"""
Update accuracy value for userID relative to gameMode in DB
:param userID: user id
:param gameMode: gameMode number
:return:
"""
newAcc = calculateAccuracy(userID, gameMode)
mode = scoreUtils.readableGameMode(gameMode)
glob.db.execute("UPDATE users_stats SET avg_accuracy_{m}_ap = %s WHERE id = %s LIMIT 1".format(m=mode),
[newAcc, userID])
def updatePP(userID, gameMode): def updatePP(userID, gameMode):
""" """
Update userID's pp with new value Update userID's pp with new value
@ -508,21 +588,21 @@ def updateStatsRx(userID, __score):
# Update total score and playcount # Update total score and playcount
glob.db.execute( glob.db.execute(
"UPDATE users_stats SET total_score_{m}=total_score_{m}+%s, playcount_{m}=playcount_{m}+1 WHERE id = %s LIMIT 1".format( "UPDATE users_stats SET total_score_{m}_rx=total_score_{m}_rx+%s, playcount_{m}_rx=playcount_{m}_rx+1 WHERE id = %s LIMIT 1".format(
m=mode), [__score.score, userID]) m=mode), [__score.score, userID])
# Calculate new level and update it # Calculate new level and update it
updateLevel(userID, __score.gameMode) updateLevelRX(userID, __score.gameMode)
# Update level, accuracy and ranked score only if we have passed the song # Update level, accuracy and ranked score only if we have passed the song
if __score.passed: if __score.passed:
# Update ranked score # Update ranked score
glob.db.execute( glob.db.execute(
"UPDATE users_stats SET ranked_score_{m}=ranked_score_{m}+%s WHERE id = %s LIMIT 1".format(m=mode), "UPDATE users_stats SET ranked_score_{m}_rx=ranked_score_{m}_rx+%s WHERE id = %s LIMIT 1".format(m=mode),
[__score.rankedScoreIncrease, userID]) [__score.rankedScoreIncrease, userID])
# Update accuracy # Update accuracy
updateAccuracy(userID, __score.gameMode) updateAccuracyRX(userID, __score.gameMode)
# Update pp # Update pp
updatePPRelax(userID, __score.gameMode) updatePPRelax(userID, __score.gameMode)
@ -546,11 +626,11 @@ def updateStatsAp(userID, __score):
# Update total score and playcount # Update total score and playcount
glob.db.execute( glob.db.execute(
"UPDATE users_stats SET total_score_{m}=total_score_{m}+%s, playcount_{m}=playcount_{m}+1 WHERE id = %s LIMIT 1".format( "UPDATE users_stats SET total_score_{m}_ap=total_score_{m}_a-+%s, playcount_{m}_ap=playcount_{m}_ap+1 WHERE id = %s LIMIT 1".format(
m=mode), [__score.score, userID]) m=mode), [__score.score, userID])
# Calculate new level and update it # Calculate new level and update it
updateLevel(userID, __score.gameMode) updateLevelAP(userID, __score.gameMode)
# Update level, accuracy and ranked score only if we have passed the song # Update level, accuracy and ranked score only if we have passed the song
if __score.passed: if __score.passed:
@ -560,7 +640,7 @@ def updateStatsAp(userID, __score):
[__score.rankedScoreIncrease, userID]) [__score.rankedScoreIncrease, userID])
# Update accuracy # Update accuracy
updateAccuracy(userID, __score.gameMode) updateAccuracyAP(userID, __score.gameMode)
# Update pp # Update pp
updatePPAuto(userID, __score.gameMode) updatePPAuto(userID, __score.gameMode)