Skip to content

Commit

Permalink
Fix score query
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanB committed Sep 13, 2024
1 parent bbb5e63 commit 7569422
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
10 changes: 5 additions & 5 deletions ranked/templates/ranked/player_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ <h5 class="mb-0">
labels: ['Wins', 'Losses', 'Draws'],
datasets: [{
data: [
{{player.matches_won}},
{{player.matches_lost}},
{{player.matches_drawn}}
{{ player.matches_won }},
{{ player.matches_lost }},
{{ player.matches_drawn }}
],
backgroundColor: [
'#28a745',
Expand All @@ -178,10 +178,10 @@ <h5 class="mb-0">
const eloHistoryChart = new Chart(document.getElementById('chart-elo-history').getContext('2d'), {
type: 'line',
data: {
labels: JSON.parse("{{ match_labels|safe }}"),
labels: {{ match_labels|safe }},
datasets: [{
label: 'ELO',
data: JSON.parse("{{ elo_history|safe }}"),
data: {{ elo_history|safe }},
backgroundColor: '#ffc107',
borderColor: '#ffc107'
}]
Expand Down
18 changes: 12 additions & 6 deletions ranked/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ def player_info(request, name, player_id):
total_matches=Count('red_alliance', filter=Q(red_alliance__in=matches)) +
Count('blue_alliance', filter=Q(blue_alliance__in=matches)),
wins=Count(Case(
When(Q(red_alliance__in=matches.filter(red_alliance=player.player), red_score__gt=F('blue_score')), then=1),
When(Q(blue_alliance__in=matches.filter(blue_alliance=player.player), blue_score__gt=F('red_score')), then=1),
When(Q(red_alliance__in=matches.filter(red_alliance=player.player)) &
Q(red_alliance__red_score__gt=F('red_alliance__blue_score')), then=1),
When(Q(blue_alliance__in=matches.filter(blue_alliance=player.player)) &
Q(blue_alliance__blue_score__gt=F('blue_alliance__red_score')), then=1),
output_field=IntegerField(),
)),
ties=Count(Case(
When(Q(red_alliance__in=matches) | Q(blue_alliance__in=matches), red_score=F('blue_score'), then=1),
When(Q(red_alliance__in=matches) | Q(blue_alliance__in=matches),
red_alliance__red_score=F('red_alliance__blue_score'), then=1),
output_field=IntegerField(),
)),
).annotate(
Expand All @@ -151,12 +154,15 @@ def player_info(request, name, player_id):
total_matches=Count('red_alliance', filter=Q(red_alliance__in=matches)) +
Count('blue_alliance', filter=Q(blue_alliance__in=matches)),
wins=Count(Case(
When(Q(red_alliance__in=matches.filter(blue_alliance=player.player), red_score__gt=F('blue_score')), then=1),
When(Q(blue_alliance__in=matches.filter(red_alliance=player.player), blue_score__gt=F('red_score')), then=1),
When(Q(red_alliance__in=matches.filter(blue_alliance=player.player)) &
Q(red_alliance__red_score__gt=F('red_alliance__blue_score')), then=1),
When(Q(blue_alliance__in=matches.filter(red_alliance=player.player)) &
Q(blue_alliance__blue_score__gt=F('blue_alliance__red_score')), then=1),
output_field=IntegerField(),
)),
ties=Count(Case(
When(Q(red_alliance__in=matches) | Q(blue_alliance__in=matches), red_score=F('blue_score'), then=1),
When(Q(red_alliance__in=matches) | Q(blue_alliance__in=matches),
red_alliance__red_score=F('red_alliance__blue_score'), then=1),
output_field=IntegerField(),
)),
).annotate(
Expand Down

0 comments on commit 7569422

Please sign in to comment.