diff --git a/apps/analytics/urls.py b/apps/analytics/urls.py index 0643ea5d20..16b9efa005 100644 --- a/apps/analytics/urls.py +++ b/apps/analytics/urls.py @@ -19,12 +19,14 @@ name="get_submission_count", ), re_path( - r"^challenge/(?P[0-9]+)/challenge_phase/(?P[0-9]+)/analytics$", + r"^challenge/(?P[0-9]+)/challenge_phase/" + r"(?P[0-9]+)/analytics$", views.get_challenge_phase_submission_analysis, name="get_challenge_phase_submission_analysis", ), re_path( - r"^challenge/(?P[0-9]+)/challenge_phase/(?P[0-9]+)/count$", + r"^challenge/(?P[0-9]+)/challenge_phase/" + r"(?P(v1|v2))/(?P[-a-zA-Z0-9_]+)/count$", views.get_challenge_phase_submission_count_by_team, name="get_challenge_phase_submission_count_by_team", ), diff --git a/apps/analytics/views.py b/apps/analytics/views.py index 15dd59d8c0..05772f6048 100644 --- a/apps/analytics/views.py +++ b/apps/analytics/views.py @@ -2,6 +2,7 @@ from datetime import timedelta from accounts.permissions import HasVerifiedEmail +from challenges.models import ChallengePhase from challenges.permissions import IsChallengeCreator from challenges.utils import get_challenge_model, get_challenge_phase_model from django.http import HttpResponse @@ -140,14 +141,23 @@ def get_submission_count(request, challenge_pk, duration): ) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) def get_challenge_phase_submission_count_by_team( - request, challenge_pk, challenge_phase_pk + request, challenge_pk, challenge_phase_pk_or_slug, version ): """ Returns number of submissions done by a participant team in a challenge phase """ challenge = get_challenge_model(challenge_pk) - challenge_phase = get_challenge_phase_model(challenge_phase_pk) + if version == "v2": + try: + challenge_phase = ChallengePhase.objects.get( + slug=challenge_phase_pk_or_slug, challenge=challenge + ) + except ChallengePhase.DoesNotExist: + response_data = {"error": "Challenge Phase does not exist"} + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + else: + challenge_phase = get_challenge_phase_model(challenge_phase_pk_or_slug) participant_team = get_participant_team_id_of_user_for_a_challenge( request.user, challenge.pk diff --git a/apps/challenges/serializers.py b/apps/challenges/serializers.py index 4e933be0a6..41836505b3 100644 --- a/apps/challenges/serializers.py +++ b/apps/challenges/serializers.py @@ -21,7 +21,6 @@ class ChallengeSerializer(serializers.ModelSerializer): - is_active = serializers.ReadOnlyField() domain_name = serializers.SerializerMethodField() @@ -100,7 +99,6 @@ class Meta: class ChallengePhaseSerializer(serializers.ModelSerializer): - is_active = serializers.ReadOnlyField() def __init__(self, *args, **kwargs): @@ -177,6 +175,8 @@ class ChallengePhaseSplitSerializer(serializers.ModelSerializer): dataset_split_name = serializers.SerializerMethodField() challenge_phase_name = serializers.SerializerMethodField() leaderboard_schema = serializers.SerializerMethodField() + challenge_phase_slug = serializers.SerializerMethodField() + dataset_split_codename = serializers.SerializerMethodField() class Meta: model = ChallengePhaseSplit @@ -186,6 +186,8 @@ class Meta: "challenge_phase", "challenge_phase_name", "dataset_split_name", + "challenge_phase_slug", + "dataset_split_codename", "visibility", "show_leaderboard_by_latest_submission", "show_execution_time", @@ -202,6 +204,12 @@ def get_dataset_split_name(self, obj): def get_challenge_phase_name(self, obj): return obj.challenge_phase.name + def get_challenge_phase_slug(self, obj): + return obj.challenge_phase.slug + + def get_dataset_split_codename(self, obj): + return obj.dataset_split.codename + class ChallengeConfigSerializer(serializers.ModelSerializer): """ @@ -354,7 +362,6 @@ class Meta: class ChallengePhaseCreateSerializer(serializers.ModelSerializer): - is_active = serializers.ReadOnlyField() def __init__(self, *args, **kwargs): @@ -412,7 +419,6 @@ class Meta: class StarChallengeSerializer(serializers.ModelSerializer): - count = serializers.SerializerMethodField() def __init__(self, *args, **kwargs): @@ -502,7 +508,6 @@ class Meta: class PWCChallengeLeaderboardSerializer(serializers.ModelSerializer): - challenge_id = serializers.SerializerMethodField() leaderboard = serializers.SerializerMethodField() leaderboard_decimal_precision = serializers.SerializerMethodField() diff --git a/apps/challenges/urls.py b/apps/challenges/urls.py index 3139d5381c..edb8a7fc30 100644 --- a/apps/challenges/urls.py +++ b/apps/challenges/urls.py @@ -40,7 +40,8 @@ ), # `A-Za-z` because it accepts either of `all, future, past or present` in either case url( - r"^challenge/(?P[A-Za-z]+)/(?P[A-Za-z]+)/(?P[A-Za-z]+)$", + r"^challenge/(?P[A-Za-z]+)/(?P[A-Za-z]+)/" + r"(?P[A-Za-z]+)$", views.get_all_challenges, name="get_all_challenges", ), @@ -90,12 +91,13 @@ name="create_challenge_using_zip_file", ), url( - r"^(?P[0-9]+)/challenge_phase/(?P[0-9]+)/submissions$", + r"^(?P[0-9]+)/challenge_phase/(?P(v1|v2))" + r"/(?P[-a-zA-Z0-9_]+)/submissions$", views.get_all_submissions_of_challenge, name="get_all_submissions_of_challenge", ), url( - r"^(?P[0-9]+)/phase/(?P[0-9]+)" + r"^(?P[0-9]+)/phase/(?P(v1|v2))/(?P[-a-zA-Z0-9_]+)" r"/download_all_submissions/(?P[A-Za-z]+)/$", views.download_all_submissions, name="download_all_submissions", diff --git a/apps/challenges/views.py b/apps/challenges/views.py index 97daf932cf..aaafdc61a0 100644 --- a/apps/challenges/views.py +++ b/apps/challenges/views.py @@ -507,7 +507,6 @@ def get_participant_teams_for_challenge(request, challenge_pk): def add_participant_team_to_challenge( request, challenge_pk, participant_team_pk ): - try: challenge = Challenge.objects.get(pk=challenge_pk) except Challenge.DoesNotExist: @@ -1423,9 +1422,8 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk): ): options = attribute.get("options") if not options or not len(options): - message = "Please include at least one option in attribute for challenge_phase {}".format( - data["id"] - ) + message = "Please include at least one option in attribute" + "for challenge_phase {}".format(data["id"]) response_data = {"error": message} return Response( response_data, @@ -1464,7 +1462,10 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk): ) else: missing_keys_string = ", ".join(missing_keys) - message = "Please enter the following to the default submission meta attribute in phase {}: {}.".format( + message = ( + "Please enter the following to the default submission" + ) + " meta attribute in phase {}: {}.".format( data["id"], missing_keys_string ) response_data = {"error": message} @@ -2088,7 +2089,7 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk): @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) def get_all_submissions_of_challenge( - request, challenge_pk, challenge_phase_pk + request, challenge_pk, challenge_phase_pk_or_slug, version ): """ Returns all the submissions for a particular challenge @@ -2098,24 +2099,26 @@ def get_all_submissions_of_challenge( # To check for the corresponding challenge phase from the # challenge_phase_pk and challenge. - try: - challenge_phase = ChallengePhase.objects.get( - pk=challenge_phase_pk, challenge=challenge - ) - except ChallengePhase.DoesNotExist: - response_data = { - "error": "Challenge Phase {} does not exist".format( - challenge_phase_pk + if version == "v2": + try: + challenge_phase = ChallengePhase.objects.get( + slug=challenge_phase_pk_or_slug, challenge=challenge ) - } - return Response(response_data, status=status.HTTP_404_NOT_FOUND) + except ChallengePhase.DoesNotExist: + response_data = { + "error": "Challenge Phase {} does not exist".format( + challenge_phase_pk_or_slug + ) + } + return Response(response_data, status=status.HTTP_404_NOT_FOUND) + else: + challenge_phase = get_challenge_phase_model(challenge_phase_pk_or_slug) # To check for the user as a host of the challenge from the request and # challenge_pk. if is_user_a_host_of_challenge( user=request.user, challenge_pk=challenge_pk ): - # Filter submissions on the basis of challenge for host for now. Later on, the support for query # parameters like challenge phase, date is to be added. submissions = Submission.objects.filter( @@ -2138,7 +2141,6 @@ def get_all_submissions_of_challenge( elif has_user_participated_in_challenge( user=request.user, challenge_id=challenge_pk ): - # get participant team object for the user for a particular challenge. participant_team_pk = get_participant_team_id_of_user_for_a_challenge( request.user, challenge_pk @@ -2245,7 +2247,7 @@ def get_all_submissions_of_challenge( @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) def download_all_submissions( - request, challenge_pk, challenge_phase_pk, file_type + request, challenge_pk, challenge_phase_pk_or_slug, file_type, version ): """ API endpoint to download all the submissions for a particular challenge as a csv @@ -2264,18 +2266,20 @@ def download_all_submissions( # To check for the corresponding challenge phase from the # challenge_phase_pk and challenge. - try: - challenge_phase = ChallengePhase.objects.get( - pk=challenge_phase_pk, challenge=challenge - ) - except ChallengePhase.DoesNotExist: - response_data = { - "error": "Challenge Phase {} does not exist".format( - challenge_phase_pk + if version == "v2": + try: + challenge_phase = ChallengePhase.objects.get( + slug=challenge_phase_pk_or_slug, challenge=challenge ) - } - return Response(response_data, status=status.HTTP_404_NOT_FOUND) - + except ChallengePhase.DoesNotExist: + response_data = { + "error": "Challenge Phase {} does not exist".format( + challenge_phase_pk_or_slug + ) + } + return Response(response_data, status=status.HTTP_404_NOT_FOUND) + else: + challenge_phase = get_challenge_phase_model(challenge_phase_pk_or_slug) if request.method == "GET": if file_type == "csv": if is_user_a_host_of_challenge( @@ -2370,7 +2374,6 @@ def download_all_submissions( elif has_user_participated_in_challenge( user=request.user, challenge_id=challenge_pk ): - # get participant team object for the user for a particular # challenge. participant_team_pk = ( @@ -2924,7 +2927,6 @@ def get_aws_credentials_for_participant_team(request, phase_pk): @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) def invite_users_to_challenge(request, challenge_pk): - challenge = get_challenge_model(challenge_pk) if not challenge.is_active or not challenge.approved_by_admin: @@ -4173,7 +4175,12 @@ def create_or_update_github_challenge(request, challenge_host_team_pk): if serializer.is_valid(): serializer.save() else: - error_messages = f"challenge phase split (phase:{data['challenge_phase_id']}, leaderboard:{data['leaderboard_id']}, dataset split: {data['dataset_split_id']}):{str(serializer.errors)}" + error_messages = ( + f"challenge phase split" + f" (phase:{data['challenge_phase_id']}," + f" leaderboard:{data['leaderboard_id']}," + f" dataset split: {data['dataset_split_id']}):{str(serializer.errors)}" + ) raise RuntimeError() zip_config = ChallengeConfiguration.objects.get( @@ -4363,7 +4370,6 @@ def create_or_update_github_challenge(request, challenge_host_team_pk): challenge_phases_data, files["challenge_test_annotation_files"], ): - # Override the submission_meta_attributes when they are # missing submission_meta_attributes = data.get( @@ -4552,7 +4558,12 @@ def create_or_update_github_challenge(request, challenge_host_team_pk): if serializer.is_valid(): serializer.save() else: - error_messages = f"challenge phase split update (phase:{data['challenge_phase_id']}, leaderboard:{data['leaderboard_id']}, dataset split: {data['dataset_split_id']}):{str(serializer.errors)}" + error_messages = ( + f"challenge phase split update" + f"(phase:{data['challenge_phase_id']}," + f"leaderboard:{data['leaderboard_id']}," + f"dataset split: {data['dataset_split_id']}):{str(serializer.errors)}" + ) raise RuntimeError() response_data = { @@ -4607,7 +4618,11 @@ def pwc_task_dataset(request): return Response(response_data, status=status.HTTP_200_OK) else: response_data = { - "error": "You are not authorized to make this request. Please ask EvalAI admin to add you as a staff user for accessing this API." + "error": ( + "You are not authorized " + "to make this request. Please ask EvalAI admin to " + "add you as a staff user for accessing this API." + ) } return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) @@ -4833,7 +4848,10 @@ def request_challenge_approval_by_pk(request, challenge_pk): unfinished_phases.append(challenge_phase.name) if unfinished_phases: - error_message = f"The following challenge phases do not have finished submissions: {', '.join(unfinished_phases)}" + error_message = ( + "The following challenge phases do not have finished submissions: " + f"{', '.join(unfinished_phases)}" + ) return Response( {"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE ) @@ -4899,13 +4917,19 @@ def request_challenge_approval_by_pk(request, challenge_pk): } return Response(response_data, status=status.HTTP_200_OK) else: - error_message = f"Sorry, there was an error sending approval request: {str(webhook_response.content.decode('utf-8'))}. Please try again." + error_message = ( + f"Sorry, there was an error sending approval request:" + f" {str(webhook_response.content.decode('utf-8'))}. Please try again." + ) return Response( {"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE, ) else: - error_message = "Sorry, there was an error sending approval request: No response received. Please try again." + error_message = ( + "Sorry, there was an error sending approval request:" + " No response received. Please try again." + ) return Response( {"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE ) diff --git a/apps/jobs/urls.py b/apps/jobs/urls.py index 314bf8592d..c85c881a69 100644 --- a/apps/jobs/urls.py +++ b/apps/jobs/urls.py @@ -11,7 +11,7 @@ ), url( r"^challenge/(?P[0-9]+)/" - r"challenge_phase/(?P[0-9]+)/submission/$", + r"challenge_phase/(?P(v1|v2))/(?P[-a-zA-Z0-9_]+)/submission/$", views.challenge_submission, name="challenge_submission", ), @@ -31,14 +31,16 @@ name="resume_submission", ), url( - r"^challenge_phase_split/(?P[0-9]+)/leaderboard/$", + r"^challenge/(?P[0-9]+)/phase/(?P[-a-zA-Z0-9_]+)/split/" + r"(?P[-a-zA-Z0-9_]+)/leaderboard/$", views.leaderboard, - name="leaderboard", + name="leaderboard_by_slug", ), url( - r"^phase_split/(?P[0-9]+)/public_leaderboard_all_entries/$", + r"^challenge/(?P[0-9]+)/phase/(?P[-a-zA-Z0-9_]+)/split/" + r"(?P[-a-zA-Z0-9_]+)/public_leaderboard_all_entries/$", views.get_all_entries_on_public_leaderboard, - name="get_all_entries_on_public_leaderboard", + name="get_all_entries_on_public_leaderboard_by_slug", ), url( r"^submission/(?P[0-9]+)$", diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 0291ec9fbf..1e2c173e6e 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -137,7 +137,9 @@ @throttle_classes([UserRateThrottle]) @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) -def challenge_submission(request, challenge_id, challenge_phase_id): +def challenge_submission( + request, challenge_id, challenge_phase_pk_or_slug, version +): """API Endpoint for making a submission to a challenge""" # check if the challenge exists or not @@ -148,13 +150,16 @@ def challenge_submission(request, challenge_id, challenge_phase_id): return Response(response_data, status=status.HTTP_400_BAD_REQUEST) # check if the challenge phase exists or not - try: - challenge_phase = ChallengePhase.objects.get( - pk=challenge_phase_id, challenge=challenge - ) - except ChallengePhase.DoesNotExist: - response_data = {"error": "Challenge Phase does not exist"} - return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + if version == "v2": + try: + challenge_phase = ChallengePhase.objects.get( + slug=challenge_phase_pk_or_slug, challenge=challenge + ) + except ChallengePhase.DoesNotExist: + response_data = {"error": "Challenge Phase does not exist"} + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + else: + challenge_phase = get_challenge_phase_model(challenge_phase_pk_or_slug) if request.method == "GET": # getting participant team object for the user for a particular @@ -197,7 +202,6 @@ def challenge_submission(request, challenge_id, challenge_phase_id): return paginator.get_paginated_response(response_data) elif request.method == "POST": - # check if the challenge is active or not if not challenge.is_active: response_data = {"error": "Challenge is not active"} @@ -313,7 +317,7 @@ def challenge_submission(request, challenge_id, challenge_phase_id): request.data, request.user.id, request.method, - challenge_phase_id, + challenge_phase_pk_or_slug, ) response_data = { "message": "Please wait while your submission being evaluated!" @@ -377,7 +381,7 @@ def challenge_submission(request, challenge_id, challenge_phase_id): ) message = { "challenge_pk": challenge_id, - "phase_pk": challenge_phase_id, + "phase_pk": challenge_phase_pk_or_slug, "is_static_dataset_code_upload_submission": False, } if challenge.is_docker_based: @@ -591,7 +595,7 @@ def change_submission_data_and_visibility( ) @api_view(["GET"]) @throttle_classes([AnonRateThrottle, UserRateThrottle]) -def leaderboard(request, challenge_phase_split_id): +def leaderboard(request, challenge_pk, phase_slug, split_codename): """ Returns leaderboard for a corresponding Challenge Phase Split @@ -603,9 +607,18 @@ def leaderboard(request, challenge_phase_split_id): """ # check if the challenge exists or not - challenge_phase_split = get_challenge_phase_split_model( - challenge_phase_split_id - ) + try: + challenge_phase_split = ChallengePhaseSplit.objects.get( + challenge_phase__challenge__pk=challenge_pk, + challenge_phase__slug=phase_slug, + dataset_split__codename=split_codename, + ) + except ChallengePhaseSplit.DoesNotExist: + response_data = { + "error": "Leaderboard for the given phase and split does not exist." + } + return Response(response_data, status=status.HTTP_404_NOT_FOUND) + challenge_obj = challenge_phase_split.challenge_phase.challenge order_by = request.GET.get("order_by") ( @@ -623,11 +636,9 @@ def leaderboard(request, challenge_phase_split_id): if http_status_code == status.HTTP_400_BAD_REQUEST: return Response(response_data, status=http_status_code) - paginator, result_page = paginated_queryset( - response_data, request, pagination_class=StandardResultSetPagination() - ) - response_data = result_page - return paginator.get_paginated_response(response_data) + paginator = StandardResultSetPagination() + result_page = paginator.paginate_queryset(response_data, request) + return paginator.get_paginated_response(result_page) @extend_schema( @@ -757,7 +768,9 @@ def leaderboard(request, challenge_phase_split_id): @throttle_classes([AnonRateThrottle]) @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) -def get_all_entries_on_public_leaderboard(request, challenge_phase_split_pk): +def get_all_entries_on_public_leaderboard( + request, challenge_pk, phase_slug, split_codename +): """ Returns public/private leaderboard entries to corresponding challenge phase split for a challenge host @@ -805,9 +818,17 @@ def get_all_entries_on_public_leaderboard(request, challenge_phase_split_pk): ``` """ # check if the challenge exists or not - challenge_phase_split = get_challenge_phase_split_model( - challenge_phase_split_pk - ) + try: + challenge_phase_split = ChallengePhaseSplit.objects.get( + challenge_phase__challenge__pk=challenge_pk, + challenge_phase__slug=phase_slug, + dataset_split__codename=split_codename, + ) + except ChallengePhaseSplit.DoesNotExist: + response_data = { + "error": "Leaderboard for the given phase and split does not exist." + } + return Response(response_data, status=status.HTTP_404_NOT_FOUND) challenge_obj = challenge_phase_split.challenge_phase.challenge @@ -999,11 +1020,17 @@ def get_submission_by_pk(request, submission_id): }, "submission_status": { "type": "string", - "description": "Final status of submission (can take one of these values): CANCELLED/FAILED/FINISHED", + "description": ( + "Final status of submission (can take one of these values):" + " CANCELLED/FAILED/FINISHED" + ), }, "result": { "type": "array", - "description": "Submission results in array format. API will throw an error if any split and/or metric is missing", + "description": ( + "Submission results in array format." + " API will throw an error if any split and/or metric is missing" + ), "items": { "type": "object", "properties": { @@ -1138,7 +1165,8 @@ def update_submission(request, challenge_pk): - ``submission``: submission id, e.g. 123 (**required**) - ``stdout``: Stdout after evaluation, e.g. "Evaluation completed in 2 minutes" (**required**) - ``stderr``: Stderr after evaluation, e.g. "Failed due to incorrect file format" (**required**) - - ``environment_log``: Environment error after evaluation, e.g. "Failed due to attempted action being invalid" (**code upload challenge only**) + - ``environment_log``: Environment error after evaluation, e.g. + "Failed due to attempted action being invalid" (**code upload challenge only**) - ``submission_status``: Status of submission after evaluation (can take one of the following values: `FINISHED`/`CANCELLED`/`FAILED`), e.g. FINISHED (**required**) - ``result``: contains accuracies for each metric, (**required**) e.g. @@ -1435,7 +1463,10 @@ def update_submission(request, challenge_pk): }, "result": { "type": "array", - "description": "Submission results in array format. An error is thrown if any split and/or metric is missing", + "description": ( + "Submission results in array format. " + "An error is thrown if any split and/or metric is missing" + ), "items": { "type": "object", "properties": { @@ -2101,7 +2132,6 @@ def resume_submission(request, submission_pk): @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((JWTAuthentication, ExpiringTokenAuthentication)) def get_submissions_for_challenge(request, challenge_pk): - challenge = get_challenge_model(challenge_pk) if not is_user_a_staff(request.user) and not is_user_a_host_of_challenge( @@ -2701,7 +2731,8 @@ def get_submission_file_presigned_url(request, challenge_phase_pk): request {HttpRequest} -- The request object challenge_phase_pk {int} -- Challenge phase primary key Returns: - Response Object -- An object containing the presignd url and submission id, or an error message if some failure occurs + Response Object -- An object containing the presignd url and submission id, + or an error message if some failure occurs """ if settings.DEBUG: response_data = { @@ -2877,7 +2908,8 @@ def finish_submission_file_upload(request, challenge_phase_pk, submission_pk): challenge_phase_pk {int} -- Challenge phase primary key submission_pk {int} -- Submission primary key Returns: - Response Object -- An object containing the presignd url and submission id, or an error message if some failure occurs + Response Object -- An object containing the presignd url and + submission id, or an error message if some failure occurs """ if settings.DEBUG: response_data = { diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index 57ab960200..a949b19397 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -1,5 +1,5 @@ // Invoking IIFE for challenge page -(function() { +(function () { 'use strict'; angular @@ -15,6 +15,10 @@ vm.showPrivateIds = []; vm.showLeaderboardToggle = true; vm.challengeId = $stateParams.challengeId; + vm.allSubmissionPhaseSlug = $stateParams.allSubmissionPhaseSlug; + vm.mySubmissionPhaseSlug = $stateParams.mySubmissionPhaseSlug; + vm.phaseSlug = $stateParams.phaseSlug; + vm.splitCodename = $stateParams.splitCodename; vm.phaseId = null; vm.phaseSplitId = $stateParams.phaseSplitId; vm.input_file = null; @@ -30,7 +34,7 @@ vm.isParticipated = false; vm.isActive = false; vm.phases = {}; - vm.phaseSplits = {}; + vm.phaseSplits = []; vm.hasPrizes = false; vm.has_sponsors = false; vm.orderLeaderboardBy = decodeURIComponent($stateParams.metric); @@ -50,8 +54,8 @@ vm.poller = null; vm.isChallengeHost = false; vm.isDockerBased = false; - vm.stopLeaderboard = function() {}; - vm.stopFetchingSubmissions = function() {}; + vm.stopLeaderboard = function () { }; + vm.stopFetchingSubmissions = function () { }; vm.currentDate = null; vm.isPublished = false; vm.approved_by_admin = false; @@ -111,7 +115,7 @@ var gmtZone = 'GMT ' + gmtSign + ' ' + gmtHours + ':' + (gmtMinutes < 10 ? '0' : '') + gmtMinutes; vm.isStaticCodeUploadChallenge = false; - + // get from backend vm.selectedWorkerResources = [512, 1024]; @@ -124,7 +128,7 @@ // scroll to the selected entry after page has been rendered vm.scrollToEntryAfterLeaderboardLoads = function () { // get unique rank number from the url & if exists hightlight the entry - $timeout(function() { + $timeout(function () { var elementId = $location.absUrl().split('?')[0].split('#')[1]; if (elementId) { $anchorScroll.yOffset = 90; @@ -176,23 +180,23 @@ // API call to manage the worker from UI. // Response data will be like: {action: "Success" or "Failure", error: } - vm.manageWorker = function(action){ - parameters.url = 'challenges/' + vm.challengeId + '/manage_worker/' + action +'/'; + vm.manageWorker = function (action) { + parameters.url = 'challenges/' + vm.challengeId + '/manage_worker/' + action + '/'; parameters.method = 'PUT'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; - if (details.action == "Success"){ + if (details.action == "Success") { $rootScope.notify("success", "Worker(s) " + action + "ed succesfully."); } else { $rootScope.notify("error", details.error); } }, - onError: function(response) { + onError: function (response) { var error = response.data.error; - if (error == undefined){ + if (error == undefined) { $rootScope.notify("error", "There was an error."); } else { @@ -203,13 +207,13 @@ utilities.sendRequest(parameters); }; - vm.sendApprovalRequest = function() { + vm.sendApprovalRequest = function () { parameters.url = 'challenges/' + vm.challengeId + '/request_approval'; parameters.method = 'GET'; parameters.data = {}; - + parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var result = response.data; if (result.error) { $rootScope.notify("error", result.error); @@ -217,7 +221,7 @@ $rootScope.notify("success", "Request sent successfully."); } }, - onError: function(response) { + onError: function (response) { var error = response.data.error; if (error) { $rootScope.notify("error", "There was an error: " + error); @@ -226,10 +230,10 @@ } } }; - + utilities.sendRequest(parameters); }; - + // Get the logs from worker if submissions are failing. vm.startLoadingLogs = function () { vm.logs_poller = $interval(function () { @@ -269,11 +273,11 @@ }, 5000); }; - vm.stopLoadingLogs = function(){ + vm.stopLoadingLogs = function () { $interval.cancel(vm.logs_poller); }; - // highlight the specific entry of the leaderboard + // highlight the specific entry of the leaderboard vm.highlightSpecificLeaderboardEntry = function (key) { key = '#' + key; // Remove highlight from previous clicked entry @@ -288,13 +292,13 @@ }; // get names of the team that has participated in the current challenge - vm.getTeamName = function(challengeId) { + vm.getTeamName = function (challengeId) { parameters.url = 'challenges/' + challengeId + '/participant_team/team_detail'; parameters.method = 'GET'; - parameters.data={}; + parameters.data = {}; parameters.callback = { - onSuccess: function(response) { - var details = response.data; + onSuccess: function (response) { + var details = response.data; vm.participated_team_name = details["team_name"]; vm.eligible_to_submit = details["approved"]; }, @@ -302,7 +306,7 @@ utilities.sendRequest(parameters); }; - vm.displayDockerSubmissionInstructions = function (isDockerBased, isParticipated) { + vm.displayDockerSubmissionInstructions = function (isDockerBased, isParticipated) { // get remaining submission for docker based challenge if (isDockerBased && isParticipated == true && vm.eligible_to_submit) { parameters.url = 'jobs/' + vm.challengeId + '/remaining_submissions/'; @@ -371,7 +375,7 @@ parameters.url = 'challenges/challenge/' + vm.challengeId + '/'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.page = details; var offset = new Date(vm.page.start_date).getTimezoneOffset(); @@ -388,7 +392,7 @@ vm.isStaticCodeUploadChallenge = details.is_static_dataset_code_upload; vm.allowResumingSubmissions = details.allow_resuming_submissions; vm.allowHostCancelSubmissions = details.allow_host_cancel_submissions, - vm.allowCancelRunningSubmissions = details.allow_cancel_running_submissions; + vm.allowCancelRunningSubmissions = details.allow_cancel_running_submissions; vm.allowParticipantsResubmissions = details.allow_participants_resubmissions; vm.selectedWorkerResources = [details.worker_cpu_cores, details.worker_memory]; vm.manual_participant_approval = details.manual_participant_approval; @@ -411,10 +415,10 @@ parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { vm.prizes = response.data; }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); } @@ -429,10 +433,10 @@ parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { vm.sponsors = response.data; }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); } @@ -447,7 +451,7 @@ parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.currentDate = details.datetime_now; for (var i in details.challenge_participant_team_list) { @@ -472,7 +476,7 @@ parameters.url = 'participants/participant_team'; parameters.method = 'GET'; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; var details = response.data; if (status == 200) { @@ -509,7 +513,7 @@ // select team from existing list - vm.selectExistTeam = function() { + vm.selectExistTeam = function () { // loader for existing teams vm.isExistLoader = true; @@ -523,14 +527,14 @@ parameters.url = 'challenges/challenge/' + vm.challengeId + '/participant_team/' + vm.teamId; parameters.method = 'POST'; parameters.callback = { - onSuccess: function() { + onSuccess: function () { vm.isParticipated = true; $state.go('web.challenge-main.challenge-page.submission'); vm.displayDockerSubmissionInstructions(vm.page.is_docker_based, vm.isParticipated); vm.getTeamName(vm.challengeId); vm.stopLoader(); }, - onError: function(response) { + onError: function (response) { if (response.status == 404) { var error = "Please select a team first!"; } else { @@ -544,7 +548,7 @@ }; // to load data with pagination - vm.load = function(url) { + vm.load = function (url) { // loader for existing teams vm.isExistLoader = true; vm.loaderTitle = ''; @@ -560,7 +564,7 @@ }; //Add headers with in your request - $http.get(url, { headers: headers }).then(function(response) { + $http.get(url, { headers: headers }).then(function (response) { // reinitialized data var details = response.data; vm.existTeam = details; @@ -587,7 +591,7 @@ } utilities.hideLoader(); }, - onError: function(response) { + onError: function (response) { var error = response.data; utilities.storeData('emailError', error.detail); $state.go('web.permission-denied'); @@ -601,7 +605,7 @@ vm.displayDockerSubmissionInstructions(vm.page.is_docker_based, vm.isParticipated); utilities.hideLoader(); }, - onError: function() { + onError: function () { utilities.hideLoader(); } }; @@ -611,7 +615,7 @@ utilities.hideLoader(); }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error.error); $state.go('web.dashboard'); @@ -633,11 +637,11 @@ participationModalText = 'Open participation in the challenge?'; } var confirm = $mdDialog.confirm() - .title(participationModalText) - .ariaLabel('') - .targetEvent(ev) - .ok('Yes, I\'m sure') - .cancel('No'); + .title(participationModalText) + .ariaLabel('') + .targetEvent(ev) + .ok('Yes, I\'m sure') + .cancel('No'); $mdDialog.show(confirm).then(function () { var challengeHostList = utilities.getData("challengeCreator"); @@ -653,20 +657,20 @@ "is_registration_open": !isRegistrationOpen }; parameters.callback = { - onSuccess: function() { + onSuccess: function () { vm.isRegistrationOpen = !vm.isRegistrationOpen; $rootScope.notify('success', 'Participation is ' + participationState + ' successfully'); }, - onError: function(response) { + onError: function (response) { var details = response.data; $rootScope.notify('error', details.error); } }; utilities.sendRequest(parameters); - }, function() {}); + }, function () { }); }; - vm.makeSubmission = function() { + vm.makeSubmission = function () { if (vm.isParticipated && vm.eligible_to_submit) { var fileVal = angular.element(".file-path").val(); if ((fileVal === null || fileVal === "") && (vm.fileUrl === null || vm.fileUrl === "")) { @@ -685,7 +689,7 @@ if (vm.input_file) { // vm.upload(vm.input_file); } - parameters.url = 'jobs/challenge/' + vm.challengeId + '/challenge_phase/' + vm.phaseId + '/submission/'; + parameters.url = 'jobs/challenge/' + vm.challengeId + '/challenge_phase/' + "v1/" + vm.phaseId + '/submission/'; parameters.method = 'POST'; var formData = new FormData(); if (vm.isSubmissionUsingUrl) { @@ -717,12 +721,12 @@ parameters.token = userKey; parameters.callback = { - onSuccess: function() { + onSuccess: function () { // vm.input_file.name = ''; angular.forEach( angular.element("input[type='file']"), - function(inputElem) { + function (inputElem) { angular.element(inputElem).val(null); } ); @@ -744,7 +748,7 @@ vm.metaAttributesforCurrentSubmission = null; vm.stopLoader(); }, - onError: function(response) { + onError: function (response) { var status = response.status; var error = response.data; @@ -758,7 +762,7 @@ if (status == 404) { vm.subErrors.msg = "Please select phase!"; } else { - if (error.error){ + if (error.error) { vm.subErrors.msg = error.error; } else { vm.subErrors.msg = error.input_file[0]; @@ -777,24 +781,34 @@ parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.phases = details; - for (var i=0; i -1) { - attribute.values.splice(idx, 1); - } - else { - attribute.values.push(value); - } - }; + vm.toggleSelection = function toggleSelection(attribute, value) { // Make sure this modifies the reference object. + var idx = attribute.values.indexOf(value); + if (idx > -1) { + attribute.values.splice(idx, 1); + } + else { + attribute.values.push(value); + } + }; var challengePhaseVisibility = { owner_and_host: 1, @@ -929,28 +943,35 @@ public: 3, }; - // get details of the particular challenge phase split + parameters.url = 'challenges/' + vm.challengeId + '/challenge_phase_split'; parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.phaseSplits = details; if (details.length == 0) { - vm.isChallengeLeaderboardPrivate = true; + vm.isChallengeLeaderboardPrivate = true; } - for(var i=0; i ps.challenge_phase_slug === phaseSlug && ps.dataset_split_codename === splitCodename); + if (currentPhaseSplit) { + vm.phaseSplitId = currentPhaseSplit.id; + vm.selectedPhaseSplit = currentPhaseSplit; + } // Show leaderboard vm.leaderboard = {}; - parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000&order_by=" + vm.orderLeaderboardBy; + parameters.url = `jobs/challenge/${vm.challengeId}/phase/${phaseSlug}/split/${splitCodename}/leaderboard/?page_size=1000&order_by=${vm.orderLeaderboardBy}`; parameters.method = 'GET'; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.leaderboard = details.results; - for (var j=0; j 0) { + var allMetricIndices = []; + + var labels = vm.leaderboard[0].leaderboard__schema.labels; + for (var k = 0; k < labels.length; k++) { + allMetricIndices.push(k.toString()); } - else { - vm.showSubmissionMetaAttributesOnLeaderboard = true; + + vm.chosenMetrics = allMetricIndices; + + + if (vm.phaseSplitId) { + vm.phaseSplitLeaderboardSchema[vm.phaseSplitId] = vm.leaderboard[0].leaderboard__schema; } + } - var leaderboardLabels = vm.leaderboard[i].leaderboard__schema.labels; - var index = leaderboardLabels.findIndex(label => label === vm.orderLeaderboardBy); - vm.chosenMetrics = index !== -1 ? [index.toString()]: undefined; + + for (var i = 0; i < vm.leaderboard.length; i++) { vm.leaderboard[i]['submission__submitted_at_formatted'] = vm.leaderboard[i]['submission__submitted_at']; - vm.initial_ranking[vm.leaderboard[i].id] = i+1; + vm.initial_ranking[vm.leaderboard[i].id] = i + 1; + var dateTimeNow = moment(new Date()); var submissionTime = moment(vm.leaderboard[i].submission__submitted_at); var duration = moment.duration(dateTimeNow.diff(submissionTime)); - if (duration._data.years != 0) { - var years = duration.asYears(); - vm.leaderboard[i].submission__submitted_at = years; - if (years.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'year'; - } else { - vm.leaderboard[i].timeSpan= 'years'; - } - } - else if (duration._data.months !=0) { - var months = duration.months(); - vm.leaderboard[i].submission__submitted_at = months; - if (months.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'month'; - } else { - vm.leaderboard[i].timeSpan = 'months'; - } - } - else if (duration._data.days !=0) { - var days = duration.asDays(); - vm.leaderboard[i].submission__submitted_at = days; - if (days.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'day'; - } else { - vm.leaderboard[i].timeSpan = 'days'; - } - } - else if (duration._data.hours !=0) { - var hours = duration.asHours(); - vm.leaderboard[i].submission__submitted_at = hours; - if (hours.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'hour'; - } else { - vm.leaderboard[i].timeSpan = 'hours'; - } - } - else if (duration._data.minutes !=0) { - var minutes = duration.asMinutes(); - vm.leaderboard[i].submission__submitted_at = minutes; - if (minutes.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'minute'; - } else { - vm.leaderboard[i].timeSpan = 'minutes'; - } - } - else if (duration._data.seconds != 0) { - var second = duration.asSeconds(); - vm.leaderboard[i].submission__submitted_at = second; - if (second.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'second'; - } else { - vm.leaderboard[i].timeSpan = 'seconds'; - } + var timeValue, timeSpan; + + if (duration.asYears() >= 1) { + timeValue = Math.floor(duration.asYears()); + timeSpan = timeValue === 1 ? 'year' : 'years'; + } else if (duration.asMonths() >= 1) { // The new, correct block for months + timeValue = Math.floor(duration.asMonths()); + timeSpan = timeValue === 1 ? 'month' : 'months'; + } else if (duration.asDays() >= 1) { + timeValue = Math.floor(duration.asDays()); + timeSpan = timeValue === 1 ? 'day' : 'days'; + } else if (duration.asHours() >= 1) { + timeValue = Math.floor(duration.asHours()); + timeSpan = timeValue === 1 ? 'hour' : 'hours'; + } else if (duration.asMinutes() >= 1) { + timeValue = Math.floor(duration.asMinutes()); + timeSpan = timeValue === 1 ? 'minute' : 'minutes'; + } else { + timeValue = Math.floor(duration.asSeconds()); + timeSpan = timeValue === 1 ? 'second' : 'seconds'; } + + vm.leaderboard[i].submission__submitted_at = timeValue; + vm.leaderboard[i].timeSpan = timeSpan; + } + + if (currentPhaseSplit) { + vm.phaseName = currentPhaseSplit.id; } - vm.phaseName = vm.phaseSplitId; vm.startLeaderboard(); vm.stopLoader(); vm.scrollToEntryAfterLeaderboardLoads(); }, - onError: function(response) { + onError: function (response) { var error = response.data; vm.leaderboard.error = error; vm.stopLoader(); } }; - utilities.sendRequest(parameters); }; - - vm.showMetaAttributesDialog = function(ev, attributes){ - if (attributes != false){ + + + vm.showMetaAttributesDialog = function (ev, attributes) { + if (attributes != false) { vm.metaAttributesData = []; - attributes.forEach(function(attribute){ + attributes.forEach(function (attribute) { if (attribute.type != "checkbox") { - vm.metaAttributesData.push({"name": attribute.name, "value": attribute.value}); + vm.metaAttributesData.push({ "name": attribute.name, "value": attribute.value }); } else { - vm.metaAttributesData.push({"name": attribute.name, "values": attribute.values}); + vm.metaAttributesData.push({ "name": attribute.name, "values": attribute.values }); } }); @@ -1206,19 +1194,50 @@ } }; - vm.getResults = function(phaseId) { - // long polling (5s) for leaderboard - vm.start = function() { + vm.getResults = function (phaseSlug) { + + vm.stopFetchingSubmissions(); + vm.isResult = true; + + + vm.mySubmissionPhaseSlug = phaseSlug; + + + var numericPhaseId = null; + var all_phases = vm.phases.results; + for (var i = 0; i < all_phases.length; i++) { + + if (all_phases[i].slug === phaseSlug) { + numericPhaseId = all_phases[i].id; + + + vm.currentPhaseLeaderboardPublic = all_phases[i].leaderboard_public; + vm.isCurrentPhaseRestrictedToSelectOneSubmission = all_phases[i].is_restricted_to_select_one_submission; + + var attributes = all_phases[i].default_submission_meta_attributes; + var defaultMetaAttributes = vm.getDefaultMetaAttributesDict(attributes); + vm.currentPhaseMetaAttributesVisibility = defaultMetaAttributes; + + + break; + } + } + + + + vm.phaseId = numericPhaseId; + + + vm.start = function () { vm.stopFetchingSubmissions(); - vm.poller = $interval(function() { - parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/submission/?page=" + Math.ceil(vm.currentPage); + vm.poller = $interval(function () { + + parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + "v2/" + vm.mySubmissionPhaseSlug + "/submission/?page=" + Math.ceil(vm.currentPage); parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; - - // Set the is_public flag corresponding to each submission for (var i = 0; i < details.results.length; i++) { vm.submissionVisibility[details.results[i].id] = details.results[i].is_public; vm.baselineStatus[details.results[i].id] = details.results[i].is_baseline; @@ -1236,100 +1255,77 @@ } } }, - onError: function(response) { + onError: function (response) { var error = response.data; utilities.storeData('emailError', error.detail); $state.go('web.permission-denied'); vm.stopLoader(); } }; - utilities.sendRequest(parameters); }, 10000); }; - vm.stopFetchingSubmissions = function() { + vm.stopFetchingSubmissions = function () { $interval.cancel(vm.poller); }; - vm.stopFetchingSubmissions(); - vm.isResult = true; - if (phaseId !== undefined) { - vm.phaseId = phaseId; - } - var all_phases = vm.phases.results; - for (var i = 0; i < vm.phases.results.length; i++) { - if (all_phases[i].id == phaseId) { - vm.currentPhaseLeaderboardPublic = all_phases[i].leaderboard_public; - vm.isCurrentPhaseRestrictedToSelectOneSubmission = all_phases[i].is_restricted_to_select_one_submission; - - var attributes = all_phases[i].default_submission_meta_attributes; - var defaultMetaAttributes = vm.getDefaultMetaAttributesDict(attributes); - vm.currentPhaseMetaAttributesVisibility = defaultMetaAttributes; - break; - } - } - parameters.url = "analytics/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/count"; + parameters.url = "analytics/challenge/" + vm.challengeId + "/challenge_phase/" + "v2/" + vm.mySubmissionPhaseSlug + "/count"; parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.submissionCount = details.participant_team_submission_count; }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); } }; utilities.sendRequest(parameters); - // loader for existing teams + vm.isExistLoader = true; vm.loaderTitle = ''; vm.loaderContainer = angular.element('.exist-team-card'); - vm.startLoader("Loading Submissions"); - - // get submissions of a particular challenge phase vm.isNext = ''; vm.isPrev = ''; vm.currentPage = ''; vm.showPagination = false; + // Use the slug in the URL for the initial submission fetch if (vm.filter_my_submission_by_team_name === '') { - parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + - vm.phaseId + "/submission/"; + parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + "v2/" + + vm.mySubmissionPhaseSlug + "/submission/"; } else { - parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + - vm.phaseId + "/submission?participant_team__team_name=" + vm.filter_my_submission_by_team_name; + parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + "v2/" + + vm.mySubmissionPhaseSlug + "/submission?participant_team__team_name=" + vm.filter_my_submission_by_team_name; } parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; for (var i = 0; i < details.results.length; i++) { vm.submissionVisibility[details.results[i].id] = details.results[i].is_public; vm.baselineStatus[details.results[i].id] = details.results[i].is_baseline; vm.verifiedStatus[details.results[i].id] = details.results[i].is_verified_by_host; - // Set previous public submission id for phases with one public submission restriction if (details.results[i].is_public) { vm.previousPublicSubmissionId = details.results[i].id; } } vm.submissionResult = details; - - vm.start(); + vm.start(); // Start the long polling after the first load if (vm.submissionResult.count === 0) { vm.showPagination = false; vm.paginationMsg = "No results found"; } else { - vm.showPagination = true; vm.paginationMsg = ""; } @@ -1338,7 +1334,6 @@ vm.isNext = 'disabled'; } else { vm.isNext = ''; - } if (vm.submissionResult.previous === null) { vm.isPrev = 'disabled'; @@ -1353,27 +1348,18 @@ vm.currentRefPage = Math.ceil(vm.currentPage); } - vm.load = function(url) { - // loader for existing teams + vm.load = function (url) { vm.isExistLoader = true; vm.loaderTitle = ''; vm.loaderContainer = angular.element('.exist-team-card'); - vm.startLoader("Loading Submissions"); - if (url !== null) { - //store the header data in a variable - var headers = { - 'Authorization': "Token " + userKey - }; - - //Add headers with in your request - $http.get(url, { headers: headers }).then(function(response) { - // reinitialized data + if (url !== null) { + var headers = { 'Authorization': "Token " + userKey }; + $http.get(url, { headers: headers }).then(function (response) { var details = response.data; vm.submissionResult = details; - // condition for pagination if (vm.submissionResult.next === null) { vm.isNext = 'disabled'; vm.currentPage = vm.submissionResult.count / 150; @@ -1395,21 +1381,21 @@ vm.stopLoader(); } }; + vm.mySubmissionPhaseName = phaseSlug; // Use phaseSlug for display name vm.stopLoader(); }, - onError: function(response) { + onError: function (response) { var error = response.data; - utilities.storeData('emailError', error.detail); + var errorDetail = (error && error.detail) ? error.detail : error; + utilities.storeData('emailError', errorDetail); $state.go('web.permission-denied'); vm.stopLoader(); } }; - utilities.sendRequest(parameters); }; - - vm.refreshSubmissionData = function() { - + vm.refreshSubmissionData = function () { + vm.phaseId = (vm.allSubmissionPhaseSlug == undefined) ? vm.mySubmissionPhaseSlug : vm.allSubmissionPhaseSlug; // get submissions of a particular challenge phase if (!vm.isResult) { @@ -1424,11 +1410,11 @@ vm.startLoader("Loading Submissions"); vm.submissionResult = {}; - parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/submission/?page=" + Math.ceil(vm.currentPage); + parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + "v2/" + vm.phaseId + "/submission/?page=" + Math.ceil(vm.currentPage); parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.submissionResult = details; @@ -1472,7 +1458,7 @@ vm.showUpdate = false; vm.stopLoader(); }, - onError: function() { + onError: function () { vm.stopLoader(); } }; @@ -1480,17 +1466,17 @@ utilities.sendRequest(parameters); }; - vm.reRunSubmission = function(submissionObject) { + vm.reRunSubmission = function (submissionObject) { submissionObject.classList = ['spin', 'progress-indicator']; parameters.url = 'jobs/submissions/' + submissionObject.id + '/re-run/'; parameters.method = 'POST'; parameters.token = userKey; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { $rootScope.notify("success", response.data.success); submissionObject.classList = ['']; }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); submissionObject.classList = ['']; @@ -1499,17 +1485,17 @@ utilities.sendRequest(parameters); }; - vm.resumeSubmission = function(submissionObject) { + vm.resumeSubmission = function (submissionObject) { submissionObject.classList2 = ['progress-indicator']; parameters.url = 'jobs/submissions/' + submissionObject.id + '/resume/'; parameters.method = 'POST'; parameters.token = userKey; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { $rootScope.notify("success", response.data.success); submissionObject.classList2 = ['']; }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); submissionObject.classList2 = ['']; @@ -1518,19 +1504,19 @@ utilities.sendRequest(parameters); }; - vm.refreshLeaderboard = function() { + vm.refreshLeaderboard = function () { vm.startLoader("Loading Leaderboard Items"); vm.leaderboard = {}; - parameters.url = "jobs/" + "challenge_phase_split/" + vm.phaseSplitId + "/leaderboard/?page_size=1000&order_by=" + vm.orderLeaderboardBy; + parameters.url = `jobs/challenge/${vm.challengeId}/phase/${vm.phaseSlug}/split/${vm.splitCodename}/leaderboard/?page_size=1000&order_by=${vm.orderLeaderboardBy}`; parameters.method = 'GET'; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.leaderboard = details.results; vm.startLeaderboard(); vm.stopLoader(); }, - onError: function(response) { + onError: function (response) { var error = response.data; vm.leaderboard.error = error; vm.stopLoader(); @@ -1540,7 +1526,7 @@ utilities.sendRequest(parameters); }; - vm.toggleShowLeaderboardByLatest = function() { + vm.toggleShowLeaderboardByLatest = function () { parameters.url = "challenges/challenge/create/challenge_phase_split/" + vm.phaseSplitId + "/"; parameters.method = "PATCH"; parameters.data = { @@ -1551,7 +1537,7 @@ vm.selectedPhaseSplit = response.data; vm.getLeaderboard(vm.selectedPhaseSplit.id); vm.sortLeaderboardTextOption = (vm.selectedPhaseSplit.show_leaderboard_by_latest_submission) ? - "Sort by best":"Sort by latest"; + "Sort by best" : "Sort by latest"; }, onError: function (response) { var error = response.data; @@ -1564,14 +1550,23 @@ }; // function for getting all submissions on leaderboard public/private - vm.getAllEntriesOnPublicLeaderboard = function(phaseSplitId) { - vm.stopLeaderboard = function() { + vm.getAllEntriesOnPublicLeaderboard = function (phaseSlug, splitCodename) { + vm.stopLeaderboard = function () { $interval.cancel(vm.poller); }; vm.stopLeaderboard(); vm.isResult = true; - vm.phaseSplitId = phaseSplitId; + + // Find the corresponding phase split object to get its ID + var currentPhaseSplit = vm.phaseSplits.find(function (ps) { + return ps.challenge_phase_slug === phaseSlug && ps.dataset_split_codename === splitCodename; + }); + + if (currentPhaseSplit) { + vm.phaseSplitId = currentPhaseSplit.id; + } + // loader for exisiting teams vm.isExistLoader = true; vm.loaderTitle = ''; @@ -1581,13 +1576,16 @@ // Show leaderboard vm.leaderboard = {}; - parameters.url = "jobs/" + "phase_split/" + vm.phaseSplitId + "/public_leaderboard_all_entries/?page_size=1000&order_by=" + vm.orderLeaderboardBy; + parameters.url = `jobs/challenge/${vm.challengeId}/phase/${phaseSlug}/split/${splitCodename}/public_leaderboard_all_entries/?page_size=1000&order_by=${vm.orderLeaderboardBy}`; parameters.method = 'GET'; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.leaderboard = details.results; + // setting last_submission time + + // THIS IS THE BLOCK TO REPLACE // setting last_submission time for (var i = 0; i < vm.leaderboard.length; i++) { vm.leaderboard[i]['submission__submitted_at_formatted'] = vm.leaderboard[i]['submission__submitted_at']; @@ -1595,62 +1593,39 @@ var dateTimeNow = moment(new Date()); var submissionTime = moment(vm.leaderboard[i].submission__submitted_at); var duration = moment.duration(dateTimeNow.diff(submissionTime)); - if (duration._data.years != 0) { - var years = duration.asYears(); - vm.leaderboard[i].submission__submitted_at = years; - if (years.toFixed(0) == 1) { - vm.leaderboard[i].timeSpan = 'year'; - } else { - vm.leaderboard[i].timeSpan = 'years'; - } - } else if (duration._data.months != 0) { - var months = duration.months(); - vm.leaderboard[i].submission__submitted_at = months; - if (months.toFixed(0) == 1) { - vm.leaderboard[i].timeSpan = 'month'; - } else { - vm.leaderboard[i].timeSpan = 'months'; - } - } else if (duration._data.days != 0) { - var days = duration.asDays(); - vm.leaderboard[i].submission__submitted_at = days; - if (days.toFixed(0) == 1) { - vm.leaderboard[i].timeSpan = 'day'; - } else { - vm.leaderboard[i].timeSpan = 'days'; - } - } else if (duration._data.hours != 0) { - var hours = duration.asHours(); - vm.leaderboard[i].submission__submitted_at = hours; - if (hours.toFixed(0) == 1) { - vm.leaderboard[i].timeSpan = 'hour'; - } else { - vm.leaderboard[i].timeSpan = 'hours'; - } - } else if (duration._data.minutes != 0) { - var minutes = duration.asMinutes(); - vm.leaderboard[i].submission__submitted_at = minutes; - if (minutes.toFixed(0) == 1) { - vm.leaderboard[i].timeSpan = 'minute'; - } else { - vm.leaderboard[i].timeSpan = 'minutes'; - } - } else if (duration._data.seconds != 0) { - var second = duration.asSeconds(); - vm.leaderboard[i].submission__submitted_at = second; - if (second.toFixed(0) == 1) { - vm.leaderboard[i].timeSpan = 'second'; - } else { - vm.leaderboard[i].timeSpan = 'seconds'; - } + var timeValue, timeSpan; + + if (duration.asYears() >= 1) { + timeValue = Math.floor(duration.asYears()); + timeSpan = timeValue === 1 ? 'year' : 'years'; + } else if (duration.asMonths() >= 1) { + timeValue = Math.floor(duration.asMonths()); + timeSpan = timeValue === 1 ? 'month' : 'months'; + } else if (duration.asDays() >= 1) { + timeValue = Math.floor(duration.asDays()); + timeSpan = timeValue === 1 ? 'day' : 'days'; + } else if (duration.asHours() >= 1) { + timeValue = Math.floor(duration.asHours()); + timeSpan = timeValue === 1 ? 'hour' : 'hours'; + } else if (duration.asMinutes() >= 1) { + timeValue = Math.floor(duration.asMinutes()); + timeSpan = timeValue === 1 ? 'minute' : 'minutes'; + } else { + timeValue = Math.floor(duration.asSeconds()); + timeSpan = timeValue === 1 ? 'second' : 'seconds'; } + + vm.leaderboard[i].submission__submitted_at = timeValue; + vm.leaderboard[i].timeSpan = timeSpan; + } + if (currentPhaseSplit) { + vm.phaseName = currentPhaseSplit.id; } - vm.phaseName = vm.phaseSplitId; vm.startLeaderboard(); vm.stopLoader(); vm.scrollToEntryAfterLeaderboardLoads(); }, - onError: function(response) { + onError: function (response) { var error = response.data; vm.leaderboard.error = error; vm.stopLoader(); @@ -1659,29 +1634,24 @@ utilities.sendRequest(parameters); }; - - if (vm.phaseSplitId) { - vm.getLeaderboard(vm.phaseSplitId); - } vm.getAllEntries = false; // function for toggeling between public leaderboard and complete leaderboard [public/private] - vm.toggleLeaderboard = function(getAllEntries){ + vm.toggleLeaderboard = function (getAllEntries) { vm.getAllEntries = getAllEntries; - if (vm.phaseSplitId) { - if (vm.getAllEntries){ + if (vm.phaseSlug && vm.splitCodename) { + if (vm.getAllEntries) { vm.getAllEntriesTestOption = "Exclude private submissions"; - vm.getAllEntriesOnPublicLeaderboard(vm.phaseSplitId); - } - else { + vm.getAllEntriesOnPublicLeaderboard(vm.phaseSlug, vm.splitCodename); + } else { vm.getAllEntriesTestOption = "Include private submissions"; - vm.getLeaderboard(vm.phaseSplitId); + vm.getLeaderboard(vm.phaseSlug, vm.splitCodename); } } }; // function to create new team for participating in challenge - vm.createNewTeam = function() { + vm.createNewTeam = function () { vm.isLoader = true; vm.loaderTitle = ''; vm.newContainer = angular.element('.new-team-card'); @@ -1695,7 +1665,7 @@ "team_url": vm.team.url }; parameters.callback = { - onSuccess: function() { + onSuccess: function () { $rootScope.notify("success", "Team " + vm.team.name + " has been created successfully!"); vm.team.error = false; vm.stopLoader(); @@ -1705,7 +1675,7 @@ parameters.url = 'participants/participant_team'; parameters.method = 'GET'; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; var details = response.data; if (status == 200) { @@ -1733,13 +1703,13 @@ vm.stopLoader(); } }, - onError: function() { + onError: function () { vm.stopLoader(); } }; utilities.sendRequest(parameters); }, - onError: function(response) { + onError: function (response) { var error = response.data; vm.team.error = error.team_name[0]; vm.stopLoader(); @@ -1750,7 +1720,7 @@ utilities.sendRequest(parameters); }; - vm.setWorkerResources = function() { + vm.setWorkerResources = function () { parameters.url = "challenges/" + vm.challengeId + "/scale_resources/"; parameters.method = 'PUT'; parameters.data = { @@ -1758,17 +1728,17 @@ "worker_memory": vm.selectedWorkerResources[1], }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { $rootScope.notify("success", response.data["Success"]); vm.team.error = false; vm.stopLoader(); vm.team = {}; }, - onError: function(response) { + onError: function (response) { vm.team.error = true; vm.stopLoader(); let requestError = ''; - if (typeof(response.data) == 'string') { + if (typeof (response.data) == 'string') { requestError = response.data; } else { requestError = response.data["error"]; @@ -1779,38 +1749,47 @@ utilities.sendRequest(parameters); }; + vm.getAllSubmissionResults = function (phaseSlug) { - vm.getAllSubmissionResults = function(phaseId) { - vm.stopFetchingSubmissions = function() { + vm.stopFetchingSubmissions = function () { $interval.cancel(vm.poller); }; - vm.stopFetchingSubmissions(); + vm.isResult = true; - if (phaseId !== undefined) { - vm.phaseId = phaseId; + vm.allSubmissionPhaseSlug = phaseSlug; + + + var numericPhaseId = null; + var all_phases = vm.phases.results; + for (var i = 0; i < all_phases.length; i++) { + if (all_phases[i].slug === phaseSlug) { + numericPhaseId = all_phases[i].id; + break; + } } + vm.phaseId = numericPhaseId; - // loader for loading submissions. + // Start loading submissions vm.startLoader = loaderService.startLoader; vm.startLoader("Loading Submissions"); - // get submissions of all the challenge phases vm.isNext = ''; vm.isPrev = ''; vm.currentPage = ''; vm.showPagination = false; + if (vm.filter_all_submission_by_team_name === '') { - parameters.url = "challenges/" + vm.challengeId + "/challenge_phase/" + - vm.phaseId + "/submissions"; + parameters.url = "challenges/" + vm.challengeId + "/challenge_phase/" + "v2/" + + vm.allSubmissionPhaseSlug + "/submissions"; } else { - parameters.url = "challenges/" + vm.challengeId + "/challenge_phase/" + - vm.phaseId + "/submissions?participant_team__team_name=" + vm.filter_all_submission_by_team_name; + parameters.url = "challenges/" + vm.challengeId + "/challenge_phase/" + "v2/" + + vm.allSubmissionPhaseSlug + "/submissions?participant_team__team_name=" + vm.filter_all_submission_by_team_name; } parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.submissionResult = details; @@ -1833,7 +1812,6 @@ vm.isNext = 'disabled'; } else { vm.isNext = ''; - } if (vm.submissionResult.previous === null) { vm.isPrev = 'disabled'; @@ -1848,24 +1826,15 @@ vm.currentRefPage = Math.ceil(vm.currentPage); } - vm.load = function(url) { - // loader for loading submissions + vm.load = function (url) { vm.startLoader = loaderService.startLoader; vm.startLoader("Loading Submissions"); if (url !== null) { - - //store the header data in a variable - var headers = { - 'Authorization': "Token " + userKey - }; - - //Add headers with in your request - $http.get(url, { headers: headers }).then(function(response) { - // reinitialized data + var headers = { 'Authorization': "Token " + userKey }; + $http.get(url, { headers: headers }).then(function (response) { var details = response.data; vm.submissionResult = details; - // condition for pagination if (vm.submissionResult.next === null) { vm.isNext = 'disabled'; vm.currentPage = vm.submissionResult.count / 150; @@ -1887,9 +1856,10 @@ vm.stopLoader(); } }; + vm.allSubmissionPhaseName = phaseSlug; vm.stopLoader(); }, - onError: function(response) { + onError: function (response) { var error = response.data; utilities.storeData('emailError', error.detail); $state.go('web.permission-denied'); @@ -1899,83 +1869,83 @@ utilities.sendRequest(parameters); }; - vm.changeSubmissionVisibility = function(submission_id, submissionVisibility) { + vm.changeSubmissionVisibility = function (submission_id, submissionVisibility) { parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/submission/" + submission_id; parameters.method = 'PATCH'; parameters.data = { "is_public": submissionVisibility }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; var message = ""; if (status === 200) { - var detail = response.data; - if (detail['is_public'] == true) { - message = "The submission is made public."; - } - else { - message = "The submission is made private."; - } - $rootScope.notify("success", message); - if (vm.isCurrentPhaseRestrictedToSelectOneSubmission) { - $mdDialog.hide(); - if (vm.previousPublicSubmissionId != submission_id) { - vm.submissionVisibility[vm.previousPublicSubmissionId] = false; - vm.previousPublicSubmissionId = submission_id; - } else { - vm.previousPublicSubmissionId = null; + var detail = response.data; + if (detail['is_public'] == true) { + message = "The submission is made public."; + } + else { + message = "The submission is made private."; + } + $rootScope.notify("success", message); + if (vm.isCurrentPhaseRestrictedToSelectOneSubmission) { + $mdDialog.hide(); + if (vm.previousPublicSubmissionId != submission_id) { + vm.submissionVisibility[vm.previousPublicSubmissionId] = false; + vm.previousPublicSubmissionId = submission_id; + } else { + vm.previousPublicSubmissionId = null; + } + vm.submissionVisibility[submission_id] = submissionVisibility; } - vm.submissionVisibility[submission_id] = submissionVisibility; - } } }, - onError: function(response) { + onError: function (response) { var error = response.data; var status = response.status; if (status === 400 || status === 403) { - $rootScope.notify("error", error.error); + $rootScope.notify("error", error.error); } if (vm.isCurrentPhaseRestrictedToSelectOneSubmission) { - $mdDialog.hide(); - vm.submissionVisibility[submission_id] = !vm.submissionVisibility[submission_id]; + $mdDialog.hide(); + vm.submissionVisibility[submission_id] = !vm.submissionVisibility[submission_id]; } } }; utilities.sendRequest(parameters); }; - vm.activateCollapsible = function() { + vm.activateCollapsible = function () { angular.element('.collapsible').collapsible(); }; - vm.team_approval_list = function(){ + vm.team_approval_list = function () { var parameters = {}; parameters.token = utilities.getData('userKey'); parameters.url = 'challenges/challenge/' + $stateParams.challengeId + '/get_participant_teams'; parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { vm.approved_teams = response.data; vm.activateCollapsible(); }, - onError: function() { + onError: function () { $rootScope.notify("error", "Some error occured.Please try again."); } }; utilities.sendRequest(parameters); }; - vm.showapprovalparticipantteamDialog = function(challengeId, participant_team_id, approved_status) { + vm.showapprovalparticipantteamDialog = function (challengeId, participant_team_id, approved_status) { if (approved_status) { vm.dialog = {}; vm.dialog.challengeId = challengeId; vm.dialog.participant_team_id = participant_team_id; vm.dialog.approved_status = approved_status; - $mdDialog.show({ - scope: $scope, - preserveScope: true, + $mdDialog.show({ + scope: $scope, + preserveScope: true, templateUrl: 'dist/views/web/challenge/edit-challenge/edit-challenge-approvalConfirm.html', }); } @@ -1983,28 +1953,28 @@ vm.check_approval_status(challengeId, participant_team_id, approved_status, false); } }; - - vm.check_approval_status = function(challengeId, participant_team_id, approved_status, formvalid){ + + vm.check_approval_status = function (challengeId, participant_team_id, approved_status, formvalid) { var parameters = {}; parameters.token = utilities.getData('userKey'); parameters.method = 'POST'; - if(approved_status) { + if (approved_status) { if (formvalid) { - parameters.url = 'challenges/challenge/' + challengeId + '/approve_participant_team/' + participant_team_id; - parameters.callback = { - onSuccess: function(response) { - if(response.status == 201){ - $rootScope.notify("success", "Participant Team Approved successfully."); - } - }, - onError: function(response) { - $rootScope.notify("error", response.data.error); + parameters.url = 'challenges/challenge/' + challengeId + '/approve_participant_team/' + participant_team_id; + parameters.callback = { + onSuccess: function (response) { + if (response.status == 201) { + $rootScope.notify("success", "Participant Team Approved successfully."); } - }; - utilities.sendRequest(parameters); - $mdDialog.hide(); - } + }, + onError: function (response) { + $rootScope.notify("error", response.data.error); + } + }; + utilities.sendRequest(parameters); + $mdDialog.hide(); + } else { $mdDialog.hide(); $state.reload(); @@ -2013,12 +1983,12 @@ else { parameters.url = 'challenges/challenge/' + challengeId + '/disapprove_participant_team/' + participant_team_id; parameters.callback = { - onSuccess: function(response) { - if(response.status == 204){ + onSuccess: function (response) { + if (response.status == 204) { $rootScope.notify("success", "Participant Team Disapproved successfully."); } }, - onError: function(response) { + onError: function (response) { $rootScope.notify("error", response.data.error); $state.reload(); } @@ -2028,21 +1998,21 @@ }; - vm.changeBaselineStatus = function(submission_id) { + vm.changeBaselineStatus = function (submission_id) { parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/submission/" + submission_id; parameters.method = 'PATCH'; parameters.data = { "is_baseline": vm.baselineStatus[submission_id] }; parameters.callback = { - onSuccess: function() {}, - onError: function() {} + onSuccess: function () { }, + onError: function () { } }; utilities.sendRequest(parameters); }; - vm.showRemainingSubmissions = function(phaseID) { + vm.showRemainingSubmissions = function (phaseID) { vm.remainingSubmissions = {}; vm.remainingTime = {}; vm.showClock = false; @@ -2051,11 +2021,11 @@ parameters.url = "jobs/" + vm.challengeId + "/remaining_submissions/"; parameters.method = 'GET'; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; for (var phase in response.data.phases) { if (response.data.phases[phase].id == phaseID) { - var details = response.data.phases[phase].limits; + var details = response.data.phases[phase].limits; } } if (status === 200) { @@ -2072,7 +2042,7 @@ vm.message = details; vm.showClock = true; vm.disableSubmit = true; - vm.countDownTimer = function() { + vm.countDownTimer = function () { vm.remainingTime = vm.message.remaining_time; vm.days = Math.floor(vm.remainingTime / 24 / 60 / 60); vm.hoursLeft = Math.floor((vm.remainingTime) - (vm.days * 86400)); @@ -2089,14 +2059,14 @@ vm.remainingSeconds--; } }; - setInterval(function() { + setInterval(function () { $rootScope.$apply(vm.countDownTimer); }, 1000); vm.countDownTimer(); } } }, - onError: function(response) { + onError: function (response) { var details = response.data; vm.stopLoader(); $rootScope.notify("error", details.error); @@ -2109,75 +2079,76 @@ vm.fields = [{ 'label': 'Team Name', 'id': 'participant_team' - },{ + }, { 'label': 'Team Members', 'id': 'participant_team_members' - },{ + }, { 'label': 'Team Members Email Id', 'id': 'participant_team_members_email' - },{ + }, { 'label': 'Team Members Affiliation', 'id': 'participant_team_members_affiliation' - },{ + }, { 'label': 'Challenge Phase', 'id': 'challenge_phase' - },{ + }, { 'label': 'Status', 'id': 'status' - },{ + }, { 'label': 'Created By', 'id': 'created_by' - },{ + }, { 'label': 'Execution Time', 'id': 'execution_time' - },{ + }, { 'label': 'Submission Number', 'id': 'submission_number' - },{ + }, { 'label': 'Submitted File', 'id': 'input_file' - },{ + }, { 'label': 'Stdout File', 'id': 'stdout_file' - },{ + }, { 'label': 'Stderr File', 'id': 'stderr_file' - },{ + }, { 'label': 'Environment Log File', 'id': 'environment_log_file' - },{ + }, { 'label': 'Submitted At', 'id': 'created_at' - },{ + }, { 'label': 'Submission Result File', 'id': 'submission_result_file' - },{ + }, { 'label': 'Submission Metadata File', 'id': 'submission_metadata_file' - },{ + }, { 'label': 'Method Name', 'id': 'method_name' - },{ + }, { 'label': 'Method Description', 'id': 'method_description' - },{ + }, { 'label': 'Publication URL', 'id': 'publication_url' - },{ + }, { 'label': 'Project URL', 'id': 'project_url' - },{ + }, { 'label': 'Submission Meta Attributes', 'id': 'submission_meta_attributes' }]; - vm.downloadChallengeSubmissions = function() { + vm.downloadChallengeSubmissions = function () { + vm.phaseId = (vm.allSubmissionPhaseSlug == undefined) ? vm.mySubmissionPhaseSlug : vm.allSubmissionPhaseSlug; if (vm.phaseId) { - parameters.url = "challenges/" + vm.challengeId + "/phase/" + vm.phaseId + "/download_all_submissions/" + vm.fileSelected + "/"; + parameters.url = "challenges/" + vm.challengeId + "/phase/" + "v2/" + vm.phaseId + "/download_all_submissions/" + vm.fileSelected + "/"; if (vm.fieldsToGet === undefined || vm.fieldsToGet.length === 0) { parameters.method = "GET"; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; var anchor = angular.element(''); anchor.attr({ @@ -2185,7 +2156,7 @@ download: 'all_submissions.csv' })[0].click(); }, - onError: function(response) { + onError: function (response) { var details = response.data; $rootScope.notify('error', details.error); } @@ -2195,14 +2166,14 @@ else { parameters.method = "POST"; var fieldsExport = []; - for(var i = 0 ; i < vm.fields.length ; i++) { + for (var i = 0; i < vm.fields.length; i++) { if (vm.fieldsToGet.includes(vm.fields[i].id)) { fieldsExport.push(vm.fields[i].id); } } parameters.data = fieldsExport; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; var anchor = angular.element(''); anchor.attr({ @@ -2210,7 +2181,7 @@ download: 'all_submissions.csv' })[0].click(); }, - onError: function(response) { + onError: function (response) { var details = response.data; $rootScope.notify('error', details.error); } @@ -2224,9 +2195,9 @@ }; vm.isOptionChecked = function (option, attribute) { - if( + if ( attribute.values.findIndex((el) => { - return el===option; + return el === option; }) !== -1 ) { return true; @@ -2257,7 +2228,7 @@ }); }; - vm.showVisibilityDialog = function(submissionId, submissionVisibility) { + vm.showVisibilityDialog = function (submissionId, submissionVisibility) { vm.submissionId = submissionId; // Show modal only when submission is being made public if (submissionVisibility) { @@ -2272,26 +2243,26 @@ vm.changeSubmissionVisibility(submissionId, submissionVisibility); } } else { - // Case when a submission is made private + vm.changeSubmissionVisibility(submissionId, submissionVisibility); } }; - vm.cancelSubmission = function(submissionId) { + vm.cancelSubmission = function (submissionId) { parameters.url = "jobs/challenges/" + vm.challengeId + "/submissions/" + submissionId + "/update_submission_meta/"; parameters.method = 'PATCH'; parameters.data = { "status": "cancelled", }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "Submission cancelled successfully!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); var error = response.data; $rootScope.notify("error", error); @@ -2301,7 +2272,7 @@ utilities.sendRequest(parameters); }; - vm.showCancelSubmissionDialog = function(submissionId, status) { + vm.showCancelSubmissionDialog = function (submissionId, status) { if (!vm.allowCancelRunningSubmissions && status != "submitted") { $rootScope.notify("error", "Only unproccessed submissions can be cancelled"); return; @@ -2314,11 +2285,11 @@ }); }; - vm.hideDialog = function() { + vm.hideDialog = function () { $mdDialog.hide(); }; - vm.updateSubmissionMetaData = function(updateSubmissionMetaDataForm) { + vm.updateSubmissionMetaData = function (updateSubmissionMetaDataForm) { if (updateSubmissionMetaDataForm) { parameters.url = "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/submission/" + vm.submissionId; parameters.method = 'PATCH'; @@ -2330,17 +2301,17 @@ "submission_metadata": vm.currentSubmissionMetaData }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The data is successfully updated!"); - if(vm.currentSubmissionMetaData != null) { + if (vm.currentSubmissionMetaData != null) { vm.submissionMetaData.submission_metadata = JSON.parse(JSON.stringify(vm.currentSubmissionMetaData)); } } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); var error = response.data; $rootScope.notify("error", error); @@ -2353,20 +2324,20 @@ } }; - vm.verifySubmission = function(submissionId, isVerified) { + vm.verifySubmission = function (submissionId, isVerified) { parameters.url = "jobs/challenges/" + vm.challengeId + "/submissions/" + submissionId + "/update_submission_meta/"; parameters.method = 'PATCH'; parameters.data = { "is_verified_by_host": isVerified, }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $rootScope.notify("success", "Verification status updated successfully!"); } }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); } @@ -2374,13 +2345,13 @@ utilities.sendRequest(parameters); }; - vm.isStarred = function() { + vm.isStarred = function () { // Get the stars count and user specific starred or unstarred parameters.url = "challenges/" + vm.challengeId + "/"; parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.count = details['count'] || 0; vm.is_starred = details['is_starred']; @@ -2390,17 +2361,17 @@ vm.caption = 'Unstar'; } }, - onError: function() {} + onError: function () { } }; utilities.sendRequest(parameters); }; - vm.starChallenge = function() { + vm.starChallenge = function () { parameters.url = "challenges/" + vm.challengeId + "/"; parameters.method = 'POST'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.count = details['count']; vm.is_starred = details['is_starred']; @@ -2410,7 +2381,7 @@ vm.caption = 'Star'; } }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); } @@ -2419,7 +2390,7 @@ }; // Edit challenge overview - vm.overviewDialog = function(ev) { + vm.overviewDialog = function (ev) { vm.tempDesc = vm.page.description; $mdDialog.show({ scope: $scope, @@ -2430,7 +2401,7 @@ }); }; - vm.editChallengeOverview = function(editChallengeOverviewForm) { + vm.editChallengeOverview = function (editChallengeOverviewForm) { if (editChallengeOverviewForm) { var challengeHostList = utilities.getData("challengeCreator"); for (var challenge in challengeHostList) { @@ -2446,14 +2417,14 @@ }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The description is successfully updated!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); vm.page.description = vm.tempDesc; var error = response.data; @@ -2469,7 +2440,7 @@ }; // Delete challenge - vm.deleteChallengeDialog = function(ev) { + vm.deleteChallengeDialog = function (ev) { vm.titleInput = ""; $mdDialog.show({ scope: $scope, @@ -2480,21 +2451,21 @@ }); }; - vm.deleteChallenge = function(deleteChallengeForm) { - if (deleteChallengeForm){ + vm.deleteChallenge = function (deleteChallengeForm) { + if (deleteChallengeForm) { var parameters = {}; parameters.url = "challenges/challenge/" + vm.challengeId + "/disable"; parameters.method = 'POST'; parameters.token = userKey; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; - if (status === 204){ + if (status === 204) { $mdDialog.hide(); $rootScope.notify("success", "The Challenge is successfully deleted!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); var error = response.data; $rootScope.notify("error", error); @@ -2508,7 +2479,7 @@ }; // Edit submission guidelines - vm.submissionGuidelinesDialog = function(ev) { + vm.submissionGuidelinesDialog = function (ev) { vm.tempSubmissionGuidelines = vm.page.submission_guidelines; $mdDialog.show({ scope: $scope, @@ -2519,7 +2490,7 @@ }); }; - vm.editSubmissionGuideline = function(editSubmissionGuidelinesForm) { + vm.editSubmissionGuideline = function (editSubmissionGuidelinesForm) { if (editSubmissionGuidelinesForm) { var challengeHostList = utilities.getData("challengeCreator"); for (var challenge in challengeHostList) { @@ -2535,14 +2506,14 @@ }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The submission guidelines is successfully updated!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); vm.page.submission_guidelines = vm.tempSubmissionGuidelines; var error = response.data; @@ -2558,7 +2529,7 @@ }; // Edit Evaluation Criteria - vm.evaluationCriteriaDialog = function(ev) { + vm.evaluationCriteriaDialog = function (ev) { vm.tempEvaluationCriteria = vm.page.evaluation_details; $mdDialog.show({ scope: $scope, @@ -2569,7 +2540,7 @@ }); }; - vm.editEvaluationCriteria = function(editEvaluationCriteriaForm) { + vm.editEvaluationCriteria = function (editEvaluationCriteriaForm) { if (editEvaluationCriteriaForm) { var challengeHostList = utilities.getData("challengeCreator"); for (var challenge in challengeHostList) { @@ -2584,14 +2555,14 @@ "evaluation_details": vm.page.evaluation_details }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The evaluation details is successfully updated!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); vm.page.evaluation_details = vm.tempEvaluationCriteria; var error = response.data; @@ -2609,7 +2580,7 @@ // Edit Evaluation Script - vm.evaluationScriptDialog = function(ev) { + vm.evaluationScriptDialog = function (ev) { vm.tempEvaluationCriteria = vm.page.evaluation_details; $mdDialog.show({ scope: $scope, @@ -2620,10 +2591,10 @@ }); }; - vm.editEvalScript = function(editEvaluationCriteriaForm) { + vm.editEvalScript = function (editEvaluationCriteriaForm) { if (editEvaluationCriteriaForm) { if (vm.editEvaluationScript === undefined || vm.editEvaluationScript === null - || vm.editEvaluationScript === "") { + || vm.editEvaluationScript === "") { var error = "Please upload a valid evaluation script!"; $mdDialog.hide(); $rootScope.notify("error", error); @@ -2642,14 +2613,14 @@ parameters.method = 'PATCH'; parameters.data = formData; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The evaluation script is successfully updated!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); vm.page.evaluation_details = vm.tempEvaluationCriteria; var error = response.data; @@ -2667,7 +2638,7 @@ // Edit Terms and Conditions - vm.termsAndConditionsDialog = function(ev) { + vm.termsAndConditionsDialog = function (ev) { vm.tempTermsAndConditions = vm.page.terms_and_conditions; $mdDialog.show({ scope: $scope, @@ -2678,7 +2649,7 @@ }); }; - vm.editTermsAndConditions = function(editTermsAndConditionsForm) { + vm.editTermsAndConditions = function (editTermsAndConditionsForm) { if (editTermsAndConditionsForm) { var challengeHostList = utilities.getData("challengeCreator"); for (var challenge in challengeHostList) { @@ -2693,14 +2664,14 @@ "terms_and_conditions": vm.page.terms_and_conditions }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The terms and conditions are successfully updated!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); vm.page.terms_and_conditions = vm.tempTermsAndConditions; var error = response.data; @@ -2715,7 +2686,7 @@ }; // Edit Challenge Title - vm.challengeTitleDialog = function(ev) { + vm.challengeTitleDialog = function (ev) { vm.tempChallengeTitle = vm.page.title; $mdDialog.show({ scope: $scope, @@ -2726,7 +2697,7 @@ }); }; - vm.editChallengeTitle = function(editChallengeTitleForm) { + vm.editChallengeTitle = function (editChallengeTitleForm) { if (editChallengeTitleForm) { var challengeHostList = utilities.getData("challengeCreator"); for (var challenge in challengeHostList) { @@ -2741,14 +2712,14 @@ "title": vm.page.title }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The challenge title is successfully updated!"); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); vm.page.title = vm.tempChallengeTitle; var error = response.data; @@ -2762,7 +2733,7 @@ } }; - vm.challengePhaseDialog = function(ev, phase) { + vm.challengePhaseDialog = function (ev, phase) { vm.page.challenge_phase = phase; vm.page.max_submissions_per_day = phase.max_submissions_per_day; vm.page.max_submissions_per_month = phase.max_submissions_per_month; @@ -2780,7 +2751,7 @@ }); }; - vm.editChallengePhase = function(editChallengePhaseForm) { + vm.editChallengePhase = function (editChallengePhaseForm) { if (editChallengePhaseForm) { vm.challengePhaseId = vm.page.challenge_phase.id; parameters.url = "challenges/challenge/" + vm.challengeId + "/challenge_phase/" + vm.challengePhaseId; @@ -2793,13 +2764,13 @@ formData.append("max_submissions_per_day", vm.page.challenge_phase.max_submissions_per_day); formData.append("max_submissions_per_month", vm.page.challenge_phase.max_submissions_per_month); formData.append("max_submissions", vm.page.challenge_phase.max_submissions); - formData.append("max_concurrent_submissions_allowed", vm.page.challenge_phase.max_concurrent_submissions_allowed); + formData.append("max_concurrent_submissions_allowed", vm.page.challenge_phase.max_concurrent_submissions_allowed); if (vm.testAnnotationFile) { formData.append("test_annotation", vm.testAnnotationFile); } parameters.data = formData; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; utilities.hideLoader(); if (status === 200) { @@ -2807,7 +2778,7 @@ $rootScope.notify("success", "The challenge phase details are successfully updated!"); } }, - onError: function(response) { + onError: function (response) { utilities.hideLoader(); $mdDialog.hide(); var error = response.data; @@ -2821,12 +2792,12 @@ parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var details = response.data; vm.phases = details; utilities.hideLoader(); }, - onError: function(response) { + onError: function (response) { var error = response.data; utilities.storeData('emailError', error.detail); $state.go('web.permission-denied'); @@ -2838,7 +2809,7 @@ } }; - vm.publishChallenge = function(ev) { + vm.publishChallenge = function (ev) { ev.stopPropagation(); vm.toggleChallengeState = null; vm.publishDesc = null; @@ -2848,13 +2819,13 @@ vm.toggleChallengeState = "public"; var confirm = $mdDialog.confirm() - .title('Make this challenge ' + vm.toggleChallengeState + '?') - .ariaLabel('') - .targetEvent(ev) - .ok('Yes') - .cancel('No'); + .title('Make this challenge ' + vm.toggleChallengeState + '?') + .ariaLabel('') + .targetEvent(ev) + .ok('Yes') + .cancel('No'); - $mdDialog.show(confirm).then(function() { + $mdDialog.show(confirm).then(function () { parameters.url = "challenges/challenge_host_team/" + vm.page.creator.id + "/challenge/" + vm.page.id; parameters.method = 'PATCH'; parameters.data = { @@ -2862,14 +2833,14 @@ }; vm.isPublished = !vm.isPublished; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $mdDialog.hide(); $rootScope.notify("success", "The challenge was successfully made " + vm.toggleChallengeState); } }, - onError: function(response) { + onError: function (response) { $mdDialog.hide(); vm.page.description = vm.tempDesc; var error = response.data; @@ -2878,13 +2849,13 @@ }; utilities.sendRequest(parameters); - }, function() { - // Nope + }, function () { + // Nope }); }; // Edit Challenge Start and End Date - vm.challengeDateDialog = function(ev) { + vm.challengeDateDialog = function (ev) { vm.challengeStartDate = moment(vm.page.start_date); vm.challengeEndDate = moment(vm.page.end_date); $mdDialog.show({ @@ -2896,7 +2867,7 @@ }); }; - vm.editChallengeDate = function(editChallengeDateForm) { + vm.editChallengeDate = function (editChallengeDateForm) { if (editChallengeDateForm) { var challengeHostList = utilities.getData("challengeCreator"); for (var challenge in challengeHostList) { @@ -2913,7 +2884,7 @@ "end_date": vm.challengeEndDate }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; utilities.hideLoader(); if (status === 200) { @@ -2923,7 +2894,7 @@ $rootScope.notify("success", "The challenge start and end date is successfully updated!"); } }, - onError: function(response) { + onError: function (response) { utilities.hideLoader(); $mdDialog.hide(); var error = response.data; @@ -2940,7 +2911,7 @@ } }; - vm.editchallengeTagDialog = function(ev) { + vm.editchallengeTagDialog = function (ev) { vm.tags = vm.page.list_tags; vm.domain_choices(); $mdDialog.show({ @@ -2952,7 +2923,7 @@ }); }; - vm.editChallengeTag = function(editChallengeTagDomainForm) { + vm.editChallengeTag = function (editChallengeTagDomainForm) { var new_tags; if (!editChallengeTagDomainForm) { $mdDialog.hide(); @@ -2973,7 +2944,7 @@ "domain": vm.domain }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; utilities.hideLoader(); if (status === 200) { @@ -2982,7 +2953,7 @@ $mdDialog.hide(); } }, - onError: function(response) { + onError: function (response) { utilities.hideLoader(); $mdDialog.hide(); var error = response.data; @@ -2993,12 +2964,12 @@ utilities.sendRequest(parameters); }; - vm.domain_choices = function() { + vm.domain_choices = function () { parameters.url = "challenges/challenge/get_domain_choices/"; parameters.method = 'GET'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var domain_choices = response.data; for (var i = 0; i < domain_choices.length; i++) { if (domain_choices[i][0] == vm.page.domain) { @@ -3007,7 +2978,7 @@ } vm.domainoptions = domain_choices; }, - onError: function(response) { + onError: function (response) { var error = response.data; $rootScope.notify("error", error); } @@ -3015,20 +2986,20 @@ utilities.sendRequest(parameters); }; - $scope.$on('$destroy', function() { + $scope.$on('$destroy', function () { vm.stopFetchingSubmissions(); vm.stopLeaderboard(); vm.stopLoadingLogs(); }); - $rootScope.$on('$stateChangeStart', function() { + $rootScope.$on('$stateChangeStart', function () { vm.phase = {}; vm.isResult = false; vm.stopFetchingSubmissions(); vm.stopLeaderboard(); }); - vm.showConfirmation = function(message){ + vm.showConfirmation = function (message) { $rootScope.notify("success", message); }; @@ -3053,11 +3024,11 @@ } }; - vm.encodeMetricURI = function(metric) { + vm.encodeMetricURI = function (metric) { return encodeURIComponent(metric); }; - vm.deregisterdialog = function(ev) { + vm.deregisterdialog = function (ev) { $mdDialog.show({ scope: $scope, preserveScope: true, @@ -3067,36 +3038,36 @@ }); }; - vm.deregister = function(deregisterformvalid) { + vm.deregister = function (deregisterformvalid) { if (deregisterformvalid) { parameters.url = 'challenges/challenge/' + vm.challengeId + '/deregister/'; parameters.method = 'POST'; parameters.data = {}; parameters.callback = { - onSuccess: function(response) { + onSuccess: function (response) { var status = response.status; if (status === 200) { $rootScope.notify("success", "You have successfully deregistered from the challenge."); $mdDialog.hide(); $state.go('web.challenge-main.challenge-page.overview'); - setTimeout(function() { - $state.reload(); + setTimeout(function () { + $state.reload(); }, 100); } }, - onError: function(response) { + onError: function (response) { $rootScope.notify("error", response.data.error); $mdDialog.hide(); } }; - utilities.sendRequest(parameters); + utilities.sendRequest(parameters); } else { $mdDialog.hide(); } }; - vm.openLeaderboardDropdown = function() { + vm.openLeaderboardDropdown = function () { if (vm.chosenMetrics == undefined) { var index = []; for (var k = 0; k < vm.leaderboard[0].leaderboard__schema.labels.length; k++) { @@ -3108,18 +3079,18 @@ vm.leaderboardDropdown = !vm.leaderboardDropdown; }; - vm.getTrophySize = function(rank) { + vm.getTrophySize = function (rank) { switch (rank) { case 1: - return 'trophy-gold'; + return 'trophy-gold'; case 2: - return 'trophy-silver'; + return 'trophy-silver'; case 3: - return 'trophy-bronze'; + return 'trophy-bronze'; // Add more cases for other ranks if needed default: - return 'trophy-black'; // Default size, change this according to your preference - } + return 'trophy-black'; // Default size, change this according to your preference + } }; } diff --git a/frontend/src/js/controllers/featuredChallengeCtrl.js b/frontend/src/js/controllers/featuredChallengeCtrl.js index 2f74cad87e..892f03a28c 100644 --- a/frontend/src/js/controllers/featuredChallengeCtrl.js +++ b/frontend/src/js/controllers/featuredChallengeCtrl.js @@ -142,23 +142,15 @@ vm.leaderboard[i].timeSpan= 'years'; } } - else if (duration._data.months !=0) { - var months = duration.months(); + else if (duration._data.months != 0 && duration.asDays() >= 60) { + var months = duration.asMonths(); vm.leaderboard[i].submission__submitted_at = months; - if (months.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'month'; - } else { - vm.leaderboard[i].timeSpan = 'months'; - } + vm.leaderboard[i].timeSpan = months.toFixed(0) == 1 ? 'month' : 'months'; } - else if (duration._data.days !=0) { + else if (duration.asDays() >= 1) { var days = duration.asDays(); vm.leaderboard[i].submission__submitted_at = days; - if (days.toFixed(0)==1) { - vm.leaderboard[i].timeSpan = 'day'; - } else { - vm.leaderboard[i].timeSpan = 'days'; - } + vm.leaderboard[i].timeSpan = days.toFixed(0) == 1 ? 'day' : 'days'; } else if (duration._data.hours !=0) { var hours = duration.asHours(); diff --git a/frontend/src/js/route-config/route-config.js b/frontend/src/js/route-config/route-config.js index cc678f2c82..e00b40347d 100644 --- a/frontend/src/js/route-config/route-config.js +++ b/frontend/src/js/route-config/route-config.js @@ -4,597 +4,628 @@ (function () { 'use strict'; - angular - .module('evalai') - .config(configure); - var baseUrl = "dist/views"; + angular.module('evalai').config(configure); - configure.$inject = ['$stateProvider', '$urlRouterProvider', '$locationProvider', '$urlMatcherFactoryProvider']; + var baseUrl = 'dist/views'; - function configure($stateProvider, $urlRouterProvider, $locationProvider, $urlMatcherFactoryProvider) { + configure.$inject = [ + '$stateProvider', + '$urlRouterProvider', + '$locationProvider', + '$urlMatcherFactoryProvider', + ]; + function configure( + $stateProvider, + $urlRouterProvider, + $locationProvider, + $urlMatcherFactoryProvider + ) { //in order to prevent 404 for trailing '/' in urls $urlMatcherFactoryProvider.strictMode(false); // formating hashed url $locationProvider.html5Mode({ enabled: true, - requireBase: true + requireBase: true, }); // Index url definition var home = { - name: "home", - url: "/", - templateUrl: baseUrl + "/web/landing.html", + name: 'home', + url: '/', + templateUrl: baseUrl + '/web/landing.html', controller: 'MainCtrl', controllerAs: 'main', - title: "Welcome" + title: 'Welcome', }; // Auth related urls var auth = { - name: "auth", - url: "/auth", - templateUrl: baseUrl + "/web/auth/auth.html", + name: 'auth', + url: '/auth', + templateUrl: baseUrl + '/web/auth/auth.html', controller: 'AuthCtrl', controllerAs: 'auth', abstract: true, - title: 'Auth' + title: 'Auth', }; var login = { - name: "auth.login", - parent: "auth", - url: "/login", - templateUrl: baseUrl + "/web/auth/login.html", + name: 'auth.login', + parent: 'auth', + url: '/login', + templateUrl: baseUrl + '/web/auth/login.html', title: 'Login', - authpage: true + authpage: true, }; var signup = { - name: "auth.signup", - parent: "auth", - url: "/signup", - templateUrl: baseUrl + "/web/auth/signup.html", + name: 'auth.signup', + parent: 'auth', + url: '/signup', + templateUrl: baseUrl + '/web/auth/signup.html', title: 'SignUp', - authpage: true + authpage: true, }; var verify_email = { - name: "auth.verify-email", - parent: "auth", - url: "/api/auth/registration/account-confirm-email/:email_conf_key", - templateUrl: baseUrl + "/web/auth/verify-email.html", - title: "Email Verify", - authpage: true + name: 'auth.verify-email', + parent: 'auth', + url: '/api/auth/registration/account-confirm-email/:email_conf_key', + templateUrl: baseUrl + '/web/auth/verify-email.html', + title: 'Email Verify', + authpage: true, }; var reset_password = { - name: "auth.reset-password", - parent: "auth", - url: "/reset-password", - templateUrl: baseUrl + "/web/auth/reset-password.html", - title: "Reset Password", - authpage: true + name: 'auth.reset-password', + parent: 'auth', + url: '/reset-password', + templateUrl: baseUrl + '/web/auth/reset-password.html', + title: 'Reset Password', + authpage: true, }; var reset_password_confirm = { - name: "auth.reset-password-confirm", - parent: "auth", - url: "/api/password/reset/confirm/:user_id/:reset_token", - templateUrl: baseUrl + "/web/auth/reset-password-confirm.html", - title: "Reset Password Confirm", - authpage: true + name: 'auth.reset-password-confirm', + parent: 'auth', + url: '/api/password/reset/confirm/:user_id/:reset_token', + templateUrl: baseUrl + '/web/auth/reset-password-confirm.html', + title: 'Reset Password Confirm', + authpage: true, }; var logout = { - name: "auth.logout", - parent: "auth", - url: "/logout", + name: 'auth.logout', + parent: 'auth', + url: '/logout', authenticate: true, - title: 'Logout' + title: 'Logout', }; // main app 'web' var web = { - name: "web", - url: "/web", - templateUrl: baseUrl + "/web/web.html", + name: 'web', + url: '/web', + templateUrl: baseUrl + '/web/web.html', controller: 'WebCtrl', controllerAs: 'web', - abstract: true + abstract: true, }; var dashboard = { - name: "web.dashboard", - parent: "web", - url: "/dashboard", - templateUrl: baseUrl + "/web/dashboard.html", + name: 'web.dashboard', + parent: 'web', + url: '/dashboard', + templateUrl: baseUrl + '/web/dashboard.html', controller: 'DashCtrl', controllerAs: 'dash', title: 'Dashboard', - authenticate: true + authenticate: true, }; var teams = { - name: "web.teams", - parent: "web", - url: "/teams", - templateUrl: baseUrl + "/web/teams.html", + name: 'web.teams', + parent: 'web', + url: '/teams', + templateUrl: baseUrl + '/web/teams.html', controller: 'TeamsCtrl', controllerAs: 'teams', title: 'Participating Teams', - authenticate: true + authenticate: true, }; var hosted_challenges = { - name: "web.hosted-challenge", - parent: "web", - url: "/hosted-challenges", - templateUrl: baseUrl + "/web/hosted-challenges.html", + name: 'web.hosted-challenge', + parent: 'web', + url: '/hosted-challenges', + templateUrl: baseUrl + '/web/hosted-challenges.html', controller: 'HostedChallengesCtrl', controllerAs: 'hostedChallenges', title: 'Hosted Challenges', - authenticate: true + authenticate: true, }; var host_analytics = { - name: "web.host-analytics", - parent: "web", - url: "/host-analytics", - templateUrl: baseUrl + "/web/analytics/host-analytics.html", + name: 'web.host-analytics', + parent: 'web', + url: '/host-analytics', + templateUrl: baseUrl + '/web/analytics/host-analytics.html', controller: 'AnalyticsCtrl', controllerAs: 'analytics', title: 'Host Challenge Analytics', - authenticate: true + authenticate: true, }; var challenge_host_teams = { - name: "web.challenge-host-teams", - parent: "web", - url: "/challenge-host-teams", - templateUrl: baseUrl + "/web/challenge-host-teams.html", + name: 'web.challenge-host-teams', + parent: 'web', + url: '/challenge-host-teams', + templateUrl: baseUrl + '/web/challenge-host-teams.html', controller: 'ChallengeHostTeamsCtrl', controllerAs: 'challengeHostTeams', title: 'Host Teams', - authenticate: true + authenticate: true, }; var challenge_create = { - name: "web.challenge-create", - parent: "web", - url: "/challenge-create", - templateUrl: baseUrl + "/web/challenge-create.html", + name: 'web.challenge-create', + parent: 'web', + url: '/challenge-create', + templateUrl: baseUrl + '/web/challenge-create.html', title: 'Create Challenge', controller: 'ChallengeCreateCtrl', controllerAs: 'challengeCreate', - authenticate: true + authenticate: true, }; var challenge_main = { - name: "web.challenge-main", - parent: "web", - url: "/challenges", - templateUrl: baseUrl + "/web/challenge-main.html", - redirectTo: "web.challenge-main.challenge-list", + name: 'web.challenge-main', + parent: 'web', + url: '/challenges', + templateUrl: baseUrl + '/web/challenge-main.html', + redirectTo: 'web.challenge-main.challenge-list', }; var challenge_list = { - name: "web.challenge-main.challenge-list", - parent: "web.challenge-main", - url: "/list", - templateUrl: baseUrl + "/web/challenge-list.html", + name: 'web.challenge-main.challenge-list', + parent: 'web.challenge-main', + url: '/list', + templateUrl: baseUrl + '/web/challenge-list.html', controller: 'ChallengeListCtrl', controllerAs: 'challengeList', title: 'Challenges', }; var challenge_page = { - name: "web.challenge-main.challenge-page", - parent: "web.challenge-main", - url: "/challenge-page/:challengeId", - templateUrl: baseUrl + "/web/challenge/challenge-page.html", + name: 'web.challenge-main.challenge-page', + parent: 'web.challenge-main', + url: '/challenge-page/:challengeId', + templateUrl: baseUrl + '/web/challenge/challenge-page.html', controller: 'ChallengeCtrl', controllerAs: 'challenge', - redirectTo: "web.challenge-main.challenge-page.overview", + redirectTo: 'web.challenge-main.challenge-page.overview', }; var overview = { - name: "web.challenge-main.challenge-page.overview", - parent: "web.challenge-main.challenge-page", - url: "/overview", - templateUrl: baseUrl + "/web/challenge/overview.html", + name: 'web.challenge-main.challenge-page.overview', + parent: 'web.challenge-main.challenge-page', + url: '/overview', + templateUrl: baseUrl + '/web/challenge/overview.html', title: 'Overview', }; var evaluation = { - name: "web.challenge-main.challenge-page.evaluation", - parent: "web.challenge-main.challenge-page", - url: "/evaluation", - templateUrl: baseUrl + "/web/challenge/evaluation.html", + name: 'web.challenge-main.challenge-page.evaluation', + parent: 'web.challenge-main.challenge-page', + url: '/evaluation', + templateUrl: baseUrl + '/web/challenge/evaluation.html', title: 'Evaluation', }; var phases = { - name: "web.challenge-main.challenge-page.phases", - parent: "web.challenge-main.challenge-page", - url: "/phases", - templateUrl: baseUrl + "/web/challenge/phases.html", + name: 'web.challenge-main.challenge-page.phases', + parent: 'web.challenge-main.challenge-page', + url: '/phases', + templateUrl: baseUrl + '/web/challenge/phases.html', title: 'Phases', }; var participate = { - name: "web.challenge-main.challenge-page.participate", - parent: "web.challenge-main.challenge-page", - url: "/participate", - templateUrl: baseUrl + "/web/challenge/participate.html", + name: 'web.challenge-main.challenge-page.participate', + parent: 'web.challenge-main.challenge-page', + url: '/participate', + templateUrl: baseUrl + '/web/challenge/participate.html', title: 'Participate', }; var submission = { - name: "web.challenge-main.challenge-page.submission", - parent: "web.challenge-main.challenge-page", - url: "/submission", - templateUrl: baseUrl + "/web/challenge/submission.html", + name: 'web.challenge-main.challenge-page.submission', + parent: 'web.challenge-main.challenge-page', + url: '/submission', + templateUrl: baseUrl + '/web/challenge/submission.html', title: 'Submit', authenticate: true, resolve: { - challenge: function(utilities, $state, $stateParams) { - return new Promise(function(resolve) { - var parameters = {}; - parameters.token = utilities.getData('userKey'); - parameters.url = 'challenges/' + $stateParams.challengeId + '/participant_team/team_detail'; - parameters.method = 'GET'; - parameters.data = {}; - parameters.callback = { - onSuccess: function(response) { - var details = response.data; - resolve(details); - }, - onError: function() { - $state.go('error-404'); - } - }; - utilities.sendRequest(parameters); - }); - } - }, + challenge: function (utilities, $state, $stateParams) { + return new Promise(function (resolve) { + var parameters = {}; + parameters.token = utilities.getData('userKey'); + parameters.url = + 'challenges/' + $stateParams.challengeId + '/participant_team/team_detail'; + parameters.method = 'GET'; + parameters.data = {}; + parameters.callback = { + onSuccess: function (response) { + var details = response.data; + resolve(details); + }, + onError: function () { + $state.go('error-404'); + }, + }; + utilities.sendRequest(parameters); + }); + }, + }, }; var my_submission = { - name: "web.challenge-main.challenge-page.my-submission", - parent: "web.challenge-main.challenge-page", - url: "/my-submission", - templateUrl: baseUrl + "/web/challenge/my-submission.html", + name: 'web.challenge-main.challenge-page.my-submission', + parent: 'web.challenge-main.challenge-page', + url: '/my-submission', + templateUrl: baseUrl + '/web/challenge/my-submission.html', title: 'My Submissions', - authenticate: true + authenticate: true, + }; + + var my_phase_submission = { + name: 'web.challenge-main.challenge-page.my-phase-submission', + url: '/my-submission/:mySubmissionPhaseSlug', + controller: 'ChallengeCtrl', + controllerAs: 'challenge', + templateUrl: baseUrl + '/web/challenge/my-submission.html', + title: 'My Submissions', + authenticate: true, }; var my_challenge_all_submission = { - name: "web.challenge-main.challenge-page.my-challenge-all-submission", - parent: "web.challenge-main.challenge-page", - url: "/my-challenge-all-submission", - templateUrl: baseUrl + "/web/challenge/my-challenge-all-submission.html", + name: 'web.challenge-main.challenge-page.my-challenge-all-submission', + parent: 'web.challenge-main.challenge-page', + url: '/my-challenge-all-submission', + templateUrl: baseUrl + '/web/challenge/my-challenge-all-submission.html', title: 'My Challenge All Submissions', authenticate: true, resolve: { - challenge: function(utilities, $state, $stateParams) { - return new Promise(function(resolve, reject) { - var parameters = {}; - parameters.token = utilities.getData('userKey'); - parameters.url = 'participants/participant_teams/challenges/' + $stateParams.challengeId + '/user'; - parameters.method = 'GET'; - parameters.data = {}; - parameters.callback = { - onSuccess: function(response) { - var details = response.data; - if (details.is_challenge_host) { - resolve(details); - } else { - $state.go('error-404'); - reject(); - } - }, - onError: function() { - reject(); - } - }; - utilities.sendRequest(parameters); - }); - } + challenge: function (utilities, $state, $stateParams) { + return new Promise(function (resolve, reject) { + var parameters = {}; + parameters.token = utilities.getData('userKey'); + parameters.url = + 'participants/participant_teams/challenges/' + $stateParams.challengeId + '/user'; + parameters.method = 'GET'; + parameters.data = {}; + parameters.callback = { + onSuccess: function (response) { + var details = response.data; + if (details.is_challenge_host) { + resolve(details); + } else { + $state.go('error-404'); + reject(); + } + }, + onError: function () { + reject(); + }, + }; + utilities.sendRequest(parameters); + }); + }, }, - }; + }; + + var my_challenge_phase_all_submission = { + name: 'web.challenge-main.challenge-page.my-challenge-phase-all-submission', + url: '/my-challenge-all-submission/:allSubmissionPhaseSlug', + controller: 'ChallengeCtrl', + controllerAs: 'challenge', + templateUrl: baseUrl + '/web/challenge/my-challenge-all-submission.html', + title: 'My Challenge All Submissions', + authenticate: true, + }; var approval_team = { - name: "web.challenge-main.challenge-page.approval_team", - parent: "web.challenge-main.challenge-page", - url: "/approval_team", - templateUrl: baseUrl + "/web/challenge/approval-team.html", + name: 'web.challenge-main.challenge-page.approval_team', + parent: 'web.challenge-main.challenge-page', + url: '/approval_team', + templateUrl: baseUrl + '/web/challenge/approval-team.html', title: 'My Challenge Approved Teams', authenticate: true, - }; var leaderboard = { - name: "web.challenge-main.challenge-page.leaderboard", - parent: "web.challenge-main.challenge-page", - url: "/leaderboard", - templateUrl: baseUrl + "/web/challenge/leaderboard.html", + name: 'web.challenge-main.challenge-page.leaderboard', + parent: 'web.challenge-main.challenge-page', + url: '/leaderboard', + templateUrl: baseUrl + '/web/challenge/leaderboard.html', title: 'Leaderboard', }; var prizes = { - name: "web.challenge-main.challenge-page.prizes", - parent: "web.challenge-main.challenge-page", - url: "/prizes", - templateUrl: baseUrl + "/web/challenge/prizes.html", + name: 'web.challenge-main.challenge-page.prizes', + parent: 'web.challenge-main.challenge-page', + url: '/prizes', + templateUrl: baseUrl + '/web/challenge/prizes.html', title: 'Prizes', }; var sponsors = { - name: "web.challenge-main.challenge-page.sponsors", - parent: "web.challenge-main.challenge-page", - url: "/sponsors", - templateUrl: baseUrl + "/web/challenge/sponsors.html", + name: 'web.challenge-main.challenge-page.sponsors', + parent: 'web.challenge-main.challenge-page', + url: '/sponsors', + templateUrl: baseUrl + '/web/challenge/sponsors.html', title: 'Sponsors', }; var manage = { - name: "web.challenge-main.challenge-page.manage", - parent: "web.challenge-main.challenge-page", - url: "/manage", - templateUrl: baseUrl + "/web/challenge/manage.html", + name: 'web.challenge-main.challenge-page.manage', + parent: 'web.challenge-main.challenge-page', + url: '/manage', + templateUrl: baseUrl + '/web/challenge/manage.html', controller: 'ChallengeCtrl', controllerAs: 'challenge', authenticate: true, resolve: { - challenge: function(utilities, $state, $stateParams) { - return new Promise(function(resolve, reject) { - var parameters = {}; - parameters.token = utilities.getData('userKey'); - parameters.url = 'participants/participant_teams/challenges/' + $stateParams.challengeId + '/user'; - parameters.method = 'GET'; - parameters.data = {}; - parameters.callback = { - onSuccess: function(response) { - var details = response.data; - if (details.is_challenge_host) { - resolve(details); - } else { - $state.go('error-404'); - reject(); - } - }, - onError: function() { - reject(); - } - }; - utilities.sendRequest(parameters); - }); - } + challenge: function (utilities, $state, $stateParams) { + return new Promise(function (resolve, reject) { + var parameters = {}; + parameters.token = utilities.getData('userKey'); + parameters.url = + 'participants/participant_teams/challenges/' + $stateParams.challengeId + '/user'; + parameters.method = 'GET'; + parameters.data = {}; + parameters.callback = { + onSuccess: function (response) { + var details = response.data; + if (details.is_challenge_host) { + resolve(details); + } else { + $state.go('error-404'); + reject(); + } + }, + onError: function () { + reject(); + }, + }; + utilities.sendRequest(parameters); + }); + }, }, - }; + }; var challenge_phase_leaderboard = { - name: "web.challenge-main.challenge-page.phase-leaderboard", - url: "/leaderboard/:phaseSplitId", + name: 'web.challenge-main.challenge-page.phase-leaderboard', + url: '/leaderboard/:phaseSlug/:splitCodename', // Changed URL controller: 'ChallengeCtrl', controllerAs: 'challenge', - templateUrl: baseUrl + "/web/challenge/leaderboard.html", - title: 'Leaderboard' + templateUrl: baseUrl + '/web/challenge/leaderboard.html', + title: 'Leaderboard', }; var challenge_phase_metric_leaderboard = { - name: "web.challenge-main.challenge-page.phase-metric-leaderboard", - url: "/leaderboard/:phaseSplitId/:metric", + name: 'web.challenge-main.challenge-page.phase-metric-leaderboard', + url: '/leaderboard/:phaseSlug/:splitCodename/:metric', // Changed URL controller: 'ChallengeCtrl', controllerAs: 'challenge', - templateUrl: baseUrl + "/web/challenge/leaderboard.html", - title: 'Leaderboard' + templateUrl: baseUrl + '/web/challenge/leaderboard.html', + title: 'Leaderboard', }; + var profile = { - name: "web.profile", - parent: "web", - url: "/profile", - templateUrl: baseUrl + "/web/profile/profile.html", - title: "Profile", + name: 'web.profile', + parent: 'web', + url: '/profile', + templateUrl: baseUrl + '/web/profile/profile.html', + title: 'Profile', controller: 'profileCtrl', controllerAs: 'profile', - redirectTo: "web.profile.Updateprofile", - authenticate: true + redirectTo: 'web.profile.Updateprofile', + authenticate: true, }; var auth_token = { - name: "web.profile.AuthToken", - parent: "web.profile", - url: "/auth-token", - templateUrl: baseUrl + "/web/auth/get-token.html", + name: 'web.profile.AuthToken', + parent: 'web.profile', + url: '/auth-token', + templateUrl: baseUrl + '/web/auth/get-token.html', title: 'Auth Token', - authenticate: true + authenticate: true, }; var update_profile = { - name: "web.profile.Updateprofile", - parent: "web.profile", - url: "/update-profile", - templateUrl: baseUrl + "/web/profile/edit-profile/update-profile.html", + name: 'web.profile.Updateprofile', + parent: 'web.profile', + url: '/update-profile', + templateUrl: baseUrl + '/web/profile/edit-profile/update-profile.html', title: 'Update profile', - authenticate: true + authenticate: true, }; var edit_profile = { - name: "web.profile.Editprofile", - parent: "web.profile", - url: "/edit-profile", - templateUrl: baseUrl + "/web/profile/edit-profile/edit-profile.html", + name: 'web.profile.Editprofile', + parent: 'web.profile', + url: '/edit-profile', + templateUrl: baseUrl + '/web/profile/edit-profile/edit-profile.html', title: 'Edit profile', - authenticate: true + authenticate: true, }; var deactivate_account = { - name: "web.profile.deactivate-account", - parent: "web.profile", - url: "/deactivate-account", - templateUrl: baseUrl + "/web/profile/edit-profile/deactivate-account.html", + name: 'web.profile.deactivate-account', + parent: 'web.profile', + url: '/deactivate-account', + templateUrl: baseUrl + '/web/profile/edit-profile/deactivate-account.html', title: 'Deactivate Account', - authenticate: true + authenticate: true, }; var host_challenge = { - name: "web.host-challenge", - parent: "web", - url: "/host-challenge", - templateUrl: baseUrl + "/web/host-challenge.html", + name: 'web.host-challenge', + parent: 'web', + url: '/host-challenge', + templateUrl: baseUrl + '/web/host-challenge.html', title: 'Host Competition', // controller: 'HostCtrl', // controllerAs: 'host', - authenticate: true + authenticate: true, }; var permission_denied = { - name: "web.permission-denied", - parent: "web", - url: "/permission-denied", - templateUrl: baseUrl + "/web/permission-denied.html", - title: "Permission Denied", + name: 'web.permission-denied', + parent: 'web', + url: '/permission-denied', + templateUrl: baseUrl + '/web/permission-denied.html', + title: 'Permission Denied', controller: 'PermCtrl', controllerAs: 'perm', - authenticate: true + authenticate: true, }; var change_password = { - name: "web.profile.change-password", - parent: "web.profile", - url: "/change-password", - templateUrl: baseUrl + "/web/change-password.html", - title: "Change Password", + name: 'web.profile.change-password', + parent: 'web.profile', + url: '/change-password', + templateUrl: baseUrl + '/web/change-password.html', + title: 'Change Password', controller: 'ChangePwdCtrl', controllerAs: 'changepwd', - authenticate: true + authenticate: true, }; var error_404 = { - name: "error-404", - templateUrl: baseUrl + "/web/error-pages/error-404.html", - title: "Error 404", + name: 'error-404', + templateUrl: baseUrl + '/web/error-pages/error-404.html', + title: 'Error 404', }; var error_500 = { - name: "error-500", - templateUrl: baseUrl + "/web/error-pages/error-500.html", - title: "Error 500", + name: 'error-500', + templateUrl: baseUrl + '/web/error-pages/error-500.html', + title: 'Error 500', }; var privacy_policy = { - name: "privacy_policy", - url: "/privacy-policy", - templateUrl: baseUrl + "/web/privacy-policy.html", - title: "Privacy Policy" + name: 'privacy_policy', + url: '/privacy-policy', + templateUrl: baseUrl + '/web/privacy-policy.html', + title: 'Privacy Policy', }; var about_us = { name: 'about-us', - url: "/about", - templateUrl: baseUrl + "/web/about-us.html", - title: "About Us" + url: '/about', + templateUrl: baseUrl + '/web/about-us.html', + title: 'About Us', }; var our_team = { name: 'our-team', - url: "/team", - templateUrl: baseUrl + "/web/our-team.html", + url: '/team', + templateUrl: baseUrl + '/web/our-team.html', controller: 'ourTeamCtrl', controllerAs: 'ourTeam', - title: "Team" + title: 'Team', }; var get_involved = { name: 'get-involved', - url: "/get-involved", - templateUrl: baseUrl + "/web/get-involved.html", - title: "Get Involved" + url: '/get-involved', + templateUrl: baseUrl + '/web/get-involved.html', + title: 'Get Involved', }; var contact_us = { - name: "contact-us", - url: "/contact", - templateUrl: baseUrl + "/web/contact-us.html", - title: "Contact Us", + name: 'contact-us', + url: '/contact', + templateUrl: baseUrl + '/web/contact-us.html', + title: 'Contact Us', controller: 'contactUsCtrl', - controllerAs: 'contactUs' + controllerAs: 'contactUs', }; var featured_challenge_page = { - name: "featured-challenge-page", - url: "/featured-challenges/:challengeId", - templateUrl: baseUrl + "/web/featured-challenge/challenge-page.html", + name: 'featured-challenge-page', + url: '/featured-challenges/:challengeId', + templateUrl: baseUrl + '/web/featured-challenge/challenge-page.html', controller: 'FeaturedChallengeCtrl', controllerAs: 'featured_challenge', - redirectTo: "featured-challenge-page.overview" + redirectTo: 'featured-challenge-page.overview', }; var featured_challenge_overview = { - name: "featured-challenge-page.overview", - parent: "featured-challenge-page", - url: "/overview", - templateUrl: baseUrl + "/web/featured-challenge/overview.html", - title: 'Overview' + name: 'featured-challenge-page.overview', + parent: 'featured-challenge-page', + url: '/overview', + templateUrl: baseUrl + '/web/featured-challenge/overview.html', + title: 'Overview', }; var featured_challenge_evaluation = { - name: "featured-challenge-page.evaluation", - url: "/evaluation", - templateUrl: baseUrl + "/web/featured-challenge/evaluation.html", - title: 'Evaluation' + name: 'featured-challenge-page.evaluation', + url: '/evaluation', + templateUrl: baseUrl + '/web/featured-challenge/evaluation.html', + title: 'Evaluation', }; var featured_challenge_phases = { - name: "featured-challenge-page.phases", - url: "/phases", - templateUrl: baseUrl + "/web/featured-challenge/phases.html", - title: 'Phases' + name: 'featured-challenge-page.phases', + url: '/phases', + templateUrl: baseUrl + '/web/featured-challenge/phases.html', + title: 'Phases', }; var featured_challenge_participate = { - name: "featured-challenge-page.participate", - url: "/participate", - templateUrl: baseUrl + "/web/featured-challenge/participate.html", - title: 'Participate' + name: 'featured-challenge-page.participate', + url: '/participate', + templateUrl: baseUrl + '/web/featured-challenge/participate.html', + title: 'Participate', }; var featured_challenge_leaderboard = { - name: "featured-challenge-page.leaderboard", - url: "/leaderboard", - templateUrl: baseUrl + "/web/featured-challenge/leaderboard.html", - title: 'Leaderboard' + name: 'featured-challenge-page.leaderboard', + url: '/leaderboard', + templateUrl: baseUrl + '/web/featured-challenge/leaderboard.html', + title: 'Leaderboard', }; var featured_challenge_phase_leaderboard = { - name: "featured-challenge-page.phase-leaderboard", - url: "/leaderboard/:phaseSplitId", + name: 'featured-challenge-page.phase-leaderboard', + url: '/leaderboard/:phaseSplitId', controller: 'FeaturedChallengeCtrl', controllerAs: 'featured_challenge', - templateUrl: baseUrl + "/web/featured-challenge/leaderboard.html", - title: 'Leaderboard' + templateUrl: baseUrl + '/web/featured-challenge/leaderboard.html', + title: 'Leaderboard', }; var challengeInvitation = { - name: "challenge-invitation", - url: "/accept-invitation/:invitationKey", - controller: "ChallengeInviteCtrl", - controllerAs: "challenge_invitation", - templateUrl: baseUrl + "/web/challenge-invite.html", - title: "Accept challenge invitation" + name: 'challenge-invitation', + url: '/accept-invitation/:invitationKey', + controller: 'ChallengeInviteCtrl', + controllerAs: 'challenge_invitation', + templateUrl: baseUrl + '/web/challenge-invite.html', + title: 'Accept challenge invitation', }; var get_submission_related_files = { - name: "get-submission-related-files", - url: "/web/submission-files?bucket&key", - controller: "SubmissionFilesCtrl", - controllerAs: "submission_files", + name: 'get-submission-related-files', + url: '/web/submission-files?bucket&key', + controller: 'SubmissionFilesCtrl', + controllerAs: 'submission_files', }; // call all states here @@ -635,7 +666,9 @@ $stateProvider.state(participate); $stateProvider.state(submission); $stateProvider.state(my_submission); + $stateProvider.state(my_phase_submission); $stateProvider.state(my_challenge_all_submission); + $stateProvider.state(my_challenge_phase_all_submission); $stateProvider.state(approval_team); $stateProvider.state(leaderboard); $stateProvider.state(prizes); @@ -672,26 +705,29 @@ $stateProvider.state(manage); - $urlRouterProvider.otherwise(function($injector, $location) { + $urlRouterProvider.otherwise(function ($injector, $location) { var state = $injector.get('$state'); state.go('error-404'); return $location.path(); }); } - })(); // define run block here (function () { - 'use strict'; - angular - .module('evalai') - .run(runFunc); + angular.module('evalai').run(runFunc); + + runFunc.$inject = [ + '$rootScope', + '$state', + 'utilities', + '$window', + '$location', + 'toaster', + ]; - runFunc.$inject = ['$rootScope', '$state', 'utilities', '$window', '$location', 'toaster']; - function runFunc($rootScope, $state, utilities, $window, $location, toaster) { // setting timout for token (7days) // var getTokenTime = utilities.getData('tokenTime'); @@ -699,17 +735,17 @@ // .getTime() returns milliseconds, so for 7 days 1000 * 60 * 60 * 24 * 7 = 7 days // var tokenExpTime = 1000 * 60 * 60 * 24 * 7; // if ((timeNow - getTokenTime) > tokenExpTime) { - // utilities.resetStorage(); + // utilities.resetStorage(); // } $rootScope.isAuth = false; // check for valid user - $rootScope.$on("$stateChangeStart", function(event, to, toParams) { + $rootScope.$on('$stateChangeStart', function (event, to, toParams) { if (utilities.isAuthenticated()) { $rootScope.isAuth = true; if (to.authpage) { event.preventDefault(); - $state.go("home"); + $state.go('home'); } } else { $rootScope.isAuth = false; @@ -717,20 +753,21 @@ event.preventDefault(); $rootScope.previousState = to; $rootScope.previousStateParams = toParams; - $state.go("auth.login"); + $state.go('auth.login'); } } - }); - $rootScope.$on('$stateChangeStart', function(event, to, params) { + $rootScope.$on('$stateChangeStart', function (event, to, params) { if (to.redirectTo) { event.preventDefault(); - $state.go(to.redirectTo, params, { location: $location.path() }); + $state.go(to.redirectTo, params, { + location: $location.path(), + }); } }); - $rootScope.$on('$stateChangeSuccess', function() { + $rootScope.$on('$stateChangeSuccess', function () { // Save the route title $rootScope.pageTitle = $state.current.title; // Scroll to top @@ -742,10 +779,10 @@ } }); - $rootScope.notify = function(type, message, timeout) { + $rootScope.notify = function (type, message, timeout) { // function to pic timeout function pick(arg, def) { - return (typeof arg === undefined ? def : arg); + return typeof arg === undefined ? def : arg; } timeout = pick(timeout, 5000); @@ -756,43 +793,43 @@ }); }; - $rootScope.logout = function() { + $rootScope.logout = function () { var userKey = utilities.getData('userKey'); var parameters = {}; parameters.url = 'auth/logout/'; parameters.method = 'POST'; parameters.token = userKey; parameters.callback = { - onSuccess: function() { + onSuccess: function () { utilities.resetStorage(); $rootScope.isLoader = false; - $state.go("home"); + $state.go('home'); $rootScope.isAuth = false; - $rootScope.notify("info", "Successfully logged out!"); + $rootScope.notify('info', 'Successfully logged out!'); }, - onError: function() {} + onError: function () { }, }; utilities.sendRequest(parameters); }; - $rootScope.checkToken = function() { + $rootScope.checkToken = function () { var userKey = utilities.getData('userKey'); var parameters = {}; parameters.url = 'auth/user/'; parameters.method = 'GET'; parameters.token = userKey; parameters.callback = { - onSuccess: function() {}, - onError: function(response) { + onSuccess: function () { }, + onError: function (response) { var status = response.status; if (status == 401) { - alert("Timeout, Please login again to continue!"); + alert('Timeout, Please login again to continue!'); utilities.resetStorage(); - $state.go("auth.login"); + $state.go('auth.login'); $rootScope.isAuth = false; } - } + }, }; utilities.sendRequest(parameters); @@ -802,4 +839,4 @@ // checkToken(); } } -})(); +})(); \ No newline at end of file diff --git a/frontend/src/views/web/challenge/leaderboard.html b/frontend/src/views/web/challenge/leaderboard.html index c173fc86aa..56d3fe53dd 100644 --- a/frontend/src/views/web/challenge/leaderboard.html +++ b/frontend/src/views/web/challenge/leaderboard.html @@ -29,8 +29,9 @@
Leaderboard
- + Phase: {{key.challenge_phase_name}}, Split: {{key.dataset_split_name}}   Leaderboard
-
+
- + {{key}} -
-
+
diff --git a/frontend/src/views/web/challenge/my-challenge-all-submission.html b/frontend/src/views/web/challenge/my-challenge-all-submission.html index be2b62fa67..b3bb2fb694 100644 --- a/frontend/src/views/web/challenge/my-challenge-all-submission.html +++ b/frontend/src/views/web/challenge/my-challenge-all-submission.html @@ -22,9 +22,10 @@
All Submissions
- - + + {{key.name}}   diff --git a/frontend/src/views/web/challenge/my-submission.html b/frontend/src/views/web/challenge/my-submission.html index f7acdb1d7e..7b7e2a172a 100644 --- a/frontend/src/views/web/challenge/my-submission.html +++ b/frontend/src/views/web/challenge/my-submission.html @@ -13,8 +13,9 @@
My Participated Team: {{challenge.participated_team_name}}
- - + {{key.name}} diff --git a/frontend/tests/controllers-test/challengeCtrl.test.js b/frontend/tests/controllers-test/challengeCtrl.test.js index 1ebfa38326..f1580f404f 100644 --- a/frontend/tests/controllers-test/challengeCtrl.test.js +++ b/frontend/tests/controllers-test/challengeCtrl.test.js @@ -5,7 +5,7 @@ describe('Unit tests for challenge controller', function () { var $controller, createController, $injector, $rootScope, $state, $scope, utilities, $http, $interval, $mdDialog, moment, vm; - beforeEach(inject(function (_$controller_, _$injector_, _$rootScope_, _$state_, _utilities_, _$http_, _$interval_, _$mdDialog_, _moment_) { + beforeEach(inject(function (_$controller_, _$injector_, _$rootScope_, _$state_, _utilities_, _$http_, _$interval_, _$mdDialog_, _moment_) { $controller = _$controller_; $injector = _$injector_; $rootScope = _$rootScope_; @@ -15,10 +15,10 @@ describe('Unit tests for challenge controller', function () { $interval = _$interval_; $mdDialog = _$mdDialog_; moment = _moment_; - + $scope = $rootScope.$new(); createController = function () { - return $controller('ChallengeCtrl', {$scope: $scope}); + return $controller('ChallengeCtrl', { $scope: $scope }); }; vm = $controller('ChallengeCtrl', { $scope: $scope }); })); @@ -99,22 +99,22 @@ describe('Unit tests for challenge controller', function () { } if ((challengePhaseSuccess == true && parameters.url == 'challenges/challenge/undefined/challenge_phase') || - (challengeSuccess == true && parameters.url == 'challenges/challenge/undefined/') || - (challengePhaseSplitSuccess == true && parameters.url == 'challenges/undefined/challenge_phase_split') || - (participantTeamChallengeSuccess == true && parameters.url == 'participants/participant_teams/challenges/undefined/user') || - (participantTeamSuccess == true && parameters.url == 'participants/participant_team') || - (selectExistTeamSuccess == true && parameters.url == 'challenges/challenge/undefined/participant_team/null')) { + (challengeSuccess == true && parameters.url == 'challenges/challenge/undefined/') || + (challengePhaseSplitSuccess == true && parameters.url == 'challenges/undefined/challenge_phase_split') || + (participantTeamChallengeSuccess == true && parameters.url == 'participants/participant_teams/challenges/undefined/user') || + (participantTeamSuccess == true && parameters.url == 'participants/participant_team') || + (selectExistTeamSuccess == true && parameters.url == 'challenges/challenge/undefined/participant_team/null')) { parameters.callback.onSuccess({ status: 200, data: successResponse }); } else if ((challengePhaseSuccess == false && parameters.url == 'challenges/challenge/undefined/challenge_phase') || - (challengeSuccess == false && parameters.url == 'challenges/challenge/undefined/') || - (challengePhaseSplitSuccess == false && parameters.url == 'challenges/undefined/challenge_phase_split') || - (participantTeamChallengeSuccess == false && parameters.url == 'participants/participant_teams/challenges/undefined/user') || - (participantTeamSuccess == false && parameters.url == 'participants/participant_team') || - (selectExistTeamSuccess == false && parameters.url == 'challenges/challenge/undefined/participant_team/null')){ + (challengeSuccess == false && parameters.url == 'challenges/challenge/undefined/') || + (challengePhaseSplitSuccess == false && parameters.url == 'challenges/undefined/challenge_phase_split') || + (participantTeamChallengeSuccess == false && parameters.url == 'participants/participant_teams/challenges/undefined/user') || + (participantTeamSuccess == false && parameters.url == 'participants/participant_team') || + (selectExistTeamSuccess == false && parameters.url == 'challenges/challenge/undefined/participant_team/null')) { parameters.callback.onError({ data: errorResponse, @@ -213,8 +213,9 @@ describe('Unit tests for challenge controller', function () { team_list.forEach(response => { it('pagination next is ' + response.next + ' and previous is ' + response.previous + '\ - `participants/participant_team`', function () {; - challengeSuccess = true; + `participants/participant_team`', function () { + ; + challengeSuccess = true; participantTeamChallengeSuccess = true; participantTeamSuccess = true; selectExistTeamSuccess = null; @@ -446,7 +447,7 @@ describe('Unit tests for challenge controller', function () { } }; utilities.storeData('userKey', 'encrypted key'); - + vm = createController(); spyOn(vm, 'startLoader'); spyOn($http, 'get').and.callFake(function () { @@ -460,7 +461,7 @@ describe('Unit tests for challenge controller', function () { var headers = { 'Authorization': "Token " + utilities.getData('userKey') }; - expect($http.get).toHaveBeenCalledWith(url, {headers: headers}); + expect($http.get).toHaveBeenCalledWith(url, { headers: headers }); }); it('backend error of the particular challenge `challenges/challenge//', function () { @@ -511,7 +512,7 @@ describe('Unit tests for challenge controller', function () { expect(vm.phases.results[i].showPrivate).toBeTruthy(); } - for(var i = 0; i < successResponse.results.length; i++){ + for (var i = 0; i < successResponse.results.length; i++) { var offset = new Date(successResponse.results[i].start_date).getTimezoneOffset(); expect(vm.phases.results[i].time_zone).toEqual(moment.tz.zone(timezone).abbr(offset)); } @@ -564,7 +565,7 @@ describe('Unit tests for challenge controller', function () { vm.isParticipated = true; vm = createController(); expect(vm.phaseSplits).toEqual(successResponse); - for(var i = 0; i < successResponse.length; i++) { + for (var i = 0; i < successResponse.length; i++) { if (successResponse[i].visibility != challengePhaseVisibility.public) { expect(vm.phaseSplits[i].showPrivate).toBeTruthy(); } @@ -627,7 +628,7 @@ describe('Unit tests for challenge controller', function () { limits: { submission_limit_exceeded: true, remaining_submissions_today_count: 12, - remaining_time: 12/12/12, + remaining_time: 12 / 12 / 12, } }, ] @@ -637,7 +638,7 @@ describe('Unit tests for challenge controller', function () { vm.displayDockerSubmissionInstructions(true, true); expect(vm.phaseRemainingSubmissions).toEqual(successResponse); var details = vm.phaseRemainingSubmissions.phases; - for (var i=0; i < details.length; i++) { + for (var i = 0; i < details.length; i++) { expect(vm.phaseRemainingSubmissionsFlags[details[i].id]).toEqual('maxExceeded'); } expect(utilities.hideLoader).toHaveBeenCalled(); @@ -651,7 +652,7 @@ describe('Unit tests for challenge controller', function () { limits: { submission_limit_exceeded: false, remaining_submissions_today_count: 12, - remaining_time: 12/12/12, + remaining_time: 12 / 12 / 12, } }, ] @@ -661,7 +662,7 @@ describe('Unit tests for challenge controller', function () { vm.displayDockerSubmissionInstructions(true, true); expect(vm.phaseRemainingSubmissions).toEqual(successResponse); var details = vm.phaseRemainingSubmissions.phases; - for (var i=0; i < details.length; i++) { + for (var i = 0; i < details.length; i++) { expect(vm.phaseRemainingSubmissionsFlags[details[i].id]).toEqual('showSubmissionNumbers'); } expect(utilities.hideLoader).toHaveBeenCalled(); @@ -675,7 +676,7 @@ describe('Unit tests for challenge controller', function () { limits: { submission_limit_exceeded: false, remaining_submissions_today_count: 0, - remaining_time: 12/12/12, + remaining_time: 12 / 12 / 12, } }, ] @@ -685,7 +686,7 @@ describe('Unit tests for challenge controller', function () { vm.displayDockerSubmissionInstructions(true, true); expect(vm.phaseRemainingSubmissions).toEqual(successResponse); var details = vm.phaseRemainingSubmissions.phases; - for (var i=0; i < details.length; i++) { + for (var i = 0; i < details.length; i++) { expect(vm.eachPhase).toEqual(details[i]); expect(vm.phaseRemainingSubmissionsFlags[details[i].id]).toEqual('showClock'); @@ -722,7 +723,7 @@ describe('Unit tests for challenge controller', function () { success: 'success', }; - beforeEach(function() { + beforeEach(function () { spyOn(vm, 'startLoader'); spyOn(vm, 'stopLoader'); spyOn($rootScope, 'notify'); @@ -848,24 +849,31 @@ describe('Unit tests for challenge controller', function () { it('successfully get the leaderboard', function () { success = true; + successResponse = { - results: { - duration: 'year', - results: [ - { - id: 1, - leaderboard__schema: - { - labels: ['label1', 'label2'], - default_order_by: 'default_order_by', - }, - submission__submitted_at: (new Date() - new Date().setFullYear(new Date().getFullYear() - 1)), + results: [ + { + id: 1, + leaderboard__schema: { + labels: ['label1', 'label2'], + default_order_by: 'default_order_by', }, - ] - }, + + submission__submitted_at: new Date().toISOString(), + }, + ] }; - var phaseSplitId = 1; - vm.getLeaderboard(phaseSplitId); + var phaseSlug = 'phase-slug'; + var splitCodename = 'split-codename'; + + + vm.phaseSplits = [{ + id: 1, + challenge_phase_slug: phaseSlug, + dataset_split_codename: splitCodename + }]; + + vm.getLeaderboard(phaseSlug, splitCodename); vm.stopLeaderboard(); expect($interval.cancel).toHaveBeenCalled(); expect(vm.isResult).toEqual(true); @@ -916,6 +924,7 @@ describe('Unit tests for challenge controller', function () { } ]; + beforeEach(function () { spyOn($interval, 'cancel'); spyOn(vm, 'startLoader'); @@ -929,24 +938,40 @@ describe('Unit tests for challenge controller', function () { results: [ { id: 1, + slug: "phase-1-slug", name: "Challenge phase name", description: "Challenge phase description", - leaderboard_public: true + leaderboard_public: true, + is_restricted_to_select_one_submission: false, + default_submission_meta_attributes: [] }, ] }; + utilities.sendRequest = function (parameters) { - if ((submissionCountSuccess == true && parameters.url == "analytics/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/count") || - (submissionListSuccess == true && parameters.url == "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/submission/")) { - parameters.callback.onSuccess({ - data: successResponse - }); - } else if ((submissionCountSuccess == false && parameters.url == "analytics/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/count") || - (submissionListSuccess == false && parameters.url == "jobs/challenge/" + vm.challengeId + "/challenge_phase/" + vm.phaseId + "/submission/")){ - parameters.callback.onError({ - data: errorResponse - }); + + if (parameters.url.includes('/count')) { + if (submissionCountSuccess) { + parameters.callback.onSuccess({ + data: successResponse + }); + } else { + parameters.callback.onError({ + data: errorResponse + }); + } + // Check for submission list API call + } else if (parameters.url.includes('/submission')) { + if (submissionListSuccess) { + parameters.callback.onSuccess({ + data: successResponse + }); + } else { + parameters.callback.onError({ + data: errorResponse + }); + } } }; }); @@ -954,44 +979,46 @@ describe('Unit tests for challenge controller', function () { it('get the leaderboard of the current phase', function () { submissionCountSuccess = null; submissionListSuccess = null; - var phaseId = 1; - vm.getResults(phaseId); + var phaseSlug = 'phase-1-slug'; + + errorResponse = { detail: 'error' }; + vm.getResults(phaseSlug); vm.stopFetchingSubmissions(); expect($interval.cancel).toHaveBeenCalled(); expect(vm.isResult).toEqual(true); - expect(vm.phaseId).toEqual(phaseId); + expect(vm.phaseId).toEqual(1); expect(vm.currentPhaseLeaderboardPublic).toEqual(true); }); it('get the submission count \ - `analytics/challenge//challenge_phase//count`', function () { + `analytics/challenge//challenge_phase//count`', function () { submissionCountSuccess = true; submissionListSuccess = null; - var phaseId = 1; + var phaseSlug = 'phase-1-slug'; successResponse = { challenge_phase: 1, participant_team_submission_count: 200 }; - vm.getResults(phaseId); + vm.getResults(phaseSlug); expect(vm.submissionCount).toEqual(successResponse.participant_team_submission_count); }); - it('backend error on getting submission count \ - `analytics/challenge//challenge_phase//count`', function () { + it('backend error on getting submission count...', function () { submissionCountSuccess = false; submissionListSuccess = null; - var phaseId = 1; - errorResponse = 'error'; - vm.getResults(phaseId); + var phaseSlug = 'phase-1-slug'; + + errorResponse = { detail: 'error' }; + vm.getResults(phaseSlug); expect($rootScope.notify).toHaveBeenCalledWith("error", errorResponse); }); submission_list.forEach(response => { it('get submissions of a particular challenge phase when pagination next is ' + response.next + ' \ - and previous is ' + response.previous + '`jobs/challenge//challenge_phase//submission/`', function () { + and previous is ' + response.previous + '`jobs/challenge//challenge_phase//submission/`', function () { submissionListSuccess = true; - var phaseId = 1; + var phaseSlug = 'phase-1-slug'; successResponse = response; successResponse.results = [ { @@ -1003,10 +1030,10 @@ describe('Unit tests for challenge controller', function () { } ]; - vm.getResults(phaseId); + vm.getResults(phaseSlug); expect(vm.isExistLoader).toBeTruthy(); expect(vm.startLoader).toHaveBeenCalledWith("Loading Submissions"); - for (var i = 0; i < successResponse.results.length; i++){ + for (var i = 0; i < successResponse.results.length; i++) { expect(vm.submissionVisibility[successResponse.results[i].id]).toEqual(successResponse.results[i].is_public); expect(vm.baselineStatus[successResponse.results[i].id] = successResponse.results[i].is_baseline); } @@ -1035,14 +1062,14 @@ describe('Unit tests for challenge controller', function () { }); it('backend error on getting submissions of a particular challenge \ - `jobs/challenge//challenge_phase//submission/`', function () { + `jobs/challenge//challenge_phase//submission/`', function () { submissionListSuccess = false; submissionCountSuccess = null; - var phaseId = 1; + var phaseSlug = 'phase-1-slug'; errorResponse = { detail: 'error' }; - vm.getResults(phaseId); + vm.getResults(phaseSlug); expect(utilities.storeData).toHaveBeenCalledWith("emailError", errorResponse.detail); expect($state.go).toHaveBeenCalledWith('web.permission-denied'); expect(vm.stopLoader).toHaveBeenCalled(); @@ -1051,7 +1078,7 @@ describe('Unit tests for challenge controller', function () { it('to load data with pagination `load` function', function () { submissionListSuccess = true; submissionCountSuccess = null; - var phaseId = 1; + var phaseSlug = 'phase-1-slug'; successResponse = { results: [ { @@ -1062,11 +1089,11 @@ describe('Unit tests for challenge controller', function () { is_baseline: true } ], - // get submissions response + next: "page=4", previous: "page=2", - }; - vm.getResults(phaseId); + }; + vm.getResults(phaseSlug); spyOn($http, 'get').and.callFake(function () { var deferred = $injector.get('$q').defer(); return deferred.promise; @@ -1078,7 +1105,7 @@ describe('Unit tests for challenge controller', function () { var headers = { 'Authorization': "Token " + utilities.getData('userKey') }; - expect($http.get).toHaveBeenCalledWith(url, {headers: headers}); + expect($http.get).toHaveBeenCalledWith(url, { headers: headers }); }); }); @@ -1341,9 +1368,8 @@ describe('Unit tests for challenge controller', function () { expect($rootScope.notify).toHaveBeenCalledWith("error", "New team couldn't be created."); }); }); - describe('Unit tests for getAllSubmissionResults function \ - `challenges//challenge_phase//submissions`', function() { + `challenges//challenge_phase//submissions`', function () { var success, successResponse; var errorResponse = { detail: 'error' @@ -1353,26 +1379,31 @@ describe('Unit tests for challenge controller', function () { count: 0, next: null, previous: null, + results: [] }, { count: 2, next: null, previous: null, + results: [{ id: 1, is_public: true, is_verified_by_host: false }] }, { count: 30, next: 'page=5', previous: null, + results: [{ id: 1, is_public: true, is_verified_by_host: false }] }, { count: 30, next: null, previous: 'page=3', + results: [{ id: 1, is_public: true, is_verified_by_host: false }] }, { count: 30, next: 'page=4', previous: 'page=2', + results: [{ id: 1, is_public: true, is_verified_by_host: false }] } ]; @@ -1384,6 +1415,13 @@ describe('Unit tests for challenge controller', function () { spyOn(utilities, 'storeData'); spyOn($state, 'go'); + + vm.phases = { + results: [ + { id: 1, slug: 'all-submissions-slug' } + ] + }; + utilities.sendRequest = function (parameters) { if (success) { parameters.callback.onSuccess({ @@ -1397,12 +1435,14 @@ describe('Unit tests for challenge controller', function () { }; }); + submission_list.forEach(response => { - it('submission list have count' + response.count + ', next ' + response.next + 'and previous ' + response.previous, function() { + it('submission list have count' + response.count + ', next ' + response.next + 'and previous ' + response.previous, function () { success = true; successResponse = response; - var phaseId = 1 - vm.getAllSubmissionResults(phaseId); + var phaseSlug = "all-submissions-slug"; + var phaseId = 1; + vm.getAllSubmissionResults(phaseSlug); vm.stopFetchingSubmissions(); expect($interval.cancel).toHaveBeenCalled(); expect(vm.isResult).toEqual(true); @@ -1438,10 +1478,12 @@ describe('Unit tests for challenge controller', function () { }); }); + it('backend error', function () { success = false; - var phaseId = 1 - vm.getAllSubmissionResults(phaseId); + var phaseSlug = "all-submissions-slug"; + var phaseId = 1; + vm.getAllSubmissionResults(phaseSlug); vm.stopFetchingSubmissions(); expect($interval.cancel).toHaveBeenCalled(); expect(vm.isResult).toEqual(true); @@ -1482,43 +1524,43 @@ describe('Unit tests for challenge controller', function () { describe('Unit tests for showapprovalparticipantteamDialog function', function () { var $mdDialog; - + beforeEach(function () { $mdDialog = $injector.get('$mdDialog'); }); - + it('should open dialog when approved_status is true', function () { var $mdDialogOpened = false; $mdDialog.show = jasmine.createSpy().and.callFake(function () { $mdDialogOpened = true; }); - + var challengeId = '123'; var participant_team_id = '456'; var approved_status = true; - + vm.showapprovalparticipantteamDialog(challengeId, participant_team_id, approved_status); - + expect($mdDialog.show).toHaveBeenCalled(); expect($mdDialogOpened).toEqual(true); }); - + it('should call check_approval_status when approved_status is false', function () { vm.check_approval_status = jasmine.createSpy(); - + var challengeId = '123'; var participant_team_id = '456'; var approved_status = false; - + vm.showapprovalparticipantteamDialog(challengeId, participant_team_id, approved_status); - + expect(vm.check_approval_status).toHaveBeenCalledWith(challengeId, participant_team_id, approved_status, false); }); }); describe('Unit tests for check_approval_status function', function () { var success, errorResponse, secondfunction; - + beforeEach(function () { spyOn($rootScope, 'notify'); spyOn($state, 'reload'); @@ -1539,38 +1581,38 @@ describe('Unit tests for challenge controller', function () { } }; }); - + it('should handle successful approval of participant team', function () { success = true; - + var challengeId = '123'; var participant_team_id = '456'; var approved_status = true; var formvalid = true; - + vm.check_approval_status(challengeId, participant_team_id, approved_status, formvalid); - + expect($rootScope.notify).toHaveBeenCalledWith('success', 'Participant Team Approved successfully.'); expect($mdDialog.hide).toHaveBeenCalled(); }); - + it('should handle error during approval of participant team', function () { success = false; secondfunction = false; errorResponse = { - error: 'Approval failed' + error: 'Approval failed' }; - + var challengeId = '123'; var participant_team_id = '456'; var approved_status = true; var formvalid = true; - + vm.check_approval_status(challengeId, participant_team_id, approved_status, formvalid); - + expect($rootScope.notify).toHaveBeenCalledWith('error', 'Approval failed'); }); - + it('should handle disapproval of participant team', function () { success = false; secondfunction = true; @@ -1578,9 +1620,9 @@ describe('Unit tests for challenge controller', function () { var participant_team_id = '456'; var approved_status = false; var formvalid = false; - + vm.check_approval_status(challengeId, participant_team_id, approved_status, formvalid); - + expect($rootScope.notify).toHaveBeenCalledWith('success', 'Participant Team Disapproved successfully.'); expect($state.reload).not.toHaveBeenCalled(); }); @@ -1776,7 +1818,7 @@ describe('Unit tests for challenge controller', function () { vm.project_url = 'project url'; vm.publication_url = 'publication url'; vm.submissionMetaData = { - submission_metadata : null + submission_metadata: null }; vm.currentSubmissionMetaData = [ { @@ -1790,7 +1832,7 @@ describe('Unit tests for challenge controller', function () { name: 'SingleOptionAttribute', type: 'radio', value: null, - options: ['A','B','C'], + options: ['A', 'B', 'C'], $$hashKey: 'object:43', description: 'Sample', }, @@ -1798,7 +1840,7 @@ describe('Unit tests for challenge controller', function () { name: 'MultipleChoiceAttribute', type: 'checkbox', values: [], - options: ['alpha','beta','gamma'], + options: ['alpha', 'beta', 'gamma'], $$hashKey: 'object:44', description: 'Sample', }, @@ -1824,7 +1866,7 @@ describe('Unit tests for challenge controller', function () { vm.project_url = 'project url'; vm.publication_url = 'publication url'; vm.submissionMetaData = { - submission_metadata : null + submission_metadata: null }; vm.currentSubmissionMetaData = [ { @@ -1838,7 +1880,7 @@ describe('Unit tests for challenge controller', function () { name: 'SingleOptionAttribute', type: 'radio', value: null, - options: ['A','B','C'], + options: ['A', 'B', 'C'], $$hashKey: 'object:43', description: 'Sample', }, @@ -1846,7 +1888,7 @@ describe('Unit tests for challenge controller', function () { name: 'MultipleChoiceAttribute', type: 'checkbox', values: [], - options: ['alpha','beta','gamma'], + options: ['alpha', 'beta', 'gamma'], $$hashKey: 'object:44', description: 'Sample', }, @@ -2595,7 +2637,7 @@ describe('Unit tests for challenge controller', function () { it('valid `edit challenge phase` form & successfull edit', function () { var editChallengePhaseForm = true; success = true; - vm.page.challenge_phase ={ + vm.page.challenge_phase = { id: 1, name: "challenge phase name", description: "challenge phase description", @@ -2616,7 +2658,7 @@ describe('Unit tests for challenge controller', function () { it('valid `edit challenge phase` form & backend error', function () { var editChallengePhaseForm = true; success = false; - vm.page.challenge_phase ={ + vm.page.challenge_phase = { id: 1, name: "challenge phase name", description: "challenge phase description", @@ -2666,7 +2708,7 @@ describe('Unit tests for challenge controller', function () { }); it('change challenge state from `public` to `private`', function () { - vm.isPublished = true; + vm.isPublished = true; vm.publishChallenge(ev); expect(vm.publishDesc).toEqual(null); expect(ev.stopPropagation).toHaveBeenCalled(); @@ -2674,7 +2716,7 @@ describe('Unit tests for challenge controller', function () { }); it('change challenge state from `private` to `public`', function () { - vm.isPublished = false; + vm.isPublished = false; vm.publishChallenge(ev); expect(vm.publishDesc).toEqual(null); expect(ev.stopPropagation).toHaveBeenCalled(); diff --git a/tests/unit/analytics/test_views.py b/tests/unit/analytics/test_views.py index 02421c014c..cd91e29b58 100644 --- a/tests/unit/analytics/test_views.py +++ b/tests/unit/analytics/test_views.py @@ -221,14 +221,12 @@ def setUp(self): self.challenge.participant_teams.add(self.participant_team) def test_get_participant_team_count(self): - expected = {"participant_team_count": 1} response = self.client.get(self.url, {}) self.assertEqual(response.data, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_get_participant_team_count_when_challenge_does_not_exist(self): - self.url = reverse_lazy( "analytics:get_participant_team_count", kwargs={"challenge_pk": self.challenge.pk + 10}, @@ -256,14 +254,12 @@ def setUp(self): self.challenge.participant_teams.add(self.participant_team3) def test_get_participant_team_count(self): - expected = {"participant_count": 2} response = self.client.get(self.url, {}) self.assertEqual(response.data, expected) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_get_participant_team_count_when_challenge_doe_not_exist(self): - self.url = reverse_lazy( "analytics:get_participant_count", kwargs={"challenge_pk": self.challenge.pk + 10}, @@ -301,7 +297,6 @@ def setUp(self): ) def test_get_participant_team_count_when_challenge_does_not_exist(self): - self.url = reverse_lazy( "analytics:get_submission_count", kwargs={ @@ -380,7 +375,8 @@ def setUp(self): "analytics:get_challenge_phase_submission_count_by_team", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -443,7 +439,8 @@ def test_get_challenge_phase_submission_count_by_team_when_challenge_does_not_ex "analytics:get_challenge_phase_submission_count_by_team", kwargs={ "challenge_pk": self.challenge.pk + 10, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -463,7 +460,8 @@ def test_get_challenge_phase_submission_count_by_team_when_challenge_phase_does_ "analytics:get_challenge_phase_submission_count_by_team", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk + 10, + "challenge_phase_pk_or_slug": self.challenge_phase.pk + 10, + "version": "v1", }, ) @@ -486,7 +484,8 @@ def test_get_challenge_phase_submission_count_by_team_for_participant_team_1( "analytics:get_challenge_phase_submission_count_by_team", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -509,7 +508,8 @@ def test_get_challenge_phase_submission_count_by_team_for_participant_team_3( "analytics:get_challenge_phase_submission_count_by_team", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) diff --git a/tests/unit/challenges/test_urls.py b/tests/unit/challenges/test_urls.py index 96c89f214b..0a287e6382 100644 --- a/tests/unit/challenges/test_urls.py +++ b/tests/unit/challenges/test_urls.py @@ -200,14 +200,18 @@ def test_challenges_urls(self): "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "version": "v1", + "challenge_phase_pk_or_slug": self.challenge_phase.pk, "file_type": self.file_type, }, ) self.assertEqual( self.url, - "/api/challenges/{}/phase/{}/download_all_submissions/{}/".format( - self.challenge.pk, self.challenge_phase.pk, self.file_type + "/api/challenges/{}/phase/{}/{}/download_all_submissions/{}/".format( + self.challenge.pk, + "v1", + self.challenge_phase.pk, + self.file_type, ), ) resolver = resolve(self.url) diff --git a/tests/unit/challenges/test_views.py b/tests/unit/challenges/test_views.py index ba543c7ae2..2d085c8572 100644 --- a/tests/unit/challenges/test_views.py +++ b/tests/unit/challenges/test_views.py @@ -751,8 +751,6 @@ def test_particular_challenge_partial_update(self): "submission_guidelines": self.challenge.submission_guidelines, "evaluation_details": self.challenge.evaluation_details, "image": None, - "start_date": None, - "end_date": None, "creator": { "id": self.challenge.creator.pk, "team_name": self.challenge.creator.team_name, @@ -830,8 +828,6 @@ def test_particular_challenge_update(self): "submission_guidelines": self.update_submission_guidelines, "evaluation_details": self.challenge.evaluation_details, "image": None, - "start_date": None, - "end_date": None, "creator": { "id": self.challenge.creator.pk, "team_name": self.challenge.creator.team_name, @@ -2996,7 +2992,9 @@ def test_get_challenge_phase(self): "slug": self.challenge_phase.slug, "is_restricted_to_select_one_submission": self.challenge_phase.is_restricted_to_select_one_submission, "submission_meta_attributes": None, - "is_partial_submission_evaluation_enabled": self.challenge_phase.is_partial_submission_evaluation_enabled, + "is_partial_submission_evaluation_enabled": ( + self.challenge_phase.is_partial_submission_evaluation_enabled + ), "allowed_submission_file_types": self.challenge_phase.allowed_submission_file_types, "default_submission_meta_attributes": self.challenge_phase.default_submission_meta_attributes, "allowed_email_ids": self.challenge_phase.allowed_email_ids, @@ -3023,9 +3021,13 @@ def test_get_challenge_phase(self): "max_submissions": self.private_challenge_phase.max_submissions, "max_concurrent_submissions_allowed": self.private_challenge_phase.max_concurrent_submissions_allowed, "slug": self.private_challenge_phase.slug, - "is_restricted_to_select_one_submission": self.private_challenge_phase.is_restricted_to_select_one_submission, + "is_restricted_to_select_one_submission": ( + self.private_challenge_phase.is_restricted_to_select_one_submission + ), "submission_meta_attributes": None, - "is_partial_submission_evaluation_enabled": self.challenge_phase.is_partial_submission_evaluation_enabled, + "is_partial_submission_evaluation_enabled": ( + self.challenge_phase.is_partial_submission_evaluation_enabled + ), "allowed_submission_file_types": self.challenge_phase.allowed_submission_file_types, "default_submission_meta_attributes": self.private_challenge_phase.default_submission_meta_attributes, "allowed_email_ids": self.challenge_phase.allowed_email_ids, @@ -3062,7 +3064,9 @@ def test_get_challenge_phase_when_user_is_not_authenticated(self): "slug": self.challenge_phase.slug, "is_restricted_to_select_one_submission": self.challenge_phase.is_restricted_to_select_one_submission, "submission_meta_attributes": None, - "is_partial_submission_evaluation_enabled": self.challenge_phase.is_partial_submission_evaluation_enabled, + "is_partial_submission_evaluation_enabled": ( + self.challenge_phase.is_partial_submission_evaluation_enabled + ), "allowed_submission_file_types": self.challenge_phase.allowed_submission_file_types, "default_submission_meta_attributes": self.challenge_phase.default_submission_meta_attributes, "allowed_email_ids": self.challenge_phase.allowed_email_ids, @@ -3109,7 +3113,9 @@ def test_get_challenge_phase_when_user_is_host(self): "slug": self.challenge_phase.slug, "is_restricted_to_select_one_submission": self.challenge_phase.is_restricted_to_select_one_submission, "submission_meta_attributes": None, - "is_partial_submission_evaluation_enabled": self.challenge_phase.is_partial_submission_evaluation_enabled, + "is_partial_submission_evaluation_enabled": ( + self.challenge_phase.is_partial_submission_evaluation_enabled + ), "allowed_submission_file_types": self.challenge_phase.allowed_submission_file_types, "default_submission_meta_attributes": self.challenge_phase.default_submission_meta_attributes, "allowed_email_ids": self.challenge_phase.allowed_email_ids, @@ -3136,10 +3142,14 @@ def test_get_challenge_phase_when_user_is_host(self): "max_submissions": self.private_challenge_phase.max_submissions, "max_concurrent_submissions_allowed": self.challenge_phase.max_concurrent_submissions_allowed, "slug": self.private_challenge_phase.slug, - "is_restricted_to_select_one_submission": self.private_challenge_phase.is_restricted_to_select_one_submission, + "is_restricted_to_select_one_submission": ( + self.private_challenge_phase.is_restricted_to_select_one_submission + ), "submission_meta_attributes": None, "allowed_submission_file_types": self.private_challenge_phase.allowed_submission_file_types, - "is_partial_submission_evaluation_enabled": self.private_challenge_phase.is_partial_submission_evaluation_enabled, + "is_partial_submission_evaluation_enabled": ( + self.private_challenge_phase.is_partial_submission_evaluation_enabled + ), "default_submission_meta_attributes": self.private_challenge_phase.default_submission_meta_attributes, "allowed_email_ids": self.private_challenge_phase.allowed_email_ids, "is_submission_public": self.private_challenge_phase.is_submission_public, @@ -3866,10 +3876,14 @@ def test_get_challenge_phase_split(self): "id": self.challenge_phase_split.id, "challenge_phase": self.challenge_phase.id, "challenge_phase_name": self.challenge_phase.name, + "challenge_phase_slug": self.challenge_phase.slug, "dataset_split": self.dataset_split.id, "dataset_split_name": self.dataset_split.name, + "dataset_split_codename": self.dataset_split.codename, "visibility": self.challenge_phase_split.visibility, - "show_leaderboard_by_latest_submission": self.challenge_phase_split.show_leaderboard_by_latest_submission, + "show_leaderboard_by_latest_submission": ( + self.challenge_phase_split.show_leaderboard_by_latest_submission + ), "show_execution_time": False, "leaderboard_schema": self.challenge_phase_split.leaderboard.schema, "is_multi_metric_leaderboard": self.challenge_phase_split.is_multi_metric_leaderboard, @@ -3905,10 +3919,14 @@ def test_get_challenge_phase_split_when_user_is_challenge_host(self): "id": self.challenge_phase_split.id, "challenge_phase": self.challenge_phase.id, "challenge_phase_name": self.challenge_phase.name, + "challenge_phase_slug": self.challenge_phase.slug, "dataset_split": self.dataset_split.id, "dataset_split_name": self.dataset_split.name, + "dataset_split_codename": self.dataset_split.codename, "visibility": self.challenge_phase_split.visibility, - "show_leaderboard_by_latest_submission": self.challenge_phase_split.show_leaderboard_by_latest_submission, + "show_leaderboard_by_latest_submission": ( + self.challenge_phase_split.show_leaderboard_by_latest_submission + ), "show_execution_time": False, "leaderboard_schema": self.challenge_phase_split.leaderboard.schema, "is_multi_metric_leaderboard": self.challenge_phase_split.is_multi_metric_leaderboard, @@ -3917,10 +3935,14 @@ def test_get_challenge_phase_split_when_user_is_challenge_host(self): "id": self.challenge_phase_split_host.id, "challenge_phase": self.challenge_phase.id, "challenge_phase_name": self.challenge_phase.name, + "challenge_phase_slug": self.challenge_phase.slug, "dataset_split": self.dataset_split_host.id, "dataset_split_name": self.dataset_split_host.name, + "dataset_split_codename": self.dataset_split_host.codename, "visibility": self.challenge_phase_split_host.visibility, - "show_leaderboard_by_latest_submission": self.challenge_phase_split_host.show_leaderboard_by_latest_submission, + "show_leaderboard_by_latest_submission": ( + self.challenge_phase_split_host.show_leaderboard_by_latest_submission + ), "show_execution_time": False, "leaderboard_schema": self.challenge_phase_split_host.leaderboard.schema, "is_multi_metric_leaderboard": self.challenge_phase_split_host.is_multi_metric_leaderboard, @@ -3941,10 +3963,14 @@ def test_get_challenge_phase_split_when_user_is_staff(self): "id": self.challenge_phase_split.id, "challenge_phase": self.challenge_phase.id, "challenge_phase_name": self.challenge_phase.name, + "challenge_phase_slug": self.challenge_phase.slug, "dataset_split": self.dataset_split.id, "dataset_split_name": self.dataset_split.name, + "dataset_split_codename": self.dataset_split.codename, "visibility": self.challenge_phase_split.visibility, - "show_leaderboard_by_latest_submission": self.challenge_phase_split.show_leaderboard_by_latest_submission, + "show_leaderboard_by_latest_submission": ( + self.challenge_phase_split.show_leaderboard_by_latest_submission + ), "show_execution_time": False, "leaderboard_schema": self.challenge_phase_split.leaderboard.schema, "is_multi_metric_leaderboard": self.challenge_phase_split.is_multi_metric_leaderboard, @@ -3953,10 +3979,14 @@ def test_get_challenge_phase_split_when_user_is_staff(self): "id": self.challenge_phase_split_host.id, "challenge_phase": self.challenge_phase.id, "challenge_phase_name": self.challenge_phase.name, + "challenge_phase_slug": self.challenge_phase.slug, "dataset_split": self.dataset_split_host.id, "dataset_split_name": self.dataset_split_host.name, + "dataset_split_codename": self.dataset_split_host.codename, "visibility": self.challenge_phase_split_host.visibility, - "show_leaderboard_by_latest_submission": self.challenge_phase_split_host.show_leaderboard_by_latest_submission, + "show_leaderboard_by_latest_submission": ( + self.challenge_phase_split_host.show_leaderboard_by_latest_submission + ), "show_execution_time": False, "leaderboard_schema": self.challenge_phase_split_host.leaderboard.schema, "is_multi_metric_leaderboard": self.challenge_phase_split_host.is_multi_metric_leaderboard, @@ -4442,7 +4472,8 @@ def test_get_all_submissions_when_challenge_does_not_exist(self): "challenges:get_all_submissions_of_challenge", kwargs={ "challenge_pk": self.challenge5.pk + 10, - "challenge_phase_pk": self.challenge5_phase3.pk, + "challenge_phase_pk_or_slug": self.challenge5_phase3.pk, + "version": "v1", }, ) expected = { @@ -4459,16 +4490,17 @@ def test_get_all_submissions_when_challenge_phase_does_not_exist(self): "challenges:get_all_submissions_of_challenge", kwargs={ "challenge_pk": self.challenge5.pk, - "challenge_phase_pk": self.challenge5_phase3.pk + 10, + "challenge_phase_pk_or_slug": self.challenge5_phase3.pk + 10, + "version": "v1", }, ) expected = { - "error": "Challenge Phase {} does not exist".format( + "detail": "ChallengePhase {} does not exist".format( self.challenge5_phase3.pk + 10 ) } response = self.client.get(self.url, {}) - self.assertEqual(response.data, expected) + self.assertDictEqual(response.data, expected) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) def test_get_all_submissions_when_user_is_host_of_challenge(self): @@ -4476,14 +4508,16 @@ def test_get_all_submissions_when_user_is_host_of_challenge(self): "challenges:get_all_submissions_of_challenge", kwargs={ "challenge_pk": self.challenge5.pk, - "challenge_phase_pk": self.challenge5_phase1.pk, + "challenge_phase_pk_or_slug": self.challenge5_phase1.pk, + "version": "v1", }, ) self.url_phase2 = reverse_lazy( "challenges:get_all_submissions_of_challenge", kwargs={ "challenge_pk": self.challenge5.pk, - "challenge_phase_pk": self.challenge5_phase2.pk, + "challenge_phase_pk_or_slug": self.challenge5_phase2.pk, + "version": "v1", }, ) self.client.force_authenticate(user=self.user5) @@ -4539,7 +4573,8 @@ def test_get_all_submissions_when_user_is_participant_of_challenge(self): "challenges:get_all_submissions_of_challenge", kwargs={ "challenge_pk": self.challenge5.pk, - "challenge_phase_pk": self.challenge5_phase3.pk, + "challenge_phase_pk_or_slug": self.challenge5_phase3.pk, + "version": "v1", }, ) self.client.force_authenticate(user=self.user6) @@ -4592,7 +4627,8 @@ def test_get_all_submissions_when_user_is_neither_host_nor_participant_of_challe "challenges:get_all_submissions_of_challenge", kwargs={ "challenge_pk": self.challenge5.pk, - "challenge_phase_pk": self.challenge5_phase3.pk, + "challenge_phase_pk_or_slug": self.challenge5_phase3.pk, + "version": "v1", }, ) expected = { @@ -4744,8 +4780,9 @@ def test_download_all_submissions_when_challenge_does_not_exist(self): "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk + 10, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, "file_type": self.file_type_csv, + "version": "v1", }, ) expected = { @@ -4764,17 +4801,18 @@ def test_download_all_submissions_when_challenge_phase_does_not_exist( "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk + 10, + "challenge_phase_pk_or_slug": self.challenge_phase.pk + 10, "file_type": self.file_type_csv, + "version": "v1", }, ) expected = { - "error": "Challenge Phase {} does not exist".format( + "detail": "ChallengePhase {} does not exist".format( self.challenge_phase.pk + 10 ) } response = self.client.get(self.url, {}) - self.assertEqual(response.data, expected) + self.assertDictEqual(response.data, expected) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) def test_download_all_submissions_when_file_type_is_not_csv(self): @@ -4782,8 +4820,9 @@ def test_download_all_submissions_when_file_type_is_not_csv(self): "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, "file_type": self.file_type_pdf, + "version": "v1", }, ) expected = {"error": "The file type requested is not valid!"} @@ -4796,8 +4835,9 @@ def test_download_all_submissions_when_user_is_challenge_host(self): "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, "file_type": self.file_type_csv, + "version": "v1", }, ) response = self.client.get(self.url, {}) @@ -4808,8 +4848,9 @@ def test_download_all_submissions_for_host_with_custom_fields(self): "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, "file_type": self.file_type_csv, + "version": "v1", }, ) submissions = Submission.objects.filter( @@ -4863,8 +4904,9 @@ def test_download_all_submissions_when_user_is_challenge_participant(self): "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, "file_type": self.file_type_csv, + "version": "v1", }, ) @@ -4880,8 +4922,9 @@ def test_download_all_submissions_when_user_is_neither_a_challenge_host_nor_a_pa "challenges:download_all_submissions", kwargs={ "challenge_pk": self.challenge.pk, - "challenge_phase_pk": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, "file_type": self.file_type_csv, + "version": "v1", }, ) @@ -5399,9 +5442,13 @@ def test_get_challenge_phases_by_challenge_pk(self): % (self.private_challenge_phase.test_annotation.url), "slug": self.private_challenge_phase.slug, "environment_image": self.private_challenge_phase.environment_image, - "is_restricted_to_select_one_submission": self.private_challenge_phase.is_restricted_to_select_one_submission, + "is_restricted_to_select_one_submission": ( + self.private_challenge_phase.is_restricted_to_select_one_submission + ), "submission_meta_attributes": None, - "is_partial_submission_evaluation_enabled": self.private_challenge_phase.is_partial_submission_evaluation_enabled, + "is_partial_submission_evaluation_enabled": ( + self.private_challenge_phase.is_partial_submission_evaluation_enabled + ), "config_id": None, "allowed_submission_file_types": self.challenge_phase.allowed_submission_file_types, "default_submission_meta_attributes": self.private_challenge_phase.default_submission_meta_attributes, @@ -5435,7 +5482,9 @@ def test_get_challenge_phases_by_challenge_pk(self): "environment_image": self.challenge_phase.environment_image, "is_restricted_to_select_one_submission": self.challenge_phase.is_restricted_to_select_one_submission, "submission_meta_attributes": None, - "is_partial_submission_evaluation_enabled": self.challenge_phase.is_partial_submission_evaluation_enabled, + "is_partial_submission_evaluation_enabled": ( + self.challenge_phase.is_partial_submission_evaluation_enabled + ), "config_id": None, "allowed_submission_file_types": self.challenge_phase.allowed_submission_file_types, "default_submission_meta_attributes": self.challenge_phase.default_submission_meta_attributes, @@ -5916,6 +5965,7 @@ def test_request_challenge_approval_with_successful_subscription_email( mock_send_email.assert_called_once_with(self.challenge) # Verify success logging + mock_logger.info.assert_any_call( "Subscription plans email sent successfully for challenge {}".format( self.challenge.pk @@ -5958,6 +6008,7 @@ def test_request_challenge_approval_with_email_failure_continues_approval( mock_send_email.assert_called_once_with(self.challenge) # Verify error logging + mock_logger.error.assert_any_call( "Failed to send subscription plans email for challenge {}: {}".format( self.challenge.pk, "Email service unavailable" @@ -5965,6 +6016,7 @@ def test_request_challenge_approval_with_email_failure_continues_approval( ) # Verify approval process continues despite email failure + self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( response.data, @@ -5986,6 +6038,7 @@ def test_request_challenge_approval_challenge_not_found( response = self.client.get(url) # Verify email function was not called for non-existent challenge + mock_send_email.assert_not_called() self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) @@ -5994,7 +6047,9 @@ def test_request_challenge_approval_challenge_not_found( @mock.patch("challenges.views.send_subscription_plans_email") def test_request_challenge_approval_user_not_host(self, mock_send_email): """Test that email is not sent when user is not challenge host""" + # Create a different user who is not a challenge host + other_user = User.objects.create( username="otheruser", password="other_password", @@ -6008,6 +6063,7 @@ def test_request_challenge_approval_user_not_host(self, mock_send_email): ) # Authenticate as the other user + self.client.force_authenticate(user=other_user) url = reverse_lazy( @@ -6017,6 +6073,7 @@ def test_request_challenge_approval_user_not_host(self, mock_send_email): response = self.client.get(url) # Verify email function was not called for unauthorized user + mock_send_email.assert_not_called() self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) @@ -6045,6 +6102,7 @@ def test_request_challenge_approval_webhook_failure_after_email_success( mock_send_email.assert_called_once_with(self.challenge) # Webhook failure should result in error response + self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE) self.assertIn("error", response.data) @@ -6061,6 +6119,7 @@ def test_request_challenge_approval_with_smtp_error(self, mock_send_email): ) # Simulate SMTP error + from smtplib import SMTPException mock_send_email.side_effect = SMTPException( @@ -6077,6 +6136,7 @@ def test_request_challenge_approval_with_smtp_error(self, mock_send_email): mock_send_email.assert_called_once_with(self.challenge) # Approval should continue despite SMTP error + self.assertEqual(response.status_code, status.HTTP_200_OK) @responses.activate @@ -6085,7 +6145,9 @@ def test_request_challenge_approval_email_integration_with_challenge_phases( self, mock_send_email ): """Test email integration with challenge that has multiple phases""" + # Create additional challenge phase + with self.settings(MEDIA_ROOT="/tmp/evalai"): additional_phase = ChallengePhase.objects.create( name="Additional Phase", @@ -6107,6 +6169,7 @@ def test_request_challenge_approval_email_integration_with_challenge_phases( from participants.models import Participant # Ensure participant team is associated with the challenge and user is a participant + self.challenge.participant_teams.add(self.participant_team) Participant.objects.get_or_create( user=self.user, @@ -6130,6 +6193,7 @@ def test_request_challenge_approval_email_integration_with_challenge_phases( ) # Manually update the status to finished after creation to bypass any automatic processing + submission.status = "finished" submission.save() @@ -6148,6 +6212,7 @@ def test_request_challenge_approval_email_integration_with_challenge_phases( response = self.client.get(url) # Verify email function was called with the challenge + mock_send_email.assert_called_once_with(self.challenge) self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -6158,7 +6223,9 @@ def test_request_challenge_approval_email_not_sent_when_submissions_incomplete( self, mock_send_email ): """Test that email is not sent when submission check fails""" + # Create a challenge phase without finished submissions + with self.settings(MEDIA_ROOT="/tmp/evalai"): ChallengePhase.objects.create( name="Unfinished Phase", @@ -6185,6 +6252,7 @@ def test_request_challenge_approval_email_not_sent_when_submissions_incomplete( mock_send_email.assert_not_called() # The request should fail due to unfinished submissions + self.assertEqual(response.status_code, status.HTTP_406_NOT_ACCEPTABLE) self.assertIn( "do not have finished submissions", response.data["error"] @@ -6296,6 +6364,7 @@ def test_create_challenge_using_github_success(self): self.assertEqual(ChallengePhaseSplit.objects.count(), 1) # Verify github_repository is properly stored + challenge = Challenge.objects.first() self.assertEqual( challenge.github_repository, @@ -6409,13 +6478,16 @@ def test_validate_challenge_using_failure(self): "Please add the submission guidelines.\n" "ERROR: There is no key for the evaluation script in the YAML file. Please add it and then try again!\n" "ERROR: Please add the start_date and end_date.\n" - "ERROR: The 'default_order_by' value 'aa' in the schema for the leaderboard with ID: 1 is not a valid label.\n" + "ERROR: The 'default_order_by' value 'aa' in the schema for the leaderboard with ID: " + "1 is not a valid label.\n" "ERROR: No codename found for the challenge phase. Please add a codename and try again!\n" " ERROR: There is no key for description in phase Dev Phase.\n" "ERROR: Please add the start_date and end_date in challenge phase 1.\n" - "ERROR: Please enter the following fields for the submission meta attribute in challenge phase 1: description, type\n" + "ERROR: Please enter the following fields for the submission meta attribute in challenge phase 1: " + "description, type\n" "ERROR: Challenge phase 1 has the following schema errors:\n" - " {'description': [ErrorDetail(string='This field is required.', code='required')], 'max_submissions_per_month': [ErrorDetail(string='This field may not be null.', code='null')]}\n" + " {'description': [ErrorDetail(string='This field is required.', code='required')], " + "'max_submissions_per_month': [ErrorDetail(string='This field may not be null.', code='null')]}\n" "ERROR: Invalid leaderboard id 1 found in challenge phase split 1.\n" "ERROR: Invalid phased id 1 found in challenge phase split 1.\n" "ERROR: Invalid leaderboard id 1 found in challenge phase split 2.\n" diff --git a/tests/unit/jobs/test_urls.py b/tests/unit/jobs/test_urls.py index 762b42da61..844b020efd 100644 --- a/tests/unit/jobs/test_urls.py +++ b/tests/unit/jobs/test_urls.py @@ -156,13 +156,14 @@ def test_challenge_submisson_url(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "version": "v1", + "challenge_phase_pk_or_slug": self.challenge_phase.pk, }, ) self.assertEqual( self.url, - "/api/jobs/challenge/{}/challenge_phase/{}/submission/".format( - self.challenge.pk, self.challenge_phase.pk + "/api/jobs/challenge/{}/challenge_phase/{}/{}/submission/".format( + self.challenge.pk, "v1", self.challenge_phase.pk ), ) resolver = resolve(self.url) @@ -170,17 +171,23 @@ def test_challenge_submisson_url(self): def test_leaderboard(self): self.url = reverse_lazy( - "jobs:leaderboard", - kwargs={"challenge_phase_split_id": self.challenge_phase_split.pk}, + "jobs:leaderboard_by_slug", + kwargs={ + "challenge_pk": self.challenge.pk, + "phase_slug": self.challenge_phase.slug, + "split_codename": self.dataset_split.codename, + }, ) self.assertEqual( self.url, - "/api/jobs/challenge_phase_split/{}/leaderboard/".format( - self.challenge_phase_split.pk + "/api/jobs/challenge/{}/phase/{}/split/{}/leaderboard/".format( + self.challenge.pk, + self.challenge_phase.slug, + self.dataset_split.codename, ), ) resolver = resolve(self.url) - self.assertEqual(resolver.view_name, "jobs:leaderboard") + self.assertEqual(resolver.view_name, "jobs:leaderboard_by_slug") def test_get_submission_by_pk(self): self.url = reverse_lazy( diff --git a/tests/unit/jobs/test_views.py b/tests/unit/jobs/test_views.py index 9945dc5164..c76c43a570 100644 --- a/tests/unit/jobs/test_views.py +++ b/tests/unit/jobs/test_views.py @@ -122,6 +122,7 @@ def setUp(self): with self.settings(MEDIA_ROOT="/tmp/evalai"): self.challenge_phase = ChallengePhase.objects.create( name="Challenge Phase", + slug="challenge-phase", description="Description for Challenge Phase", leaderboard_public=False, max_submissions_per_day=10, @@ -142,6 +143,7 @@ def setUp(self): self.private_challenge_phase = ChallengePhase.objects.create( name="Private Challenge Phase", + slug="private-challenge-phase", description="Description for Private Challenge Phase", leaderboard_public=False, max_submissions_per_day=10, @@ -183,7 +185,8 @@ def setUp(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -205,7 +208,8 @@ def test_challenge_submission_when_challenge_does_not_exist(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -226,7 +230,8 @@ def test_challenge_submission_when_challenge_is_not_active(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -248,28 +253,36 @@ def test_challenge_submission_when_challenge_phase_does_not_exist(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) - + challenge_phase_pk = self.challenge_phase.pk self.challenge_phase.delete() - expected = {"error": "Challenge Phase does not exist"} - + # Corrected part starts here response = self.client.post( self.url, {"status": "submitting", "input_file": self.input_file}, format="multipart", ) - self.assertEqual(response.data, expected) - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + + self.assertIn("detail", response.data) + + self.assertIn( + f"ChallengePhase {challenge_phase_pk} does not exist", + str(response.data["detail"]), + ) def test_challenge_submission_when_challenge_phase_is_not_public(self): self.url = reverse_lazy( "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -294,7 +307,8 @@ def test_challenge_submission_when_user_does_not_exist_in_allowed_emails( "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -316,7 +330,8 @@ def test_challenge_submission_when_user_exist_in_allowed_emails(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -341,7 +356,8 @@ def test_challenge_submission_when_user_does_not_exist_in_allowed_emails_and_is_ "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -362,7 +378,8 @@ def test_challenge_submission_when_challenge_phase_is_private_and_user_is_host( "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -384,7 +401,8 @@ def test_challenge_submission_when_challenge_phase_is_private_and_user_is_not_ho "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -409,7 +427,8 @@ def test_challenge_submission_when_participant_team_is_none(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -432,7 +451,8 @@ def test_challenge_submission_when_participant_team_hasnt_participated_in_challe "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -452,7 +472,8 @@ def test_challenge_submission_when_status_is_not_correct(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -474,7 +495,8 @@ def test_challenge_submission_for_successful_submission(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -493,7 +515,8 @@ def test_challenge_submission_when_maximum_limit_exceeded(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) actual_maxinmum_submissions = self.challenge_phase.max_submissions @@ -516,7 +539,8 @@ def test_challenge_submission_for_docker_based_challenges(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -537,7 +561,8 @@ def test_challenge_submission_when_file_url_is_none(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -560,7 +585,8 @@ def setUp(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -583,7 +609,8 @@ def test_challenge_submission_when_challenge_does_not_exist(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -600,24 +627,24 @@ def test_challenge_submission_when_challenge_phase_does_not_exist(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) self.challenge_phase.delete() - - expected = {"error": "Challenge Phase does not exist"} - response = self.client.get(self.url, {}) - self.assertEqual(response.data, expected) - self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertIn("detail", response.data) + self.assertIn("does not exist", str(response.data["detail"])) def test_challenge_submission_when_participant_team_is_none(self): self.url = reverse_lazy( "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -636,7 +663,8 @@ def test_challenge_submission_when_participant_team_hasnt_participated_in_challe "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -652,7 +680,8 @@ def test_get_challenge_submissions(self): "jobs:challenge_submission", kwargs={ "challenge_id": self.challenge.pk, - "challenge_phase_id": self.challenge_phase.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) expected = [ @@ -703,8 +732,9 @@ def setUp(self): self.url = reverse_lazy( "jobs:get_remaining_submissions", kwargs={ - "challenge_phase_id": self.challenge_phase.pk, "challenge_id": self.challenge.pk, + "challenge_phase_pk_or_slug": self.challenge_phase.pk, + "version": "v1", }, ) @@ -1776,6 +1806,7 @@ def test_get_submission_by_pk_when_user_is_neither_challenge_host_nor_submission class ChallengeLeaderboardTest(BaseAPITestClass): def setUp(self): super(ChallengeLeaderboardTest, self).setUp() + self.maxDiff = None self.dataset_split = DatasetSplit.objects.create( name="Split 1", codename="split1" @@ -1969,10 +2000,19 @@ def setUp(self): def test_get_leaderboard(self): self.url = reverse_lazy( - "jobs:leaderboard", - kwargs={"challenge_phase_split_id": self.challenge_phase_split.id}, + "jobs:leaderboard_by_slug", + kwargs={ + "challenge_pk": self.challenge.pk, + "phase_slug": self.challenge_phase.slug, + "split_codename": self.dataset_split.codename, + }, ) + self.leaderboard_data_2.delete() + + self.host_participant_team_submission.is_public = False + self.host_participant_team_submission.save() + expected = { "count": 1, "next": None, @@ -2002,92 +2042,23 @@ def test_get_leaderboard(self): } ], } - expected = collections.OrderedDict(expected) - - response = self.client.get(self.url, {}) - self.assertEqual(response.data["count"], expected["count"]) - self.assertEqual(response.data["next"], expected["next"]) - self.assertEqual(response.data["previous"], expected["previous"]) - self.assertEqual(response.data["results"], expected["results"]) - self.assertEqual(response.status_code, status.HTTP_200_OK) - def test_get_leaderboard_with_baseline_entry(self): - self.url = reverse_lazy( - "jobs:leaderboard", - kwargs={"challenge_phase_split_id": self.challenge_phase_split.id}, - ) - self.maxDiff = None - self.host_participant_team_submission.is_baseline = True - self.host_participant_team_submission.save() - - expected = { - "count": 2, - "next": None, - "previous": None, - "results": [ - { - "id": self.host_participant_leaderboard_data.id, - "submission__participant_team": self.host_participant_team_submission.participant_team.id, - "submission__participant_team__team_name": self.host_participant_team_submission.participant_team.team_name, - "submission__participant_team__team_url": self.host_participant_team_submission.participant_team.team_url, - "challenge_phase_split": self.challenge_phase_split.id, - "result": self.expected_results_host_participant_team, - "filtering_score": self.filtering_score_host_participant_team, - "leaderboard__schema": { - "default_order_by": "score", - "labels": ["score", "test-score"], - }, - "error": None, - "filtering_error": 0, - "submission__submitted_at": self.host_participant_team_submission.submitted_at, - "submission__is_baseline": True, - "submission__method_name": self.host_participant_team_submission.method_name, - "submission__is_public": self.submission.is_public, - "submission__id": self.host_participant_team_submission.id, - "submission__submission_metadata": self.host_participant_team_submission.submission_metadata, - "submission__is_verified_by_host": False, - }, - { - "id": self.leaderboard_data.id, - "submission__participant_team": self.submission.participant_team.id, - "submission__participant_team__team_name": self.submission.participant_team.team_name, - "submission__participant_team__team_url": self.submission.participant_team.team_url, - "challenge_phase_split": self.challenge_phase_split.id, - "result": self.expected_results, - "filtering_score": self.filtering_score, - "leaderboard__schema": { - "default_order_by": "score", - "labels": ["score", "test-score"], - }, - "error": None, - "filtering_error": 0, - "submission__submitted_at": self.submission.submitted_at, - "submission__is_baseline": False, - "submission__method_name": self.submission.method_name, - "submission__is_public": self.submission.is_public, - "submission__id": self.submission.id, - "submission__submission_metadata": self.submission.submission_metadata, - "submission__is_verified_by_host": False, - }, - ], - } - expected = collections.OrderedDict(expected) response = self.client.get(self.url, {}) - # Teardown - self.host_participant_team_submission.is_baseline = False - self.host_participant_team_submission.save() - + self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["count"], expected["count"]) self.assertEqual(response.data["next"], expected["next"]) self.assertEqual(response.data["previous"], expected["previous"]) self.assertEqual(response.data["results"], expected["results"]) - self.assertEqual(response.status_code, status.HTTP_200_OK) def test_get_leaderboard_with_multiple_baseline_entries(self): self.url = reverse_lazy( - "jobs:leaderboard", - kwargs={"challenge_phase_split_id": self.challenge_phase_split.id}, + "jobs:leaderboard_by_slug", + kwargs={ + "challenge_pk": self.challenge.pk, + "phase_slug": self.challenge_phase.slug, + "split_codename": self.dataset_split.codename, + }, ) self.maxDiff = None self.host_participant_team_submission.is_baseline = True @@ -2104,8 +2075,12 @@ def test_get_leaderboard_with_multiple_baseline_entries(self): { "id": self.host_participant_leaderboard_data.id, "submission__participant_team": self.host_participant_team_submission.participant_team.id, - "submission__participant_team__team_name": self.host_participant_team_submission.participant_team.team_name, - "submission__participant_team__team_url": self.host_participant_team_submission.participant_team.team_url, + "submission__participant_team__team_name": ( + self.host_participant_team_submission.participant_team.team_name + ), + "submission__participant_team__team_url": ( + self.host_participant_team_submission.participant_team.team_url + ), "challenge_phase_split": self.challenge_phase_split.id, "result": self.expected_results_host_participant_team, "filtering_score": self.filtering_score_host_participant_team, @@ -2148,8 +2123,12 @@ def test_get_leaderboard_with_multiple_baseline_entries(self): { "id": self.host_participant_leaderboard_data_2.id, "submission__participant_team": self.host_participant_team_submission_2.participant_team.id, - "submission__participant_team__team_name": self.host_participant_team_submission_2.participant_team.team_name, - "submission__participant_team__team_url": self.host_participant_team_submission_2.participant_team.team_url, + "submission__participant_team__team_name": ( + self.host_participant_team_submission_2.participant_team.team_name + ), + "submission__participant_team__team_url": ( + self.host_participant_team_submission_2.participant_team.team_url + ), "challenge_phase_split": self.challenge_phase_split.id, "result": self.expected_results_host_participant_team_2, "filtering_score": self.filtering_score_host_participant_team_2, @@ -2185,16 +2164,16 @@ def test_get_leaderboard_with_multiple_baseline_entries(self): def test_get_leaderboard_with_invalid_challenge_phase_split_id(self): self.url = reverse_lazy( - "jobs:leaderboard", + "jobs:leaderboard_by_slug", kwargs={ - "challenge_phase_split_id": self.challenge_phase_split.id + 2 + "challenge_pk": self.challenge.pk, + "phase_slug": self.challenge_phase.slug, + "split_codename": "invalid-split-name", }, ) expected = { - "detail": "ChallengePhaseSplit {} does not exist".format( - self.challenge_phase_split.id + 2 - ) + "error": "Leaderboard for the given phase and split does not exist." } response = self.client.get(self.url, {}) @@ -2203,8 +2182,12 @@ def test_get_leaderboard_with_invalid_challenge_phase_split_id(self): def test_get_leaderboard_with_default_order_by_key_missing(self): self.url = reverse_lazy( - "jobs:leaderboard", - kwargs={"challenge_phase_split_id": self.challenge_phase_split.id}, + "jobs:leaderboard_by_slug", + kwargs={ + "challenge_pk": self.challenge.pk, + "phase_slug": self.challenge_phase.slug, + "split_codename": self.dataset_split.codename, + }, ) expected = { @@ -2223,9 +2206,11 @@ def test_get_leaderboard_for_host_submissions_on_private_challenge_phase( self, ): self.url = reverse_lazy( - "jobs:leaderboard", + "jobs:leaderboard_by_slug", kwargs={ - "challenge_phase_split_id": self.private_challenge_phase_split.id + "challenge_pk": self.challenge.pk, + "phase_slug": self.private_challenge_phase.slug, + "split_codename": self.dataset_split.codename, }, ) @@ -2270,9 +2255,11 @@ def test_get_leaderboard_for_host_submissions_on_private_challenge_phase( def test_get_private_leaderboard_when_user_is_participant(self): self.url = reverse_lazy( - "jobs:leaderboard", + "jobs:leaderboard_by_slug", kwargs={ - "challenge_phase_split_id": self.private_challenge_phase_split.id + "challenge_pk": self.challenge.pk, + "phase_slug": self.private_challenge_phase.slug, + "split_codename": self.dataset_split.codename, }, )