mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 03:58:26 +02:00
Add tweaks to update notes
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament
|
||||
from .models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament, Tweak
|
||||
|
||||
|
||||
@admin.register(Team)
|
||||
@ -57,3 +57,8 @@ class SynthesisAdmin(admin.ModelAdmin):
|
||||
class TournamentAdmin(admin.ModelAdmin):
|
||||
list_display = ('name',)
|
||||
search_fields = ('name',)
|
||||
|
||||
|
||||
@admin.register(Tweak)
|
||||
class TweakAdmin(admin.ModelAdmin):
|
||||
list_display = ('participation', 'pool', 'diff',)
|
||||
|
27
apps/participation/migrations/0009_tweak.py
Normal file
27
apps/participation/migrations/0009_tweak.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Generated by Django 3.2.13 on 2022-05-15 14:40
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('participation', '0008_auto_20220429_1853'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Tweak',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('diff', models.IntegerField(help_text='Score to add/remove on the final score', verbose_name='difference')),
|
||||
('participation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tweaks', to='participation.participation', verbose_name='participation')),
|
||||
('pool', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='participation.pool', verbose_name='passage')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'tweak',
|
||||
'verbose_name_plural': 'tweaks',
|
||||
},
|
||||
),
|
||||
]
|
@ -380,7 +380,8 @@ class Pool(models.Model):
|
||||
return Solution.objects.filter(participation__in=self.participations, final_solution=self.tournament.final)
|
||||
|
||||
def average(self, participation):
|
||||
return sum(passage.average(participation) for passage in self.passages.all())
|
||||
return sum(passage.average(participation) for passage in self.passages.all()) \
|
||||
+ sum(tweak.diff for tweak in participation.tweaks.filter(pool=self).all())
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse_lazy("participation:pool_detail", args=(self.pk,))
|
||||
@ -514,6 +515,30 @@ class Passage(models.Model):
|
||||
verbose_name_plural = _("passages")
|
||||
|
||||
|
||||
class Tweak(models.Model):
|
||||
pool = models.ForeignKey(
|
||||
Pool,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("passage"),
|
||||
)
|
||||
|
||||
participation = models.ForeignKey(
|
||||
Participation,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_("participation"),
|
||||
related_name='tweaks',
|
||||
)
|
||||
|
||||
diff = models.IntegerField(
|
||||
verbose_name=_("difference"),
|
||||
help_text=_("Score to add/remove on the final score"),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("tweak")
|
||||
verbose_name_plural = _("tweaks")
|
||||
|
||||
|
||||
def get_solution_filename(instance, filename):
|
||||
return f"solutions/{instance.participation.team.trigram}_{instance.problem}" \
|
||||
+ ("final" if instance.final_solution else "")
|
||||
|
Reference in New Issue
Block a user