Skip to content

Commit

Permalink
annotate matches
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo1291 authored and n8kim1 committed Jan 25, 2023
1 parent e359c10 commit d7851f5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions backend/siarnaq/api/teams/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,13 @@ def avatar(self, request, pk=None, *, episode_id):
def record(self, request, pk=None, *, episode_id):
"""Retrieve the win/loss record of a team"""
team = request.data["id"]
matches = Match.objects.filter(participants__team=team)
matches = Match.objects.filter(participants__team=team, status="OK!")

matches.annotate(
matches = matches.annotate(
score_1=Max("participants__score", filter=Q(participants__team=team)),
score_2=Max("participants__score", filter=~Q(participants__team=team)),
score_2=Max("participants__score", exclude=Q(participants__team=team)),
)

win_count = matches.filter(score_1__gt=F("score_2")).count()

loss_count = matches.filter(score_1__lt=F("score_2")).count()

return Response({"wins": win_count, "losses": loss_count})

0 comments on commit d7851f5

Please sign in to comment.