This commit is contained in:
salam committed 2026-06-17 12:42:43 +02:00
1 parent 3376eb6d2e
commit ec60adb074
9 files changed
+194 -195

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
<?php
namespace App\Actions;
use App\Models\CompetitionGroup;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
class LoadSeasons
{
public static function load($league_id)
{
// $res = CompetitionGroup::with('country')->where('id', $league_id)->first();
// $season_mode = $res->country->season_mode;
$res = StatistikoEvent::where('league_id', $league_id)
->groupBy('season')
->orderBy('starttime', 'ASC')
->get();
if (! $res) {
return [];
}
$arr = [];
foreach ($res as $val) {
$arr[$val->season] = $val->season;
}
return $arr;
}
}
+62 -38
View File
@@ -2,6 +2,7 @@
namespace App\Filament\Pages;
use App\Actions\LoadSeasons;
use App\Actions\LoadStatisticFixturesLeaguesOptions;
use App\Actions\LoadStatisticFixturesMatchOptions;
use App\Models\Element;
@@ -10,6 +11,7 @@ use App\Models\StatistikoDetail;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Slider;
use Filament\Pages\Dashboard as BaseDashboard;
@@ -21,7 +23,6 @@ use Filament\Schemas\Schema;
use Filament\Support\RawJs;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;
use PhpOption\None;
class Statistic extends BaseDashboard
{
@@ -56,8 +57,8 @@ class Statistic extends BaseDashboard
->components([
Grid::make([
'default' => 1,
'sm' => 2,
'md' => 4,
'sm' => 3,
'md' => 5,
])
->columnSpanFull()
->extraAttributes([
@@ -102,8 +103,6 @@ class Statistic extends BaseDashboard
return 'danger';
}
})
// ->prefixIconColor(fn (Get $get): string => $get('similar_past_matches') == 'none' ? 'primary' : '')
// ->hidden(fn (Get $get) => $get('similar_past_matches') != 'none')
->prefixIcon('phosphor-users-three')
->disabled(fn(Get $get) => $get('similar_past_matches') != 'none')
->options(function (Get $get) {
@@ -128,7 +127,6 @@ class Statistic extends BaseDashboard
->hiddenLabel()
->placeholder('Team Position')
->prefix('Team Position')
// ->prefixIconColor(fn (Get $get): string => $get('similar_past_matches') == 'none' ? 'primary' : '')
->prefixIcon('phosphor-map-pin')
->disabled(fn(Get $get) => $get('similar_past_matches') != 'none')
->default('all')
@@ -138,33 +136,20 @@ class Statistic extends BaseDashboard
'home' => 'Home',
'away' => 'Away',
]),
DatePicker::make('start_date')
Select::make('season')
->hiddenLabel()
->native(false)
->placeholder('Season')
->hidden(fn(Get $get) => $get('season_or_date') == 'date')
->prefixIcon('phosphor-calendar-star')
->prefixIconColor('primary')
->prefixIcon('phosphor-calendar')
->live()
->prefix('Start')
->suffixAction(
Action::make('clear_start')
->icon('phosphor-x')
->color('gray')
->action(fn(Set $set) => $set('start_date', null))
),
DatePicker::make('end_date')
->hiddenLabel()
->native(false)
->prefixIconColor('primary')
->prefixIcon('phosphor-calendar')
->live()
->prefix('End')
->suffixAction(
Action::make('clear_end')
->icon('phosphor-x')
->color('gray')
->action(fn(Set $set) => $set('end_date', null))
),
->options(function (Get $get) {
return LoadSeasons::load($get('league_id'));
})
->afterStateUpdated(function (callable $set) {
$set('team_id', null);
$set('tm_player_id', null);
})
->live(),
Select::make('statistic_type')
->hiddenLabel()
->placeholder('Statistic Type')
@@ -186,10 +171,10 @@ class Statistic extends BaseDashboard
->placeholder('Similar Past Matches')
->prefixIconColor('primary')
->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>') : '')
->columnSpan([
'default' => 1,
'xl' => 2,
])
// ->columnSpan([
// 'default' => 1,
// 'xl' => 2,
// ])
->prefixAction(
Action::make('iconInfo')
->icon('phosphor-question')
@@ -204,9 +189,9 @@ class Statistic extends BaseDashboard
$set('team_position', null);
})
->options([
'none' => 'Similar Past Matches: None',
'league' => 'Similar Past Matches: League',
'all' => 'Similar Past Matches: All Database',
'none' => 'SPM: None',
'league' => 'SPM: League',
'all' => 'SPM: All Database',
]),
Slider::make('accuracy')
// ->label('Accuracy min: 0, max: 0.25, steps: 0.025')
@@ -262,6 +247,44 @@ class Statistic extends BaseDashboard
'substituted' => 'Substituted',
])
->live(),
DatePicker::make('start_date')
->hiddenLabel()
->hidden(fn(Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor('primary')
->prefixIcon('phosphor-calendar')
->live()
->prefix('Start')
->suffixAction(
Action::make('clear_start')
->icon('phosphor-x')
->color('gray')
->action(fn(Set $set) => $set('start_date', null))
),
DatePicker::make('end_date')
->hiddenLabel()
->hidden(fn(Get $get) => $get('season_or_date') == 'season')
->native(false)
->prefixIconColor('primary')
->prefixIcon('phosphor-calendar')
->live()
->prefix('End')
->suffixAction(
Action::make('clear_end')
->icon('phosphor-x')
->color('gray')
->action(fn(Set $set) => $set('end_date', null))
),
Radio::make('season_or_date')
->columnSpan(2)
->inline()
->live()
->default('season')
->hiddenLabel()
->options([
'season' => 'Season',
'date' => 'Date Picker',
]),
]),
]);
}
@@ -269,6 +292,7 @@ class Statistic extends BaseDashboard
protected function tooltip_similar_past_matches(): HtmlString
{
$str = '<div class="m-3 grid grid-cols-4 gap-2 max-w-lg">';
$str .= '<div class="col-span-4 font-bold">Similar Past Matches (SMP)</div>';
$str .= '<div class="font-bold">None</div>';
$str .= '<div class="col-span-3"><u>Team</u> within selected league</div>';
$str .= '<div class="font-bold">League</div>';
@@ -0,0 +1,13 @@
<?php
namespace App\Filament\Widgets\Data;
class HelperTeamPosition
{
public static function get($filter): string
{
$tmp = $filter['team_position'] ?? 'none';
return ucfirst($tmp);
}
}
+34 -16
View File
@@ -27,6 +27,10 @@ class LoadEvents
$team_id = (int) $filter['team_id'] ?? 0;
$season_or_date = $filter['season_or_date'] ?? 'season';
// dd($season_or_date);
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
$start = $filter['start_date'] ?? 0;
@@ -511,7 +515,8 @@ class LoadEvents
if ($res) {
$media_team = [];
$media_league = [];
$media_league_h = [];
$media_league_a = [];
// 1) la media dei falli di tutte le partite giocate dal Flamengo
// (esempio, giocate 6 partite con falli 17-11-15-14-15-12, la media è 14)
@@ -557,39 +562,52 @@ class LoadEvents
switch ($statistic_type) {
case 'gls':
$media_league[] = (int) $value['gls_h'];
$media_league[] = (int) $value['gls_a'];
$media_league_h[] = (int) $value['gls_h'];
$media_league_a[] = (int) $value['gls_a'];
break;
case 'crn':
$media_league[] = (int) $value['crn_h'];
$media_league[] = (int) $value['crn_a'];
$media_league_h[] = (int) $value['crn_h'];
$media_league_a[] = (int) $value['crn_a'];
break;
case 'fls':
$media_league[] = (int) $value['fls_h'];
$media_league[] = (int) $value['fls_a'];
$media_league_h[] = (int) $value['fls_h'];
$media_league_a[] = (int) $value['fls_a'];
break;
case 'ofs':
$media_league[] = (int) $value['ofs_h'];
$media_league[] = (int) $value['ofs_a'];
$media_league_h[] = (int) $value['ofs_h'];
$media_league_a[] = (int) $value['ofs_a'];
break;
case 'crd':
$media_league[] = (int) $value['crd_h'];
$media_league[] = (int) $value['crd_a'];
$media_league_h[] = (int) $value['crd_h'];
$media_league_a[] = (int) $value['crd_a'];
break;
case 'snt':
$media_league[] = (int) $value['snt_h'];
$media_league[] = (int) $value['snt_a'];
$media_league_h[] = (int) $value['snt_h'];
$media_league_a[] = (int) $value['snt_a'];
break;
case 'tsh':
$media_league[] = (int) $value['tsh_h'];
$media_league[] = (int) $value['tsh_a'];
$media_league_h[] = (int) $value['tsh_h'];
$media_league_a[] = (int) $value['tsh_a'];
break;
}
}
$average_team = 0;
if ($team_id)
$average_team = round(array_sum($media_team) / \count($media_team), 2);
$average_league = round(array_sum($media_league) / \count($media_league), 2);
switch ($team_position) {
case 'home':
$average_league = round(array_sum($media_league_h) / \count($media_league_h), 2);
break;
case 'away':
$average_league = round(array_sum($media_league_a) / \count($media_league_a), 2);
break;
default:
$media_league = $media_league_a + $media_league_h;
$average_league = round(array_sum($media_league) / \count($media_league), 2);
break;
}
$data_team = array_fill(0, count($labels), $average_team);
$data_league = array_fill(0, count($labels), $average_league);
+7 -15
View File
@@ -3,6 +3,7 @@
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\HelperTeamPosition;
use App\Filament\Widgets\Data\LoadEvents;
use App\Utilities\Round;
use Filament\Widgets\StatsOverviewWidget;
@@ -30,6 +31,8 @@ class StatsMedianAverage extends StatsOverviewWidget
{
$data = LoadEvents::load($this->filters, false);
$team_position = HelperTeamPosition::get($this->filters);
if (!$data)
return [];
@@ -71,17 +74,6 @@ class StatsMedianAverage extends StatsOverviewWidget
$home_team = $data['home_team'];
$away_team = $data['away_team'];
}
// dd($arr_home);
// if (! $total_home) {
// return [
// Stat::make('Number of events', 0),
// Stat::make('Average ' . $statistic_type, self::template(0, 0, $home_team, $away_team)),
// Stat::make('Median ' . $statistic_type, self::template(0, 0, $home_team, $away_team)),
// Stat::make('Win', 0),
// Stat::make('Draw', 0),
// Stat::make('Lost', 0),
// ];
// }
if ($arr_home)
$median_home = self::getMedian($arr_home);
@@ -112,15 +104,15 @@ class StatsMedianAverage extends StatsOverviewWidget
$value_away = 0;
$boxes = [];
$boxes[] = Stat::make('Events', new HtmlString('<div id="number-of-events">' . $total_home . '</div>'))->description('Number')->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
$boxes[] = Stat::make($statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->description('Average Team')->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away, 0)"]);
$boxes[] = Stat::make('Number', new HtmlString('<div id="number-of-events">' . $total_home . '</div>'))->description('Events')->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
$boxes[] = Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team))->description('Team ' . $team_position)->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away, 0)"]);
foreach ($data['datasets'] as $value) {
if ($value['label'] == "Average League") {
$str = $value['data'][0] ?? 0;
$boxes[] = Stat::make($statistic_type, new HtmlString('<div id="number-of-events">' . $str . '</div>'))->description('Average League')->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
$boxes[] = Stat::make('Average ' . $statistic_type, new HtmlString('<div id="number-of-events">' . $str . '</div>'))->description('League ' . $team_position)->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]);
}
}
$boxes[] = Stat::make($statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->description('Median')->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]);
$boxes[] = Stat::make('Median ' . $statistic_type, self::template('mehome', 'meaway', $home_team, $away_team))->description($team_position)->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]);
$boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? '1' : 'Win: ' . $data['results']['w'], new HtmlString('<div id="number-of-win">' . $win . '</div>'))->extraAttributes(['x-init' => "animate('number-of-win', $win, 1)"]);
$boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? 'X' : 'Draw: ' . $data['results']['d'], new HtmlString('<div id="number-of-draw">' . $draw . '</div>'))->extraAttributes(['x-init' => "animate('number-of-draw', $draw, 1)"]);
$boxes[] = Stat::make($data['similar_past_matches'] != 'none' ? '2' : 'Lost: ' . $data['results']['l'], new HtmlString('<div id="number-of-lost">' . $lost . '</div>'))->extraAttributes(['x-init' => "animate('number-of-lost', $lost, 1)"]);