changes Ubaldo before Logomatic

This commit is contained in:
salam committed 2026-10-07 04:52:23 +02:00
1 parent 498660e9cc
commit f9e8b17d58
11 files changed
+607 -843

No files matched your search

+3 -1
View File
@@ -2,7 +2,6 @@
namespace App\Actions; namespace App\Actions;
use App\Models\SofaScoreCategory;
use App\Models\SofaScoreTournament; use App\Models\SofaScoreTournament;
use App\Models\StatisticFixtures; use App\Models\StatisticFixtures;
@@ -20,6 +19,9 @@ class LoadSofaScoreCategory
foreach ($res as $value) { foreach ($res as $value) {
$arr[$value->sofa_score_category_id] = $value->sofascore_category->name; $arr[$value->sofa_score_category_id] = $value->sofascore_category->name;
} }
asort($arr);
return $arr; return $arr;
} }
} }
+389 -377
View File
@@ -26,7 +26,7 @@ use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Utilities\Get; use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set; use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema; use Filament\Schemas\Schema;
use Filament\Support\Enums\Size; use Filament\Support\Enums\Alignment;
use Filament\Support\RawJs; use Filament\Support\RawJs;
use Illuminate\Contracts\Support\Htmlable; use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString; use Illuminate\Support\HtmlString;
@@ -37,6 +37,8 @@ class Statistic extends BaseDashboard
protected static string|BackedEnum|null $navigationIcon = 'phosphor-chart-line-up'; protected static string|BackedEnum|null $navigationIcon = 'phosphor-chart-line-up';
protected ?Alignment $headerActionsAlignment = Alignment::End;
protected string $view = 'filament.pages.statistic'; protected string $view = 'filament.pages.statistic';
protected ?string $pollingInterval = null; protected ?string $pollingInterval = null;
@@ -82,34 +84,11 @@ class Statistic extends BaseDashboard
return ''; return '';
} }
// protected function getHeaderActions(): array
// {
// return [
// Action::make('esc')
// ->label('Reset')
// ->icon('phosphor-x-circle')
// ->color('gray')
// ->keyBindings(['esc'])
// ->action('resetFilters'),
// Action::make('openDispatcherBoard')
// ->modalHeading('')
// ->label('Calculate')
// ->icon('icon-player')
// ->color(fn (): string => $this->filters['team_id'] ? 'primary' : 'gray')
// ->disabled(fn (): string => $this->filters['team_id'] ? false : true)
// ->slideOver()
// ->slideOverPosition(SlideOverPosition::Start)
// ->modalWidth(Width::Screen)
// ->modalSubmitAction(false)
// ->modalCancelAction(false)
// ->modalContent(fn (): View => view('livewire.board-dispatcher-modal-wrapper', ['filters' => $this->filters])),
// ];
// }
public function filtersForm(Schema $schema): Schema public function filtersForm(Schema $schema): Schema
{ {
return $schema return $schema
->components([ ->components([
// change sport TODO
// ToggleButtons::make('status') // ToggleButtons::make('status')
// ->columnSpanFull() // ->columnSpanFull()
// ->hiddenLabel() // ->hiddenLabel()
@@ -136,365 +115,21 @@ class Statistic extends BaseDashboard
->columnSpanFull() ->columnSpanFull()
->schema([ ->schema([
Hidden::make('seasonmode'), Hidden::make('seasonmode'),
Select::make('sofascore_category_id') $this->selectSofascoreCategoryId(),
->live() $this->selectLeagueId(),
->preload() $this->selectMatchId(),
->searchable(false) $this->selectTeamId(),
->prefixIconColor(fn (Get $get): string => $get('sofascore_category_id') ? 'success' : 'danger') $this->selectTeamPosition(),
->prefixIcon('phosphor-globe')
->hiddenLabel()
->options(fn () => LoadSofaScoreCategory::load())
->placeholder('Select Country')
->afterStateUpdated(function (callable $set, $state) {
$set('seasonmode', SofaScoreCategory::where('id', $state)->value('season_mode'));
$set('league_id', null);
$set('match_id', null);
$set('team_id', null);
$set('ss_player_id', null);
$set('season', null);
}),
Select::make('league_id')
->live()
->preload()
->prefixIconColor(fn (Get $get): string => $get('league_id') ? 'success' : 'danger')
->prefixIcon('phosphor-trophy')
->hiddenLabel()
->options(fn (Get $get) => LoadStatisticFixturesLeaguesOptions::load($get('sofascore_category_id')))
->placeholder('Select League')
->afterStateUpdated(function (callable $set) {
$set('match_id', null);
$set('team_id', null);
$set('ss_player_id', null);
$this->dispatch('reset-tab');
}),
Select::make('match_id')
->live()
->hiddenLabel()
->columnSpan(fn (Get $get) => $get('similar_past_matches') != 'none' ? 2 : 1)
->prefixIconColor(fn (Get $get): string => $get('match_id') ? 'success' : 'danger')
->prefixIcon('phosphor-calendar-check')
->options(function (Get $get) {
return LoadStatisticFixturesMatchOptions::load($get('league_id'));
})
->afterStateUpdated(function (callable $set) {
$set('team_id', null);
$set('ss_player_id', null);
$this->dispatch('reset-tab');
})
->placeholder('Select Event'),
Action::make('esc')
->hiddenLabel()
->visible(fn (Get $get) => $get('similar_past_matches') != 'none')
->tooltip('Clear All (esc)')
->icon('phosphor-x-circle')
->color('danger')
->keyBindings(['esc'])
->size(Size::Medium)
->outlined()
->action('resetFilters'),
Select::make('team_id')
->live()
->hiddenLabel()
->prefixIconColor(function (Get $get): string {
if ($get('team_id')) {
return 'success';
} elseif ($get('similar_past_matches') != 'none') {
return 'gray';
} else {
return 'danger';
}
})
->prefixIcon('phosphor-users')
->suffixAction(Action::make('reset')
->icon('phosphor-x-circle')
->tooltip('Clear Team')
->action(fn (callable $set) => $set('team_id', null))
->color(fn (Get $get): string => $get('team_id') != 0 ? 'danger' : 'gray'))
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->options(function (Get $get) {
if ($get('match_id')) {
$res = StatisticFixtures::where('id', $get('match_id'))->first();
$arr = [];
if ($res) {
$arr[$res->home_id] = SofaScoreRosa::query()->where('ss_team_id', $res->home_id)->value('ss_team_name');
$arr[$res->away_id] = SofaScoreRosa::query()->where('ss_team_id', $res->away_id)->value('ss_team_name');
}
return $arr;
}
})
->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
$set('team_position', null);
$this->dispatch('reset-tab');
})
->placeholder('Select Team'),
Select::make('team_position')
->live()
->hiddenLabel()
->placeholder('Select Team Position')
->prefix('TP')
->prefixAction(
Action::make('iconInfo')
->color('success')
->icon('phosphor-question')
->tooltip(fn () => 'Team Position')
)
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->default('all')
->selectablePlaceholder(false)
->options([
'all' => 'All',
'home' => 'Home',
'away' => 'Away',
])->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
}),
]),
Grid::make([
'default' => 1,
'sm' => 3,
'md' => 4,
])
->columnSpanFull()
->schema([
Select::make('statistic_type')
->live()
->hiddenLabel()
->allowHtml()
->placeholder('Statistic Type')
->prefixIconColor('success')
->prefixIcon(function (Get $get) {
return match ($get('statistic_type')) {
'gls' => 'phosphor-soccer-ball',
'crn' => 'phosphor-angle',
'fls' => 'phosphor-first-aid-kit',
'ofs' => 'phosphor-arrow-fat-lines-right',
'crd' => 'phosphor-cards',
'snt' => 'phosphor-target',
'tsh' => 'phosphor-chart-polar',
default => 'phosphor-soccer-ball',
};
})
->default('gls')
->selectablePlaceholder(false)
->options([
'gls' => 'Goals',
'crn' => 'Corner',
'fls' => 'Fouls Commited',
'ofs' => 'Offside',
'crd' => 'Cards',
'snt' => 'Shots On Target',
'tsh' => 'Total Shots',
]),
/************************
* SMP
************************/
Select::make('similar_past_matches')
->live()
// ->columnSpan(2)
->hiddenLabel()
->hidden(fn (Get $get) => $get('team_id') != null)
->columnSpan(fn (Get $get) => $get('similar_past_matches') != 'none' ? 2 : 1)
->suffixAction(Action::make('reset')
->icon('phosphor-x-circle')
->tooltip('Clear SMP')
->action(fn (callable $set) => $set('similar_past_matches', 'none'))
->color(fn (Get $get): string => $get('similar_past_matches') != 'none' ? 'danger' : 'gray'))
->placeholder('Similar Past Matches')
->suffix(fn (Get $get): string|HtmlString => $get('similar_past_matches') != 'none' ? new HtmlString('<div class="text-center w-24 font-bold rounded p-1 bg-blue-600 dark:bg-blue-700 text-white dark:text-gray-300">± '.$get('accuracy').'</div>') : '')
->prefix('SPM')
->prefixAction(
Action::make('iconInfo')
->icon('phosphor-question')
->color(fn (Get $get): string => $get('similar_past_matches') != 'none' ? 'success' : 'danger')
->tooltip(fn () => $this->tooltip_similar_past_matches())
)
->default('none')
->selectablePlaceholder(false)
->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
$set('team_position', null);
$this->dispatch('reset-tab');
})
->options([
'none' => 'None',
'league' => 'League',
'all' => 'All Database',
]),
/************************
* SLIDER
************************/
Slider::make('accuracy')
->live()
->hiddenLabel()
->hidden(fn (Get $get) => $get('similar_past_matches') == 'none')
->fillTrack()
->minValue(0)
->maxValue(0.25)
->default(0.125)
->step(0.025)
->decimalPlaces(3)
->pips()
->pipsFormatter(RawJs::make(<<<'JS'
`${$value.toFixed(2)}`
JS)),
/************************
* PLAYER
************************/
Select::make('ss_player_id')
->live()
->hiddenLabel()
->allowHtml()
->columnSpan(2)
->placeholder('Player')
->visible(fn (Get $get) => $get('team_id'))
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->prefixIconColor(fn (Get $get): string => $get('similar_past_matches') == 'none' ? 'success' : '')
->prefixIcon('icon-player')
->preload()
->searchable()
->extraAttributes(fn () => [
'id' => 'player_selector',
'style' => 'width: 100%;',
])
->suffixAction(
Action::make('iconInfo')
->icon('phosphor-question')
->color('success')
->tooltip(fn () => $this->tooltip_player_info())
)
->options(function (Get $get) {
$team_id = $get('team_id');
$team_position = $get('team_position');
$sofascore_category_id = $get('sofascore_category_id');
$season = $get('season');
$seasonmode = $get('seasonmode');
return LoadPlayerSelection::load($team_id, $team_position, $sofascore_category_id, $season, $seasonmode);
}),
Select::make('player_on_field')
->live()
->hiddenLabel()
->placeholder('Time on field')
->prefixIcon('phosphor-watch')
->default('all')
->hidden(fn (Get $get) => ! $get('ss_player_id'))
->prefixIconColor('success')
->selectablePlaceholder(false)
->options([
'all' => 'All',
'lineup' => 'Lineup',
'substituted' => 'Substituted',
'notplayed' => 'Not Played',
]),
]),
Grid::make([
'default' => 7,
'sm' => 7,
])
->columnSpanFull()
->schema([
Radio::make('season_or_date')
->live()
->extraAttributes([
'class' => 'radio-statistic-group',
])
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->columnSpan(2)
->inline()
->default('season')
->hiddenLabel()
->options([
'season' => 'Season',
'date' => 'Date',
]),
/************************
* SEASON full time
************************/
Select::make('season')
->live()
->columnSpan(2)
->hiddenLabel()
->multiple()
->placeholder('Current Season')
->prefixIconColor('success')
->visible(fn (Get $get) => $get('seasonmode'))
->hidden(fn (Get $get) => $get('seasonmode') == 'halfyear' || $get('season_or_date') == 'date' || $get('similar_past_matches') != 'none')
->prefixIcon('phosphor-calendar-star')
->options([
'2026' => '2026',
'2025' => '2025',
'2024' => '2024',
])
->afterStateUpdated(function (callable $set, Get $get) {
$set('ss_player_id', null);
}),
/************************
* SEASON half time
************************/
Select::make('season')
->live()
->columnSpan(2)
->hiddenLabel()
->multiple()
->placeholder('Current Season')
->prefixIconColor('success')
->visible(fn (Get $get) => $get('seasonmode'))
->hidden(fn (Get $get) => $get('seasonmode') == 'fullyear' || $get('season_or_date') == 'date' || $get('similar_past_matches') != 'none')
->prefixIcon('phosphor-calendar-star')
->options([
'26/27' => '26/27',
'25/26' => '25/26',
'24/25' => '24/25',
])
->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
}),
/************************
* DATE PICKER
************************/
DatePicker::make('start_date')
->live()
->hiddenLabel()
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor(fn (Get $get): string => $get('start_date') ? 'success' : 'primary')
->prefixIcon('phosphor-calendar')
->prefix('Start')
->suffixAction(
Action::make('clear_start')
->icon('phosphor-x')
->color('gray')
->action(fn (Set $set) => $set('start_date', null))
),
DatePicker::make('end_date')
->live()
->hiddenLabel()
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor(fn (Get $get): string => $get('end_date') ? 'success' : 'primary')
->prefixIcon('phosphor-calendar')
->prefix('End')
->suffixAction(
Action::make('clear_end')
->icon('phosphor-x')
->color('gray')
->action(fn (Set $set) => $set('end_date', null))
),
Actions::make([ Actions::make([
Action::make('esc') Action::make('esc')
->hiddenLabel() ->hiddenLabel()
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none') ->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->tooltip('Clear All (esc)') ->tooltip('Clear All (esc)')
->icon('phosphor-x-circle') ->icon('phosphor-x')
->color(fn (Get $get) => $get('sofascore_category_id') ? 'danger' : 'gray') ->color('gray')
->keyBindings(['esc']) ->keyBindings(['esc'])
->outlined() ->outlined()
->size(Size::Medium)
->action('resetFilters'), ->action('resetFilters'),
Action::make('copy') Action::make('copy')
->hiddenLabel() ->hiddenLabel()
@@ -502,7 +137,6 @@ class Statistic extends BaseDashboard
->visible(fn (Get $get) => $get('team_id')) ->visible(fn (Get $get) => $get('team_id'))
->tooltip('Copy data for pasting into spreadsheet') ->tooltip('Copy data for pasting into spreadsheet')
->color('success') ->color('success')
->size(Size::Medium)
->outlined() ->outlined()
->icon('phosphor-copy') ->icon('phosphor-copy')
->action(function ($livewire) { ->action(function ($livewire) {
@@ -519,6 +153,30 @@ class Statistic extends BaseDashboard
}), }),
]), ]),
]), ]),
Grid::make([
'default' => 1,
'sm' => 3,
'md' => 4,
])
->columnSpanFull()
->schema([
$this->selectStatisticType(),
$this->selectSimilarPastMatches(),
$this->sliderAccuracy(),
$this->selectPlayerId(),
$this->selectPlayerOnField(),
]),
Grid::make([
'default' => 8,
'sm' => 8,
])
->columnSpanFull()
->schema([
$this->radioSeasonOrDate(),
$this->selectSeason(),
$this->datePickerStartDate(),
$this->datePickerEndDate(),
]),
]); ]);
} }
@@ -640,4 +298,358 @@ class Statistic extends BaseDashboard
return new HtmlString($str); return new HtmlString($str);
} }
/**
* FROM HERE ONLY FORM FILTERS
* Komplexe Filter in eigene Methoden auslagern (faster)
*/
private function selectSofascoreCategoryId(): Select
{
return Select::make('sofascore_category_id')
->live()
->preload()
->searchable(false)
->prefixIconColor(fn (Get $get): string => $get('sofascore_category_id') ? 'success' : 'danger')
->prefixIcon('phosphor-globe')
->hiddenLabel()
->options(fn () => LoadSofaScoreCategory::load())
->placeholder('Select Country')
->afterStateUpdated(function (callable $set, $state) {
$set('seasonmode', SofaScoreCategory::where('id', $state)->value('season_mode'));
$set('league_id', null);
$set('match_id', null);
$set('team_id', null);
$set('ss_player_id', null);
$set('season', null);
});
}
private function selectLeagueId(): Select
{
return Select::make('league_id')
->live()
->preload()
->prefixIconColor(fn (Get $get): string => $get('league_id') ? 'success' : 'danger')
->prefixIcon('phosphor-trophy')
->hiddenLabel()
->options(fn (Get $get) => LoadStatisticFixturesLeaguesOptions::load($get('sofascore_category_id')))
->placeholder('Select League')
->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
$set('match_id', null);
$set('team_id', null);
$this->dispatch('reset-tab');
});
}
private function selectMatchId(): Select
{
return Select::make('match_id')
->live()
->hiddenLabel()
->columnSpan(fn (Get $get) => $get('similar_past_matches') != 'none' ? 2 : 1)
->prefixIconColor(fn (Get $get): string => $get('match_id') ? 'success' : 'danger')
->prefixIcon('phosphor-calendar-check')
->options(function (Get $get) {
return LoadStatisticFixturesMatchOptions::load($get('league_id'));
})
->afterStateUpdated(function (callable $set) {
$set('team_id', null);
$set('ss_player_id', null);
$this->dispatch('reset-tab');
})
->placeholder('Select Event');
}
private function selectTeamId(): Select
{
return Select::make('team_id')
->live()
->hiddenLabel()
->prefixIconColor(function (Get $get): string {
if ($get('team_id')) {
return 'success';
} elseif ($get('similar_past_matches') != 'none') {
return 'gray';
} else {
return 'danger';
}
})
->prefixIcon('phosphor-users')
->suffixAction(Action::make('reset')
->icon('phosphor-x')
->tooltip('Clear Team')
->action(fn (callable $set) => $set('team_id', 0).$set('ss_player_id', null))
->color('gray'))
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->options(function (Get $get) {
if ($get('match_id')) {
$res = StatisticFixtures::where('id', $get('match_id'))->first();
$arr = [];
if ($res) {
$arr[$res->home_id] = SofaScoreRosa::query()->where('ss_team_id', $res->home_id)->value('ss_team_name');
$arr[$res->away_id] = SofaScoreRosa::query()->where('ss_team_id', $res->away_id)->value('ss_team_name');
}
return $arr;
}
})
->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
$set('team_position', 'all');
$this->dispatch('reset-tab');
})
->placeholder('Select Team');
}
private function selectTeamPosition(): Select
{
return Select::make('team_position')
->live()
->hiddenLabel()
->placeholder('Select Team Position')
->prefix('TP')
->prefixAction(
Action::make('iconInfo')
->color('success')
->icon('phosphor-question')
->tooltip(fn () => 'Team Position')
)
->visible(fn (Get $get) => $get('team_id'))
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->default('all')
->selectablePlaceholder(false)
->options([
'all' => 'All',
'home' => 'Home',
'away' => 'Away',
])->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
});
}
private function selectStatisticType(): Select
{
return Select::make('statistic_type')
->live()
->hiddenLabel()
->allowHtml()
->placeholder('Statistic Type')
->prefixIconColor('success')
->prefixIcon(function (Get $get) {
return match ($get('statistic_type')) {
'gls' => 'phosphor-soccer-ball',
'crn' => 'phosphor-angle',
'fls' => 'phosphor-first-aid-kit',
'ofs' => 'phosphor-arrow-fat-lines-right',
'crd' => 'phosphor-cards',
'snt' => 'phosphor-target',
'tsh' => 'phosphor-chart-polar',
default => 'phosphor-soccer-ball',
};
})
->default('gls')
->selectablePlaceholder(false)
->options([
'gls' => 'Goals',
'crn' => 'Corner',
'fls' => 'Fouls Commited',
'ofs' => 'Offside',
'crd' => 'Cards',
'snt' => 'Shots On Target',
'tsh' => 'Total Shots',
]);
}
private function selectSimilarPastMatches(): Select
{
return Select::make('similar_past_matches')
->live()
// ->columnSpan(2)
->hiddenLabel()
->hidden(fn (Get $get) => $get('team_id') != null)
->columnSpan(fn (Get $get) => $get('similar_past_matches') != 'none' ? 2 : 1)
->suffixAction(Action::make('reset')
->icon('phosphor-x')
->tooltip('Clear SMP')
->action(fn (callable $set) => $set('similar_past_matches', 'none'))
->color('gray'))
->placeholder('Similar Past Matches')
->suffix(fn (Get $get): string|HtmlString => $get('similar_past_matches') != 'none' ? new HtmlString('<div class="text-center w-24 font-bold rounded p-1 bg-blue-600 dark:bg-blue-700 text-white dark:text-gray-300">± '.$get('accuracy').'</div>') : '')
->prefix('SPM')
->prefixAction(
Action::make('iconInfo')
->icon('phosphor-question')
->color(fn (Get $get): string => $get('similar_past_matches') != 'none' ? 'success' : 'danger')
->tooltip(fn () => $this->tooltip_similar_past_matches())
)
->default('none')
->selectablePlaceholder(false)
->afterStateUpdated(function (callable $set) {
$set('ss_player_id', null);
$set('team_position', null);
$this->dispatch('reset-tab');
})
->options([
'none' => 'None',
'league' => 'League',
'all' => 'All Database',
]);
}
private function sliderAccuracy(): Slider
{
return Slider::make('accuracy')
->live()
->hiddenLabel()
->hidden(fn (Get $get) => $get('similar_past_matches') == 'none')
->fillTrack()
->minValue(0)
->maxValue(0.25)
->default(0.125)
->step(0.025)
->decimalPlaces(3)
->pips()
->pipsFormatter(RawJs::make(<<<'JS'
`${$value.toFixed(2)}`
JS));
}
private function selectPlayerId(): Select
{
return Select::make('ss_player_id')
->live()
->hiddenLabel()
->allowHtml()
->columnSpan(2)
->placeholder('Player')
->visible(fn (Get $get) => $get('team_id'))
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->prefixIconColor(fn (Get $get): string => $get('similar_past_matches') == 'none' ? 'success' : '')
->prefixIcon('icon-player')
->preload()
->searchable()
->extraAttributes(fn () => [
'id' => 'player_selector',
'style' => 'width: 100%;',
])
->suffixAction(
Action::make('iconInfo')
->icon('phosphor-question')
->color('success')
->tooltip(fn () => $this->tooltip_player_info())
)
->options(function (Get $get) {
$team_id = $get('team_id');
$team_position = $get('team_position');
$sofascore_category_id = $get('sofascore_category_id');
$season = $get('season');
$seasonmode = $get('seasonmode');
return LoadPlayerSelection::load($team_id, $team_position, $sofascore_category_id, $season, $seasonmode);
});
}
private function selectPlayerOnField(): Select
{
return Select::make('player_on_field')
->live()
->hiddenLabel()
->placeholder('Time on field')
->prefixIcon('phosphor-watch')
->default('all')
->visible(fn (Get $get) => $get('ss_player_id'))
->prefixIconColor('success')
->selectablePlaceholder(false)
->options([
'all' => 'All',
'lineup' => 'Lineup',
'substituted' => 'Substituted',
'notplayed' => 'Not Played',
]);
}
private function radioSeasonOrDate(): Radio
{
return Radio::make('season_or_date')
->live()
->extraAttributes([
'class' => 'radio-statistic-group',
])
->visible(fn (Get $get) => $get('team_id'))
->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->columnSpan(2)
->inline()
->default('season')
->hiddenLabel()
->options([
'season' => 'Season',
'date' => 'Date',
]);
}
private function selectSeason(): Select
{
return Select::make('season')
->live()
->columnSpan(2)
->hiddenLabel()
->multiple()
->placeholder('Current Season')
->prefixIconColor('success')
->visible(fn (Get $get) => $get('team_id'))
->hidden(fn (Get $get) => $get('season_or_date') == 'date' || $get('similar_past_matches') != 'none')
->prefixIcon('phosphor-calendar-star')
->options(function (Get $get) {
if ($get('seasonmode') == 'halfyear') {
return ['26/27' => '26/27', '25/26' => '25/26', '24/25' => '24/25'];
} else {
return ['2026' => '2026', '2025' => '2025', '2024' => '2024'];
}
})
->afterStateUpdated(function (callable $set, Get $get) {
$set('ss_player_id', null);
});
}
private function datePickerStartDate(): DatePicker
{
return DatePicker::make('start_date')
->live()
->hiddenLabel()
->columnSpan(2)
->visible(fn (Get $get) => $get('team_id'))
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor(fn (Get $get): string => $get('start_date') ? 'success' : 'primary')
->prefixIcon('phosphor-calendar')
->prefix('Start')
->suffixAction(
Action::make('clear_start')
->icon('phosphor-x')
->color('gray')
->action(fn (Set $set) => $set('start_date', null))
);
}
private function datePickerEndDate(): DatePicker
{
return DatePicker::make('end_date')
->live()
->hiddenLabel()
->columnSpan(2)
->visible(fn (Get $get) => $get('team_id'))
->hidden(fn (Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor(fn (Get $get): string => $get('end_date') ? 'success' : 'primary')
->prefixIcon('phosphor-calendar')
->prefix('End')
->suffixAction(
Action::make('clear_end')
->icon('phosphor-x')
->color('gray')
->action(fn (Set $set) => $set('end_date', null))
);
}
} }
@@ -8,12 +8,14 @@ use App\Models\StatistikoEvent;
class AverageTeamSeason class AverageTeamSeason
{ {
public static function load(array &$expectations, array $filter) public static function load(array &$expectations, array $filter, object $match)
{ {
$tournament_id = (int) $filter['league_id'] ?? 0; $tournament_id = (int) $filter['league_id'] ?? 0;
$team_position = $filter['team_position']; $team_position = $filter['team_position'];
$team_id = (int) $filter['team_id'] ?? 0; $team_id = (int) $filter['team_id'] ?? 0;
$seasonmode = $filter['seasonmode']; $seasonmode = $filter['seasonmode'];
$home_id = $match->home_id;
$away_id = $match->away_id;
$active_season = GetSeason::active($seasonmode); $active_season = GetSeason::active($seasonmode);
// Box 2 // Box 2
@@ -23,16 +25,9 @@ class AverageTeamSeason
$res = StatistikoEvent::where('league_id', $tournament_id) $res = StatistikoEvent::where('league_id', $tournament_id)
->when($active_season, function ($query) use ($active_season) { ->when($active_season, function ($query) use ($active_season) {
return $query->where('season', $active_season); return $query->where('season', $active_season);
})->when($team_id, function ($query) use ($team_position, $team_id) { })->when($team_id, function ($query) use ($team_id) {
switch ($team_position) { return $query->orWhere('home_id', $team_id)
case 'home': ->orWhere('away_id', '=', $team_id);
return $query->where('home_id', $team_id);
case 'away':
return $query->where('away_id', $team_id);
default:
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
}
})->get(); })->get();
$result = []; $result = [];
@@ -44,32 +39,40 @@ class AverageTeamSeason
// 2) la media dei falli di tutte le partite giocate nel campionato Brasiliano // 2) la media dei falli di tutte le partite giocate nel campionato Brasiliano
// (esempio 6 giornate giocate = 60 partite quindi 120 squadre, quindi 120 dati tipo 17-12-12-15-8-15-13-21-..., // (esempio 6 giornate giocate = 60 partite quindi 120 squadre, quindi 120 dati tipo 17-12-12-15-8-15-13-21-...,
// quindi la media di questi 120 dati) // quindi la media di questi 120 dati)
foreach ($res as $val) { foreach ($res as $val) {
if ($team_position == 'home' && $team_id == $val->home_id) { ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a); ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_h, $val->fls_a); ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_h, $val->ofs_a); ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_h, $val->crd_a); ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_h, $val->snt_a); ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_h, $val->tsh_a);
} elseif ($team_position == 'away' && $team_id == $val->away_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
} else {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
}
} }
// foreach ($res as $val) {
// if ($team_position == 'home' && $team_id == $val->home_id) {
// ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a);
// ExpectationAverage::filter($result, 'team', 'fls', $val->fls_h, $val->fls_a);
// ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_h, $val->ofs_a);
// ExpectationAverage::filter($result, 'team', 'crd', $val->crd_h, $val->crd_a);
// ExpectationAverage::filter($result, 'team', 'snt', $val->snt_h, $val->snt_a);
// ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_h, $val->tsh_a);
// } elseif ($team_position == 'away' && $team_id == $val->away_id) {
// ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
// ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
// ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
// ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
// ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
// ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
// } else {
// ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
// ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
// ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
// ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
// ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
// ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
// }
// }
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh']; $bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
if ($result) { if ($result) {
foreach ($bets as $bet) { foreach ($bets as $bet) {
@@ -40,7 +40,7 @@ class LoadEventsBoxes
*/ */
if ($team_id != 0 && $similar_past_matches == 'none') { if ($team_id != 0 && $similar_past_matches == 'none') {
AverageTeam::load($expectations, $filter); AverageTeam::load($expectations, $filter);
AverageTeamSeason::load($expectations, $filter); AverageTeamSeason::load($expectations, $filter, $match);
AverageLeagueSeason::load($expectations, $filter); AverageLeagueSeason::load($expectations, $filter);
} }
+9 -2
View File
@@ -32,11 +32,18 @@ class BoxesBettypeAll extends StatsOverviewWidget
protected function getStats(): array protected function getStats(): array
{ {
$data = LoadEventsBoxes::load($this->filters, false);
$similar_past_matches = $this->filters['similar_past_matches']; $similar_past_matches = $this->filters['similar_past_matches'];
$team_position = $this->filters['team_position']; $team_position = $this->filters['team_position'];
$team_id = (int) $this->filters['team_id'] ?? 0;
if (! $team_id && $similar_past_matches == 'none') {
return [];
}
$data = LoadEventsBoxes::load($this->filters, false);
$team_position = in_array($this->filters['team_position'], ['home', 'away']) ? ucfirst($this->filters['team_position']) : 'Both Position'; $team_position = in_array($this->filters['team_position'], ['home', 'away']) ? ucfirst($this->filters['team_position']) : 'Both Position';
if (! $data) { if (! $data) {
-345
View File
@@ -1,345 +0,0 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\Charts\HelperStatisticType;
use App\Filament\Widgets\Charts\LoadEvents;
use App\Utilities\Round;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Carbon;
use Illuminate\Support\HtmlString;
use Livewire\Attributes\Reactive;
// use Illuminate\Support\Facades\Log;
class BoxesBettypeSingle extends StatsOverviewWidget
{
use InteractsWithPageFilters;
protected ?string $pollingInterval = null;
protected int|array|null $columns = null;
#[Reactive]
public ?array $filters = [];
public ?int $count;
public function mount(array $filters)
{
$this->filters = $filters;
}
protected function getStats(): array
{
$data = LoadEvents::load($this->filters, false);
$team_id = (int) $this->filters['team_id'] ?? 0;
$season = $this->filters['season'] ?? 0;
$season_or_date = $this->filters['season_or_date'];
$similar_past_matches = $this->filters['similar_past_matches'];
$date_events = '';
switch ($season_or_date) {
case 'season':
if ($season) {
$date_events = implode(', ', $season);
} else {
$date_events = 'Current Season';
}
break;
default:
$start = $this->filters['start_date'] ?? 0;
$end = $this->filters['end_date'] ?? 0;
$tmp = [];
if ($start) {
$tmp[] = 'From: '.Carbon::createFromDate($start)->format('Y-m-d');
}
if ($end) {
$tmp[] = 'To: '.Carbon::createFromDate($end)->format('Y-m-d');
}
if ($tmp) {
$date_events = implode('<br>', $tmp);
} else {
$date_events = 'All Dates';
}
break;
}
$team_position = $this->filters['team_position'] ? ucfirst($this->filters['team_position']) : 'Position Both';
if (! $data) {
return [];
}
$statistic_type = HelperStatisticType::get($this->filters);
if (! isset($data['datasets'][0])) {
$data['datasets'][0]['data'] = [];
$data['datasets'][1]['data'] = [];
$total_home = 0;
$total_away = 0;
$summe_home = 0;
$summe_away = 0;
$home_team = '';
$away_team = '';
} else {
$arr_home = $data['datasets'][0]['data'];
$arr_away = $data['datasets'][1]['data'];
$total_home = count($arr_home);
$total_away = count($arr_away);
$summe_home = array_sum($arr_home);
$summe_away = array_sum($arr_away);
$home_team = $data['home_team'];
$away_team = $data['away_team'];
}
if (isset($data['results'])) {
$win = $data['results']['w'] ? number_format(Round::odd($total_home / $data['results']['w']), 2) : 0;
$draw = $data['results']['d'] ? number_format(Round::odd($total_home / $data['results']['d']), 2) : 0;
$lost = $data['results']['l'] ? number_format(Round::odd($total_home / $data['results']['l']), 2) : 0;
} else {
$win = 0;
$draw = 0;
$lost = 0;
}
if ($total_home) {
$value_home = number_format($summe_home / $total_home, 1);
} else {
$value_home = 0;
}
if ($total_away) {
$value_away = number_format($summe_away / $total_away, 1);
} else {
$value_away = 0;
}
$max_boxes = 3;
$average_team_home = 0;
$average_team_away = 0;
$average_league_home = 0;
$average_league_away = 0;
$expectations_home = 0;
$expectations_away = 0;
$expectations_home = $data['expectations_home'] ?? 0;
$expectations_away = $data['expectations_away'] ?? 0;
foreach ($data['datasets'] as $value) {
if ($value['label'] == 'Average Team') {
$average_team_home = $value['average_team_home'] ?? 0;
$average_team_away = $value['average_team_away'] ?? 0;
$max_boxes++;
}
if ($value['label'] == 'Average League') {
$average_league_home = $value['average_league_home'] ?? 0;
$average_league_away = $value['average_league_away'] ?? 0;
$max_boxes++;
}
}
// i box 1 3 4 5 devono sempre avere 1 decimale, se il valore è 12 fai scrivere 12.0
// il box 2 sempre un numero intero
// il box 6 sempre a due decimali, se trovi 2 fai scrivere 2.00
$boxes = [];
if ($similar_past_matches != 'none') {
// BOX 2
$boxes[] = Stat::make('Total', self::template_box2($total_home))
->description(fn () => $similar_past_matches == 'all' ? 'SPM Source Database' : 'SPM Source League')
->extraAttributes([
'x-init' => "animate('number-of-events', $total_home);",
'class' => 'box-info',
]);
// BOX 3
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box3('Home', 'Away', $value_home, $value_away))
->description('Team '.$team_position)
->extraAttributes([
'x-init' => "animate('average_home', $value_home, 1); animate('average_away', $value_away, 1)",
'class' => 'box-success',
]);
// BOX 6
$boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost))
->description($team_position)
->extraAttributes([
'x-init' => "animate('win', $win); animate('draw', $draw); animate('lost', $lost)",
'class' => 'box-purple',
]);
} else {
// BOX 1
$boxes[] = Stat::make($statistic_type, self::template_box1($expectations_home, $expectations_away))
->description('Expected Values')
->extraAttributes([
'x-init' => "animate('expectations_home', $expectations_home, 1); animate('expectations_away', $expectations_away, 1)",
'class' => 'box-yellow',
]);
if ($team_id) {
// BOX 2
$boxes[] = Stat::make('Total', self::template_box2($total_home))
->description(fn () => new HtmlString($date_events))
->extraAttributes([
'x-init' => "animate('number-of-events', $total_home);",
'class' => 'box-info',
]);
// BOX 3
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box3($home_team, $away_team, $value_home, $value_away))
->description('Team '.$team_position)
->extraAttributes([
'x-init' => "animate('average_home', $value_home, 1); animate('average_away', $value_away, 1)",
'class' => 'box-success',
]);
// BOX 4
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box4($home_team, $away_team, $average_team_home, $average_team_away))
->description('Team Season')
->extraAttributes([
'x-init' => "animate('av_team_home', $average_team_home, 1); animate('av_team_away', $average_team_away, 1)",
'class' => 'box-success',
]);
// BOX 5
$boxes[] = Stat::make('Average '.$statistic_type, self::template_box5('Home', 'Away', $average_league_home, $average_league_away))
->description('League Season')
->extraAttributes([
'x-init' => "animate('av_league_home', $average_league_home, 1); animate('av_league_away', $average_league_away, 1)",
'class' => 'box-success',
]);
// BOX 6
$boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost))
->description($team_position)
->extraAttributes([
'x-init' => "animate('win', $win, 2); animate('draw', $draw, 2); animate('lost', $lost, 2)",
'class' => 'box-purple',
]);
}
}
$this->columns = [
'default' => 1,
'sm' => 2,
'md' => 3,
'xl' => 6,
];
return $boxes;
}
// TEAMPLATE BOX 1
protected function template_box1(float $expectations_home, float $expectations_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="expectations_home">'.$expectations_home.'</span>
<span class="text-center" id="expectations_away">'.$expectations_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">Home</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">Away</span>
</div>');
}
// TEAMPLATE BOX 2
protected function template_box2(float $total_home): HtmlString
{
return new HtmlString('<div class="grid grid-cols-1 justify-center font-bold text-2xl">
<span class="text-center" id="number-of-events">'.$total_home.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">Events</span>
</div>');
}
// TEAMPLATE BOX 3
protected function template_box3(string $home_team, string $away_team, float $value_home, float $value_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="average_home">'.$value_home.'</span>
<span class="text-center" id="average_away">'.$value_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$home_team.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_team.'</span>
</div>');
}
// TEAMPLATE BOX 4
protected function template_box4(string $home_team, string $away_team, float $value_home, float $value_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="av_team_home">'.$value_home.'</span>
<span class="text-center" id="av_team_away">'.$value_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$home_team.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_team.'</span>
</div>');
}
// TEAMPLATE BOX 5
protected function template_box5(string $home_team, string $away_team, float $value_home, float $value_away): HtmlString
{
return new HtmlString('<div class="grid grid-cols-2 justify-center font-bold text-2xl">
<span class="text-center" id="av_league_home">'.$value_home.'</span>
<span class="text-center" id="av_league_away">'.$value_away.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$home_team.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$away_team.'</span>
</div>');
}
// TEAMPLATE BOX 6 odds
protected function templateOdds(array &$data, float $win, float $draw, float $lost): HtmlString
{
if ($data['similar_past_matches'] != 'none') {
$name_win = '<b>1</b> ('.$data['results']['w'].')';
$name_draw = '<b>X</b> ('.$data['results']['d'].')';
$name_lost = '<b>2</b> ('.$data['results']['l'].')';
} else {
$name_win = '<b>Win</b> ('.$data['results']['w'].')';
$name_draw = '<b>Draw</b> ('.$data['results']['d'].')';
$name_lost = '<b>Lost</b> ('.$data['results']['l'].')';
}
return new HtmlString('<div class="grid grid-cols-3 justify-center">
<span class="text-center font-bold text-xl" id="win">'.number_format($win, 2).'</span>
<span class="text-center font-bold text-xl" id="draw">'.number_format($draw, 2).'</span>
<span class="text-center font-bold text-xl" id="lost">'.number_format($lost, 2).'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$name_win.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$name_draw.'</span>
<span class="text-center text-xs text-gray-500 dark:text-gray-400">'.$name_lost.'</span>
</div>');
}
protected function getMedian(array $arr)
{
sort($arr);
$size = count($arr);
if ($size % 2 == 0) {
// even
$m = ($size) / 2;
$m1 = $m - 1;
$m2 = $m;
// dd($m1, $m2, $arr);
// dd('GERADE', $arr, $size, $m, $m1, $m2);
if (isset($arr[$m1]) && isset($arr[$m2])) {
return round(($arr[$m1] + $arr[$m2]) / 2, 2);
}
} else {
// odd (add 1 because array starts with 0)
$m = (int) ceil($size / 2);
// dd($m, $arr);
// dd('UNGERADE', $m, $arr, $arr[$m]);
if (isset($arr[$m])) {
return $arr[$m];
}
}
}
}
+55 -52
View File
@@ -17,7 +17,6 @@ class LoadEvents
$team_id = (int) $filter['team_id'] ?? 0; $team_id = (int) $filter['team_id'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 'gls'; $statistic_type = $filter['statistic_type'] ?? 'gls';
$team_position = $filter['team_position']; $team_position = $filter['team_position'];
$seasonmode = $filter['seasonmode'];
$accuracy = (float) $filter['accuracy'] ?? 0.5; $accuracy = (float) $filter['accuracy'] ?? 0.5;
$similar_past_matches = $filter['similar_past_matches']; $similar_past_matches = $filter['similar_past_matches'];
@@ -28,6 +27,10 @@ class LoadEvents
return []; return [];
} }
if (! $team_id && $similar_past_matches == 'none') {
return [];
}
if ($statistic_type == 'none') { if ($statistic_type == 'none') {
$statistic_type = 'gls'; $statistic_type = 'gls';
} }
@@ -128,10 +131,10 @@ class LoadEvents
break; break;
} }
if ($statistic_type == 'gls') { // if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_home'], 1); // $dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1); // $dataset_exp_away[] = (float) round($value['exp_away'], 1);
} // }
} else { } else {
if ($team_position == 'home') { if ($team_position == 'home') {
switch ($value['result_code']) { switch ($value['result_code']) {
@@ -148,10 +151,10 @@ class LoadEvents
break; break;
} }
if ($statistic_type == 'gls') { // if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_home'], 1); // $dataset_exp_home[] = (float) round($value['exp_home'], 1);
$dataset_exp_away[] = (float) round($value['exp_away'], 1); // $dataset_exp_away[] = (float) round($value['exp_away'], 1);
} // }
} elseif ($team_position == 'away') { } elseif ($team_position == 'away') {
switch ($value['result_code']) { switch ($value['result_code']) {
@@ -168,10 +171,10 @@ class LoadEvents
break; break;
} }
if ($statistic_type == 'gls') { // if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_away'], 1); // $dataset_exp_home[] = (float) round($value['exp_away'], 1);
$dataset_exp_away[] = (float) round($value['exp_home'], 1); // $dataset_exp_away[] = (float) round($value['exp_home'], 1);
} // }
} else { } else {
// dd($team_id, $value['home_id'], $value['away_id']); // dd($team_id, $value['home_id'], $value['away_id']);
@@ -200,10 +203,10 @@ class LoadEvents
break; break;
} }
if ($statistic_type == 'gls') { // if ($statistic_type == 'gls') {
$dataset_exp_home[] = (float) round($value['exp_away'], 1); // $dataset_exp_home[] = (float) round($value['exp_away'], 1);
$dataset_exp_away[] = (float) round($value['exp_home'], 1); // $dataset_exp_away[] = (float) round($value['exp_home'], 1);
} // }
} }
} }
if (isset($val_home) && isset($val_away)) { if (isset($val_home) && isset($val_away)) {
@@ -240,8 +243,8 @@ class LoadEvents
$dataset_home2 = []; $dataset_home2 = [];
$dataset_away2 = []; $dataset_away2 = [];
$home_id = $match->home_id; // $home_id = $match->home_id;
$away_id = $match->away_id; // $away_id = $match->away_id;
foreach ($res[$team_position] as $value) { foreach ($res[$team_position] as $value) {
@@ -310,13 +313,13 @@ class LoadEvents
'results_per_event' => $results_per_event, 'results_per_event' => $results_per_event,
'data' => $dataset_home, 'data' => $dataset_home,
'tension' => 0.5, 'tension' => 0.5,
'borderColor' => '#fb2c36', 'borderColor' => '#00c950',
'backgroundColor' => '#fb2c36', 'backgroundColor' => '#00c950',
'pointStyle' => $hasdots, 'pointStyle' => $hasdots,
'fill' => [ 'fill' => [
'target' => 1, 'target' => 1,
'above' => '#fb2c3680', 'above' => '#00c95080',
'below' => '#fdc70080', 'below' => '#2b7fff80',
], ],
], ],
[ [
@@ -326,11 +329,11 @@ class LoadEvents
'results_per_event' => $results_per_event, 'results_per_event' => $results_per_event,
'data' => $dataset_away, 'data' => $dataset_away,
'tension' => 0.5, 'tension' => 0.5,
'borderColor' => '#fdc700', 'borderColor' => '#2b7fff',
'backgroundColor' => '#fdc700', 'backgroundColor' => '#2b7fff',
'pointStyle' => $hasdots, 'pointStyle' => $hasdots,
'fill' => false, 'fill' => false,
'hidden' => true, 'hidden' => false,
], ],
], ],
'labels' => $labels, 'labels' => $labels,
@@ -342,32 +345,32 @@ class LoadEvents
'expectations_home' => $expectations['home'], 'expectations_home' => $expectations['home'],
'expectations_away' => $expectations['away'], 'expectations_away' => $expectations['away'],
]; ];
if ($team_id && $statistic_type == 'gls') { // if ($team_id && $statistic_type == 'gls') {
$data['datasets'][] = [ // $data['datasets'][] = [
'label' => 'Goals '.$label1, // 'label' => 'Goals '.$label1,
'events' => $events, // 'events' => $events,
'playing_date' => $playing_date, // 'playing_date' => $playing_date,
'results_per_event' => $results_per_event, // 'results_per_event' => $results_per_event,
'data' => $dataset_exp_home, // 'data' => $dataset_exp_home,
'tension' => 0.5, // 'tension' => 0.5,
'borderColor' => '#00c950', // 'borderColor' => '#00c950',
'backgroundColor' => '#00c950', // 'backgroundColor' => '#00c950',
'pointStyle' => $hasdots, // 'pointStyle' => $hasdots,
'hidden' => true, // 'hidden' => true,
]; // ];
$data['datasets'][] = [ // $data['datasets'][] = [
'label' => 'Goals '.$label2, // 'label' => 'Goals '.$label2,
'events' => $events, // 'events' => $events,
'playing_date' => $playing_date, // 'playing_date' => $playing_date,
'results_per_event' => $results_per_event, // 'results_per_event' => $results_per_event,
'data' => $dataset_exp_away, // 'data' => $dataset_exp_away,
'tension' => 0.5, // 'tension' => 0.5,
'borderColor' => '#2b7fff', // 'borderColor' => '#2b7fff',
'backgroundColor' => '#2b7fff', // 'backgroundColor' => '#2b7fff',
'pointStyle' => $hasdots, // 'pointStyle' => $hasdots,
'hidden' => true, // 'hidden' => true,
]; // ];
} // }
if (isset($dataset_home2) && isset($dataset_away2)) { if (isset($dataset_home2) && isset($dataset_away2)) {
$data['datasets'][] = [ $data['datasets'][] = [
@@ -252,8 +252,8 @@ class LoadEventsAverages
'events' => $events, 'events' => $events,
'data' => $data_team, 'data' => $data_team,
'tension' => 0.5, 'tension' => 0.5,
'borderColor' => '#ad46ff', 'borderColor' => '#00c950',
'backgroundColor' => '#ad46ff', // 'backgroundColor' => '#ad46ff',
'borderDash' => [5, 5], 'borderDash' => [5, 5],
'pointStyle' => false, 'pointStyle' => false,
'hidden' => false, 'hidden' => false,
@@ -265,8 +265,8 @@ class LoadEventsAverages
'events' => $events, 'events' => $events,
'data' => $data_league, 'data' => $data_league,
'tension' => 0.5, 'tension' => 0.5,
'borderColor' => '#00bba7', 'borderColor' => '#2b7fff',
'backgroundColor' => '#00bba7', // 'backgroundColor' => '#00bba7',
'borderDash' => [5, 5], 'borderDash' => [5, 5],
'pointStyle' => false, 'pointStyle' => false,
'hidden' => false, 'hidden' => false,
@@ -48,17 +48,23 @@ class LoadEventsQueryAll
$matches_played = []; $matches_played = [];
if ($ss_player_id) { if ($ss_player_id) {
// $matches_season = StatistikoEvent::whereIn('season', $season)
// ->where(function ($query) use ($team_id, $team_position) {
// switch ($team_position) {
// case 'home':
// return $query->where('home_id', '=', $team_id);
// case 'away':
// return $query->where('away_id', '=', $team_id);
// default:
// return $query->where('home_id', '=', $team_id)
// ->orWhere('away_id', '=', $team_id);
// }
// })->pluck('match_id')->toArray();
$matches_season = StatistikoEvent::whereIn('season', $season) $matches_season = StatistikoEvent::whereIn('season', $season)
->where(function ($query) use ($team_id, $team_position) { ->where(function ($query) use ($team_id) {
switch ($team_position) { return $query->where('home_id', '=', $team_id)
case 'home': ->orWhere('away_id', '=', $team_id);
return $query->where('home_id', '=', $team_id);
case 'away':
return $query->where('away_id', '=', $team_id);
default:
return $query->where('home_id', '=', $team_id)
->orWhere('away_id', '=', $team_id);
}
})->pluck('match_id')->toArray(); })->pluck('match_id')->toArray();
$matches_played = StatistikoPlayer::query() $matches_played = StatistikoPlayer::query()
@@ -101,19 +107,23 @@ class LoadEventsQueryAll
return $query->where('league_id', $league_id); return $query->where('league_id', $league_id);
} }
}) })
->where(function ($query) use ($team_id, $similar_past_matches, $team_position) { ->where(function ($query) use ($team_id) {
if ($team_id && $similar_past_matches == 'none') { return $query->where('home_id', '=', $team_id)
switch ($team_position) { ->orWhere('away_id', '=', $team_id);
case 'home':
return $query->where('home_id', '=', $team_id);
case 'away':
return $query->where('away_id', '=', $team_id);
default:
return $query->where('home_id', '=', $team_id)
->orWhere('away_id', '=', $team_id);
}
}
}) })
// ->where(function ($query) use ($team_id, $similar_past_matches, $team_position) {
// if ($team_id && $similar_past_matches == 'none') {
// switch ($team_position) {
// case 'home':
// return $query->where('home_id', '=', $team_id);
// case 'away':
// return $query->where('away_id', '=', $team_id);
// default:
// return $query->where('home_id', '=', $team_id)
// ->orWhere('away_id', '=', $team_id);
// }
// }
// })
->when($matches_played, function ($query) use ($matches_played, $player_on_field) { ->when($matches_played, function ($query) use ($matches_played, $player_on_field) {
if ($player_on_field == 'notplayed') { if ($player_on_field == 'notplayed') {
return $query->whereNotIn('match_id', $matches_played); return $query->whereNotIn('match_id', $matches_played);
@@ -2,6 +2,7 @@
namespace App\Filament\Widgets\Charts; namespace App\Filament\Widgets\Charts;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\SofaScoreRosa; use App\Models\SofaScoreRosa;
use App\Models\StatisticFixtures; use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent; use App\Models\StatistikoEvent;
@@ -21,14 +22,34 @@ class LoadPerformance
$match_id = (int) $filter['match_id'] ?? 0; $match_id = (int) $filter['match_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$team_position = $filter['team_position']; $team_position = $filter['team_position'];
$similar_past_matches = $filter['similar_past_matches'];
$accuracy = (float) $filter['accuracy'] ?? 0.5;
if (! $league_id) { if (! $league_id) {
return []; return [];
} }
if (! $match_id) { if (! $match_id) {
return []; return [];
} }
if (! $team_id && $similar_past_matches == 'none') {
return [];
}
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$season_or_date = $filter['season_or_date'];
$season = $filter['season'];
$seasonmode = $filter['seasonmode'];
if ($season_or_date == 'season') {
$start = 0;
$end = 0;
}
$season = GetSeason::load($season, $seasonmode);
$team_map = SofaScoreRosa::pluck('ss_team_name', 'ss_team_id')->toArray(); $team_map = SofaScoreRosa::pluck('ss_team_name', 'ss_team_id')->toArray();
@@ -39,7 +60,56 @@ class LoadPerformance
$home_id = $match->home_id ?? 0; $home_id = $match->home_id ?? 0;
$away_id = $match->away_id ?? 0; $away_id = $match->away_id ?? 0;
$res = StatistikoEvent::where('league_id', $league_id)->get(); $handicap_range = [];
$total_range = [];
if ($similar_past_matches != 'none') {
$team_position = '';
$exp_handicap = $match->exp_away - $match->exp_home;
$exp_total = $match->exp_away + $match->exp_home;
$handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
$total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
}
// $res = LoadEventsQuery::load($filter, $handicap_range, $total_range, $match, 1);
// $res = StatistikoEvent::where('league_id', $league_id)->get();
$res = StatistikoEvent::where(function ($query) use ($league_id, $similar_past_matches) {
switch ($similar_past_matches) {
case 'none':
case 'league':
return $query->where('league_id', $league_id);
}
})
->where(function ($query) use ($home_id, $away_id, $similar_past_matches) {
if ($similar_past_matches == 'none') {
return $query->where('home_id', $home_id)->orWhere('away_id', $home_id)->orWhere('away_id', $away_id)->orWhere('away_id', $away_id);
}
})
->when($handicap_range, function ($query) use ($handicap_range) {
return $query->whereBetween('exp_handicap', $handicap_range);
})->when($total_range, function ($query) use ($total_range) {
return $query->whereBetween('exp_total', $total_range);
})
->when($start, function ($query) use ($start) {
return $query->whereDate('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->whereDate('starttime', '<=', $end);
})
->when($season, function ($query) use ($season, $season_or_date, $similar_past_matches) {
if ($similar_past_matches == 'none' && $season_or_date == 'season') {
return $query->whereIn('season', $season);
}
})
->orderBy('starttime', 'ASC')
->get();
$home_matches = []; $home_matches = [];
$away_matches = []; $away_matches = [];
@@ -66,7 +136,7 @@ class LoadPerformance
$labels[] = round($val->starttime->diffInDays(Carbon::now())); $labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('Y-m-d H:i'); $date_away[] = $val['starttime']->format('Y-m-d H:i');
$results_away[] = $val['gls_h'].' : '.$val['gls_a']; $results_away[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id]; $events_away[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$away_matches[] = $val->match_id; $away_matches[] = $val->match_id;
} }
break; break;
@@ -82,7 +152,7 @@ class LoadPerformance
$labels[] = round($val->starttime->diffInDays(Carbon::now())); $labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('Y-m-d H:i'); $date_away[] = $val['starttime']->format('Y-m-d H:i');
$results_away[] = $val['gls_h'].' : '.$val['gls_a']; $results_away[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id]; $events_away[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$away_matches[] = $val->match_id; $away_matches[] = $val->match_id;
} }
break; break;
@@ -98,7 +168,7 @@ class LoadPerformance
$labels[] = round($val->starttime->diffInDays(Carbon::now())); $labels[] = round($val->starttime->diffInDays(Carbon::now()));
$date_away[] = $val['starttime']->format('Y-m-d H:i'); $date_away[] = $val['starttime']->format('Y-m-d H:i');
$results_away[] = $val['gls_h'].' : '.$val['gls_a']; $results_away[] = $val['gls_h'].' : '.$val['gls_a'];
$events_home[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id]; $events_away[] = $team_map[$val->home_id].' vs '.$team_map[$val->away_id];
$away_matches[] = $val->match_id; $away_matches[] = $val->match_id;
} }
break; break;
@@ -241,6 +311,9 @@ class LoadPerformance
'borderDash' => [5, 5], 'borderDash' => [5, 5],
'hidden' => true, 'hidden' => true,
], ],
/**
* AWAY
*/
[ [
'label' => $team_map[$match->away_id], 'label' => $team_map[$match->away_id],
'playing_date' => $date_away, 'playing_date' => $date_away,
@@ -16,7 +16,6 @@
{{ $this->filtersForm }} {{ $this->filtersForm }}
{{-- @livewire(\App\Filament\Widgets\BoxesBettypeSingle::class, ['filters' => $this->filters]) --}}
@livewire(\App\Filament\Widgets\BoxesBettypeAll::class, ['filters' => $this->filters]) @livewire(\App\Filament\Widgets\BoxesBettypeAll::class, ['filters' => $this->filters])
<div x-data="{ activeTab: 'tab1' }" id="charttabs"> <div x-data="{ activeTab: 'tab1' }" id="charttabs">