Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes in MPContestController #153

Merged
merged 17 commits into from
Dec 12, 2023
Merged
16 changes: 15 additions & 1 deletion oioioi/mp/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from oioioi.base.utils.query_helpers import Q_always_true
from oioioi.base.utils.redirect import safe_redirect
from oioioi.contests.models import Submission
from oioioi.contests.models import Submission, SubmissionReport
from oioioi.mp.models import MPRegistration, SubmissionScoreMultiplier
from oioioi.mp.score import FloatScore
from oioioi.participants.controllers import ParticipantsController
Expand Down Expand Up @@ -139,8 +139,20 @@ def update_user_result_for_problem(self, result):
):
best_submission = [submission, score]

try:
report = SubmissionReport.objects.get(
submission=best_submission[0], status='ACTIVE', kind='NORMAL'
)
except SubmissionReport.DoesNotExist:
report = None

result.score = best_submission[1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change typo of best_submission from tuple to normal variable and use following logic

  • best_submission (currently best submission)
  • add new variable best_submission_score (initially None, currently best score)
    This would make this part of the code much more readable.

result.status = best_submission[0].status
result.submission_report = report
else:
result.score = None
result.status = None
result.submission_report = None

def can_submit(self, request, problem_instance, check_round_times=True):
"""Contest admin can always submit.
Expand All @@ -155,6 +167,8 @@ def can_submit(self, request, problem_instance, check_round_times=True):
return True
if not is_participant(request):
return False
if problem_instance.round is None:
return False

rtimes = self.get_round_times(None, problem_instance.round)
round_over_contest_running = rtimes.is_past(
Expand Down
22 changes: 22 additions & 0 deletions oioioi/mp/fixtures/test_mp_contest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
"enable_editor": false
}
},
{
"model": "participants.participant",
"pk": 1,
"fields": {
"contest": "contest1",
"user": 2,
"status": "ACTIVE",
"anonymous": false
}
},
{
"model": "problems.problem",
"pk": 1,
Expand Down Expand Up @@ -105,6 +115,18 @@
"needs_rejudge": false
}
},
{
"model": "contests.probleminstance",
"pk": 5,
"fields": {
"contest": "contest1",
"round": null,
"problem": 1,
"short_name": "squ2",
"submissions_limit": 10,
"needs_rejudge": false
}
},
{
"model": "contests.submission",
"pk": 1,
Expand Down
17 changes: 17 additions & 0 deletions oioioi/mp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ def test_no_zero_scores_in_ranking(self):
self.assertFalse(re.search(b'<td[^>]*>Test User4', response.content))


class TestNoRoundProblem(TestCase):
fixtures = ['test_mp_users', 'test_mp_contest']

def test_no_round_problem(self):
self.assertTrue(self.client.login(username='test_user1'))
contest = Contest.objects.get()
url = reverse('submit', kwargs={'contest_id': contest.id})
with fake_time(datetime(2023, 1, 5, 12, 10, tzinfo=utc)):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertIn('form', response.context)
form = response.context['form']
# there are 3 problems, one of them doesn't have round
# +1 because of blank field
self.assertEqual(len(form.fields['problem_instance_id'].choices), 3)


class TestSubmissionScoreMultiplier(TestCase):
def _create_result(user, pi):
res = UserResultForProblem()
Expand Down