-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add compete data to teaminfo #558
Open
apollo1291
wants to merge
9
commits into
main
Choose a base branch
from
compete-based-teamcard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−74
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cfb2dd9
add compete data to teaminfo
apollo1291 f260215
build endpoint for win record
apollo1291 746146d
create getTeamWinStats in api.js
apollo1291 549d17d
calculate win/loss record without loops
apollo1291 89098b5
annotate matches
apollo1291 48d62e2
Correctly calculate win/loss record
apollo1291 e9f6172
Prevent tournament matches from appearing in W/L record
apollo1291 d3c809a
Show Rating only, no Ranking
apollo1291 aac0a66
Move filtering to right part of query
n8kim1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,15 @@ | |
|
||
import structlog | ||
from django.db import transaction | ||
from django.db.models import F, OuterRef, Subquery | ||
from django.shortcuts import get_object_or_404 | ||
from drf_spectacular.utils import extend_schema | ||
from rest_framework import filters, mixins, status, viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
|
||
from siarnaq.api.compete.models import Match, MatchParticipant | ||
from siarnaq.api.episodes.permissions import IsEpisodeAvailable | ||
from siarnaq.api.teams.exceptions import TeamMaxSizeExceeded | ||
from siarnaq.api.teams.filters import TeamActiveSubmissionFilter, TeamOrderingFilter | ||
|
@@ -173,3 +175,33 @@ def avatar(self, request, pk=None, *, episode_id): | |
titan.upload_image(avatar, profile.get_avatar_path()) | ||
|
||
return Response(None, status=status.HTTP_204_NO_CONTENT) | ||
|
||
@action( | ||
detail=False, | ||
methods=["post"], | ||
serializer_class=None, | ||
permission_classes=(IsAuthenticated, IsEpisodeAvailable), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might suggest removing IsAuthenticated, to allow this to be viewable by the public |
||
) | ||
def record(self, request, pk=None, *, episode_id): | ||
n8kim1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Retrieve the win/loss record of a team""" | ||
team = request.data["id"] | ||
matches = Match.objects.filter(participants__team=team, status="OK!") | ||
n8kim1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
matches = Match.objects.annotate( | ||
my_score=Subquery( | ||
MatchParticipant.objects.filter(match=OuterRef("pk")) | ||
.filter(team=team) | ||
.values("score") | ||
), | ||
opponent_score=Subquery( | ||
MatchParticipant.objects.filter(match=OuterRef("pk")) | ||
.exclude(team=team) | ||
.values("score")[:1] | ||
), | ||
).filter( | ||
my_score__isnull=False, | ||
) | ||
apollo1291 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
win_count = matches.filter(my_score__gt=F("opponent_score")).count() | ||
loss_count = matches.filter(my_score__lt=F("opponent_score")).count() | ||
|
||
return Response({"wins": win_count, "losses": loss_count}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be
get
, since it’s a non mutator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need detail = True to get pk