From 3627a78989ab3596cbb107a6e5d41e114f478649 Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 27 Jul 2026 18:36:54 +0200 Subject: [PATCH] wip --- .../Data/LoadEvents/LoadEventsAverages.php | 92 +++++++++---------- app/Filament/Widgets/StatsMedianAverage.php | 14 +-- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/app/Filament/Widgets/Data/LoadEvents/LoadEventsAverages.php b/app/Filament/Widgets/Data/LoadEvents/LoadEventsAverages.php index 5483aa02..9afdcbba 100644 --- a/app/Filament/Widgets/Data/LoadEvents/LoadEventsAverages.php +++ b/app/Filament/Widgets/Data/LoadEvents/LoadEventsAverages.php @@ -7,7 +7,7 @@ use App\Models\StatistikoEvent; class LoadEventsAverages { - public static function load(array &$data, array $filter,array $labels, array $events) + public static function load(array &$data, array $filter, array $labels, array $events) { $league_id = (int) $filter['league_id'] ?? 0; @@ -46,7 +46,6 @@ class LoadEventsAverages // quindi la media di questi 120 dati) foreach ($res as $value) { - switch ($statistic_type) { case 'gls': $league_home[] = (int) $value['gls_h']; @@ -78,135 +77,134 @@ class LoadEventsAverages break; } - if ($team_position == 'all' && ($team_id == $value['home_id'] or $team_id == $value['away_id'])) { + // dd($team_position, $team_id, $value); + + if ((!$team_position || $team_position == 'all') && ($team_id == $value['home_id'] or $team_id == $value['away_id'])) { switch ($statistic_type) { case 'gls': if ($team_id == $value['home_id']) { $team_home[] = (int) $value['gls_h']; - $team_away[] =(int) $value['gls_a']; + $team_away[] = (int) $value['gls_a']; } else { $team_home[] = (int) $value['gls_a']; - $team_away[] =(int) $value['gls_h']; + $team_away[] = (int) $value['gls_h']; } break; case 'crn': if ($team_id == $value['home_id']) { $team_home[] = (int) $value['crn_h']; - $team_away[] =(int) $value['crn_a']; + $team_away[] = (int) $value['crn_a']; } else { $team_home[] = (int) $value['crn_a']; - $team_away[] =(int) $value['crn_h']; + $team_away[] = (int) $value['crn_h']; } break; case 'fls': if ($team_id == $value['home_id']) { $team_home[] = (int) $value['fls_h']; - $team_away[] =(int) $value['fls_a']; + $team_away[] = (int) $value['fls_a']; } else { $team_home[] = (int) $value['fls_a']; - $team_away[] =(int) $value['fls_h']; + $team_away[] = (int) $value['fls_h']; } break; case 'ofs': if ($team_id == $value['home_id']) { $team_home[] = (int) $value['ofs_h']; - $team_away[] =(int) $value['ofs_a']; + $team_away[] = (int) $value['ofs_a']; } else { $team_home[] = (int) $value['ofs_a']; - $team_away[] =(int) $value['ofs_h']; + $team_away[] = (int) $value['ofs_h']; } break; case 'crd': if ($team_id == $value['home_id']) { $team_home[] = (int) $value['crd_h']; - $team_away[] =(int) $value['crd_a']; + $team_away[] = (int) $value['crd_a']; } else { $team_home[] = (int) $value['crd_a']; - $team_away[] =(int) $value['crd_h']; + $team_away[] = (int) $value['crd_h']; } break; case 'snt': if ($team_id == $value['home_id']) { $team_home[] = (int) $value['snt_h']; - $team_away[] =(int) $value['snt_a']; + $team_away[] = (int) $value['snt_a']; } else { $team_home[] = (int) $value['snt_a']; - $team_away[] =(int) $value['snt_h']; + $team_away[] = (int) $value['snt_h']; } break; case 'tsh': if ($team_id == $value['home_id']) { $team_home[] = (int) $value['tsh_h']; - $team_away[] =(int) $value['tsh_a']; + $team_away[] = (int) $value['tsh_a']; } else { $team_home[] = (int) $value['tsh_a']; - $team_away[] =(int) $value['tsh_h']; + $team_away[] = (int) $value['tsh_h']; } break; - } - } - - else if ($team_position == 'home' && $team_id == $value['home_id']) { + } + } else if ($team_position == 'home' && $team_id == $value['home_id']) { switch ($statistic_type) { case 'gls': $team_home[] = (int) $value['gls_h']; - $team_away[] =(int) $value['gls_a']; + $team_away[] = (int) $value['gls_a']; break; case 'crn': $team_home[] = (int) $value['crn_h']; - $team_away[] =(int) $value['crn_a']; + $team_away[] = (int) $value['crn_a']; break; case 'fls': $team_home[] = (int) $value['fls_h']; - $team_away[] =(int) $value['fls_a']; + $team_away[] = (int) $value['fls_a']; break; case 'ofs': $team_home[] = (int) $value['ofs_h']; - $team_away[] =(int) $value['ofs_a']; + $team_away[] = (int) $value['ofs_a']; break; case 'crd': $team_home[] = (int) $value['crd_h']; - $team_away[] =(int) $value['crd_a']; + $team_away[] = (int) $value['crd_a']; break; case 'snt': $team_home[] = (int) $value['snt_h']; - $team_away[] =(int) $value['snt_a']; + $team_away[] = (int) $value['snt_a']; break; case 'tsh': $team_home[] = (int) $value['tsh_h']; - $team_away[] =(int) $value['tsh_a']; + $team_away[] = (int) $value['tsh_a']; break; } - } - else if ($team_position == 'away' && $team_id == $value['away_id']) { + } else if ($team_position == 'away' && $team_id == $value['away_id']) { switch ($statistic_type) { case 'gls': $team_home[] = (int) $value['gls_a']; - $team_away[] =(int) $value['gls_h']; + $team_away[] = (int) $value['gls_h']; break; case 'crn': $team_home[] = (int) $value['crn_a']; - $team_away[] =(int) $value['crn_h']; + $team_away[] = (int) $value['crn_h']; break; case 'fls': $team_home[] = (int) $value['fls_a']; - $team_away[] =(int) $value['fls_h']; + $team_away[] = (int) $value['fls_h']; break; case 'ofs': $team_home[] = (int) $value['ofs_a']; - $team_away[] =(int) $value['ofs_h']; + $team_away[] = (int) $value['ofs_h']; break; case 'crd': $team_home[] = (int) $value['crd_a']; - $team_away[] =(int) $value['crd_h']; + $team_away[] = (int) $value['crd_h']; break; case 'snt': $team_home[] = (int) $value['snt_a']; - $team_away[] =(int) $value['snt_h']; + $team_away[] = (int) $value['snt_h']; break; case 'tsh': $team_home[] = (int) $value['tsh_a']; - $team_away[] =(int) $value['tsh_h']; + $team_away[] = (int) $value['tsh_h']; break; } } @@ -219,22 +217,24 @@ class LoadEventsAverages $average_league_home = 0; $average_league_away = 0; - if ($team_id && $team_home){ + // dd($team_home); + + if ($team_id && $team_home) { $sum = array_sum($team_home) + array_sum($team_away); - + $count = count($team_home) + count($team_away); - + $average_team = round($sum / $count, 1); - + $average_team_home = round(array_sum($team_home) / count($team_home), 1); - + $average_team_away = round(array_sum($team_away) / count($team_away), 1); - $average_league_home = $league_home ? round(array_sum($league_home) / \count($league_home), 1):0; - - $average_league_away = $league_away ? round(array_sum($league_away) / \count($league_away), 1):0; - + $average_league_home = $league_home ? round(array_sum($league_home) / \count($league_home), 1) : 0; + + $average_league_away = $league_away ? round(array_sum($league_away) / \count($league_away), 1) : 0; + $media_league = array_merge($league_away, $league_home); $average_league = $media_league ? round(array_sum($media_league) / \count($media_league), 1) : 0; diff --git a/app/Filament/Widgets/StatsMedianAverage.php b/app/Filament/Widgets/StatsMedianAverage.php index 1660955f..b9f27a94 100644 --- a/app/Filament/Widgets/StatsMedianAverage.php +++ b/app/Filament/Widgets/StatsMedianAverage.php @@ -105,6 +105,8 @@ class StatsMedianAverage extends StatsOverviewWidget $average_league_home = 0; $average_league_away = 0; + // Log::debug($data); + foreach ($data['datasets'] as $value) { if ($value['label'] == 'Average Team') { $average_team_home = $value['average_team_home'] ?? 0; @@ -121,16 +123,16 @@ class StatsMedianAverage extends StatsOverviewWidget $boxes = []; // BOX 1 $boxes[] = Stat::make('Number', new HtmlString('
' . $total_home . '
')) - ->description('Events') - ->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); + ->description('Events'); + // ->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); // BOX 2 - Log::debug([$home_team, $value_home]); $boxes[] = Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team, $value_home, $value_away)) ->description('Team ' . $team_position); // ->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]); // BOX 3 + // Log::debug([$average_team_home, $average_team_away]); $boxes[] = Stat::make('Average ' . $statistic_type, self::template('av_team_home', 'av_team_away', $home_team, $away_team, $average_team_home, $average_team_away)) ->description('Team Season'); // ->extraAttributes(['x-init' => "animate('av_team_home', $average_team_home); animate('av_team_away', $average_team_away)"]); @@ -142,15 +144,15 @@ class StatsMedianAverage extends StatsOverviewWidget // BOX 5 $boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost)) - ->description($team_position) - ->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]); + ->description($team_position); + // ->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]); $this->columns = [ 'default' => 1, 'sm' => 2, 'md' => 3, 'lg' => 4, - 'xl' => $max_boxes, + 'xl' => 5, ]; return $boxes;