From 0cd10bc54329abc7f74f20ed26d6a798ff45f682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=92=95=E8=B0=B7=E9=85=B1?= Date: Tue, 23 Sep 2025 02:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=92=E8=A1=8C=E6=A6=9C?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=94=A8=E6=88=B7=E6=95=B0=E9=87=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/router/v2/ranking.py | 52 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/app/router/v2/ranking.py b/app/router/v2/ranking.py index 2f32b12..ffd61fa 100644 --- a/app/router/v2/ranking.py +++ b/app/router/v2/ranking.py @@ -106,20 +106,25 @@ async def get_team_ranking( continue pp = 0 + total_ranked_score = 0 + total_play_count = 0 + member_count = 0 + + for stat in statistics: + total_ranked_score += stat.ranked_score + total_play_count += stat.play_count + pp += stat.pp + member_count += 1 + stats = TeamStatistics( team_id=team.id, ruleset_id=int(ruleset), - play_count=0, - ranked_score=0, - performance=0, + play_count=total_play_count, + ranked_score=total_ranked_score, + performance=round(pp), team=team, - member_count=0, + member_count=member_count, ) - for stat in statistics: - stats.ranked_score += stat.ranked_score - pp += stat.pp - stats.member_count += 1 - stats.performance = round(pp) valid_teams.append(stats) # 排序 @@ -248,19 +253,23 @@ async def get_country_ranking( continue pp = 0 + active_users = 0 + total_play_count = 0 + total_ranked_score = 0 + + for stat in statistics: + active_users += 1 + total_play_count += stat.play_count + total_ranked_score += stat.ranked_score + pp += stat.pp + country_stats = CountryStatistics( code=country, - active_users=0, - play_count=0, - ranked_score=0, - performance=0, + active_users=active_users, + play_count=total_play_count, + ranked_score=total_ranked_score, + performance=round(pp), ) - for stat in statistics: - country_stats.active_users += 1 - country_stats.play_count += stat.play_count - country_stats.ranked_score += stat.ranked_score - pp += stat.pp - country_stats.performance = round(pp) response.ranking.append(country_stats) if sort == "performance": @@ -333,7 +342,7 @@ async def get_user_ranking( wheres = [ col(UserStatistics.mode) == ruleset, col(UserStatistics.pp) > 0, - col(UserStatistics.is_ranked).is_(True), + col(UserStatistics.is_ranked) == True, ] include = ["user"] if sort == "performance": @@ -345,7 +354,8 @@ async def get_user_ranking( wheres.append(col(UserStatistics.user).has(country_code=country.upper())) # 查询总数 - total_count_result = await session.exec(select(func.count()).select_from(UserStatistics).where(*wheres)) + count_query = select(func.count(UserStatistics.id)).where(*wheres) + total_count_result = await session.exec(count_query) total_count = total_count_result.one() statistics_list = await session.exec(