Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/apps/api/serializers/leaderboards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db.models import Sum, Q
from django.db.models import Sum, Q, F
from drf_writable_nested import WritableNestedModelSerializer
from rest_framework import serializers

Expand Down Expand Up @@ -102,7 +102,11 @@ def get_submissions(self, instance):
# asc == colname
primary_col = instance.columns.get(index=instance.primary_index)
# Order first by primary column. Then order by other columns after for tie breakers.
ordering = [f'{"-" if primary_col.sorting == "desc" else ""}primary_col']
ordering = [
F('primary_col').desc(nulls_last=True)
if primary_col.sorting == 'desc'
else F('primary_col').asc(nulls_last=True)
]
submissions = (
Submission.objects.filter(
leaderboard=instance,
Expand All @@ -114,7 +118,11 @@ def get_submissions(self, instance):
)
for column in instance.columns.exclude(id=primary_col.id).order_by('index'):
col_name = f'col{column.index}'
ordering.append(f'{"-" if column.sorting == "desc" else ""}{col_name}')
ordering.append(
F(col_name).desc(nulls_last=True)
if column.sorting == 'desc'
else F(col_name).asc(nulls_last=True)
)
kwargs = {
col_name: Sum('scores__score', filter=Q(scores__column__index=column.index))
}
Expand Down Expand Up @@ -157,7 +165,11 @@ def get_submissions(self, instance):
# desc == -colname
# asc == colname
primary_col = instance.leaderboard.columns.get(index=instance.leaderboard.primary_index)
ordering = [f'{"-" if primary_col.sorting == "desc" else ""}primary_col']
ordering = [
F('primary_col').desc(nulls_last=True)
if primary_col.sorting == 'desc'
else F('primary_col').asc(nulls_last=True)
]
submissions = (
Submission.objects.filter(
phase=instance,
Expand All @@ -177,7 +189,11 @@ def get_submissions(self, instance):
.order_by('index')
):
col_name = f'col{column.index}'
ordering.append(f'{"-" if column.sorting == "desc" else ""}{col_name}')
ordering.append(
F(col_name).desc(nulls_last=True)
if column.sorting == 'desc'
else F(col_name).asc(nulls_last=True)
)
kwargs = {
col_name: Sum('scores__score', filter=Q(scores__column__index=column.index))
}
Expand Down
18 changes: 16 additions & 2 deletions src/static/riot/competitions/detail/leaderboards.tag
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
{ pretty_date(submission.created_when) }
</td>
<td>{submission.id}</td>
<td each="{ column in filtered_columns }">
<td each="{ column in filtered_columns }"
data-sort="{ get_score_sort_value(column, submission) }"
data-sort-value="{ get_score_sort_value(column, submission) }">
<a if="{column.title == 'Detailed Results'}" href="detailed_results/{get_detailed_result_submisison_id(column, submission)}" target="_blank" class="eye-icon-link">
<i class="icon grey eye eye-icon"></i>
</a>
Expand Down Expand Up @@ -227,6 +229,18 @@
return dt.isValid ? dt.toMillis() : 0
}

self.get_score_sort_value = function(column, submission) {
if (column.task_id === -1) {
let value = _.get(submission, 'fact_sheet_answers[' + column.key + ']')
return (value !== null && typeof value !== 'undefined' && value !== '') ? value : ''
}
let score = _.get(_.find(submission.scores, {
task_id: column.task_id,
column_key: column.key
}), 'score')
return (score !== null && typeof score !== 'undefined' && score !== '') ? score : ''
}

self.bold_class = function(column, submission){
return_class = ''
if(column.task_id != -1){
Expand All @@ -245,7 +259,7 @@
return _.get(submission, 'fact_sheet_answers[' + column.key + ']', 'n/a')
} else {
let score = _.get(_.find(submission.scores, {'task_id': column.task_id, 'column_key': column.key}), 'score')
if (score) {
if (score !== null && typeof score !== 'undefined' && score !== '') {
return score
}
}
Expand Down