Skip to content

Commit

Permalink
Merge pull request #302 from ZdruzenieSTROM/freeze
Browse files Browse the repository at this point in the history
Freeze
  • Loading branch information
mmihalik authored Dec 9, 2023
2 parents 508b39a + 117fb93 commit 715d44e
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 78 deletions.
13 changes: 9 additions & 4 deletions competition/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ class SeriesAdmin(admin.ModelAdmin):

list_filter = (
'semester__competition',
'complete',
)

@staticmethod
def active(obj):
def complete(obj: Series):
return obj.complete
complete.boolean = True
complete.admin_order_field = 'complete'

@staticmethod
def active(obj: Series):
return not obj.is_past_deadline
active.boolean = True

@staticmethod
def competition(obj):
def competition(obj: Series):
return obj.semester.competition
active.admin_order_field = 'semester__competition'
competition.admin_order_field = 'semester__competition'


@admin.register(Event)
Expand Down
3 changes: 3 additions & 0 deletions competition/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

class FreezingNotClosedResults(Exception):
"""Snažíš sa zamraziť výsledky série, ktorá nemá opravené všetky riešenia"""
42 changes: 14 additions & 28 deletions competition/fixtures/semesters.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"fields": {
"semester": 0,
"order": 1,
"deadline": "2099-01-01T20:00:00+02:00",
"complete": false
"deadline": "2099-01-01T20:00:00+02:00"
}
},
{
Expand All @@ -35,8 +34,7 @@
"fields": {
"semester": 0,
"order": 2,
"deadline": "2099-01-01T20:00:00+02:00",
"complete": false
"deadline": "2099-01-01T20:00:00+02:00"
}
},
{
Expand Down Expand Up @@ -195,8 +193,7 @@
"fields": {
"semester": 1,
"order": 1,
"deadline": "2019-10-28T00:00:00+02:00",
"complete": false
"deadline": "2019-10-28T00:00:00+02:00"
}
},
{
Expand All @@ -205,8 +202,7 @@
"fields": {
"semester": 1,
"order": 2,
"deadline": "2019-12-02T00:00:00+02:00",
"complete": false
"deadline": "2019-12-02T00:00:00+02:00"
}
},
{
Expand Down Expand Up @@ -343,8 +339,7 @@
"fields": {
"semester": 2,
"order": 1,
"deadline": "2019-03-18T00:00:00+02:00",
"complete": false
"deadline": "2019-03-18T00:00:00+02:00"
}
},
{
Expand All @@ -353,8 +348,7 @@
"fields": {
"semester": 2,
"order": 2,
"deadline": "2019-04-24T00:00:00+02:00",
"complete": false
"deadline": "2019-04-24T00:00:00+02:00"
}
},
{
Expand Down Expand Up @@ -490,8 +484,7 @@
"fields": {
"semester": 3,
"order": 1,
"deadline": "2018-10-29T00:00:00+02:00",
"complete": false
"deadline": "2018-10-29T00:00:00+02:00"
}
},
{
Expand All @@ -500,8 +493,7 @@
"fields": {
"semester": 3,
"order": 2,
"deadline": "2018-12-03T00:00:00+02:00",
"complete": false
"deadline": "2018-12-03T00:00:00+02:00"
}
},
{
Expand Down Expand Up @@ -637,8 +629,7 @@
"fields": {
"semester": 4,
"order": 1,
"deadline": "2018-03-19T00:00:00+02:00",
"complete": false
"deadline": "2018-03-19T00:00:00+02:00"
}
},
{
Expand All @@ -647,8 +638,7 @@
"fields": {
"semester": 4,
"order": 2,
"deadline": "2018-05-07T00:00:00+02:00",
"complete": false
"deadline": "2018-05-07T00:00:00+02:00"
}
},
{
Expand Down Expand Up @@ -784,8 +774,7 @@
"fields": {
"semester": 5,
"order": 1,
"deadline": "2017-10-23T00:00:00+02:00",
"complete": false
"deadline": "2017-10-23T00:00:00+02:00"
}
},
{
Expand All @@ -794,8 +783,7 @@
"fields": {
"semester": 5,
"order": 2,
"deadline": "2017-11-20T00:00:00+02:00",
"complete": false
"deadline": "2017-11-20T00:00:00+02:00"
}
},
{
Expand Down Expand Up @@ -931,8 +919,7 @@
"fields": {
"semester": 10,
"order": 1,
"deadline": "2020-03-01T20:00:00+02:00",
"complete": false
"deadline": "2020-03-01T20:00:00+02:00"
}
},
{
Expand All @@ -941,8 +928,7 @@
"fields": {
"semester": 10,
"order": 2,
"deadline": "2020-06-01T20:00:00+02:00",
"complete": false
"deadline": "2020-06-01T20:00:00+02:00"
}
}
]
44 changes: 31 additions & 13 deletions competition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from base.models import RestrictedFileField
from base.validators import school_year_validator
from competition import utils
from competition.exceptions import FreezingNotClosedResults
from competition.querysets import ActiveQuerySet
from personal.models import Profile, School
from user.models import User
Expand Down Expand Up @@ -215,21 +216,23 @@ def save(self, *args, **kwargs) -> None:
self.frozen_results = None
return super().save(*args, **kwargs)

def get_first_series(self):
def get_first_series(self) -> 'Series':
return self.series_set.get(order=1)

def get_second_series(self):
def get_second_series(self) -> 'Series':
return self.series_set.get(order=2)

def freeze_results(self, results):
if any(not series.complete for series in self.series_set.all()):
raise FreezingNotClosedResults()
self.frozen_results = results

@property
def is_active(self):
def is_active(self) -> bool:
return self.series_set.filter(complete=False).exists()

@property
def is_at_least_one_series_open(self):
def is_at_least_one_series_open(self) -> bool:
return self.series_set.filter(can_submit=True).exists()

def __str__(self):
Expand All @@ -250,8 +253,6 @@ class Meta:
order = models.PositiveSmallIntegerField(verbose_name='poradie série')

deadline = models.DateTimeField(verbose_name='termín série')
complete = models.BooleanField(
verbose_name='séria uzavretá', help_text='Séria má finálne poradie a už sa nebude meniť')

# Implementuje bonfikáciu
sum_method = models.CharField(
Expand All @@ -271,11 +272,11 @@ def __str__(self):
return f'{self.semester} - {self.order}. séria'

@property
def is_past_deadline(self):
def is_past_deadline(self) -> bool:
return now() > self.deadline

@property
def time_to_deadline(self):
def time_to_deadline(self) -> datetime.timedelta:
remaining_time = self.deadline - now()

if remaining_time.total_seconds() < 0:
Expand All @@ -284,7 +285,7 @@ def time_to_deadline(self):
return remaining_time

@property
def can_submit(self):
def can_submit(self) -> bool:
"""
Vráti True, ak užívateľ ešte môže odovzdať úlohu.
Pozerá sa na maximálne možné omeškanie v LateFlagoch.
Expand All @@ -296,12 +297,16 @@ def can_submit(self):
return now() < self.deadline + max_late_tag_value

@property
def can_resubmit(self):
def can_resubmit(self) -> bool:
late_flag = self.get_actual_late_flag()
if late_flag:
return late_flag.can_resubmit
return False

@property
def complete(self) -> bool:
return self.frozen_results is not None

def get_actual_late_flag(self) -> Optional[LateTag]:
"""
Vráti late flag, ktorý má byť v tomto okamihu priradený riešeniu,
Expand All @@ -316,16 +321,21 @@ def get_actual_late_flag(self) -> Optional[LateTag]:
.first()

def freeze_results(self, results):
if any(
problem.num_solutions != problem.num_corrected_solutions
for problem in self.problems.all()
):
raise FreezingNotClosedResults()
self.frozen_results = results

@property
def num_problems(self):
def num_problems(self) -> int:
return self.problems.count()

def can_user_modify(self, user):
def can_user_modify(self, user: User) -> bool:
return self.semester.can_user_modify(user)

def can_user_participate(self, user):
def can_user_participate(self, user: User) -> bool:
return self.semester.can_user_participate(user)


Expand Down Expand Up @@ -374,6 +384,14 @@ def get_stats(self):
total_solutions if total_solutions else '?'
return stats

@property
def num_solutions(self):
return self.solution_set.count()

@property
def num_corrected_solutions(self):
return self.solution_set.filter(score__isnull=False).count()

def can_user_modify(self, user):
return self.series.can_user_modify(user)

Expand Down
Loading

0 comments on commit 715d44e

Please sign in to comment.