diff --git a/src/apps/api/serializers/submissions.py b/src/apps/api/serializers/submissions.py index a8d8ed071..db4b91e91 100644 --- a/src/apps/api/serializers/submissions.py +++ b/src/apps/api/serializers/submissions.py @@ -98,7 +98,8 @@ class Meta: 'scores', 'display_name', 'slug_url', - 'organization' + 'organization', + 'detailed_result' ) extra_kwargs = { "scores": {"read_only": True}, diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index d27a3fe5e..3a2b9c897 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -517,6 +517,7 @@ def get_leaderboard(self, request, pk): } columns = [col for col in query['columns']] submissions_keys = {} + submission_detailed_results = {} for submission in query['submissions']: # count number of entries/number of submissions for the owner of this submission for this phase @@ -529,12 +530,24 @@ def get_leaderboard(self, request, pk): .strftime('%Y-%m-%d') submission_key = f"{submission['owner']}{submission['parent'] or submission['id']}" + + # gather detailed result from submissions for each task + # detailed_results are gathered based on submission key + # `id` is used to fetch the right detailed result in detailed results page + # `detailed_result` url is not needed + submission_detailed_results.setdefault(submission_key, []).append({ + # 'detailed_result': submission['detailed_result'], + 'task': submission['task'], + 'id': submission['id'] + }) + if submission_key not in submissions_keys: submissions_keys[submission_key] = len(response['submissions']) response['submissions'].append({ 'id': submission['id'], 'owner': submission['display_name'] or submission['owner'], 'scores': [], + 'detailed_results': [], 'fact_sheet_answers': submission['fact_sheet_answers'], 'slug_url': submission['slug_url'], 'organization': submission['organization'], @@ -559,6 +572,11 @@ def get_leaderboard(self, request, pk): tempScore['score'] = str(round(float(tempScore["score"]), precision)) 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 tempTask = { diff --git a/src/static/riot/competitions/detail/leaderboards.tag b/src/static/riot/competitions/detail/leaderboards.tag index d289060ef..8ac68917a 100644 --- a/src/static/riot/competitions/detail/leaderboards.tag +++ b/src/static/riot/competitions/detail/leaderboards.tag @@ -30,7 +30,6 @@ Task: { task.name } - # @@ -38,7 +37,7 @@ Entries Date of last entry {column.title} - Detailed Results + @@ -60,8 +59,12 @@ {submission.num_entries} {submission.last_entry_date} { submission.organization.name } - { get_score(column, submission) } - Show detailed results + + Show detailed results + {get_score(column, submission)} + + + @@ -101,6 +104,7 @@ 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){ @@ -143,10 +147,20 @@ self.selected_leaderboard.tasks.unshift(fake_metadata_task) } for(task of self.selected_leaderboard.tasks){ + for(column of task.columns){ column.task_id = task.id self.columns.push(column) } + // -1 id is used for fact sheet answers + if(self.enable_detailed_results & task.id != -1){ + self.columns.push({ + task_id: task.id, + title: "Detailed Results" + }) + task.colWidth += 1 + } + console.log(task) } self.filter_columns() $('#leaderboardTable').tablesort() @@ -154,6 +168,15 @@ }) } + self.get_detailed_result_submisison_id = function(column, submisison){ + for (index in submisison.detailed_results) { + if(column.task_id == submisison.detailed_results[index].task){ + return submisison.detailed_results[index].id + } + } + } + + CODALAB.events.on('phase_selected', data => { self.phase_id = data.id self.update_leaderboard()