Skip to content

Commit

Permalink
Fixed rank being broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Mar 11, 2024
1 parent 5137217 commit 3a781e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 14 additions & 2 deletions gameserver/models/cache.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import TYPE_CHECKING, Self, Optional

from django.apps import apps
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.db import models, transaction
from django.db.models import Count, F, Sum, Window, Value, When, BooleanField, Case
from django.db.models import Count, F, Sum, Window, Value, When, BooleanField, Case, Q
from django.db.models.functions import Coalesce, Rank

if TYPE_CHECKING:
Expand Down Expand Up @@ -105,7 +107,17 @@ def contest(self):
@classmethod
def ranks(cls, contest: "Contest", queryset: Optional[models.QuerySet] = None, participation: Optional["ContestParticipation"] = None) -> models.QuerySet:
assert queryset is None or participation is None, "Only one of queryset or participation can be set"
query = cls.objects.filter(participation__contest=contest).prefetch_related("participation")
# contest_content_type = ContentType.objects.get_for_model(apps.get_model("gameserver", "Contest"))
# perm_edit_all_contests = Permission.objects.get(
# codename="edit_all_contests", content_type=contest_content_type
# )
query = cls.objects.filter(participation__contest=contest).prefetch_related("participation")#.exclude(
# Q(participants__is_superuser=True)
# | Q(participants__groups__permissions=perm_edit_all_contests)
# | Q(participants__user_permissions=perm_edit_all_contests)
# | Q(participants__in=contest.organizers.all())
# | Q(participants__in=contest.curators.all())
# )
data = query.annotate(is_solo=Case(
When(participation__team_id=None, then=Value(False)),
default=Value(True),
Expand Down
16 changes: 2 additions & 14 deletions gameserver/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,23 +300,11 @@ def time_taken(self) -> str:
return strfdelta(timedelta(seconds=round((solve_time - self.contest.start_time).total_seconds())))

def rank(self):
return self.contest.ranks().filter(
participation=self)

if isinstance(self.points, int):
points = self.points
else:
points = self.points()

return (
self.contest.ranks()
.annotate(num_participants=Count("participants"))
.filter(
Q(points__gt=points)
| Q(points=points, most_recent_solve_time__lt=self.last_solve_time)
self.contest.ranks().filter(
Q(points__gte=self.points())
)
.count()
+ 1
)

def has_attempted(self, problem):
Expand Down

0 comments on commit 3a781e0

Please sign in to comment.