252 lines
11 KiB
PHP
252 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
|
use App\Actions\LoadStatisticFixturesMatchOptions;
|
|
use App\Filament\Widgets\ChartMovingAverageEvent;
|
|
use App\Filament\Widgets\ChartMovingAveragePlayer;
|
|
use App\Filament\Widgets\ChartPunctualEvent;
|
|
use App\Filament\Widgets\ChartPunctualPlayer;
|
|
use App\Filament\Widgets\StatsMedianAverage;
|
|
use App\Models\Element;
|
|
use App\Models\StatisticFixtures;
|
|
use App\Models\StatistikoDetail;
|
|
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;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Schemas\Components\Utilities\Set;
|
|
use Filament\Schemas\Schema;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
class Statistic extends BaseDashboard
|
|
{
|
|
use HasFiltersForm;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = 'phosphor-chart-line-up';
|
|
|
|
protected ?string $pollingInterval = null;
|
|
|
|
protected static ?string $title = 'Statistic';
|
|
|
|
protected int|string|array $columnSpan = [
|
|
'md' => 2,
|
|
'xl' => 3,
|
|
];
|
|
|
|
public function getHeading(): string|Htmlable|null
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function filtersForm(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Grid::make([
|
|
'default' => 2,
|
|
'sm' => 2,
|
|
'md' => 3,
|
|
'lg' => 4,
|
|
])
|
|
->columnSpanFull()
|
|
->extraAttributes([
|
|
'class' => 'bg-gray-100 dark:bg-blue-950 rounded-lg p-5 border border-gray-400 dark:border-blue-800',
|
|
])
|
|
->schema([
|
|
Select::make('league_id')
|
|
->prefixIconColor('primary')
|
|
->prefixIcon('phosphor-trophy')
|
|
->options(fn () => LoadStatisticFixturesLeaguesOptions::load(1))
|
|
->live()
|
|
->label('League')
|
|
->afterStateUpdated(function (callable $set) {
|
|
$set('match_id', null);
|
|
}),
|
|
Select::make('match_id')
|
|
->prefixIconColor('primary')
|
|
->prefixIcon('phosphor-calendar-check')
|
|
->options(function (Get $get) {
|
|
return LoadStatisticFixturesMatchOptions::load($get('league_id'));
|
|
})
|
|
->afterStateUpdated(function (callable $set) {
|
|
$set('team_id', null);
|
|
$set('tm_player_id', null);
|
|
})
|
|
->live()
|
|
->label('Events'),
|
|
Select::make('team_id')
|
|
->prefixIconColor('primary')
|
|
->prefixIcon('phosphor-users-three')
|
|
->options(function (Get $get) {
|
|
if ($get('match_id')) {
|
|
$res = StatisticFixtures::where('id', $get('match_id'))->get();
|
|
$arr = [];
|
|
foreach ($res as $value) {
|
|
$arr[] = $value->home_id;
|
|
$arr[] = $value->away_id;
|
|
}
|
|
|
|
return Element::query()->whereIn('id', $arr)->pluck('name', 'id');
|
|
}
|
|
})
|
|
->afterStateUpdated(function (callable $set) {
|
|
$set('tm_player_id', null);
|
|
})
|
|
->live()
|
|
->label('Team'),
|
|
|
|
Select::make('team_position')
|
|
->prefixIconColor('primary')
|
|
->prefixIcon('phosphor-map-pin')
|
|
->default('all')
|
|
->selectablePlaceholder(false)
|
|
->options([
|
|
'all' => 'All',
|
|
'home' => 'Home',
|
|
'away' => 'Away',
|
|
]),
|
|
|
|
Select::make('statistic_type')
|
|
->columnSpan([
|
|
'default' => 1,
|
|
'xl' => 2,
|
|
])
|
|
->prefixIconColor('primary')
|
|
->prefixIcon('phosphor-dots-three-outline')
|
|
->default('none')
|
|
->selectablePlaceholder(false)
|
|
->options([
|
|
'gls' => 'Goals',
|
|
'crn' => 'Corner',
|
|
'fls' => 'Fouls commited',
|
|
'ofs' => 'Offside',
|
|
'crd' => 'Cards',
|
|
'snt' => 'Shot on target',
|
|
'tsh' => 'Total shots',
|
|
]),
|
|
DatePicker::make('start_date')
|
|
->native(false)
|
|
->prefixIcon('phosphor-calendar')
|
|
->live()
|
|
->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')
|
|
->live()
|
|
->suffixAction(
|
|
Action::make('clear_end')
|
|
->icon('phosphor-x')
|
|
->color('gray')
|
|
->action(fn (Set $set) => $set('end_date', null))
|
|
),
|
|
Select::make('similar_past_matches')
|
|
->prefixIcon('phosphor-approximate-equals')
|
|
->suffixAction(
|
|
Action::make('iconInfo')
|
|
->color('gray')
|
|
->icon('phosphor-question')
|
|
->tooltip(fn () => $this->tooltip_similar_past_matches())
|
|
)
|
|
->default('none')
|
|
->live()
|
|
->selectablePlaceholder(false)
|
|
->options([
|
|
'none' => 'None',
|
|
'league' => 'League',
|
|
'all' => 'All Database',
|
|
]),
|
|
Slider::make('accuracy')
|
|
->hiddenLabel()
|
|
->disabled(fn (Get $get) => $get('similar_past_matches') == 'none')
|
|
// ->fillTrack()
|
|
->default(5)
|
|
->step(0.1)
|
|
->decimalPlaces(1)
|
|
->tooltips()
|
|
->range(minValue: 0, maxValue: 1)
|
|
->pips()
|
|
->live(),
|
|
Select::make('tm_player_id')
|
|
->label('Player')
|
|
->prefixIcon('icon-player')
|
|
->suffixAction(
|
|
Action::make('copyCostToPrice')
|
|
->action(function (callable $set) {
|
|
$set('tm_player_id', null);
|
|
$set('player_on_field', null);
|
|
})
|
|
->color('gray')
|
|
->icon('phosphor-x'),
|
|
)
|
|
->preload()
|
|
// ->searchable()
|
|
->options(function (Get $get) {
|
|
return StatistikoDetail::where('txodds_id', $get('team_id'))->pluck('name', 'tm_player_id');
|
|
})
|
|
->live(),
|
|
Select::make('player_on_field')
|
|
->label('Time on field')
|
|
->prefixIcon('phosphor-watch')
|
|
->default('all')
|
|
->disabled(fn (Get $get) => ! $get('tm_player_id'))
|
|
->selectablePlaceholder(false)
|
|
->options([
|
|
'all' => 'All',
|
|
'lineup' => 'Lineup',
|
|
'substituted' => 'Substituted',
|
|
])
|
|
->live(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function getFooterWidgetsColumns(): int|array
|
|
{
|
|
return [
|
|
'default' => 1,
|
|
'sm' => 2,
|
|
'lg' => 3,
|
|
'xl' => 4,
|
|
];
|
|
}
|
|
|
|
protected function getFooterWidgets(): array
|
|
{
|
|
return [
|
|
StatsMedianAverage::make(),
|
|
ChartPunctualEvent::make(),
|
|
ChartMovingAverageEvent::make(),
|
|
ChartPunctualPlayer::make(),
|
|
ChartMovingAveragePlayer::make(),
|
|
];
|
|
}
|
|
|
|
protected function tooltip_similar_past_matches(): HtmlString
|
|
{
|
|
$str = '<div class="grid grid-cols-4 gap-4 max-w-lg">';
|
|
$str .= '<div class="font-bold">None</div>';
|
|
$str .= '<div class="col-span-3">Only selected team within selected league is considered.</div>';
|
|
$str .= '<div class="font-bold">League</div>';
|
|
$str .= '<div class="col-span-3">All events in seleceted league are considered, filtered expected goal handicap and total parameter in the range of <span class="text-blue-500">Accuracy Slider</span> setting.</div>';
|
|
$str .= '<div class="font-bold">All Database</div>';
|
|
$str .= '<div class="col-span-3">Eintire database is considered, filtered expected goal handicap and total parameter in the range of the <br><span class="text-blue-500">Accuracy Slider</span> setting.</div>';
|
|
$str .= '</div>';
|
|
|
|
return new HtmlString($str);
|
|
|
|
}
|
|
}
|