File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4949 views .get_all_challenges_submission_metrics ,
5050 name = "get_all_challenges_submission_metrics" ,
5151 ),
52+ url (
53+ r"^challenge/get_submission_metrics_by_pk/(?P<pk>[0-9]+)/$" ,
54+ views .get_challenge_submission_metrics_by_pk ,
55+ name = "get_challenge_submission_metrics_by_pk" ,
56+ ),
5257 url (
5358 r"^challenges/participated/(?P<challenge_time>[A-Za-z]+)/$" ,
5459 views .get_all_participated_challenges ,
Original file line number Diff line number Diff line change @@ -753,6 +753,30 @@ def get_all_challenges_submission_metrics(request):
753753 return Response (submission_metrics , status = status .HTTP_200_OK )
754754
755755
756+ @api_view (["GET" ])
757+ @throttle_classes ([AnonRateThrottle ])
758+ def get_challenge_submission_metrics_by_pk (request , pk ):
759+ """
760+ Returns the submission metrics for a given challenge by primary key and their phases
761+ """
762+ if not is_user_a_staff (request .user ):
763+ response_data = {"error" : "Sorry, you are not authorized to make this request" }
764+ return Response (response_data , status = status .HTTP_403_FORBIDDEN )
765+ challenge = get_challenge_model (pk )
766+ challenge_phases = ChallengePhase .objects .filter (challenge = challenge )
767+ submission_metrics = {}
768+
769+ submission_statuses = [status [0 ] for status in Submission .STATUS_OPTIONS ]
770+
771+ # Fetch challenge phases for the challenge
772+ challenge_phases = ChallengePhase .objects .filter (challenge = challenge )
773+ for submission_status in submission_statuses :
774+ count = Submission .objects .filter (challenge_phase__in = challenge_phases , status = submission_status ).count ()
775+ submission_metrics [submission_status ] = count
776+
777+ return Response (submission_metrics , status = status .HTTP_200_OK )
778+
779+
756780@api_view (["GET" ])
757781@throttle_classes ([AnonRateThrottle ])
758782def get_featured_challenges (request ):
You can’t perform that action at this time.
0 commit comments