Skip to content

Commit

Permalink
(SIO-2329) Fixed task archive server error for some users
Browse files Browse the repository at this point in the history
Submissions with non-integer results are now treated separately.
Having only one of the pair (score, max_score) be an integer contradicts
the internal logic and such results will be ignored by the task archive.
Additionally, problem names and labels are now organised in two columns
for better clarity.

Change-Id: I837368cba7ffeb3e42a70b0a603367ccbb50b5e3
  • Loading branch information
jbhayven committed Mar 17, 2020
1 parent 2fed728 commit a1438ce
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 52 deletions.
41 changes: 24 additions & 17 deletions oioioi/problems/templates/problems/task-archive-problemgroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@
{% endif %}
{% endfor %}
{% else %}
{% for problem, result in problems.problem_info %}
<p>
<a href="{% url 'problem_site' site_key=problem.problemsite.url_key %}">
{{ problem }}
</a>
{% if result.exists %}
{% if result.score == result.max_score %}
<a class="label label-success" href="{{ result.submission_url }}"> {{ result.score }}</a>
{% elif result.score > 0 %}
<a class="label label-warning" href="{{ result.submission_url }}"> {{ result.score }}</a>
{% else %}
<a class="label label-danger" href="{{ result.submission_url }}"> {{ result.score }}</a>
{% endif %}
{% endif %}

</p>
{% endfor %}
<table class="table table-condensed table--auto-width table--borderless">
<tbody>
{% for problem, result in problems.problem_info %}
<tr>
<td>
<a href="{% url 'problem_site' site_key=problem.problemsite.url_key %}">
{{ problem }}
</a>
</td>
<td>
{% if result.exists %}
{% if result.score == result.max_score %}
<a class="label label-success" href="{{ result.submission_url }}"> {{ result.score }}</a>
{% elif result.score > 0 %}
<a class="label label-warning" href="{{ result.submission_url }}"> {{ result.score }}</a>
{% else %}
<a class="label label-danger" href="{{ result.submission_url }}"> {{ result.score }}</a>
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}

{% if value or id == "problemgroups" %}
Expand Down
32 changes: 31 additions & 1 deletion oioioi/problems/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
from oioioi.base.utils.test_migrations import TestCaseMigrations
from oioioi.contests.current_contest import ContestMode
from oioioi.contests.handlers import update_problem_statistics
from oioioi.contests.models import Contest, ProblemInstance, Round, Submission
from oioioi.contests.models import Contest, ProblemInstance, Round, ScoreReport, \
Submission, SubmissionReport, UserResultForProblem
from oioioi.contests.scores import IntegerScore
from oioioi.filetracker.tests import TestStreamingMixin
from oioioi.problems.controllers import ProblemController
from oioioi.problems.management.commands import recalculate_statistics
Expand Down Expand Up @@ -2216,6 +2218,7 @@ def test_task_archive_progress_labels(self):
url = reverse('task_archive_tag', args=('oi',))

self.assertTrue(self.client.login(username='test_user'))

response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)

Expand Down Expand Up @@ -2249,3 +2252,30 @@ def test_task_archive_progress_labels(self):
self.assertTrue(pos != -1)
pos = html.find('label-success')
self.assertTrue(pos == -1)

def test_can_access_with_result(score, max_score):
user = User.objects.get(username='test_user2')
problem_instance = ProblemInstance.objects.get(pk=4)
submission = Submission.objects.create(problem_instance=problem_instance, \
score=score, user=user)
submission_report = SubmissionReport.objects.create(kind='NORMAL', \
submission=submission)
score_report = ScoreReport.objects.create(score=score, status="OK", \
max_score=max_score, submission_report=submission_report)
user_result = UserResultForProblem.objects.create(score=score, status='OK', \
user=user, submission_report=submission_report, problem_instance=problem_instance)

response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)

user_result.delete()
score_report.delete()
submission_report.delete()
submission.delete()

# we assume that if a max_score exists it never equals zero
# test_can_access_with_result(IntegerScore(0), IntegerScore(0))
test_can_access_with_result(None, None)
test_can_access_with_result(IntegerScore(50), IntegerScore(100))
test_can_access_with_result(None, IntegerScore(100))
test_can_access_with_result(IntegerScore(50), None)
85 changes: 51 additions & 34 deletions oioioi/problems/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,30 +552,6 @@ def _recursive_group_problems(problems, result_info, categories, div_id):

return node


def _filter_problems_prefetched(problems, filter_multivaluedict):
result = []

for problem in problems:
remaining_filters = set(filter_multivaluedict.keys())

for infovalue in problem.origininfovalue_set.all():
category = infovalue.category
value = infovalue.value

# Check if this info-value combo violates any filters
if category.name in remaining_filters:
remaining_filters.remove(category.name)
allowed_values = filter_multivaluedict.getlist(category.name)
if value not in allowed_values:
break
else:
# If filtering info=value don't include problems with no value
if not remaining_filters:
result.append(problem)

return result

def _get_results_info(request, problems):
if request.user.is_authenticated == False:
return {problem: {'exists': False} for problem in problems}
Expand Down Expand Up @@ -605,20 +581,61 @@ def _get_results_info(request, problems):
if result is None:
results_info[problem] = {'exists': False}
else:
results_info[problem] = {
'exists': True,
'score': result.score.to_int(),
'max_score': result.submission_report.score_report.max_score.to_int(),
'submission_url':
reverse('submission',
kwargs={'submission_id':
result.submission_report.submission.id}
)
}
try:
score = result.score
max_score = result.submission_report.score_report.max_score

def result_info(_int_score, _int_max_score):
return {'exists': True,
'score': _int_score,
'max_score': _int_max_score,
'submission_url':
reverse('submission',
kwargs={'submission_id':
result.submission_report.submission.id}
)
}

if score is None and max_score is None:
if result.status is None or result.status == '?' \
or result.status == 'INI_OK' or result.status == 'INI_ERR':
results_info[problem] = {'exists': False}
elif result.status == 'OK':
results_info[problem] = result_info(1, 1)
else:
results_info[problem] = result_info(0, 1)
else:
results_info[problem] = result_info(score.to_int(), max_score.to_int())

except AttributeError:
results_info[problem] = {'exists': False}

return results_info


def _filter_problems_prefetched(problems, filter_multivaluedict):
result = []

for problem in problems:
remaining_filters = set(filter_multivaluedict.keys())

for infovalue in problem.origininfovalue_set.all():
category = infovalue.category
value = infovalue.value

# Check if this info-value combo violates any filters
if category.name in remaining_filters:
remaining_filters.remove(category.name)
allowed_values = filter_multivaluedict.getlist(category.name)
if value not in allowed_values:
break
else:
# If filtering info=value don't include problems with no value
if not remaining_filters:
result.append(problem)

return result

def task_archive_tag_view(request, origin_tag):
origin_tag = OriginTag.objects.filter(name=origin_tag) \
.prefetch_related('localizations',
Expand Down

0 comments on commit a1438ce

Please sign in to comment.