From f328c04cf9e4bdd9c0a44ef417888ca6a63ef91f Mon Sep 17 00:00:00 2001 From: Mikko Heikkinen Date: Fri, 23 Aug 2024 14:22:12 +0300 Subject: [PATCH] Refactor counting participants --- app/controllers/admin.py | 2 +- app/controllers/challenge.py | 2 +- app/helpers/common_helpers.py | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin.py b/app/controllers/admin.py index a10afe7..b0a1ee1 100644 --- a/app/controllers/admin.py +++ b/app/controllers/admin.py @@ -33,7 +33,7 @@ def make_participations_stats_html(participations): target_taxa_count_reached = 0 taxa_count_total = 0 - number_of_participants = common_helpers.get_participant_count(participations, target_count) + number_of_participants = common_helpers.get_participant_count(participations, 1) for participation in participations: if participation.get("taxa_count", 0) >= target_count: diff --git a/app/controllers/challenge.py b/app/controllers/challenge.py index ac2abf6..c67e35d 100644 --- a/app/controllers/challenge.py +++ b/app/controllers/challenge.py @@ -78,7 +78,7 @@ def make_participant_html(participations): table += "" - number_of_participants = common_helpers.get_participant_count(participations, target_count) + number_of_participants = common_helpers.get_participant_count(participations, 1) # Avoid division by zero if number_of_participants > 0: diff --git a/app/helpers/common_helpers.py b/app/helpers/common_helpers.py index 7d68b87..5b58b33 100644 --- a/app/helpers/common_helpers.py +++ b/app/helpers/common_helpers.py @@ -350,8 +350,8 @@ def make_taxa_html(participations, challenge_data, taxa_json = ""): # Function to calculate how many participants have reached at least a given proportion or number of taxa def get_participant_count(participations, target_count): - # Proprtion ''' + # Proportion, UNTESTED proportion = 0.1 count = 0 for participation in participations: @@ -360,10 +360,9 @@ def get_participant_count(participations, target_count): ''' # Number - limit = 1 count = 0 for participation in participations: - if participation["taxa_count"] >= limit: + if participation["taxa_count"] >= target_count: count += 1 return count