Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/apps/api/serializers/leaderboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class LeaderboardPhaseSerializer(serializers.ModelSerializer):
submissions = serializers.SerializerMethodField(read_only=True)
columns = serializers.SerializerMethodField()
tasks = PhaseTaskInstanceSerializer(source='task_instances', many=True)
primary_index = serializers.SerializerMethodField()

def get_columns(self, instance):
columns = Column.objects.filter(leaderboard=instance.leaderboard, hidden=False)
Expand All @@ -131,6 +132,9 @@ def get_columns(self, instance):
else:
return ColumnSerializer(columns, many=len(columns) >= 1).data

def get_primary_index(self, instance):
return instance.leaderboard.primary_index

class Meta:
model = Phase
fields = (
Expand All @@ -140,6 +144,7 @@ class Meta:
'tasks',
'leaderboard',
'columns',
'primary_index',
)
depth = 1

Expand Down
19 changes: 17 additions & 2 deletions src/apps/api/views/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def get_leaderboard(self, request, pk):
'submissions': [],
'tasks': [],
'fact_sheet_keys': fact_sheet_keys or None,
'primary_index': query['leaderboard']['primary_index']
}
columns = [col for col in query['columns']]
submissions_keys = {}
Expand Down Expand Up @@ -600,26 +601,40 @@ def get_leaderboard(self, request, pk):
})
for score in submission['scores']:

# to check if a column is found
# this is useful because of `hidden` field
# if a column is hidden it will not be shown here so
# we will not return that score to the front-end
column_found = False
# default precision is set to 2
precision = 2
# default hidden is set to false
hidden = False

# loop over columns to find a column with the same index
# replace default precision with column precision
for col in columns:
if col["index"] == score["index"]:
precision = col["precision"]
hidden = col["hidden"]
column_found = True
break

tempScore = score
tempScore['task_id'] = submission['task']
# round the score to 'precision' decimal points
tempScore['score'] = str(round(float(tempScore["score"]), precision))
response['submissions'][submissions_keys[submission_key]]['scores'].append(tempScore)

# only add scores to the scores list
# if this column is found
# and
# column is not hidden
if column_found and not hidden:
response['submissions'][submissions_keys[submission_key]]['scores'].append(tempScore)

# put detailed results in its submission
for k, v in submissions_keys.items():
response['submissions'][v]['detailed_results'] = submission_detailed_results[k]
print(f"\n{response['submissions']}\n")

for task in query['tasks']:
# This can be used to rendered variable columns on each task
Expand Down
22 changes: 19 additions & 3 deletions src/static/riot/competitions/detail/leaderboards.tag
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<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>
<span if="{column.title != 'Detailed Results'}">{get_score(column, submission)}</span>
<span if="{column.title != 'Detailed Results'}" class="{bold_class(column, submission)}">{get_score(column, submission)}</span>
</td>


Expand All @@ -81,6 +81,22 @@
self.competition_id = null
self.enable_detailed_results = false


self.bold_class = function(column, submission){
// Return `text-bold` if submission has
// more than one scores and score index == leaderbaord.primary_index
// otherwise return empty string
return_class = '' // default class value
if(column.task_id != -1){ // factsheet check
if(submission.scores.length > 1){ // score length check
let column_index = _.get(column, 'index')
if(column_index === self.selected_leaderboard.primary_index){ // column index check
return_class = 'text-bold'
}
}
}
return return_class
}
self.get_score = function(column, submission) {
if(column.task_id === -1){
return _.get(submission, 'fact_sheet_answers[' + column.key + ']', 'n/a')
Expand All @@ -106,7 +122,6 @@
self.filter_columns = () => {
let search_key = self.refs.leaderboardFilter.value.toLowerCase()
self.filtered_tasks = JSON.parse(JSON.stringify(self.selected_leaderboard.tasks))
console.log(self.filtered_tasks)
if(search_key){
self.filtered_columns = []
for (const column of self.columns){
Expand Down Expand Up @@ -162,7 +177,6 @@
})
task.colWidth += 1
}
console.log(task)
}
self.filter_columns()
$('#leaderboardTable').tablesort()
Expand Down Expand Up @@ -220,5 +234,7 @@
top: 50%
left: 50%
transform: translate(-50%, -50%)
.text-bold
font-weight: bold
</style>
</leaderboards>