Skip to content

Commit

Permalink
Add accuracy leaderboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekuruu committed Dec 16, 2023
1 parent cbb3743 commit 8ab321c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions cache/leaderboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def update(stats: DBStats, country: str) -> None:
{stats.user_id: stats.ppv1}
)

# Playcount
# Accuracy
app.session.redis.zadd(
f'bancho:playcount:{stats.mode}',
{stats.user_id: stats.playcount}
f'bancho:acc:{stats.mode}',
{stats.user_id: stats.acc}
)

app.session.redis.zadd(
f'bancho:playcount:{stats.mode}:{country.lower()}',
{stats.user_id: stats.playcount}
f'bancho:acc:{stats.mode}:{country.lower()}',
{stats.user_id: stats.acc}
)

def remove(
Expand Down Expand Up @@ -102,22 +102,22 @@ def remove(
)

app.session.redis.zrem(
f'bancho:playcount:{mode}',
f'bancho:ppv1:{mode}',
user_id
)

app.session.redis.zrem(
f'bancho:playcount:{mode}:{country.lower()}',
f'bancho:ppv1:{mode}:{country.lower()}',
user_id
)

app.session.redis.zrem(
f'bancho:ppv1:{mode}',
f'bancho:acc:{mode}',
user_id
)

app.session.redis.zrem(
f'bancho:ppv1:{mode}:{country.lower()}',
f'bancho:acc:{mode}:{country.lower()}',
user_id
)

Expand Down Expand Up @@ -246,16 +246,16 @@ def total_score(
)
return score if score is not None else 0

def playcount(
def accuracy(
user_id: int,
mode: int
) -> int:
"""Get total playcount of player"""
playcount = app.session.redis.zscore(
f'bancho:playcount:{mode}',
) -> float:
"""Get player's accuracy"""
acc = app.session.redis.zscore(
f'bancho:acc:{mode}',
user_id
)
return playcount if playcount is not None else 0
return acc if acc is not None else 0

def top_players(
mode: int,
Expand Down

0 comments on commit 8ab321c

Please sign in to comment.