From 837707229ced95bc9eb31874d4bd0f4a720f607b Mon Sep 17 00:00:00 2001 From: Pavel Shuvalov Date: Mon, 16 Sep 2024 10:05:53 +0400 Subject: [PATCH] Optimize S6 apps sorting to avoid rounding issues --- backends/toncenter_cpp/apps_v2_projects.py | 5 +++-- models/results.py | 1 + seasons/app_models.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backends/toncenter_cpp/apps_v2_projects.py b/backends/toncenter_cpp/apps_v2_projects.py index ee2a392..6c07936 100644 --- a/backends/toncenter_cpp/apps_v2_projects.py +++ b/backends/toncenter_cpp/apps_v2_projects.py @@ -49,7 +49,7 @@ def _do_calculate(self, config: SeasonConfig, dry_run: bool = False): group by address having count(1) > 1 ) select project, url, count(distinct address) as total_uaw, coalesce(sum(eligible), 0) as enrolled_wallets, - coalesce(cast(sum(points) / sum(eligible) as int), 0) as average_score + coalesce(cast(sum(points) / sum(eligible) as int), 0) as average_score, coalesce(sum(points), 0) as total_points from project_names left join tol.apps_users_stats_{config.safe_season_name()} using(project) left join eligible using(address) @@ -75,7 +75,8 @@ def _do_calculate(self, config: SeasonConfig, dry_run: bool = False): ProjectStat.URL: row['url'], ProjectStat.APP_ONCHAIN_UAW: row['total_uaw'], ProjectStat.APP_ONCHAIN_ENROLLED_UAW: row['enrolled_wallets'], - ProjectStat.APP_AVERAGE_SCORE: row['average_score'] + ProjectStat.APP_AVERAGE_SCORE: row['average_score'], + ProjectStat.APP_TOTAL_POINTS: row['total_points'] } ) diff --git a/models/results.py b/models/results.py index 00e3d62..a64d509 100644 --- a/models/results.py +++ b/models/results.py @@ -18,6 +18,7 @@ class ProjectStat: APP_ONCHAIN_UAW = 'onchain_uaw' APP_ONCHAIN_ENROLLED_UAW = 'onchain_enrolled_uaw' APP_AVERAGE_SCORE = 'average_score' + APP_TOTAL_POINTS = 'total_points' APP_ONCHAIN_MEDIAN_TX = 'onchain_median_tx' TOKEN_TVL_CATEGORY = 'token_tvl_category' diff --git a/seasons/app_models.py b/seasons/app_models.py index e6fb619..72960ec 100644 --- a/seasons/app_models.py +++ b/seasons/app_models.py @@ -57,4 +57,4 @@ def __init__(self): super().__init__() def calculate(self, metrics: List[ProjectStat]): - return sorted(metrics, key=lambda m: m.metrics[ProjectStat.APP_ONCHAIN_ENROLLED_UAW] * m.metrics[ProjectStat.APP_AVERAGE_SCORE], reverse=True) + return sorted(metrics, key=lambda m: m.metrics[ProjectStat.APP_TOTAL_POINTS], reverse=True)