From 314ab7885b8fa17b53b542409f58087690c80b3a Mon Sep 17 00:00:00 2001 From: salam Date: Fri, 22 May 2026 14:52:33 +0200 Subject: [PATCH] ImportPlayer add cars and penalty --- app/Actions/Statistics/StatisticEvents.php | 8 -- app/Filament/Imports/Helper/ImportPlayer.php | 2 +- app/Filament/Pages/Statistic.php | 29 ++-- .../Widgets/DB}/LoadEvents.php | 30 +++- .../Widgets/DB}/LoadEventsAspGoal.php | 20 ++- .../Widgets/DB/LoadMoveingAveragePlayer.php | 0 .../Widgets/DB/LoadPunctualChartPlayer.php | 135 ++++++++++++++++++ .../Widgets/DB}/MoveingAverage.php | 2 +- .../Widgets/DB}/StatisticType.php | 2 +- ...ianAverageWidget.php => MedianAverage.php} | 6 +- app/Filament/Widgets/MovingAverageChart.php | 8 +- .../Widgets/MovingAverageChartPlayer.php | 48 +++++++ app/Filament/Widgets/PunctualChart.php | 7 +- app/Filament/Widgets/PunctualChartPlayer.php | 48 +++++++ 14 files changed, 308 insertions(+), 37 deletions(-) delete mode 100644 app/Actions/Statistics/StatisticEvents.php rename app/{Actions/Statistics => Filament/Widgets/DB}/LoadEvents.php (86%) rename app/{Actions/Statistics => Filament/Widgets/DB}/LoadEventsAspGoal.php (92%) create mode 100644 app/Filament/Widgets/DB/LoadMoveingAveragePlayer.php create mode 100644 app/Filament/Widgets/DB/LoadPunctualChartPlayer.php rename app/{Actions/Statistics => Filament/Widgets/DB}/MoveingAverage.php (95%) rename app/{Actions/Statistics => Filament/Widgets/DB}/StatisticType.php (93%) rename app/Filament/Widgets/{MedianAverageWidget.php => MedianAverage.php} (90%) create mode 100644 app/Filament/Widgets/MovingAverageChartPlayer.php create mode 100644 app/Filament/Widgets/PunctualChartPlayer.php diff --git a/app/Actions/Statistics/StatisticEvents.php b/app/Actions/Statistics/StatisticEvents.php deleted file mode 100644 index d8e4c705..00000000 --- a/app/Actions/Statistics/StatisticEvents.php +++ /dev/null @@ -1,8 +0,0 @@ -getRows() diff --git a/app/Filament/Pages/Statistic.php b/app/Filament/Pages/Statistic.php index bf73be57..29ef8fcf 100644 --- a/app/Filament/Pages/Statistic.php +++ b/app/Filament/Pages/Statistic.php @@ -3,9 +3,11 @@ namespace App\Filament\Pages; use App\Actions\LoadStatisticFixturesLeaguesOptions; -use App\Filament\Widgets\MedianAverageWidget; +use App\Filament\Widgets\MedianAverage; use App\Filament\Widgets\MovingAverageChart; +use App\Filament\Widgets\MovingAverageChartPlayer; use App\Filament\Widgets\PunctualChart; +use App\Filament\Widgets\PunctualChartPlayer; use App\Models\Element; use App\Models\StatisticFixtures; use App\Models\StatistikoDetail; @@ -13,7 +15,6 @@ use BackedEnum; use Filament\Actions\Action; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\Select; -use Filament\Forms\Components\Slider; use Filament\Pages\Dashboard as BaseDashboard; use Filament\Pages\Dashboard\Concerns\HasFiltersForm; use Filament\Schemas\Components\Grid; @@ -75,6 +76,16 @@ class Statistic extends BaseDashboard ->searchable() ->live() ->label('Team'), + + Select::make('team_position') + ->prefixIcon('phosphor-map-pin') + ->default('all') + ->selectablePlaceholder(false) + ->options([ + 'all' => 'All', + 'home' => 'Home', + 'away' => 'Away', + ]), DatePicker::make('start_date') ->native(false) ->prefixIcon('phosphor-calendar') @@ -93,7 +104,7 @@ class Statistic extends BaseDashboard ->color('gray') ->action(fn (Set $set) => $set('end_date', null)) ), - ])->columns(4) + ])->columns(5) ->columnSpanFull(), Grid::make() ->schema([ @@ -106,14 +117,14 @@ class Statistic extends BaseDashboard return StatistikoDetail::where('txodds_id', $get('team_id'))->pluck('name', 'tm_player_id'); }) ->live(), - Select::make('team_position') - ->prefixIcon('phosphor-map-pin') + Select::make('player_on_field') + ->prefixIcon('phosphor-watch') ->default('all') ->selectablePlaceholder(false) ->options([ 'all' => 'All', - 'home' => 'Home', - 'away' => 'Away', + 'lineup' => 'Lineup', + 'substituted' => 'Substituted', ]), Select::make('statistic_type') ->prefixIcon('phosphor-cell-signal-full') @@ -178,9 +189,11 @@ class Statistic extends BaseDashboard protected function getFooterWidgets(): array { return [ - MedianAverageWidget::make(), + MedianAverage::make(), PunctualChart::make(), MovingAverageChart::make(), + PunctualChartPlayer::make(), + // MovingAverageChartPlayer::make(), ]; } diff --git a/app/Actions/Statistics/LoadEvents.php b/app/Filament/Widgets/DB/LoadEvents.php similarity index 86% rename from app/Actions/Statistics/LoadEvents.php rename to app/Filament/Widgets/DB/LoadEvents.php index d13ae0cd..4b5e05e4 100644 --- a/app/Actions/Statistics/LoadEvents.php +++ b/app/Filament/Widgets/DB/LoadEvents.php @@ -1,9 +1,10 @@ pluck('match_id')->toArray(); + } else { + $matches_played = false; + } + /** * STATTISTIC DATA */ @@ -65,7 +79,9 @@ class LoadEvents case 'home': $res = StatistikoEvent::where('league_id', $league_id) ->where('home_id', '=', $team_id) - ->when($start, function ($query) use ($start) { + ->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); @@ -76,7 +92,9 @@ class LoadEvents case 'away': $res = StatistikoEvent::where('league_id', $league_id) ->where('away_id', '=', $team_id) - ->when($start, function ($query) use ($start) { + ->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); @@ -89,7 +107,9 @@ class LoadEvents ->where(function ($query) use ($team_id) { $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id); }) - ->when($start, function ($query) use ($start) { + ->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); @@ -106,7 +126,7 @@ class LoadEvents } foreach ($res as $value) { - $labels[] = $value['starttime']->format('d. M.y'); + $labels[] = $value['starttime']->format('d.M.y'); if ($team_position == 'home') { diff --git a/app/Actions/Statistics/LoadEventsAspGoal.php b/app/Filament/Widgets/DB/LoadEventsAspGoal.php similarity index 92% rename from app/Actions/Statistics/LoadEventsAspGoal.php rename to app/Filament/Widgets/DB/LoadEventsAspGoal.php index b85a7f19..5d6dcc84 100644 --- a/app/Actions/Statistics/LoadEventsAspGoal.php +++ b/app/Filament/Widgets/DB/LoadEventsAspGoal.php @@ -1,9 +1,10 @@ pluck('match_id')->toArray(); + } else { + $matches_played = false; + } + $similar_past_matches = $filter['similar_past_matches'] ?? 0; 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) { @@ -88,6 +102,8 @@ class LoadEventsAspGoal 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) { @@ -132,7 +148,7 @@ class LoadEventsAspGoal } foreach ($res as $value) { - $labels[] = $value['starttime']->format('d. M.y'); + $labels[] = $value['starttime']->format('d.M.y'); // dd($filter); diff --git a/app/Filament/Widgets/DB/LoadMoveingAveragePlayer.php b/app/Filament/Widgets/DB/LoadMoveingAveragePlayer.php new file mode 100644 index 00000000..e69de29b diff --git a/app/Filament/Widgets/DB/LoadPunctualChartPlayer.php b/app/Filament/Widgets/DB/LoadPunctualChartPlayer.php new file mode 100644 index 00000000..7c82db5a --- /dev/null +++ b/app/Filament/Widgets/DB/LoadPunctualChartPlayer.php @@ -0,0 +1,135 @@ + "all" + // "statistic_type" => "gls" + // "similar_past_matches" => "none" + // "accuracy" => "0.5" + // "player_on_field" => "all" + // "league_id" => "26" + // "team_id" => "571991" + // "start_date" => null + // "end_date" => null + // "tm_player_id" => null + + // 'gls' => 'Goals', // goals + // 'crn' => 'Corner', + // 'fls' => 'Fouls commited', // fouls + // 'ofs' => 'Offside', // offsides + // 'crd' => 'Cards', + // 'snt' => 'Shot on target', // shots_on_target + // 'tsh' => 'Total shots', // shots_off_target + + $league_id = (int) $filter['league_id'] ?? 0; + + $team_id = (int) $filter['team_id'] ?? 0; + + $tm_player_id = (int) $filter['tm_player_id'] ?? 0; + + if (! $league_id) { + return []; + } + if (! $team_id) { + return []; + } + if (! $tm_player_id) { + return []; + } + + $team_position = $filter['team_position']; + + $player_on_field = $filter['player_on_field']; + + $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(); + + $statistic_type = $filter['statistic_type'] ?? 0; + + // $fields = 'goals,fouls,offsides,shots_on_target,shots_off_target, subtype_event_during_the_match'; + + $labels = []; + foreach ($res as $key => $value) { + + if (isset($value->event->starttime)) { + + $labels[] = $value->event->starttime->format('d.M.y'); + + switch ($statistic_type) { + case 'gls': + $val = (int) $value['goals']; + break; + case 'crn': + $val = (int) 0; + break; + case 'fls': + $val = (int) $value['fouls']; + break; + case 'ofs': + $val = (int) $value['offsides']; + break; + case 'crd': + $val = (int) $value['crd_h']; + break; + case 'snt': + $val = (int) $value['shots_on_target']; + break; + case 'tsh': + $val = (int) $value['shots_off_target']; + break; + } + } + + $datasets[] = $val; + } + + $data = [ + 'datasets' => [ + [ + 'label' => ucfirst($team_position), + 'data' => $datasets, + 'fill' => true, + 'tension' => 0.5, + 'borderColor' => '#36A2EB', + ], + ], + 'labels' => $labels, + ]; + + return $data; + } +} diff --git a/app/Actions/Statistics/MoveingAverage.php b/app/Filament/Widgets/DB/MoveingAverage.php similarity index 95% rename from app/Actions/Statistics/MoveingAverage.php rename to app/Filament/Widgets/DB/MoveingAverage.php index 030030f8..aa3f4538 100644 --- a/app/Actions/Statistics/MoveingAverage.php +++ b/app/Filament/Widgets/DB/MoveingAverage.php @@ -1,6 +1,6 @@ [ + 'legend' => [ + 'display' => false, + ], + ], + ]; + + public function getDescription(): ?string + { + return 'Player Moving Average'; + } + + protected function getData(): array + { + $this->heading = StatisticType::get($this->filters); + + $data = LoadEvents::load($this->filters); + + if ($data) { + // MoveingAveragePlayer::get($data); + } + + return $data; + } + + protected function getType(): string + { + return 'line'; + } +} diff --git a/app/Filament/Widgets/PunctualChart.php b/app/Filament/Widgets/PunctualChart.php index 140b8249..1c456f73 100644 --- a/app/Filament/Widgets/PunctualChart.php +++ b/app/Filament/Widgets/PunctualChart.php @@ -2,9 +2,8 @@ namespace App\Filament\Widgets; -// use App\Actions\Statistics\StatisticEvents; -use App\Actions\Statistics\LoadEvents; -use App\Actions\Statistics\StatisticType; +use App\Filament\Widgets\DB\LoadEvents; +use App\Filament\Widgets\DB\StatisticType; use Filament\Widgets\ChartWidget; use Filament\Widgets\Concerns\InteractsWithPageFilters; @@ -26,7 +25,7 @@ class PunctualChart extends ChartWidget public function getDescription(): ?string { - return 'Punctual'; + return 'Events Punctual'; } protected function getData(): array diff --git a/app/Filament/Widgets/PunctualChartPlayer.php b/app/Filament/Widgets/PunctualChartPlayer.php new file mode 100644 index 00000000..4f15a97a --- /dev/null +++ b/app/Filament/Widgets/PunctualChartPlayer.php @@ -0,0 +1,48 @@ + [ + 'legend' => [ + 'display' => false, + ], + ], + ]; + + public function getDescription(): ?string + { + return 'Player Punctual'; + } + + protected function getData(): array + { + if ($this->filters['statistic_type'] == 'crn') { + return []; + } + + $this->heading = StatisticType::get($this->filters); + + $data = LoadPunctualChartPlayer::load($this->filters); + + return $data; + } + + protected function getType(): string + { + return 'line'; + } +}