From 4664a30924e40eb11e3f3e68b66e47413756a0c8 Mon Sep 17 00:00:00 2001 From: rtkells Date: Thu, 21 Nov 2024 15:37:10 -0600 Subject: [PATCH 1/2] Had to do the same thing again because git is really great :-) --- .../Routes/Completed_assessment_routes.py | 4 ++++ BackEndFlask/models/queries.py | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/BackEndFlask/controller/Routes/Completed_assessment_routes.py b/BackEndFlask/controller/Routes/Completed_assessment_routes.py index 7013c362d..eadf8c013 100644 --- a/BackEndFlask/controller/Routes/Completed_assessment_routes.py +++ b/BackEndFlask/controller/Routes/Completed_assessment_routes.py @@ -109,6 +109,10 @@ def get_all_completed_assessments(): get_assessment_task(assessment_task_id) # Trigger an error if not exists. completed_assessments = get_completed_assessment_with_team_name(assessment_task_id) + + if not completed_assessments: + completed_assessments = get_completed_assessment_with_user_name(assessment_task_id) + completed_count = get_completed_assessment_count(assessment_task_id) result = [ {**completed_assessment_schema.dump(assessment), 'completed_count': completed_count} diff --git a/BackEndFlask/models/queries.py b/BackEndFlask/models/queries.py index f66838a7b..2064bbb61 100644 --- a/BackEndFlask/models/queries.py +++ b/BackEndFlask/models/queries.py @@ -1082,9 +1082,6 @@ def get_course_name_by_at_id(at_id:int) -> str : return course_name[0][0] - - - def get_completed_assessment_ratio(course_id: int, assessment_task_id: int) -> int: """ Description: @@ -1096,14 +1093,25 @@ def get_completed_assessment_ratio(course_id: int, assessment_task_id: int) -> i Return: int (Ratio of users who have completed an assessment task rounded to the nearest whole number) """ + ratio = 0 + all_usernames_for_completed_task = get_completed_assessment_with_user_name(assessment_task_id) - all_students_in_course = get_users_by_course_id_and_role_id(course_id, 5) - ratio = (len(all_usernames_for_completed_task) / len(all_students_in_course)) * 100 + + if all_usernames_for_completed_task: + all_students_in_course = get_users_by_course_id_and_role_id(course_id, 5) + + ratio = len(all_usernames_for_completed_task) / len(all_students_in_course) * 100 + else: + all_teams_in_course = get_team_members_in_course(course_id) + all_teams_for_completed_task = get_completed_assessment_with_team_name(assessment_task_id) + + ratio = len(all_teams_for_completed_task) / len(all_teams_in_course) * 100 ratio_rounded = round(ratio) return ratio_rounded + def is_admin_by_user_id(user_id: int) -> bool: """ Description: From 1b0dad0476a5dfe1d0db61e45e1b9a3c1a461a82 Mon Sep 17 00:00:00 2001 From: rtkells Date: Thu, 21 Nov 2024 15:38:12 -0600 Subject: [PATCH 2/2] Removed blank line in queries.py --- BackEndFlask/models/queries.py | 1 - 1 file changed, 1 deletion(-) diff --git a/BackEndFlask/models/queries.py b/BackEndFlask/models/queries.py index 2064bbb61..3429077ac 100644 --- a/BackEndFlask/models/queries.py +++ b/BackEndFlask/models/queries.py @@ -1111,7 +1111,6 @@ def get_completed_assessment_ratio(course_id: int, assessment_task_id: int) -> i return ratio_rounded - def is_admin_by_user_id(user_id: int) -> bool: """ Description: