From fbaadcd248ed3dc8d4aa741e19a3da45051d474f Mon Sep 17 00:00:00 2001 From: salam Date: Sat, 23 May 2026 08:38:34 +0200 Subject: [PATCH] wip --- app/Filament/Pages/Statistic.php | 12 +- .../Widgets/ChartMovingAverageEvent.php | 4 +- ...layer.php => ChartMovingAveragePlayer.php} | 10 +- app/Filament/Widgets/ChartPunctualEvent.php | 4 +- ...hartPlayer.php => ChartPunctualPlayer.php} | 6 +- .../Widgets/Data/EventsLoadAspGoal.php | 178 +++++++++++------- .../Data/{EventsLoad.php => LoadEvents.php} | 120 ++++-------- .../Data/{PlayerLoad.php => LoadPlayer.php} | 87 +++++---- app/Filament/Widgets/StatsMedianAverage.php | 11 +- 9 files changed, 213 insertions(+), 219 deletions(-) rename app/Filament/Widgets/{MovingAverageChartPlayer.php => ChartMovingAveragePlayer.php} (79%) rename app/Filament/Widgets/{PunctualChartPlayer.php => ChartPunctualPlayer.php} (86%) rename app/Filament/Widgets/Data/{EventsLoad.php => LoadEvents.php} (62%) rename app/Filament/Widgets/Data/{PlayerLoad.php => LoadPlayer.php} (67%) diff --git a/app/Filament/Pages/Statistic.php b/app/Filament/Pages/Statistic.php index dbf80979..b206eccb 100644 --- a/app/Filament/Pages/Statistic.php +++ b/app/Filament/Pages/Statistic.php @@ -4,9 +4,9 @@ namespace App\Filament\Pages; use App\Actions\LoadStatisticFixturesLeaguesOptions; use App\Filament\Widgets\ChartMovingAverageEvent; +use App\Filament\Widgets\ChartMovingAveragePlayer; use App\Filament\Widgets\ChartPunctualEvent; -use App\Filament\Widgets\MovingAverageChartPlayer; -use App\Filament\Widgets\PunctualChartPlayer; +use App\Filament\Widgets\ChartPunctualPlayer; use App\Filament\Widgets\StatsMedianAverage; use App\Models\Element; use App\Models\StatisticFixtures; @@ -99,6 +99,7 @@ class Statistic extends BaseDashboard DatePicker::make('start_date') ->native(false) ->prefixIcon('phosphor-calendar') + ->live() ->suffixAction( Action::make('clear_start') ->icon('phosphor-x') @@ -108,6 +109,7 @@ class Statistic extends BaseDashboard DatePicker::make('end_date') ->native(false) ->prefixIcon('phosphor-calendar') + ->live() ->suffixAction( Action::make('clear_end') ->icon('phosphor-x') @@ -131,6 +133,7 @@ class Statistic extends BaseDashboard ->action(function (callable $set) { $set('tm_player_id', null); }) + ->color('gray') ->icon('phosphor-x'), ) ->preload() @@ -140,6 +143,7 @@ class Statistic extends BaseDashboard }) ->live(), Select::make('player_on_field') + ->label('Time on field') ->prefixIcon('phosphor-watch') ->default('all') ->selectablePlaceholder(false) @@ -224,8 +228,8 @@ class Statistic extends BaseDashboard StatsMedianAverage::make(), ChartPunctualEvent::make(), ChartMovingAverageEvent::make(), - PunctualChartPlayer::make(), - MovingAverageChartPlayer::make(), + // ChartPunctualPlayer::make(), + // ChartMovingAveragePlayer::make(), ]; } diff --git a/app/Filament/Widgets/ChartMovingAverageEvent.php b/app/Filament/Widgets/ChartMovingAverageEvent.php index 53c8a5ff..82b66267 100644 --- a/app/Filament/Widgets/ChartMovingAverageEvent.php +++ b/app/Filament/Widgets/ChartMovingAverageEvent.php @@ -2,9 +2,9 @@ namespace App\Filament\Widgets; -use App\Filament\Widgets\Data\EventsLoad; use App\Filament\Widgets\Data\HelperMoveingAverage; use App\Filament\Widgets\Data\HelperStatisticType; +use App\Filament\Widgets\Data\LoadEvents; use Filament\Widgets\ChartWidget; use Filament\Widgets\Concerns\InteractsWithPageFilters; @@ -33,7 +33,7 @@ class ChartMovingAverageEvent extends ChartWidget { $this->heading = HelperStatisticType::get($this->filters); - $data = EventsLoad::load($this->filters); + $data = LoadEvents::load($this->filters); if ($data) { HelperMoveingAverage::get($data); diff --git a/app/Filament/Widgets/MovingAverageChartPlayer.php b/app/Filament/Widgets/ChartMovingAveragePlayer.php similarity index 79% rename from app/Filament/Widgets/MovingAverageChartPlayer.php rename to app/Filament/Widgets/ChartMovingAveragePlayer.php index 4832bf7c..d0ce7952 100644 --- a/app/Filament/Widgets/MovingAverageChartPlayer.php +++ b/app/Filament/Widgets/ChartMovingAveragePlayer.php @@ -4,11 +4,11 @@ namespace App\Filament\Widgets; use App\Filament\Widgets\Data\HelperMoveingAverage; use App\Filament\Widgets\Data\HelperStatisticType; -use App\Filament\Widgets\Data\PlayerLoad; +use App\Filament\Widgets\Data\LoadPlayer; use Filament\Widgets\ChartWidget; use Filament\Widgets\Concerns\InteractsWithPageFilters; -class MovingAverageChartPlayer extends ChartWidget +class ChartMovingAveragePlayer extends ChartWidget { use InteractsWithPageFilters; @@ -31,9 +31,13 @@ class MovingAverageChartPlayer extends ChartWidget protected function getData(): array { + if ($this->filters['statistic_type'] == 'crn') { + return []; + } + $this->heading = HelperStatisticType::get($this->filters); - $data = PlayerLoad::load($this->filters); + $data = LoadPlayer::load($this->filters); if ($data) { HelperMoveingAverage::get($data); diff --git a/app/Filament/Widgets/ChartPunctualEvent.php b/app/Filament/Widgets/ChartPunctualEvent.php index ede7b2f7..ac886f65 100644 --- a/app/Filament/Widgets/ChartPunctualEvent.php +++ b/app/Filament/Widgets/ChartPunctualEvent.php @@ -2,8 +2,8 @@ namespace App\Filament\Widgets; -use App\Filament\Widgets\Data\EventsLoad; use App\Filament\Widgets\Data\HelperStatisticType; +use App\Filament\Widgets\Data\LoadEvents; use Filament\Widgets\ChartWidget; use Filament\Widgets\Concerns\InteractsWithPageFilters; @@ -32,7 +32,7 @@ class ChartPunctualEvent extends ChartWidget { $this->heading = HelperStatisticType::get($this->filters); - $data = EventsLoad::load($this->filters); + $data = LoadEvents::load($this->filters); return $data; } diff --git a/app/Filament/Widgets/PunctualChartPlayer.php b/app/Filament/Widgets/ChartPunctualPlayer.php similarity index 86% rename from app/Filament/Widgets/PunctualChartPlayer.php rename to app/Filament/Widgets/ChartPunctualPlayer.php index 6e1fef85..63822a08 100644 --- a/app/Filament/Widgets/PunctualChartPlayer.php +++ b/app/Filament/Widgets/ChartPunctualPlayer.php @@ -3,11 +3,11 @@ namespace App\Filament\Widgets; use App\Filament\Widgets\Data\HelperStatisticType; -use App\Filament\Widgets\Data\PlayerLoad; +use App\Filament\Widgets\Data\LoadPlayer; use Filament\Widgets\ChartWidget; use Filament\Widgets\Concerns\InteractsWithPageFilters; -class PunctualChartPlayer extends ChartWidget +class ChartPunctualPlayer extends ChartWidget { use InteractsWithPageFilters; @@ -36,7 +36,7 @@ class PunctualChartPlayer extends ChartWidget $this->heading = HelperStatisticType::get($this->filters); - $data = PlayerLoad::load($this->filters); + $data = LoadPlayer::load($this->filters); return $data; } diff --git a/app/Filament/Widgets/Data/EventsLoadAspGoal.php b/app/Filament/Widgets/Data/EventsLoadAspGoal.php index d669e3c6..1befdc8f 100644 --- a/app/Filament/Widgets/Data/EventsLoadAspGoal.php +++ b/app/Filament/Widgets/Data/EventsLoadAspGoal.php @@ -2,15 +2,14 @@ namespace App\Filament\Widgets\Data; -use App\Models\StatisticFixtures; use App\Models\StatistikoEvent; use App\Models\StatistikoPlayer; -class EventsLoadAspGoal +class LoadEventsAspGoal { public static function load($filter) { - // dd($filter); + dd($filter); $league_id = (int) $filter['league_id'] ?? 0; @@ -23,27 +22,41 @@ class EventsLoadAspGoal return []; } + /** + * WITH PLAYER + */ + $tm_player_id = $filter['tm_player_id']; + + if ($tm_player_id) { + $matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray(); + } else { + $matches_played = false; + } + $team_position = $filter['team_position']; /** - * ACCURACY DATA + * STATTISTIC DATA */ - switch ($filter['team_position']) { - case 'home': - $res = StatisticFixtures::where('league_id', $league_id)->where('home_id', $team_id)->first(); - break; - - case 'away': - $res = StatisticFixtures::where('league_id', $league_id)->where('away_id', $team_id)->first(); - break; - - default: - $res = StatisticFixtures::where('league_id', $league_id) - ->where(function ($query) use ($team_id) { - $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id); - })->first(); - break; - } + $res = StatistikoEvent::where('league_id', $league_id) + ->where(function ($query) use ($team_id, $team_position) { + switch ($team_position) { + case 'home': + return $query->where('home_id', '=', $team_id); + case 'away': + return $query->where('away_id', '=', $team_id); + default: + return $query->where('home_id', '=', $team_id) + ->orWhere('away_id', '=', $team_id); + } + }) + ->when($matches_played, function ($query) use ($matches_played) { + return $query->whereIn('match_id', $matches_played); + })->when($start, function ($query) use ($start) { + return $query->where('starttime', '>=', $start); + })->when($end, function ($query) use ($end) { + return $query->where('starttime', '<=', $end); + })->first(); $start = $filter['start_date'] ?? 0; @@ -81,63 +94,84 @@ class EventsLoadAspGoal $similar_past_matches = $filter['similar_past_matches'] ?? 0; - switch ($similar_past_matches) { - case 'league': - $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) { + $res = StatistikoEvent::when($league_id, function ($query) use ($league_id, $similar_past_matches) { + switch ($similar_past_matches) { + case 'league': return $query->where('league_id', $league_id); - })->when($matches_played, function ($query) use ($matches_played) { - return $query->whereIn('match_id', $matches_played); - })->when($handicap_range, function ($query) use ($handicap_range) { + default: return $query->whereBetween('exp_handicap', $handicap_range); - })->when($total_range, function ($query) use ($total_range) { - return $query->whereBetween('exp_total', $total_range); - })->when($start, function ($query) use ($start) { - return $query->where('starttime', '>=', $start); - })->when($end, function ($query) use ($end) { - return $query->where('starttime', '<=', $end); - }) - ->get(); + } - break; - case 'all': - $res = StatistikoEvent::when($handicap_range, function ($query) use ($handicap_range) { - return $query->whereBetween('exp_handicap', $handicap_range); - })->when($matches_played, function ($query) use ($matches_played) { - return $query->whereIn('match_id', $matches_played); - })->when($total_range, function ($query) use ($total_range) { - return $query->whereBetween('exp_total', $total_range); - })->when($start, function ($query) use ($start) { - return $query->where('starttime', '>=', $start); - })->when($end, function ($query) use ($end) { - return $query->where('starttime', '<=', $end); - }) - ->get(); + })->when($matches_played, function ($query) use ($matches_played) { + return $query->whereIn('match_id', $matches_played); + })->when($handicap_range, function ($query) use ($handicap_range) { + return $query->whereBetween('exp_handicap', $handicap_range); + })->when($total_range, function ($query) use ($total_range) { + return $query->whereBetween('exp_total', $total_range); + })->when($start, function ($query) use ($start) { + return $query->where('starttime', '>=', $start); + })->when($end, function ($query) use ($end) { + return $query->where('starttime', '<=', $end); + }) + ->get(); - break; - // case 'none': - // $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) { - // return $query->where('league_id', $league_id); - // })->when($team_id, function ($query) use ($team_id, $team_position) { - // switch ($team_position) { - // case 'home': - // return $query->where('home_id', $team_id); - // break; - // case 'away': - // return $query->where('away_id', $team_id); - // break; - // default: - // return $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id); - // break; - // } - // })->when($start, function ($query) use ($start) { - // return $query->where('starttime', '>=', $start); - // })->when($end, function ($query) use ($end) { - // return $query->where('starttime', '<=', $end); - // }) - // ->get(); + // switch ($similar_past_matches) { + // case 'league': + // $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) { + // return $query->where('league_id', $league_id); + // })->when($matches_played, function ($query) use ($matches_played) { + // return $query->whereIn('match_id', $matches_played); + // })->when($handicap_range, function ($query) use ($handicap_range) { + // return $query->whereBetween('exp_handicap', $handicap_range); + // })->when($total_range, function ($query) use ($total_range) { + // return $query->whereBetween('exp_total', $total_range); + // })->when($start, function ($query) use ($start) { + // return $query->where('starttime', '>=', $start); + // })->when($end, function ($query) use ($end) { + // return $query->where('starttime', '<=', $end); + // }) + // ->get(); - // break; - } + // break; + // case 'all': + // $res = StatistikoEvent::when($handicap_range, function ($query) use ($handicap_range) { + // return $query->whereBetween('exp_handicap', $handicap_range); + // })->when($matches_played, function ($query) use ($matches_played) { + // return $query->whereIn('match_id', $matches_played); + // })->when($total_range, function ($query) use ($total_range) { + // return $query->whereBetween('exp_total', $total_range); + // })->when($start, function ($query) use ($start) { + // return $query->where('starttime', '>=', $start); + // })->when($end, function ($query) use ($end) { + // return $query->where('starttime', '<=', $end); + // }) + // ->get(); + + // break; + // // case 'none': + // // $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) { + // // return $query->where('league_id', $league_id); + // // })->when($team_id, function ($query) use ($team_id, $team_position) { + // // switch ($team_position) { + // // case 'home': + // // return $query->where('home_id', $team_id); + // // break; + // // case 'away': + // // return $query->where('away_id', $team_id); + // // break; + // // default: + // // return $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id); + // // break; + // // } + // // })->when($start, function ($query) use ($start) { + // // return $query->where('starttime', '>=', $start); + // // })->when($end, function ($query) use ($end) { + // // return $query->where('starttime', '<=', $end); + // // }) + // // ->get(); + + // // break; + // } $datasets = []; $labels = []; diff --git a/app/Filament/Widgets/Data/EventsLoad.php b/app/Filament/Widgets/Data/LoadEvents.php similarity index 62% rename from app/Filament/Widgets/Data/EventsLoad.php rename to app/Filament/Widgets/Data/LoadEvents.php index fb381c67..a03f07a4 100644 --- a/app/Filament/Widgets/Data/EventsLoad.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -2,11 +2,10 @@ namespace App\Filament\Widgets\Data; -use App\Models\StatisticFixtures; use App\Models\StatistikoEvent; -use App\Models\StatistikoPlayer; +use Illuminate\Support\Facades\Log; -class EventsLoad +class LoadEvents { public static $last_query = []; @@ -14,12 +13,24 @@ class EventsLoad { // dd($filter); + if (self::$last_query) { + return self::$last_query; + } + $league_id = (int) $filter['league_id'] ?? 0; $team_id = (int) $filter['team_id'] ?? 0; $tm_player_id = (int) $filter['tm_player_id'] ?? 0; + $start = $filter['start_date'] ?? 0; + + $end = $filter['end_date'] ?? 0; + + $similar_past_matches = $filter['similar_past_matches'] ?? 0; + + $statistic_type = $filter['statistic_type'] ?? 0; + if (! $league_id) { return []; } @@ -29,89 +40,34 @@ class EventsLoad $team_position = $filter['team_position']; - /** - * ACCURACY DATA - */ - switch ($filter['team_position']) { - case 'home': - $res = StatisticFixtures::where('league_id', $league_id)->where('home_id', $team_id)->first(); - break; - - case 'away': - $res = StatisticFixtures::where('league_id', $league_id)->where('away_id', $team_id)->first(); - break; - - default: - $res = StatisticFixtures::where('league_id', $league_id) - ->where(function ($query) use ($team_id) { - $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id); - })->first(); - break; - } - - $start = $filter['start_date'] ?? 0; - - $end = $filter['end_date'] ?? 0; - - $similar_past_matches = $filter['similar_past_matches'] ?? 0; - - $statistic_type = $filter['statistic_type'] ?? 0; - - /** - * WITH PLAYER - */ - $tm_player_id = $filter['tm_player_id']; - - if ($tm_player_id) { - $matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray(); - } else { - $matches_played = false; - } - /** * STATTISTIC DATA */ - switch ($filter['team_position']) { - case 'home': - $res = StatistikoEvent::where('league_id', $league_id) - ->where('home_id', '=', $team_id) - ->when($matches_played, function ($query) use ($matches_played) { - return $query->whereIn('match_id', $matches_played); - })->when($start, function ($query) use ($start) { - return $query->where('starttime', '>=', $start); - })->when($end, function ($query) use ($end) { - return $query->where('starttime', '<=', $end); - }) - ->get(); - break; + $res = StatistikoEvent::where('league_id', $league_id) + ->where(function ($query) use ($team_id, $team_position) { + switch ($team_position) { + case 'home': + return $query->where('home_id', '=', $team_id); + case 'away': + return $query->where('away_id', '=', $team_id); + default: + return $query->where('home_id', '=', $team_id) + ->orWhere('away_id', '=', $team_id); + } + }) + ->when($start, function ($query) use ($start) { + return $query->where('starttime', '>=', $start); + })->when($end, function ($query) use ($end) { + return $query->where('starttime', '<=', $end); + }) + ->orderBy('starttime') + ->get(); - case 'away': - $res = StatistikoEvent::where('league_id', $league_id) - ->where('away_id', '=', $team_id) - ->when($matches_played, function ($query) use ($matches_played) { - return $query->whereIn('match_id', $matches_played); - })->when($start, function ($query) use ($start) { - return $query->where('starttime', '>=', $start); - })->when($end, function ($query) use ($end) { - return $query->where('starttime', '<=', $end); - }) - ->get(); - break; + // dd($res); - default: - $res = StatistikoEvent::where('league_id', $league_id) - ->where(function ($query) use ($team_id) { - $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id); - }) - ->when($matches_played, function ($query) use ($matches_played) { - return $query->whereIn('match_id', $matches_played); - })->when($start, function ($query) use ($start) { - return $query->where('starttime', '>=', $start); - })->when($end, function ($query) use ($end) { - return $query->where('starttime', '<=', $end); - })->get(); - break; - } + $total = count($res); + // Log::info($res); + // Log::info($total); $datasets = []; $labels = []; @@ -243,6 +199,8 @@ class EventsLoad 'labels' => $labels, ]; + self::$last_query = $data; + return $data; } } diff --git a/app/Filament/Widgets/Data/PlayerLoad.php b/app/Filament/Widgets/Data/LoadPlayer.php similarity index 67% rename from app/Filament/Widgets/Data/PlayerLoad.php rename to app/Filament/Widgets/Data/LoadPlayer.php index bc09e198..c0a62975 100644 --- a/app/Filament/Widgets/Data/PlayerLoad.php +++ b/app/Filament/Widgets/Data/LoadPlayer.php @@ -2,9 +2,9 @@ namespace App\Filament\Widgets\Data; -use App\Models\StatistikoPlayer; +use App\Models\StatistikoEvent; -class PlayerLoad +class LoadPlayer { public static $last_query = []; @@ -12,6 +12,10 @@ class PlayerLoad { // dd($filter); + if (self::$last_query) { + return self::$last_query; + } + // "team_position" => "all" // "statistic_type" => "gls" // "similar_past_matches" => "none" @@ -37,6 +41,18 @@ class PlayerLoad $tm_player_id = (int) $filter['tm_player_id'] ?? 0; + $team_position = $filter['team_position']; + + $player_on_field = $filter['player_on_field']; + + $statistic_type = $filter['statistic_type'] ?? 0; + + $similar_past_matches = $filter['similar_past_matches'] ?? 0; + + $start = $filter['start_date'] ?? 0; + + $end = $filter['end_date'] ?? 0; + if (! $league_id) { return []; } @@ -47,49 +63,28 @@ class PlayerLoad return []; } - $team_position = $filter['team_position']; - - $player_on_field = $filter['player_on_field']; - - if (self::$last_query) { - $res = self::$last_query; - } else { - - $res = StatistikoPlayer::with('event')->where('tm_player_id', $tm_player_id) - ->when($team_position, function ($query) use ($team_id, $team_position) { - /** - * TEAM HOME/AWAY - */ - switch ($team_position) { - case 'home': - return $query->where('activeteam_id', $team_id); - break; - - case 'away': - return $query->where('activeteam_id', '!=', $team_id); - break; - } - })->when($player_on_field, function ($query) use ($player_on_field) { - /** - * LINEUP - */ - switch ($player_on_field) { - case 'lineup': - return $query->where('lineup', 'T'); - break; - case 'substituted': - return $query->where('lineup', 'P'); - break; - } - - })->get(); - - self::$last_query = $res; - } - - $statistic_type = $filter['statistic_type'] ?? 0; - - // $fields = 'goals,fouls,offsides,shots_on_target,shots_off_target, subtype_event_during_the_match'; + /** + * STATTISTIC DATA + */ + $res = StatistikoEvent::where('league_id', $league_id) + ->where(function ($query) use ($team_id, $team_position) { + switch ($team_position) { + case 'home': + return $query->where('home_id', '=', $team_id); + case 'away': + return $query->where('away_id', '=', $team_id); + default: + return $query->where('home_id', '=', $team_id) + ->orWhere('away_id', '=', $team_id); + } + }) + ->when($matches_played, function ($query) use ($matches_played) { + return $query->whereIn('match_id', $matches_played); + })->when($start, function ($query) use ($start) { + return $query->where('starttime', '>=', $start); + })->when($end, function ($query) use ($end) { + return $query->where('starttime', '<=', $end); + })->first(); $labels = []; $datasets = []; @@ -142,6 +137,8 @@ class PlayerLoad 'labels' => $labels, ]; + self::$last_query = $data; + return $data; } } diff --git a/app/Filament/Widgets/StatsMedianAverage.php b/app/Filament/Widgets/StatsMedianAverage.php index 5b6423be..462c6a98 100644 --- a/app/Filament/Widgets/StatsMedianAverage.php +++ b/app/Filament/Widgets/StatsMedianAverage.php @@ -2,8 +2,7 @@ namespace App\Filament\Widgets; -use App\Filament\Widgets\Data\EventsLoad; -use App\Filament\Widgets\Data\EventsLoadAspGoal; +use App\Filament\Widgets\Data\LoadEvents; use Filament\Widgets\Concerns\InteractsWithPageFilters; use Filament\Widgets\StatsOverviewWidget; use Filament\Widgets\StatsOverviewWidget\Stat; @@ -12,15 +11,13 @@ class StatsMedianAverage extends StatsOverviewWidget { use InteractsWithPageFilters; + protected ?string $pollingInterval = null; + protected function getStats(): array { $filters = $this->filters; - if ($filters['similar_past_matches'] == 'none') { - $data = EventsLoad::load($filters); - } else { - $data = EventsLoadAspGoal::load($filters); - } + $data = LoadEvents::load($filters); if (! isset($data['datasets'][0])) { return [];