From 9681aa68b4849908eb8e29bfadfa65e2afba4a3d Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Mon, 25 Aug 2025 12:10:47 +0000 Subject: [PATCH] feat(banchobot): show weighted pp in score commands --- app/database/score.py | 2 +- app/router/notification/banchobot.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/database/score.py b/app/database/score.py index 869c999..c331865 100644 --- a/app/database/score.py +++ b/app/database/score.py @@ -355,7 +355,7 @@ class ScoreAround(SQLModel): lower: MultiplayerScores | None = None -async def get_best_id(session: AsyncSession, score_id: int) -> None: +async def get_best_id(session: AsyncSession, score_id: int) -> int | None: rownum = ( func.row_number().over(partition_by=col(PPBestScore.user_id), order_by=col(PPBestScore.pp).desc()).label("rn") ) diff --git a/app/router/notification/banchobot.py b/app/router/notification/banchobot.py index 4463255..2f32696 100644 --- a/app/router/notification/banchobot.py +++ b/app/router/notification/banchobot.py @@ -7,12 +7,13 @@ from math import ceil import random import shlex +from app.calculator import calculate_weighted_pp from app.const import BANCHOBOT_ID from app.database import ChatMessageResp from app.database.beatmap import Beatmap from app.database.chat import ChannelType, ChatChannel, ChatMessage, MessageType from app.database.lazer_user import User -from app.database.score import Score +from app.database.score import Score, get_best_id from app.database.statistics import UserStatistics, get_rank from app.dependencies.fetcher import get_fetcher from app.exception import InvokeException @@ -210,8 +211,8 @@ async def _stats(user: User, args: list[str], session: AsyncSession, channel: Ch return f"""Stats for {target_user.username} ({gamemode.name.lower()}): Score: {statistics.total_score} (#{await get_rank(session, statistics)}) Plays: {statistics.play_count} (lv{ceil(statistics.level_current)}) -Accuracy: {statistics.hit_accuracy} -PP: {statistics.pp} +Accuracy: {statistics.hit_accuracy:.2%} +PP: {statistics.pp:.2f} """ @@ -576,10 +577,14 @@ async def _score( score = (await session.exec(q)).first() if score is None: return "You have no scores." + best_id = await get_best_id(session, score.id) + bp_pp = "" + if best_id: + bp_pp = f"(b{best_id} -> {calculate_weighted_pp(score.pp, best_id):.2f}pp)" result = f"""{score.beatmap.beatmapset.title} [{score.beatmap.version}] ({score.gamemode.name.lower()}) Played at {score.started_at} -{score.pp:.2f}pp {score.accuracy:.2%} {",".join(mod_to_save(score.mods))} {score.rank.name.upper()} +{score.pp:.2f}pp {bp_pp} {score.accuracy:.2%} {",".join(mod_to_save(score.mods))} {score.rank.name.upper()} Great: {score.n300}, Good: {score.n100}, Meh: {score.n50}, Miss: {score.nmiss}""" if score.gamemode == GameMode.MANIA: keys = next((mod["acronym"] for mod in score.mods if mod["acronym"].endswith("K")), None)