Skip to content

Commit

Permalink
api: add submission filtering by contest + contest info
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Jun 2, 2024
1 parent 5946470 commit d6a3ff3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion judge/views/api/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def get_object(self, key):
return Problem.objects.get(code=key)


class ContestSimpleFilter(BaseSimpleFilter):
def get_object(self, key):
return Contest.objects.get(key=key)


class BaseListFilter:
def to_filter(self, key_list):
raise NotImplementedError()
Expand Down Expand Up @@ -566,6 +571,7 @@ class APISubmissionList(APIListView):
basic_filters = (
('user', ProfileSimpleFilter('user')),
('problem', ProblemSimpleFilter('problem')),
('contest', ContestSimpleFilter('contest_object')),
)
list_filters = (
('id', 'id'),
Expand All @@ -590,7 +596,7 @@ def get_unfiltered_queryset(self):
)
return (
queryset
.select_related('problem', 'user__user', 'language')
.select_related('problem', 'contest', 'contest__participation', 'contest_object', 'user__user', 'language')
.order_by('id')
.only(
'id',
Expand All @@ -602,6 +608,10 @@ def get_unfiltered_queryset(self):
'memory',
'points',
'result',
'contest_object__key',
'contest__points',
'contest__participation__virtual',
'contest__participation__real_start',
)
)

Expand All @@ -616,6 +626,12 @@ def get_object_data(self, submission):
'memory': submission.memory,
'points': submission.points,
'result': submission.result,
'contest': None if not submission.contest_object else {
'key': submission.contest_object.key,
'points': submission.contest.points,
'virtual_participation_number': submission.contest.participation.virtual,
'time_since_start_of_participation': submission.date - submission.contest.participation.real_start,
},
}


Expand Down

0 comments on commit d6a3ff3

Please sign in to comment.