From feaf704d7a053c95ba02d79ce7d9c3e38c93af60 Mon Sep 17 00:00:00 2001 From: Jason Cameron Date: Thu, 4 Apr 2024 17:09:18 +0000 Subject: [PATCH] added partial last sub time that is impossible to debug with db data (will test at home) --- gameserver/api/routes.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gameserver/api/routes.py b/gameserver/api/routes.py index 11dd154..da3ad49 100644 --- a/gameserver/api/routes.py +++ b/gameserver/api/routes.py @@ -1,8 +1,8 @@ -from django.db.models import F +from django.db.models import F, OuterRef, Subquery from gameserver.models.cache import ContestScore -from gameserver.models.contest import ContestProblem +from gameserver.models.contest import ContestProblem, ContestSubmission from ninja import NinjaAPI, Schema -from typing import List +from typing import List, Any def unicode_safe(string): return string.encode("unicode_escape").decode() @@ -13,6 +13,7 @@ class CTFSchema(Schema): pos: int team: str score: int + lastAccept: Any class CTFTimeSchema(Schema): standings: List[CTFSchema] @@ -20,7 +21,10 @@ class CTFTimeSchema(Schema): @api.get("/ctftime", response=CTFTimeSchema) def add(request, contest_id: int): - standings = ContestScore.ranks(contest=contest_id).annotate(pos=F("rank"), score=F("points"), team=F("participation__team__name")) + last_sub_time = ContestSubmission.objects.filter( + participation=OuterRef("pk"), submission__is_correct=True + ).values("submission__date_created") + standings = ContestScore.ranks(contest=contest_id).annotate(pos=F("rank"), score=F("points"), team=F("participation__team__name"), lastAccept=Subquery(last_sub_time)) # .only("pos", "team", "score") task_names = ContestProblem.objects.filter(contest_id=contest_id).prefetch_related("problem__name").values_list("problem__name")