From 1f4fb9cf8a0eb2fcd91fe1b780c7d8e312a0c13c Mon Sep 17 00:00:00 2001 From: salam Date: Sat, 23 May 2026 14:38:44 +0200 Subject: [PATCH] LoadEvents with description --- .../Widgets/ChartMovingAverageEvent.php | 40 +-------- .../Widgets/ChartMovingAveragePlayer.php | 3 + app/Filament/Widgets/ChartPunctualEvent.php | 87 +------------------ app/Filament/Widgets/ChartPunctualPlayer.php | 3 + app/Filament/Widgets/Data/LoadEvents.php | 21 ++++- app/Filament/Widgets/Data/LoadPlayer.php | 38 ++++---- 6 files changed, 48 insertions(+), 144 deletions(-) diff --git a/app/Filament/Widgets/ChartMovingAverageEvent.php b/app/Filament/Widgets/ChartMovingAverageEvent.php index 820ea7a1..208eae49 100644 --- a/app/Filament/Widgets/ChartMovingAverageEvent.php +++ b/app/Filament/Widgets/ChartMovingAverageEvent.php @@ -5,7 +5,6 @@ namespace App\Filament\Widgets; use App\Filament\Widgets\Data\HelperMoveingAverage; use App\Filament\Widgets\Data\HelperStatisticType; use App\Filament\Widgets\Data\LoadEvents; -use Filament\Support\RawJs; use Filament\Widgets\ChartWidget; use Filament\Widgets\Concerns\InteractsWithPageFilters; @@ -15,8 +14,6 @@ class ChartMovingAverageEvent extends ChartWidget protected ?string $pollingInterval = null; - public ?string $header; - protected ?array $options = [ 'plugins' => [ 'legend' => [ @@ -28,19 +25,16 @@ class ChartMovingAverageEvent extends ChartWidget ], ]; - public function getDescription(): ?string - { - return 'Events Moving Average'; - } - protected function getData(): array { - $this->heading = HelperStatisticType::get($this->filters); + $this->heading = 'Events '.HelperStatisticType::get($this->filters); $data = LoadEvents::load($this->filters); if ($data) { HelperMoveingAverage::get($data); + + $this->description = 'Moving Average '.$data['description']; } return $data; @@ -50,32 +44,4 @@ class ChartMovingAverageEvent extends ChartWidget { return 'line'; } - - // protected function getOptions(): array|RawJs|null - // { - // return [ - // 'plugins' => [ - // 'legend' => [ - // 'display' => display, - // ], - // 'tooltip' => [ - // 'callbacks' => [ - // 'label' => RawJs::make(<<<'JS' - // function(context) { - // let label = context.dataset.label || ''; - - // if (label) { - // label += ': '; - // } - // return label; - // } - // JS), - // ], - // ], - // ], - // 'interaction' => [ - // 'intersect' => false, - // ], - // ]; - // } } diff --git a/app/Filament/Widgets/ChartMovingAveragePlayer.php b/app/Filament/Widgets/ChartMovingAveragePlayer.php index d0ce7952..4a026008 100644 --- a/app/Filament/Widgets/ChartMovingAveragePlayer.php +++ b/app/Filament/Widgets/ChartMovingAveragePlayer.php @@ -22,6 +22,9 @@ class ChartMovingAveragePlayer extends ChartWidget 'display' => false, ], ], + 'interaction' => [ + 'intersect' => false, + ], ]; public function getDescription(): ?string diff --git a/app/Filament/Widgets/ChartPunctualEvent.php b/app/Filament/Widgets/ChartPunctualEvent.php index e6b6aad7..bf8bc14b 100644 --- a/app/Filament/Widgets/ChartPunctualEvent.php +++ b/app/Filament/Widgets/ChartPunctualEvent.php @@ -4,7 +4,6 @@ namespace App\Filament\Widgets; use App\Filament\Widgets\Data\HelperStatisticType; use App\Filament\Widgets\Data\LoadEvents; -// use Filament\Support\RawJs; use Filament\Widgets\ChartWidget; use Filament\Widgets\Concerns\InteractsWithPageFilters; @@ -14,8 +13,6 @@ class ChartPunctualEvent extends ChartWidget protected ?string $pollingInterval = null; - public ?string $header; - protected ?array $options = [ 'plugins' => [ 'legend' => [ @@ -25,29 +22,16 @@ class ChartPunctualEvent extends ChartWidget 'interaction' => [ 'intersect' => false, ], - // 'scales' => [ - // 'xAxes' => [ - // 'type' => 'time', - // 'time' => [ - // 'tooltipFormat' => 'MM/DD/YYYY', - // 'displayFormats' => 'HH:mm:ss', - // ], - - // ], - // ], ]; - public function getDescription(): ?string - { - return 'Events Punctual'; - } - protected function getData(): array { - $this->heading = HelperStatisticType::get($this->filters); + $this->heading = 'Events '.HelperStatisticType::get($this->filters); $data = LoadEvents::load($this->filters); + $this->description = 'Punctual '.$data['description']; + return $data; } @@ -55,69 +39,4 @@ class ChartPunctualEvent extends ChartWidget { return 'line'; } - - // protected function getOptions(): RawJs|array - // { - // return RawJs::make(<<<'JS' - // { - // plugins: { - // legend: { - // display: false - // }, - // datalabels: { - // backgroundColor: function(context) { - // return context.active ? context.dataset.backgroundColor : 'white'; - // }, - // borderColor: function(context) { - // return context.dataset.backgroundColor; - // }, - // borderRadius: function(context) { - // return context.active ? 0 : 32; - // }, - // borderWidth: 3, - // color: function(context) { - // return context.active ? 'white' : context.dataset.backgroundColor; - // }, - // font: { - // weight: 'bold' - // }, - // formatter: function(value, context) { - // value = Math.round(value * 100) / 100; - // return context.active - // ? context.dataset.label + '\n' + value + '%' - // : Math.round(value); - // }, - // offset: 8, - // padding: 5, - // textAlign: 'center' - // } - // }, - // // Core options - // aspectRatio: 5 / 3, - // layout: { - // padding: { - // bottom: 16, - // right: 40, - // left: 8, - // top: 40 - // } - // }, - // hover: { - // mode: 'index', - // intersect: false - // }, - // elements: { - // line: { - // fill: false, - // tension: 0.4 - // } - // }, - // scales: { - // y: { - // stacked: true - // } - // } - // } - // JS); - // } } diff --git a/app/Filament/Widgets/ChartPunctualPlayer.php b/app/Filament/Widgets/ChartPunctualPlayer.php index 63822a08..34ee67e3 100644 --- a/app/Filament/Widgets/ChartPunctualPlayer.php +++ b/app/Filament/Widgets/ChartPunctualPlayer.php @@ -21,6 +21,9 @@ class ChartPunctualPlayer extends ChartWidget 'display' => false, ], ], + 'interaction' => [ + 'intersect' => false, + ], ]; public function getDescription(): ?string diff --git a/app/Filament/Widgets/Data/LoadEvents.php b/app/Filament/Widgets/Data/LoadEvents.php index 0f4e4393..3137d379 100644 --- a/app/Filament/Widgets/Data/LoadEvents.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -2,7 +2,9 @@ namespace App\Filament\Widgets\Data; +use App\Models\StatistikoDetail; use App\Models\StatistikoEvent; +use App\Models\StatistikoPlayer; use Illuminate\Support\Facades\Log; class LoadEvents @@ -11,8 +13,6 @@ class LoadEvents public static function load($filter) { - // dd($filter); - if (self::$last_query) { return self::$last_query; } @@ -43,6 +43,17 @@ class LoadEvents return []; } + /** + * IF WITH PLAYER + */ + if ($tm_player_id) { + $matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray(); + + $description = ' (with '.StatistikoDetail::where('tm_player_id', (int) $tm_player_id)->value('name').')'; + + } else { + $matches_played = 0; + } /** * STATTISTIC DATA */ @@ -57,8 +68,9 @@ class LoadEvents return $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); @@ -202,6 +214,7 @@ class LoadEvents ], ], 'labels' => $labels, + 'description' => $description ?? '', ]; self::$last_query = $data; diff --git a/app/Filament/Widgets/Data/LoadPlayer.php b/app/Filament/Widgets/Data/LoadPlayer.php index c0a62975..f49b3664 100644 --- a/app/Filament/Widgets/Data/LoadPlayer.php +++ b/app/Filament/Widgets/Data/LoadPlayer.php @@ -16,25 +16,6 @@ class LoadPlayer return self::$last_query; } - // "team_position" => "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; @@ -47,6 +28,8 @@ class LoadPlayer $statistic_type = $filter['statistic_type'] ?? 0; + $accuracy = (float) $filter['accuracy']; + $similar_past_matches = $filter['similar_past_matches'] ?? 0; $start = $filter['start_date'] ?? 0; @@ -86,6 +69,23 @@ class LoadPlayer return $query->where('starttime', '<=', $end); })->first(); + if ($res == null) { + + $handicap_range = 0; + + $total_range = 0; + + } else { + + $exp_handicap = $res['exp_away'] - $res['exp_home']; + + $exp_total = $res['exp_away'] + $res['exp_home']; + + $handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy]; + + $total_range = [$exp_total - $accuracy, $exp_total + $accuracy]; + } + $labels = []; $datasets = []; foreach ($res as $key => $value) {