diff --git a/src/apps/api/serializers/leaderboards.py b/src/apps/api/serializers/leaderboards.py
index 74aede7f5..2ab509898 100644
--- a/src/apps/api/serializers/leaderboards.py
+++ b/src/apps/api/serializers/leaderboards.py
@@ -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)
@@ -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 = (
@@ -140,6 +144,7 @@ class Meta:
'tasks',
'leaderboard',
'columns',
+ 'primary_index',
)
depth = 1
diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py
index 4dc0e4b30..e4f0695c2 100644
--- a/src/apps/api/views/competitions.py
+++ b/src/apps/api/views/competitions.py
@@ -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 = {}
@@ -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
diff --git a/src/static/riot/competitions/detail/leaderboards.tag b/src/static/riot/competitions/detail/leaderboards.tag
index 7176cc213..6e27641c0 100644
--- a/src/static/riot/competitions/detail/leaderboards.tag
+++ b/src/static/riot/competitions/detail/leaderboards.tag
@@ -63,7 +63,7 @@
- {get_score(column, submission)}
+ {get_score(column, submission)}
@@ -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')
@@ -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){
@@ -162,7 +177,6 @@
})
task.colWidth += 1
}
- console.log(task)
}
self.filter_columns()
$('#leaderboardTable').tablesort()
@@ -220,5 +234,7 @@
top: 50%
left: 50%
transform: translate(-50%, -50%)
+ .text-bold
+ font-weight: bold