254 lines
11 KiB
PHP
254 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
|
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\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,
|
|
])
|
|
->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');
|
|
}
|
|
})
|
|
->afterStateUpdated(function (callable $set) {
|
|
$set('tm_player_id', null);
|
|
})
|
|
->preload()
|
|
->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')
|
|
->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))
|
|
),
|
|
])->columns(5)
|
|
->columnSpanFull(),
|
|
Grid::make([
|
|
'default' => 2,
|
|
'sm' => 2,
|
|
'md' => 3,
|
|
'lg' => 4,
|
|
])
|
|
->schema([
|
|
Select::make('tm_player_id')
|
|
->label('Player')
|
|
->prefixIcon('icon-player')
|
|
->suffixAction(
|
|
Action::make('copyCostToPrice')
|
|
->action(function (callable $set) {
|
|
$set('tm_player_id', 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')
|
|
->selectablePlaceholder(false)
|
|
->options([
|
|
'all' => 'All',
|
|
'lineup' => 'Lineup',
|
|
'substituted' => 'Substituted',
|
|
])
|
|
->live(),
|
|
Select::make('statistic_type')
|
|
->prefixIcon('phosphor-cell-signal-full')
|
|
->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(fn () => $this->tooltip_similar_past_matches())
|
|
)
|
|
->default('none')
|
|
->live()
|
|
->selectablePlaceholder(false)
|
|
->options([
|
|
'none' => 'None',
|
|
'league' => 'League',
|
|
'all' => 'All Database',
|
|
]),
|
|
Select::make('accuracy')
|
|
->disabled(fn (Get $get) => $get('similar_past_matches') == 'none')
|
|
->default(0.5)
|
|
->options([
|
|
'0.1' => '0.1',
|
|
'0.2' => '0.2',
|
|
'0.3' => '0.3',
|
|
'0.4' => '0.4',
|
|
'0.5' => '0.5',
|
|
'0.6' => '0.6',
|
|
'0.7' => '0.7',
|
|
'0.8' => '0.8',
|
|
'0.9' => '0.9',
|
|
'1' => '1.0',
|
|
])
|
|
->native(false),
|
|
// Slider::make('accuracy')
|
|
// ->disabled(fn (Get $get) => $get('similar_past_matches') == 'none')
|
|
// ->fillTrack()
|
|
// ->default(5)
|
|
// ->step(0.1)
|
|
// ->decimalPlaces(1)
|
|
// ->tooltips()
|
|
// ->range(minValue: 0, maxValue: 1)
|
|
// ->pips(),
|
|
])->columns(5)
|
|
->columnSpanFull(),
|
|
|
|
]);
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
}
|