From 3823c5d44538a116ad1c0c3635552e6cee07a66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Wed, 8 Sep 2021 17:32:52 +0200 Subject: [PATCH] Reduce the technical debt by using maths Dynamically compute the percentage by rounding the given result rather than using a result matrix. --- tournesolbot/tournesolbot.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/tournesolbot/tournesolbot.py b/tournesolbot/tournesolbot.py index cc13664..71ea755 100644 --- a/tournesolbot/tournesolbot.py +++ b/tournesolbot/tournesolbot.py @@ -16,21 +16,11 @@ def get_top_percentage(criteria_row): # Get the top percentage categorie (Top 1,2,5,10,20,50%) from the quantile value (in the row) - if criteria_row['quantile_val'] < 0.01: - return "Top 1%" - elif criteria_row['quantile_val'] < 0.02: - return "Top 2%" - elif criteria_row['quantile_val'] < 0.05: - return "Top 5%" - elif criteria_row['quantile_val'] < 0.1: - return "Top 10%" - elif criteria_row['quantile_val'] < 0.2: - return "Top 20%" - elif criteria_row['quantile_val'] < 0.5: - return "Top 50%" - else: + if criteria_row['quantile_val'] >= 0.5: return "Not in Top 50%" + return "Top {val}%".format(val=round(criteria_row['quantile_val'] * 100)) + def get_top_criteria(video_dict): # Get the top creteria ranked by their quantile ranking