Erweiterte Spielerstatistiken: 7-Meter, Strafen, Spielzeit
Neue Metriken für Jugendhandball: 7m-Würfe/-Tore, Gelbe Karten, 2-Minuten-Strafen und Spielzeit. Migration, Model, Controller, Views und Übersetzungen (6 Sprachen) vollständig implementiert. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Models\EventParticipant;
|
||||
use App\Models\EventPlayerStat;
|
||||
use App\Models\EventTimekeeper;
|
||||
use App\Models\Player;
|
||||
use App\Models\Season;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
@@ -32,6 +33,7 @@ class StatisticsController extends Controller
|
||||
|
||||
$request->validate([
|
||||
'team_id' => ['nullable', 'integer', 'exists:teams,id'],
|
||||
'season_id' => ['nullable', 'integer', 'exists:seasons,id'],
|
||||
'from' => ['nullable', 'date'],
|
||||
'to' => ['nullable', 'date'],
|
||||
]);
|
||||
@@ -49,12 +51,20 @@ class StatisticsController extends Controller
|
||||
$query->where('team_id', $request->team_id);
|
||||
}
|
||||
|
||||
if ($request->filled('from')) {
|
||||
$query->where('start_at', '>=', $request->from);
|
||||
}
|
||||
|
||||
if ($request->filled('to')) {
|
||||
$query->where('start_at', '<=', $request->to . ' 23:59:59');
|
||||
// Saison-Filter (hat Vorrang vor from/to)
|
||||
$activeSeason = null;
|
||||
if ($request->filled('season_id')) {
|
||||
$activeSeason = Season::find($request->season_id);
|
||||
if ($activeSeason) {
|
||||
$query->whereBetween('start_at', [$activeSeason->start_date, $activeSeason->end_date->endOfDay()]);
|
||||
}
|
||||
} elseif ($request->filled('from') || $request->filled('to')) {
|
||||
if ($request->filled('from')) {
|
||||
$query->where('start_at', '>=', $request->from);
|
||||
}
|
||||
if ($request->filled('to')) {
|
||||
$query->where('start_at', '<=', $request->to . ' 23:59:59');
|
||||
}
|
||||
}
|
||||
|
||||
$games = $query->orderByDesc('start_at')->get();
|
||||
@@ -93,7 +103,7 @@ class StatisticsController extends Controller
|
||||
$chartWinLoss = [
|
||||
'labels' => [__('admin.wins'), __('admin.losses'), __('admin.draws')],
|
||||
'data' => [$wins, $losses, $draws],
|
||||
'colors' => ['#22c55e', '#ef4444', '#9ca3af'],
|
||||
'colors' => ['#3e7750', '#8f504b', '#8e9db3'],
|
||||
];
|
||||
|
||||
// Spieler-Teilnahme pro Spiel (nur die letzten 15 Spiele)
|
||||
@@ -138,7 +148,12 @@ class StatisticsController extends Controller
|
||||
DB::raw('COALESCE(SUM(goals), 0) as total_goals_agg'),
|
||||
DB::raw('COALESCE(SUM(shots), 0) as total_shots_agg'),
|
||||
DB::raw('COALESCE(SUM(goalkeeper_saves), 0) as total_gk_saves'),
|
||||
DB::raw('COALESCE(SUM(goalkeeper_shots), 0) as total_gk_shots')
|
||||
DB::raw('COALESCE(SUM(goalkeeper_shots), 0) as total_gk_shots'),
|
||||
DB::raw('COALESCE(SUM(penalty_goals), 0) as total_penalty_goals'),
|
||||
DB::raw('COALESCE(SUM(penalty_shots), 0) as total_penalty_shots'),
|
||||
DB::raw('COALESCE(SUM(yellow_cards), 0) as total_yellow_cards'),
|
||||
DB::raw('COALESCE(SUM(two_minute_suspensions), 0) as total_suspensions'),
|
||||
DB::raw('AVG(playing_time_minutes) as avg_playing_time')
|
||||
)
|
||||
->groupBy('player_id')
|
||||
->get()
|
||||
@@ -195,6 +210,11 @@ class StatisticsController extends Controller
|
||||
'is_primary_gk' => $isPrimaryGk,
|
||||
'performance_rate' => $performanceRate,
|
||||
'performance_color' => $performanceColor,
|
||||
'total_penalty_goals' => $agg ? (int) $agg->total_penalty_goals : 0,
|
||||
'total_penalty_shots' => $agg ? (int) $agg->total_penalty_shots : 0,
|
||||
'total_yellow_cards' => $agg ? (int) $agg->total_yellow_cards : 0,
|
||||
'total_suspensions' => $agg ? (int) $agg->total_suspensions : 0,
|
||||
'avg_playing_time' => $agg && $agg->avg_playing_time ? (int) round($agg->avg_playing_time) : null,
|
||||
];
|
||||
})
|
||||
->filter()
|
||||
@@ -270,11 +290,14 @@ class StatisticsController extends Controller
|
||||
$totalCateringEvents = $cateringEventIds->count();
|
||||
$totalTimekeeperEvents = $timekeeperEventIds->count();
|
||||
|
||||
$seasons = Season::orderByDesc('start_date')->get();
|
||||
|
||||
return view('admin.statistics.index', compact(
|
||||
'games', 'teams', 'wins', 'losses', 'draws', 'winRate', 'totalWithScore',
|
||||
'chartWinLoss', 'chartPlayerParticipation', 'chartParentInvolvement',
|
||||
'playerRanking', 'totalGames', 'courtPlayers',
|
||||
'parentRanking', 'totalCateringEvents', 'totalTimekeeperEvents'
|
||||
'parentRanking', 'totalCateringEvents', 'totalTimekeeperEvents',
|
||||
'seasons', 'activeSeason'
|
||||
));
|
||||
}
|
||||
|
||||
@@ -296,6 +319,12 @@ class StatisticsController extends Controller
|
||||
$gkGames = $stats->where('is_goalkeeper', true);
|
||||
$totalGkSaves = $gkGames->sum('goalkeeper_saves');
|
||||
$totalGkShots = $gkGames->sum('goalkeeper_shots');
|
||||
$totalPenaltyGoals = $stats->sum('penalty_goals');
|
||||
$totalPenaltyShots = $stats->sum('penalty_shots');
|
||||
$totalYellowCards = $stats->sum('yellow_cards');
|
||||
$totalSuspensions = $stats->sum('two_minute_suspensions');
|
||||
$playingTimeStats = $stats->whereNotNull('playing_time_minutes');
|
||||
$avgPlayingTime = $playingTimeStats->count() > 0 ? (int) round($playingTimeStats->avg('playing_time_minutes')) : null;
|
||||
|
||||
return response()->json([
|
||||
'player' => [
|
||||
@@ -312,6 +341,12 @@ class StatisticsController extends Controller
|
||||
'total_saves' => $totalGkSaves,
|
||||
'total_gk_shots' => $totalGkShots,
|
||||
'save_rate' => $totalGkShots > 0 ? round(($totalGkSaves / $totalGkShots) * 100, 1) : null,
|
||||
'total_penalty_goals' => $totalPenaltyGoals,
|
||||
'total_penalty_shots' => $totalPenaltyShots,
|
||||
'penalty_rate' => $totalPenaltyShots > 0 ? round(($totalPenaltyGoals / $totalPenaltyShots) * 100, 1) : null,
|
||||
'total_yellow_cards' => $totalYellowCards,
|
||||
'total_suspensions' => $totalSuspensions,
|
||||
'avg_playing_time' => $avgPlayingTime,
|
||||
],
|
||||
'games' => $stats->map(fn ($s) => [
|
||||
'date' => $s->event->start_at->format('d.m.Y'),
|
||||
@@ -320,6 +355,11 @@ class StatisticsController extends Controller
|
||||
'position' => $s->position?->shortLabel(),
|
||||
'goals' => $s->goals,
|
||||
'shots' => $s->shots,
|
||||
'penalty_goals' => $s->penalty_goals,
|
||||
'penalty_shots' => $s->penalty_shots,
|
||||
'yellow_cards' => $s->yellow_cards,
|
||||
'two_minute_suspensions' => $s->two_minute_suspensions,
|
||||
'playing_time_minutes' => $s->playing_time_minutes,
|
||||
'is_goalkeeper' => $s->is_goalkeeper,
|
||||
'goalkeeper_saves' => $s->goalkeeper_saves,
|
||||
'goalkeeper_shots' => $s->goalkeeper_shots,
|
||||
|
||||
Reference in New Issue
Block a user