Feat: Supporter-Team-Statistiken in der Team-Statistikansicht
Erweitert die Team-Statistikansicht um zwei neue Metriken: - 'Games with Supporters': Zeigt die Anzahl der Spiele an, die mit Unterstützung durch ein zweites Team (Supporter-Team) stattgefunden haben. - 'Avg. Supporter Share': Berechnet den durchschnittlichen Prozentsatz der Spieler, die in diesen Spielen vom Supporter-Team gestellt wurden. Diese Statistiken helfen, den Grad der Abhängigkeit von externer Spielerunterstützung zu analysieren. Die Anzeige erfolgt in einer neuen Karte auf der Team-Statistikseite. Änderungen umfassen: - Anpassung der Funktion in zur Berechnung der neuen Metriken unter Berücksichtigung von und . - Erweiterung des Templates um eine neue 'Supporter Stats'-Karte zur Anzeige der berechneten Werte.
This commit is contained in:
parent
a37954de65
commit
fb782d85db
@ -67,9 +67,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Luck-O-Meter and Inning Heatmap -->
|
<!-- Luck-O-Meter, Supporter Stats -->
|
||||||
<div class="row mt-4">
|
<div class="row mt-4">
|
||||||
<div class="col-md-4">
|
<div class="col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">Luck-O-Meter</div>
|
<div class="card-header">Luck-O-Meter</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@ -78,7 +78,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-8">
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">Supporter Stats</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p>Games with Supporters: {{ stats.games_with_supporters }}</p>
|
||||||
|
<p>Avg. Supporter Share: {{ stats.avg_supporter_player_percentage|floatformat:2 }}%</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Inning Heatmap -->
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">Inning Heatmap (Runs Scored)</div>
|
<div class="card-header">Inning Heatmap (Runs Scored)</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|||||||
@ -2,13 +2,13 @@ from django.shortcuts import render, get_object_or_404
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseForbidden
|
||||||
from clubs.models import Team
|
from clubs.models import Team
|
||||||
from calendars.models import Game
|
from calendars.models import Game, EventParticipation
|
||||||
|
|
||||||
def _calculate_statistics(team, season=None):
|
def _calculate_statistics(team, season=None):
|
||||||
"""
|
"""
|
||||||
Calculates statistics for a given team and season.
|
Calculates statistics for a given team and season.
|
||||||
"""
|
"""
|
||||||
games_query = Game.objects.filter(team=team, result__isnull=False)
|
games_query = Game.objects.filter(team=team, result__isnull=False).prefetch_related('opened_for_teams')
|
||||||
if season:
|
if season:
|
||||||
games_query = games_query.filter(season=season)
|
games_query = games_query.filter(season=season)
|
||||||
|
|
||||||
@ -20,10 +20,25 @@ def _calculate_statistics(team, season=None):
|
|||||||
runs_allowed = 0
|
runs_allowed = 0
|
||||||
inning_runs = {i: 0 for i in range(1, 10)}
|
inning_runs = {i: 0 for i in range(1, 10)}
|
||||||
streak_counter = 0
|
streak_counter = 0
|
||||||
current_streak_type = None
|
|
||||||
last_game_result = None
|
last_game_result = None
|
||||||
|
|
||||||
|
games_with_supporters = 0
|
||||||
|
total_supporter_player_percentage = 0
|
||||||
|
|
||||||
for game in games:
|
for game in games:
|
||||||
|
# Supporter stats
|
||||||
|
if game.opened_for_teams.exists():
|
||||||
|
games_with_supporters += 1
|
||||||
|
|
||||||
|
attending_players = EventParticipation.objects.filter(event=game, status='attending').select_related('user__team')
|
||||||
|
total_attendees = attending_players.count()
|
||||||
|
|
||||||
|
if total_attendees > 0:
|
||||||
|
supporter_players_count = attending_players.exclude(user__team=game.team).count()
|
||||||
|
supporter_percentage = (supporter_players_count / total_attendees) * 100
|
||||||
|
total_supporter_player_percentage += supporter_percentage
|
||||||
|
|
||||||
|
# Standard game stats
|
||||||
result = game.result
|
result = game.result
|
||||||
|
|
||||||
sorted_items = sorted(result.inning_results.items(), key=lambda x: int(x[0].split('_')[1]))
|
sorted_items = sorted(result.inning_results.items(), key=lambda x: int(x[0].split('_')[1]))
|
||||||
@ -85,6 +100,8 @@ def _calculate_statistics(team, season=None):
|
|||||||
else:
|
else:
|
||||||
pythagorean_pct = 0
|
pythagorean_pct = 0
|
||||||
|
|
||||||
|
avg_supporter_player_percentage = (total_supporter_player_percentage / games_with_supporters) if games_with_supporters > 0 else 0
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'team': team,
|
'team': team,
|
||||||
'wins': wins,
|
'wins': wins,
|
||||||
@ -96,6 +113,8 @@ def _calculate_statistics(team, season=None):
|
|||||||
'pythagorean_pct': pythagorean_pct,
|
'pythagorean_pct': pythagorean_pct,
|
||||||
'inning_runs': inning_runs,
|
'inning_runs': inning_runs,
|
||||||
'total_games': total_games,
|
'total_games': total_games,
|
||||||
|
'games_with_supporters': games_with_supporters,
|
||||||
|
'avg_supporter_player_percentage': avg_supporter_player_percentage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user