diff --git a/app/Actions/Statistics/EventData.php b/app/Actions/Statistics/EventData.php new file mode 100644 index 00000000..8fe54da2 --- /dev/null +++ b/app/Actions/Statistics/EventData.php @@ -0,0 +1,71 @@ +where('home_id', '=', $team_id)->get(); + break; + + case 'away': + $res = StatistikoEvent::where('league_id', $league_id)->where('away_id', '=', $team_id)->get(); + break; + + 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); + })->get(); + break; + } + + $datasets = []; + $labels = []; + + foreach ($res as $value) { + $labels[] = $value['starttime']->format('d. M.y'); + + $tmp = []; + $tmp['crd_a'] = (int) $value['crd_a']; + $tmp['crd_h'] = (int) $value['crd_h']; + $tmp['crn_a'] = (int) $value['crn_a']; + $tmp['crn_h'] = (int) $value['crn_h']; + $tmp['fls_a'] = (int) $value['fls_a']; + $tmp['fls_h'] = (int) $value['fls_h']; + $tmp['gls_a'] = (int) $value['gls_a']; + $tmp['gls_h'] = (int) $value['gls_h']; + $tmp['ofs_a'] = (int) $value['ofs_a']; + $tmp['ofs_h'] = (int) $value['ofs_h']; + $tmp['snt_a'] = (int) $value['snt_a']; + $tmp['snt_h'] = (int) $value['snt_h']; + $tmp['tsh_a'] = (int) $value['tsh_a']; + $tmp['tsh_h'] = (int) $value['tsh_h']; + + $tmp['exp_handicap'] = (float) $value['exp_handicap']; + $tmp['exp_total'] = (float) $value['exp_total']; + $tmp['exp_away'] = (float) $value['expgoalsaway_value']; + $tmp['exp_home'] = (float) $value['expgoalshome_value']; + + $datasets[] = $tmp; + } + + return ['lables' => $labels, 'datasets' => $datasets]; + + } +} diff --git a/app/Actions/Statistics/StatisticEvents.php b/app/Actions/Statistics/StatisticEvents.php new file mode 100644 index 00000000..7257d025 --- /dev/null +++ b/app/Actions/Statistics/StatisticEvents.php @@ -0,0 +1,44 @@ + "away" + "similar_past_matches" => "none" + "statistic_type" => "none" + "accuracy" => 0.5 + "league_id" => "87" + "team_id" => null + "startDate" => null + "endDate" => null + "palyer_id" => null + + 'sport_id', + 'league_id', + 'home_id', + 'away_id', + 'starttime', + */ + + // $res = StatistikoEvent::where('league_id', $league_id)->get(); + // $result = DB::connection('mongodb') + // ->table('movies') + // ->where('league_id', $league_id) + // ->orWhere('home_id', $home_id) + // ->get(); + + } +} diff --git a/app/Filament/Pages/Statistic.php b/app/Filament/Pages/Statistic.php index da07cbe9..4dd9ed15 100644 --- a/app/Filament/Pages/Statistic.php +++ b/app/Filament/Pages/Statistic.php @@ -3,9 +3,13 @@ namespace App\Filament\Pages; use App\Actions\LoadStatisticFixturesLeaguesOptions; +use App\Actions\Statistics\StatisticEvents; +use App\Filament\Widgets\MovingAverageChart; +use App\Filament\Widgets\PunctualChart; use App\Models\Element; use App\Models\StatisticFixtures; use BackedEnum; +use Filament\Actions\Action; use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\Select; use Filament\Forms\Components\Slider; @@ -23,7 +27,20 @@ class Statistic extends BaseDashboard protected static ?string $title = 'Statistic'; - protected int|string|array $columnSpan = 'full'; + protected static array $types = [ + 'gls' => 'Goals', + 'crn' => 'Corner', + 'fls' => 'Fouls commited', + 'ofs' => 'Offside', + 'crd' => 'Cards', + 'snt' => 'Shot on target', + 'tsh' => 'Total shots', + ]; + + public function getColumns(): int|array + { + return 2; + } public function filtersForm(Schema $schema): Schema { @@ -77,15 +94,27 @@ class Statistic extends BaseDashboard ->live(), Select::make('team_position') ->prefixIcon('phosphor-map-pin') - ->default('home') + ->suffixAction( + Action::make('iconInfo') + ->color('gray') + ->icon('phosphor-question') + ->tooltip('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.') + ) + ->default('all') ->selectablePlaceholder(false) ->options([ + 'all' => 'All', 'home' => 'Home', 'away' => 'Away', - 'all' => 'All', ]), Select::make('similar_past_matches') ->prefixIcon('phosphor-align-center-horizontal') + ->suffixAction( + Action::make('iconInfo') + ->color('gray') + ->icon('phosphor-question') + ->tooltip('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.') + ) ->default('none') ->selectablePlaceholder(false) ->options([ @@ -95,10 +124,16 @@ class Statistic extends BaseDashboard ]), Select::make('statistic_type') ->prefixIcon('phosphor-cell-signal-full') + ->suffixAction( + Action::make('iconInfo') + ->color('gray') + ->icon('phosphor-question') + ->tooltip('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.') + ) ->default('none') ->selectablePlaceholder(false) ->options([ - 'gls' => 'Gouls', + 'gls' => 'Goals', 'crn' => 'Corner', 'fls' => 'Fouls commited', 'ofs' => 'Offside', @@ -117,4 +152,27 @@ class Statistic extends BaseDashboard ->pips(), ]); } + + protected function getFooterWidgets(): array + { + + $data = StatisticEvents::load($this->filters); + + $type = self::$types[$this->filters['statistic_type']]; + + // $data = [ + // 'datasets' => [ + // [ + // 'label' => 'test', + // 'data' => [0, 10, 5, 2, 21, 32, 45, 74, 65, 45, 77, 89], + // ], + // ], + // 'labels' => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], + // ]; + + return [ + MovingAverageChart::make(['filters' => $data, 'header' => $type.' Punctual']), + PunctualChart::make(['filters' => $data, 'header' => $type.' Moving Avverage']), + ]; + } } diff --git a/app/Filament/Widgets/MovingAverageChart.php b/app/Filament/Widgets/MovingAverageChart.php new file mode 100644 index 00000000..b3129cd8 --- /dev/null +++ b/app/Filament/Widgets/MovingAverageChart.php @@ -0,0 +1,24 @@ +heading = $this->header; + + return $this->filters; + } + + protected function getType(): string + { + return 'line'; + } +} diff --git a/app/Filament/Widgets/StatisticChart.php b/app/Filament/Widgets/PunctualChart.php similarity index 54% rename from app/Filament/Widgets/StatisticChart.php rename to app/Filament/Widgets/PunctualChart.php index 4f930fde..b0ee4958 100644 --- a/app/Filament/Widgets/StatisticChart.php +++ b/app/Filament/Widgets/PunctualChart.php @@ -4,15 +4,17 @@ namespace App\Filament\Widgets; use Filament\Widgets\ChartWidget; -class StatisticChart extends ChartWidget +class PunctualChart extends ChartWidget { - protected ?string $heading = 'Statistic Chart'; + public ?array $filters = []; + + public ?string $header; protected function getData(): array { - return [ - // - ]; + $this->heading = $this->header; + + return $this->filters; } protected function getType(): string diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index d8742105..b0e1a39e 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -5,7 +5,6 @@ namespace App\Providers\Filament; // use Agencetwogether\HooksHelper\HooksHelperPlugin; use App\Filament\Exports\BetfairExporter; use App\Filament\Pages\Statistic; -use App\Filament\Widgets\StatisticChart; use App\Http\Middleware\RecordUserActivity; use Awcodes\LightSwitch\Enums\Alignment; use Awcodes\LightSwitch\LightSwitchPlugin; @@ -85,7 +84,7 @@ class AdminPanelProvider extends PanelProvider ->viteTheme('resources/css/filament/admin/theme.css') ->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources') ->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages') - ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets') + // ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets') ->discoverClusters(in: app_path('Filament/Clusters'), for: 'App\\Filament\\Clusters') ->maxContentWidth(Width::ScreenTwoExtraLarge) ->breadcrumbs(false) @@ -100,9 +99,7 @@ class AdminPanelProvider extends PanelProvider ->pages([ Statistic::class, ]) - ->widgets([ - StatisticChart::class, - ]) + ->widgets([]) ->middleware([ EncryptCookies::class, AddQueuedCookiesToResponse::class,