diff --git a/oioioi/programs/controllers.py b/oioioi/programs/controllers.py index c6911504f..78638bd19 100644 --- a/oioioi/programs/controllers.py +++ b/oioioi/programs/controllers.py @@ -753,6 +753,11 @@ def render_report(self, request, report): signals_to_explain.add(signal) except ValueError: pass + if test.result_percentage_numerator and test.result_percentage_denominator: + test.result_percentage = f"""{round( + test.result_percentage_numerator / test.result_percentage_denominator, + 2 + ):g}""" tests_records = [ {'display_type': get_report_display_type(request, test), 'test': test} diff --git a/oioioi/programs/handlers.py b/oioioi/programs/handlers.py index 8dbf6f783..e8e26a4b6 100755 --- a/oioioi/programs/handlers.py +++ b/oioioi/programs/handlers.py @@ -1,6 +1,7 @@ import functools import logging from collections import defaultdict +from fractions import Fraction from django.conf import settings from django.db import transaction @@ -555,6 +556,10 @@ def make_report(env, kind='NORMAL', save_scores=True, **kwargs): test_report.score = result['score'] if save_scores else None test_report.status = result['status'] test_report.time_used = result['time_used'] + percentage = Fraction(*result.get('result_percentage', (0, 1))) + if percentage != 100 and percentage != 0: + test_report.result_percentage_numerator = percentage.numerator + test_report.result_percentage_denominator = percentage.denominator comment = result.get('result_string', '') if comment.lower() in ['ok', 'time limit exceeded']: # Annoying diff --git a/oioioi/programs/migrations/0020_testreport_result_percentage_denominator_and_more.py b/oioioi/programs/migrations/0020_testreport_result_percentage_denominator_and_more.py new file mode 100644 index 000000000..ce217f7c6 --- /dev/null +++ b/oioioi/programs/migrations/0020_testreport_result_percentage_denominator_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2024-05-05 14:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('programs', '0019_add_limits_override'), + ] + + operations = [ + migrations.AddField( + model_name='testreport', + name='result_percentage_denominator', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AddField( + model_name='testreport', + name='result_percentage_numerator', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/oioioi/programs/models.py b/oioioi/programs/models.py index b7bddb62f..2529f67ea 100644 --- a/oioioi/programs/models.py +++ b/oioioi/programs/models.py @@ -326,6 +326,8 @@ class TestReport(models.Model): max_score = ScoreField(null=True, blank=True) time_used = models.IntegerField(blank=True) output_file = FileField(upload_to=make_output_filename, null=True, blank=True) + result_percentage_numerator = models.IntegerField(null=True, blank=True) + result_percentage_denominator = models.IntegerField(null=True, blank=True) test = models.ForeignKey(Test, blank=True, null=True, on_delete=models.SET_NULL) test_name = models.CharField(max_length=30) diff --git a/oioioi/programs/templates/programs/report-comments.html b/oioioi/programs/templates/programs/report-comments.html index ee956f2e5..b53367514 100644 --- a/oioioi/programs/templates/programs/report-comments.html +++ b/oioioi/programs/templates/programs/report-comments.html @@ -8,7 +8,7 @@ {% for group in groups %} {% for record in group.tests %} {% with test=record.test %} - {% if test.comment and allow_test_comments or test.get_status_display != 'OK' and allow_download_out and test.test %} + {% if test.comment or test.result_percentage and allow_test_comments or test.get_status_display != 'OK' and allow_download_out and test.test %}
  • {{ test.test_name }} {% if allow_download_out and test.test %} @@ -27,7 +27,22 @@ {% endif %} {% endif %} {% if allow_test_comments %} - {{ test.comment }} + + {% if test.comment %} + {% if test.result_percentage %} + {% blocktranslate with test.result_percentage as percentage %} + Granted {{ percentage }}% points, comment: + {% endblocktranslate %} + {% endif %} + {{ test.comment }} + {% else %} + {% if test.result_percentage %} + {% blocktranslate with test.result_percentage as percentage %} + Granted {{ percentage }}% points. + {% endblocktranslate %} + {% endif %} + {% endif %} + {% endif %}
  • {% endif %}