Fix decimal points in contest total score

This commit is contained in:
cuom1999 2020-10-26 15:13:17 -05:00
parent 6d192cf54d
commit 26c277c612
4 changed files with 33 additions and 6 deletions

View file

@ -110,7 +110,7 @@ class ContestAdmin(VersionAdmin):
fieldsets = (
(None, {'fields': ('key', 'name', 'organizers')}),
(_('Settings'), {'fields': ('is_visible', 'use_clarifications', 'hide_problem_tags', 'hide_scoreboard',
'run_pretests_only')}),
'run_pretests_only', 'points_precision')}),
(_('Scheduling'), {'fields': ('start_time', 'end_time', 'time_limit')}),
(_('Details'), {'fields': ('description', 'og_image', 'logo_override_image', 'tags', 'summary')}),
(_('Format'), {'fields': ('format_name', 'format_config')}),

View file

@ -53,7 +53,7 @@ class DefaultContestFormat(BaseContestFormat):
self.best_solution_state(format_data['points'], contest_problem.points)),
url=reverse('contest_user_submissions',
args=[self.contest.key, participation.user.user.username, contest_problem.problem.code]),
points=floatformat(format_data['points']),
points=floatformat(format_data['points'], -self.contest.points_precision),
time=nice_repr(timedelta(seconds=format_data['time']), 'noday'),
)
else:
@ -62,7 +62,7 @@ class DefaultContestFormat(BaseContestFormat):
def display_participation_result(self, participation):
return format_html(
u'<td class="user-points">{points}<div class="solving-time">{cumtime}</div></td>',
points=floatformat(participation.score),
points=floatformat(participation.score, -self.contest.points_precision),
cumtime=nice_repr(timedelta(seconds=participation.cumtime), 'noday'),
)

View file

@ -0,0 +1,24 @@
# Generated by Django 2.2.12 on 2020-10-26 19:51
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('judge', '0110_notification_author'),
]
operations = [
migrations.AddField(
model_name='contest',
name='points_precision',
field=models.IntegerField(default=2, help_text='Number of digits to round points to.', validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(10)], verbose_name='precision points'),
),
migrations.AlterField(
model_name='contestparticipation',
name='score',
field=models.FloatField(db_index=True, default=0, verbose_name='score'),
),
]

View file

@ -1,5 +1,5 @@
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator, RegexValidator
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
from django.db import models, transaction
from django.db.models import CASCADE
from django.urls import reverse
@ -113,7 +113,10 @@ class Contest(models.Model):
help_text=_('A JSON object to serve as the configuration for the chosen contest format '
'module. Leave empty to use None. Exact format depends on the contest format '
'selected.'))
points_precision = models.IntegerField(verbose_name=_('precision points'), default=2,
validators=[MinValueValidator(0), MaxValueValidator(10)],
help_text=_('Number of digits to round points to.'))
@cached_property
def format_class(self):
return contest_format.formats[self.format_name]
@ -256,7 +259,7 @@ class ContestParticipation(models.Model):
contest = models.ForeignKey(Contest, verbose_name=_('associated contest'), related_name='users', on_delete=CASCADE)
user = models.ForeignKey(Profile, verbose_name=_('user'), related_name='contest_history', on_delete=CASCADE)
real_start = models.DateTimeField(verbose_name=_('start time'), default=timezone.now, db_column='start')
score = models.IntegerField(verbose_name=_('score'), default=0, db_index=True)
score = models.FloatField(verbose_name=_('score'), default=0, db_index=True)
cumtime = models.PositiveIntegerField(verbose_name=_('cumulative time'), default=0)
is_disqualified = models.BooleanField(verbose_name=_('is disqualified'), default=False,
help_text=_('Whether this participation is disqualified.'))