Skip to content

Commit

Permalink
Refactor codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Ram81 committed Aug 7, 2021
1 parent 8764a42 commit d8f271c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Generated by Django 2.2.13 on 2021-06-20 14:33
# Generated by Django 2.2.20 on 2021-08-07 14:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("challenges", "0084_challenge_is_static_dataset_code_upload"),
("challenges", "0085_challenge_submission_time_limit"),
]

operations = [
migrations.AddField(
model_name="challenge",
model_name="challengephasesplit",
name="is_multi_metric_leaderboard",
field=models.BooleanField(default=False),
field=models.BooleanField(default=True),
),
]
4 changes: 2 additions & 2 deletions apps/challenges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def __init__(self, *args, **kwargs):
desired_worker_instance = models.IntegerField(
null=True, blank=True, default=1
)
# Allow ordering leaderboard by all metrics
is_multi_metric_leaderboard = models.BooleanField(default=False)

class Meta:
app_label = "challenges"
Expand Down Expand Up @@ -404,6 +402,8 @@ class ChallengePhaseSplit(TimeStampedModel):
is_leaderboard_order_descending = models.BooleanField(default=True)
show_leaderboard_by_latest_submission = models.BooleanField(default=False)
show_execution_time = models.BooleanField(default=False)
# Allow ordering leaderboard by all metrics
is_multi_metric_leaderboard = models.BooleanField(default=True)

def __str__(self):
return "{0} : {1}".format(
Expand Down
3 changes: 1 addition & 2 deletions apps/challenges/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ class Meta:
"show_leaderboard_by_latest_submission",
"show_execution_time",
"leaderboard_schema",
"is_multi_metric_leaderboard",
)

def get_leaderboard_schema(self, obj):
print(obj.leaderboard.schema)
return obj.leaderboard.schema

def get_dataset_split_name(self, obj):
Expand Down Expand Up @@ -268,7 +268,6 @@ class Meta:
"max_worker_instance",
"min_worker_instance",
"desired_worker_instance",
"is_multi_metric_leaderboard",
)


Expand Down
1 change: 0 additions & 1 deletion apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,6 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk):
challenge_phase_data[
field
] = challenge_phase_data_from_hosts.get(field)

try:
with transaction.atomic():
serializer = ZipChallengeSerializer(
Expand Down
20 changes: 17 additions & 3 deletions apps/jobs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ def calculate_distinct_sorted_leaderboard_data(

# Get the default order by key to rank the entries on the leaderboard
default_order_by = None
is_leaderboard_order_descending = (
challenge_phase_split.is_leaderboard_order_descending
)
try:
default_order_by = leaderboard.schema["default_order_by"]
except KeyError:
Expand All @@ -271,6 +274,19 @@ def calculate_distinct_sorted_leaderboard_data(
}
return response_data, status.HTTP_400_BAD_REQUEST

leaderboard_schema = leaderboard.schema
if (
leaderboard_schema.get("metadata") is not None
and leaderboard_schema.get("metadata").get(default_order_by)
is not None
):
is_leaderboard_order_descending = (
leaderboard_schema["metadata"][default_order_by].get(
"sort_ascending"
)
is False
)

# Exclude the submissions done by members of the host team
# while populating leaderboard
challenge_hosts_emails = (
Expand Down Expand Up @@ -408,9 +424,7 @@ def calculate_distinct_sorted_leaderboard_data(
float(k["filtering_score"]),
float(-k["filtering_error"]),
),
reverse=True
if challenge_phase_split.is_leaderboard_order_descending
else False,
reverse=True if is_leaderboard_order_descending else False,
)
distinct_sorted_leaderboard_data = []
team_list = []
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/js/controllers/challengeCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
vm.projectUrl = "";
vm.publicationUrl = "";
vm.isPublicSubmission = null;
vm.isMultiMetricLeaderboardEnabled = false;
vm.isMultiMetricLeaderboardEnabled = {};
vm.wrnMsg = {};
vm.page = {};
vm.isParticipated = false;
Expand Down Expand Up @@ -316,7 +316,6 @@
vm.isRegistrationOpen = details.is_registration_open;
vm.approved_by_admin = details.approved_by_admin;
vm.isRemoteChallenge = details.remote_evaluation;
vm.isMultiMetricLeaderboardEnabled = details.is_multi_metric_leaderboard;
vm.getTeamName(vm.challengeId);

if (vm.page.image === null) {
Expand Down Expand Up @@ -833,6 +832,7 @@
vm.phaseSplits[i].showPrivate = true;
vm.showPrivateIds.push(vm.phaseSplits[i].id);
}
vm.isMultiMetricLeaderboardEnabled[vm.phaseSplits[i].id] = vm.phaseSplits[i].is_multi_metric_leaderboard;
vm.phaseSplitLeaderboardSchema[vm.phaseSplits[i].id] = vm.phaseSplits[i].leaderboard_schema;
}
utilities.hideLoader();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/web/challenge/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h5 class="w-300">Leaderboard</h5>
</span>
</div>
</div>
<div class="row" ng-if="challenge.isMultiMetricLeaderboardEnabled">
<div class="row" ng-if="challenge.isMultiMetricLeaderboardEnabled[challenge.phaseSplitId]">
<div class="col xs12 s6">
<span>
<md-select ng-model="challenge.orderLeaderboardBy" placeholder="Order by metric" class="rm-margin">
Expand Down

0 comments on commit d8f271c

Please sign in to comment.