Files
nuhodds_fi4/app/Filament/Pages/Statistic.php
T
2026-05-21 17:31:00 +02:00

183 lines
7.6 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Actions\LoadStatisticFixturesLeaguesOptions;
use App\Filament\Widgets\MedianAverageWidget;
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;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema;
use Illuminate\Contracts\Support\Htmlable;
class Statistic extends BaseDashboard
{
use HasFiltersForm;
protected static string|BackedEnum|null $navigationIcon = 'phosphor-chart-line-up';
protected static ?string $title = 'Statistic';
public function getHeading(): string|Htmlable|null
{
return '';
}
public function filtersForm(Schema $schema): Schema
{
return $schema
->components([
Section::make()
->compact()
->schema([
Select::make('league_id')
->prefixIcon('phosphor-trophy')
->options(fn () => LoadStatisticFixturesLeaguesOptions::load(1))
->preload()
->searchable()
->live()
->label('League')
->afterStateUpdated(function (callable $set) {
$set('team_id', null);
}),
Select::make('team_id')
->prefixIcon('icon-team')
->options(function (Get $get) {
if ($get('league_id')) {
$res = StatisticFixtures::where('league_id', $get('league_id'))->get();
$arr = [];
foreach ($res as $value) {
$arr[] = $value->home_id;
$arr[] = $value->away_id;
}
$arr = array_unique($arr);
return Element::query()->whereIn('id', $arr)->orderBy('name')->pluck('name', 'id');
}
})
->preload()
->searchable()
->label('Team'),
DatePicker::make('start_date')
->native(false)
->prefixIcon('phosphor-calendar')
->suffixAction(
Action::make('clear_start')
->icon('phosphor-x')
->color('gray')
->action(fn (Set $set) => $set('start_date', null))
),
DatePicker::make('end_date')
->native(false)
->prefixIcon('phosphor-calendar')
->suffixAction(
Action::make('clear_end')
->icon('phosphor-x')
->color('gray')
->action(fn (Set $set) => $set('end_date', null))
),
])->columns(4)
->columnSpanFull(),
Section::make()
->compact()
->schema([
Select::make('tm_player_id')
->label('Player')
->prefixIcon('icon-player')
->options([
'draft' => 'Sep Maier',
])
->preload()
->searchable()
->live(),
Select::make('team_position')
->prefixIcon('phosphor-map-pin')
->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',
]),
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' => 'Goals',
'crn' => 'Corner',
'fls' => 'Fouls commited',
'ofs' => 'Offside',
'crd' => 'Cards',
'snt' => 'Shot on target',
'tsh' => 'Total shots',
]),
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')
->live()
->selectablePlaceholder(false)
->options([
'none' => 'None',
'league' => 'League',
'all' => 'All Database',
]),
Slider::make('accuracy')
->disabled(fn (Get $get) => $get('similar_past_matches') == 'none')
->default(0.5)
->decimalPlaces(1)
->tooltips()
->fillTrack()
->range(minValue: 0, maxValue: 1),
// ->pips(),
])->columns(5)
->columnSpanFull(),
]);
}
public function update()
{
dd($this->filter);
}
protected function getFooterWidgets(): array
{
return [
MedianAverageWidget::make(),
PunctualChart::make(),
MovingAverageChart::make(),
];
}
}