From 3376eb6d2e4c2484d8b0e2b1bffcf6fe003ba0e1 Mon Sep 17 00:00:00 2001 From: salam Date: Tue, 16 Jun 2026 17:08:51 +0200 Subject: [PATCH] wip --- app/Filament/Widgets/Data/LoadPerformance.php | 102 +++++++++++++----- app/Filament/Widgets/StatsMedianAverage.php | 10 +- resources/css/filament/admin/theme.css | 6 +- 3 files changed, 85 insertions(+), 33 deletions(-) diff --git a/app/Filament/Widgets/Data/LoadPerformance.php b/app/Filament/Widgets/Data/LoadPerformance.php index a43d1b0e..0e303716 100644 --- a/app/Filament/Widgets/Data/LoadPerformance.php +++ b/app/Filament/Widgets/Data/LoadPerformance.php @@ -21,6 +21,10 @@ class LoadPerformance $match_id = (int) $filter['match_id'] ?? 0; + $team_position = $filter['team_position']; + + $team_id = (int) $filter['team_id'] ?? 0; + if (! $league_id) { return []; } @@ -33,6 +37,8 @@ class LoadPerformance $home_id = $match->home_id; $away_id = $match->away_id; + + $res = StatistikoEvent::where('league_id', $league_id)->get(); $home_matches = []; @@ -47,37 +53,78 @@ class LoadPerformance $labels = []; foreach ($res as $val) { $league_matches[] = $val->match_id; - - if ($val->home_id == $home_id or $val->away_id == $home_id) { - $labels[] = round($val->starttime->diffInDays(Carbon::now())); - $date_home[] = $val['starttime']->format('d. F Y H:i'); - $results_home[] = $val['gls_h'] . ' : ' . $val['gls_a']; - $events_home[] = $val->home->name . ' vs ' . $val->away->name; - $home_matches[] = $val->match_id; - } - if ($val->home_id == $away_id or $val->away_id == $away_id) { - $labels[] = round($val->starttime->diffInDays(Carbon::now())); - $date_away[] = $val['starttime']->format('d. F Y H:i'); - $results_away[] = $val['gls_h'] . ' : ' . $val['gls_a']; - $events_away[] = $val->home->name . ' vs ' . $val->away->name; - $away_matches[] = $val->match_id; + switch ($team_position) { + case 'home': + if ($val->home_id == $home_id) { + $labels[] = round($val->starttime->diffInDays(Carbon::now())); + $date_home[] = $val['starttime']->format('d. F Y H:i'); + $results_home[] = $val['gls_h'] . ' : ' . $val['gls_a']; + $events_home[] = $val->home->name . ' vs ' . $val->away->name; + $home_matches[] = $val->match_id; + } + if ($val->away_id == $away_id) { + $labels[] = round($val->starttime->diffInDays(Carbon::now())); + $date_away[] = $val['starttime']->format('d. F Y H:i'); + $results_away[] = $val['gls_h'] . ' : ' . $val['gls_a']; + $events_away[] = $val->home->name . ' vs ' . $val->away->name; + $away_matches[] = $val->match_id; + } + break; + case 'away': + if ($val->away_id == $home_id) { + $labels[] = round($val->starttime->diffInDays(Carbon::now())); + $date_home[] = $val['starttime']->format('d. F Y H:i'); + $results_home[] = $val['gls_h'] . ' : ' . $val['gls_a']; + $events_home[] = $val->home->name . ' vs ' . $val->away->name; + $home_matches[] = $val->match_id; + } + if ($val->home_id == $away_id) { + $labels[] = round($val->starttime->diffInDays(Carbon::now())); + $date_away[] = $val['starttime']->format('d. F Y H:i'); + $results_away[] = $val['gls_h'] . ' : ' . $val['gls_a']; + $events_away[] = $val->home->name . ' vs ' . $val->away->name; + $away_matches[] = $val->match_id; + } + break; + default: + if ($val->home_id == $home_id or $val->away_id == $home_id) { + $labels[] = round($val->starttime->diffInDays(Carbon::now())); + $date_home[] = $val['starttime']->format('d. F Y H:i'); + $results_home[] = $val['gls_h'] . ' : ' . $val['gls_a']; + $events_home[] = $val->home->name . ' vs ' . $val->away->name; + $home_matches[] = $val->match_id; + } + if ($val->home_id == $away_id or $val->away_id == $away_id) { + $labels[] = round($val->starttime->diffInDays(Carbon::now())); + $date_away[] = $val['starttime']->format('d. F Y H:i'); + $results_away[] = $val['gls_h'] . ' : ' . $val['gls_a']; + $events_away[] = $val->home->name . ' vs ' . $val->away->name; + $away_matches[] = $val->match_id; + } + break; } } + // dd($home_matches); + $res = StatistikoPlayer::whereIn('match_id', $home_matches)->select('match_id', 'minutes_played', 'playerrating_value', 'player_position')->get(); $homes = self::filterMatches($res, $home_matches); + // dd($homes); + $res = StatistikoPlayer::whereIn('match_id', $away_matches)->select('match_id', 'minutes_played', 'playerrating_value', 'player_position')->get(); $aways = self::filterMatches($res, $away_matches); + $length = max(count($homes['all']), count($aways['all'])); + self::shortenEnding($labels, $homes, $aways); - $home_av = self::makeAv($homes); - $away_av = self::makeAv($aways); + $home_av = self::makeAv($homes, $length); + $away_av = self::makeAv($aways, $length); $res = StatistikoPlayer::whereIn('match_id', $league_matches)->select('match_id', 'minutes_played', 'playerrating_value', 'player_position')->get(); $league = self::filterMatches($res, $league_matches); - $league_av = self::leagueAv($league, count($homes['all'])); + $league_av = self::leagueAv($league, $length); $data = [ 'datasets' => [ @@ -374,8 +421,9 @@ class LoadPerformance public static function filterMatches($res, array $matches) { if (!$res->count()) { - return []; + return ['all', 'def', 'att', 'mid']; } + $result = []; foreach ($res as $value) { @@ -480,17 +528,17 @@ class LoadPerformance $labels = range(1, $keeps); } - public static function makeAv(array &$arr) + public static function makeAv(array &$arr, $length) { - $all = array_sum($arr['all']) / count($arr['all']); - $def = array_sum($arr['def']) / count($arr['def']); - $mid = array_sum($arr['mid']) / count($arr['mid']); - $att = array_sum($arr['att']) / count($arr['att']); + $all = isset($arr['all']) ? array_sum($arr['all']) / count($arr['all']) : 1; + $def = isset($arr['def']) ? array_sum($arr['def']) / count($arr['def']) : 1; + $mid = isset($arr['mid']) ? array_sum($arr['mid']) / count($arr['mid']) : 1; + $att = isset($arr['att']) ? array_sum($arr['att']) / count($arr['att']) : 1; $ret = []; - $ret['all'] = array_fill(0, count($arr['all']), round($all, 2)); - $ret['def'] = array_fill(0, count($arr['def']), round($def, 2)); - $ret['mid'] = array_fill(0, count($arr['mid']), round($mid, 2)); - $ret['att'] = array_fill(0, count($arr['att']), round($att, 2)); + $ret['all'] = array_fill(0, $length, round($all, 2)); + $ret['def'] = array_fill(0, $length, round($def, 2)); + $ret['mid'] = array_fill(0, $length, round($mid, 2)); + $ret['att'] = array_fill(0, $length, round($att, 2)); return $ret; } diff --git a/app/Filament/Widgets/StatsMedianAverage.php b/app/Filament/Widgets/StatsMedianAverage.php index 4d63423c..6100c74d 100644 --- a/app/Filament/Widgets/StatsMedianAverage.php +++ b/app/Filament/Widgets/StatsMedianAverage.php @@ -112,15 +112,15 @@ class StatsMedianAverage extends StatsOverviewWidget $value_away = 0; $boxes = []; - $boxes[] = Stat::make('Events', new HtmlString('
' . $total_home . '
'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); - $boxes[] = Stat::make('Avg ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away, 0)"]); + $boxes[] = Stat::make('Events', new HtmlString('
' . $total_home . '
'))->description('Number')->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); + $boxes[] = Stat::make($statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->description('Average Team')->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away, 0)"]); foreach ($data['datasets'] as $value) { if ($value['label'] == "Average League") { $str = $value['data'][0] ?? 0; - $boxes[] = Stat::make('Avg League', new HtmlString('
' . $str . '
'))->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); + $boxes[] = Stat::make($statistic_type, new HtmlString('
' . $str . '
'))->description('Average League')->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); } } - $boxes[] = Stat::make('Med ' . $statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]); + $boxes[] = Stat::make($statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->description('Median')->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]); $boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? '1' : 'Win: ' . $data['results']['w'], new HtmlString('
' . $win . '
'))->extraAttributes(['x-init' => "animate('number-of-win', $win, 1)"]); $boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? 'X' : 'Draw: ' . $data['results']['d'], new HtmlString('
' . $draw . '
'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw, 1)"]); $boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? '2' : 'Lost: ' . $data['results']['l'], new HtmlString('
' . $lost . '
'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost, 1)"]); @@ -130,7 +130,7 @@ class StatsMedianAverage extends StatsOverviewWidget protected function template(string $home_id, string $away_id, string $home_name, string $away_name): HtmlString { - return new HtmlString('
+ return new HtmlString('
0 0 ' . $home_name . ' diff --git a/resources/css/filament/admin/theme.css b/resources/css/filament/admin/theme.css index 000c2d64..3b3c9e07 100644 --- a/resources/css/filament/admin/theme.css +++ b/resources/css/filament/admin/theme.css @@ -118,7 +118,11 @@ widget space to filter } .fi-wi-stats-overview-stat-label { - @apply text-lg font-bold mx-auto + @apply text-sm font-bold mx-auto text-amber-500 +} + +.fi-wi-stats-overview-stat-description span { + @apply mx-auto text-blue-500; } .fi-wi-stats-overview-stat-value {