Skip to content

Commit

Permalink
actually useful changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Apr 5, 2024
1 parent 68fb5ff commit 82b1a5a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
31 changes: 17 additions & 14 deletions gameserver/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ def ctftime_standings(request, contest_name: str):
.order_by("-submission__date_created")
.values("submission__date_created")
)
standings = ContestScore.ranks(contest=contest_id).annotate(
pos=F("rank"),
score=F("points"),
team=F("participation__team__name"),
# team=Coalesce(F("participation__team__name"), F("participation__participants__username")),
# Using Coalesce and indexing
# team=Case(
# When(F("participation__team__isnull")==True, then=Q(("participation__participants")[0]["username"])),
# default=F("team_name"),
# output_field=TextField(),
# ),
lastAccept=Subquery(last_sub_time),
).values("pos", "score", "team", "lastAccept")
# .only("pos", "team", "score")
standings = (
ContestScore.ranks(contest=contest_id)
.annotate(
pos=F("rank"),
score=F("points"),
team=F("participation__team__name"),
# team=Coalesce(F("participation__team__name"), F("participation__participants__username")),
# Using Coalesce and indexing
# team=Case(
# When(F("participation__team__isnull")==True, then=Q(("participation__participants")[0]["username"])),
# default=F("team_name"),
# output_field=TextField(),
# ),
lastAccept=Subquery(last_sub_time),
)
.values("pos", "score", "team", "lastAccept")
)
task_names = (
ContestProblem.objects.filter(contest_id=contest_id)
.prefetch_related("problem__name")
Expand Down
4 changes: 2 additions & 2 deletions gameserver/forms/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ContestJoinForm(forms.Form):
)

def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user", None)
self.contest = kwargs.pop("contest", None)
self.user: models.User = kwargs.pop("user", None)
self.contest: models.Contest = kwargs.pop("contest", None)
super(ContestJoinForm, self).__init__(*args, **kwargs)

if (
Expand Down
2 changes: 1 addition & 1 deletion gameserver/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs):

organizers = models.ManyToManyField("User", related_name="contests_organized", blank=True)
curators = models.ManyToManyField("User", related_name="contests_curated", blank=True)
organizations = models.ManyToManyField("Organization", related_name="contests", blank=True)
organizations = models.ManyToManyField("Organization", related_name="contests", blank=True, help_text="Only users of these organizations can access the contest")

name = models.CharField(max_length=128)
slug = models.SlugField(unique=True, db_index=True)
Expand Down

0 comments on commit 82b1a5a

Please sign in to comment.