statistic filter player grafics wip

This commit is contained in:
salam committed 2026-05-24 09:41:52 +02:00
1 parent 4de73f9275
commit 3bc956e0b9
5 files changed
+93 -29

No files matched your search

@@ -0,0 +1,22 @@
<?php
namespace App\Actions;
use App\Models\StatisticFixtures;
class LoadStatisticFixturesMatchOptions
{
public static function load($league_id)
{
if (! $league_id) {
return [];
}
$res = StatisticFixtures::where('league_id', $league_id)->get();
foreach ($res as $val) {
$arr[$val->id] = $val->home->name.' vs '.$val->away->name;
}
return $arr;
}
}
+19 -13
View File
@@ -3,6 +3,7 @@
namespace App\Filament\Pages; namespace App\Filament\Pages;
use App\Actions\LoadStatisticFixturesLeaguesOptions; use App\Actions\LoadStatisticFixturesLeaguesOptions;
use App\Actions\LoadStatisticFixturesMatchOptions;
use App\Filament\Widgets\ChartMovingAverageEvent; use App\Filament\Widgets\ChartMovingAverageEvent;
use App\Filament\Widgets\ChartMovingAveragePlayer; use App\Filament\Widgets\ChartMovingAveragePlayer;
use App\Filament\Widgets\ChartPunctualEvent; use App\Filament\Widgets\ChartPunctualEvent;
@@ -58,34 +59,39 @@ class Statistic extends BaseDashboard
Select::make('league_id') Select::make('league_id')
->prefixIcon('phosphor-trophy') ->prefixIcon('phosphor-trophy')
->options(fn () => LoadStatisticFixturesLeaguesOptions::load(1)) ->options(fn () => LoadStatisticFixturesLeaguesOptions::load(1))
->preload()
->searchable()
->live() ->live()
->label('League') ->label('League')
->afterStateUpdated(function (callable $set) { ->afterStateUpdated(function (callable $set) {
$set('team_id', null); $set('match_id', null);
}), }),
Select::make('match_id')
->prefixIcon('icon-team')
->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') Select::make('team_id')
->prefixIcon('icon-team') ->prefixIcon('icon-team')
->options(function (Get $get) { ->options(function (Get $get) {
if ($get('league_id')) { if ($get('match_id')) {
$res = StatisticFixtures::where('league_id', $get('league_id'))->get(); $res = StatisticFixtures::where('id', $get('match_id'))->get();
$arr = []; $arr = [];
foreach ($res as $value) { foreach ($res as $value) {
$arr[] = $value->home_id; $arr[] = $value->home_id;
$arr[] = $value->away_id; $arr[] = $value->away_id;
} }
$arr = array_unique($arr); return Element::query()->whereIn('id', $arr)->pluck('name', 'id');
return Element::query()->whereIn('id', $arr)->orderBy('name')->pluck('name', 'id');
} }
}) })
->afterStateUpdated(function (callable $set) { ->afterStateUpdated(function (callable $set) {
$set('tm_player_id', null); $set('tm_player_id', null);
}) })
->preload()
->searchable()
->live() ->live()
->label('Team'), ->label('Team'),
@@ -118,7 +124,7 @@ class Statistic extends BaseDashboard
->color('gray') ->color('gray')
->action(fn (Set $set) => $set('end_date', null)) ->action(fn (Set $set) => $set('end_date', null))
), ),
])->columns(5) ])->columns(6)
->columnSpanFull(), ->columnSpanFull(),
Grid::make([ Grid::make([
'default' => 2, 'default' => 2,
@@ -233,8 +239,8 @@ class Statistic extends BaseDashboard
StatsMedianAverage::make(), StatsMedianAverage::make(),
ChartPunctualEvent::make(), ChartPunctualEvent::make(),
ChartMovingAverageEvent::make(), ChartMovingAverageEvent::make(),
// ChartPunctualPlayer::make(), ChartPunctualPlayer::make(),
// ChartMovingAveragePlayer::make(), ChartMovingAveragePlayer::make(),
]; ];
} }
+8 -3
View File
@@ -20,6 +20,8 @@ class LoadEvents
$league_id = (int) $filter['league_id'] ?? 0; $league_id = (int) $filter['league_id'] ?? 0;
$match_id = (int) $filter['match_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0; $team_id = (int) $filter['team_id'] ?? 0;
$tm_player_id = (int) $filter['tm_player_id'] ?? 0; $tm_player_id = (int) $filter['tm_player_id'] ?? 0;
@@ -28,20 +30,23 @@ class LoadEvents
$end = $filter['end_date'] ?? 0; $end = $filter['end_date'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 'gls'; $statistic_type = $filter['statistic_type'];
$team_position = $filter['team_position']; $team_position = $filter['team_position'];
$player_on_field = $filter['player_on_field']; $player_on_field = $filter['player_on_field'];
$accuracy = (float) $filter['accuracy'];
if (! $league_id) { if (! $league_id) {
return []; return [];
} }
if (! $team_id) { if (! $team_id) {
return []; return [];
} }
if (! $statistic_type) {
return []; if ($statistic_type == 'none') {
$statistic_type = 'gls';
} }
/** /**
+37 -10
View File
@@ -18,23 +18,25 @@ class LoadPlayer
$league_id = (int) $filter['league_id'] ?? 0; $league_id = (int) $filter['league_id'] ?? 0;
$match_id = (int) $filter['match_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0; $team_id = (int) $filter['team_id'] ?? 0;
$tm_player_id = (int) $filter['tm_player_id'] ?? 0; $tm_player_id = (int) $filter['tm_player_id'] ?? 0;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$statistic_type = $filter['statistic_type'];
$team_position = $filter['team_position']; $team_position = $filter['team_position'];
$player_on_field = $filter['player_on_field']; $player_on_field = $filter['player_on_field'];
$statistic_type = $filter['statistic_type'] ?? 0;
$accuracy = (float) $filter['accuracy']; $accuracy = (float) $filter['accuracy'];
$similar_past_matches = $filter['similar_past_matches'] ?? 0; $similar_past_matches = $filter['similar_past_matches'];
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
if (! $league_id) { if (! $league_id) {
return []; return [];
@@ -46,6 +48,31 @@ class LoadPlayer
return []; return [];
} }
if ($statistic_type == 'none') {
$statistic_type = 'gls';
}
/**
* IF WITH SIMILAR_PAST_MATCHES
*
* 'none' => 'None',
* 'league' => 'League',
* 'all' => 'All Database',
*/
// $handicap_range = 0;
// $total_range = 0;
// if ($similar_past_matches != 'none') {
// $res = StatisticFixtures::where('id', (int) $match_id)->first();
// $exp_handicap = $res->exp_away - $res->exp_home;
// $exp_total = $res->exp_away + $res->exp_home;
// $handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
// $total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
// }
/** /**
* STATTISTIC DATA * STATTISTIC DATA
*/ */
@@ -60,9 +87,9 @@ class LoadPlayer
return $query->where('home_id', '=', $team_id) return $query->where('home_id', '=', $team_id)
->orWhere('away_id', '=', $team_id); ->orWhere('away_id', '=', $team_id);
} }
}) // })
->when($matches_played, function ($query) use ($matches_played) { // ->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played); // return $query->whereIn('match_id', $matches_played);
})->when($start, function ($query) use ($start) { })->when($start, function ($query) use ($start) {
return $query->where('starttime', '>=', $start); return $query->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) { })->when($end, function ($query) use ($end) {
+7 -3
View File
@@ -55,13 +55,17 @@ class StatsMedianAverage extends StatsOverviewWidget
$median = $arr[$m]; $median = $arr[$m];
} }
$win = $data['results']['w'] ? number_format(Round::odd($total / $data['results']['w']), 2) : 0;
$draw = $data['results']['d'] ? number_format(Round::odd($total / $data['results']['d']), 2) : 0;
$lost = $data['results']['l'] ? number_format(Round::odd($total / $data['results']['l']), 2) : 0;
return [ return [
Stat::make('Number of events', $total), Stat::make('Number of events', $total),
Stat::make('Average', round($summe / $total, 1)), Stat::make('Average', round($summe / $total, 1)),
Stat::make('Median', $median), Stat::make('Median', $median),
Stat::make('Win: '.$data['results']['w'], number_format(Round::odd($total / $data['results']['w']), 2)), Stat::make('Win: '.$data['results']['w'], $win),
Stat::make('Draw: '.$data['results']['d'], number_format(Round::odd($total / $data['results']['d']), 2)), Stat::make('Draw: '.$data['results']['d'], $draw),
Stat::make('Lost: '.$data['results']['l'], number_format(Round::odd($total / $data['results']['l']), 2)), Stat::make('Lost: '.$data['results']['l'], $lost),
]; ];
} }
} }