ImportPlayer add cars and penalty

This commit is contained in:
salam committed 2026-05-22 14:52:33 +02:00
1 parent d7d4ab9ea1
commit 314ab7885b
14 files changed
+308 -37

No files matched your search

@@ -1,8 +0,0 @@
<?php
namespace App\Actions\Statistics;
class StatisticEvents
{
public static function load($filter) {}
}
+1 -1
View File
@@ -10,7 +10,7 @@ class ImportPlayer
{ {
public static function run(string $filePath): void public static function run(string $filePath): void
{ {
$fieldnames = ['activeteam_id', 'playersubstitute_id', 'goals', 'assists', 'own_goals', 'shots_on_target', 'shots_off_target', 'shots_blocked', 'fouls', 'was_fouled', 'offsides', 'possessions_lost', 'total_tackles', 'touches', 'total_cross', 'cross_done', 'total_dribbles', 'dribbles_won', 'total_ground_duels', 'total_ground_duels_won', 'total_aerial_duels', 'total_duels_aerial_won', 'total_pass', 'pass', 'total_long_balls', 'long_balls', 'blocked_shots', 'clearances', 'dribbled_past', 'hit_woodwork', 'interceptions', 'key_pass', 'last_man_tackle', 'dispossessed', 'clearance_off_line', 'bcc', 'bcm', 'errors_lead_to_a_goal', 'errors_lead_to_a_shot', 'penalty_committed', 'penalty_miss', 'penalty_save', 'penalty_won', 'saves', 'saves_from_in_box', 'total_runs_out', 'runs_out', 'punches', 'good_high_claim', 'minutes_played', 'lineup', 'minute_event_during_the_match', 'type_event_during_the_match', 'description_event_during_the_match', 'subtype_event_during_the_match', 'player_position', 'playerrating_value']; $fieldnames = ['activeteam_id', 'playersubstitute_id', 'goals', 'assists', 'own_goals', 'shots_on_target', 'shots_off_target', 'shots_blocked', 'fouls', 'was_fouled', 'offsides', 'possessions_lost', 'total_tackles', 'touches', 'total_cross', 'cross_done', 'total_dribbles', 'dribbles_won', 'total_ground_duels', 'total_ground_duels_won', 'total_aerial_duels', 'total_duels_aerial_won', 'total_pass', 'pass', 'total_long_balls', 'long_balls', 'blocked_shots', 'clearances', 'dribbled_past', 'hit_woodwork', 'interceptions', 'key_pass', 'last_man_tackle', 'dispossessed', 'clearance_off_line', 'bcc', 'bcm', 'errors_lead_to_a_goal', 'errors_lead_to_a_shot', 'penalty_committed', 'penalty_miss', 'penalty_save', 'penalty_won', 'saves', 'saves_from_in_box', 'total_runs_out', 'runs_out', 'punches', 'good_high_claim', 'minutes_played', 'lineup', 'minute_event_during_the_match', 'type_event_during_the_match', 'description_event_during_the_match', 'subtype_event_during_the_match', 'card_yellow', 'card_yellowred', 'card_red', 'ingamepenalty_missed', 'penaltyshoutout_scored', 'penaltyshoutout_missed', 'player_position', 'playerrating_value'];
SimpleExcelReader::create(storage_path('app/public/'.$filePath)) SimpleExcelReader::create(storage_path('app/public/'.$filePath))
->getRows() ->getRows()
+21 -8
View File
@@ -3,9 +3,11 @@
namespace App\Filament\Pages; namespace App\Filament\Pages;
use App\Actions\LoadStatisticFixturesLeaguesOptions; use App\Actions\LoadStatisticFixturesLeaguesOptions;
use App\Filament\Widgets\MedianAverageWidget; use App\Filament\Widgets\MedianAverage;
use App\Filament\Widgets\MovingAverageChart; use App\Filament\Widgets\MovingAverageChart;
use App\Filament\Widgets\MovingAverageChartPlayer;
use App\Filament\Widgets\PunctualChart; use App\Filament\Widgets\PunctualChart;
use App\Filament\Widgets\PunctualChartPlayer;
use App\Models\Element; use App\Models\Element;
use App\Models\StatisticFixtures; use App\Models\StatisticFixtures;
use App\Models\StatistikoDetail; use App\Models\StatistikoDetail;
@@ -13,7 +15,6 @@ use BackedEnum;
use Filament\Actions\Action; use Filament\Actions\Action;
use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
use Filament\Forms\Components\Slider;
use Filament\Pages\Dashboard as BaseDashboard; use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm; use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Schemas\Components\Grid; use Filament\Schemas\Components\Grid;
@@ -75,6 +76,16 @@ class Statistic extends BaseDashboard
->searchable() ->searchable()
->live() ->live()
->label('Team'), ->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') DatePicker::make('start_date')
->native(false) ->native(false)
->prefixIcon('phosphor-calendar') ->prefixIcon('phosphor-calendar')
@@ -93,7 +104,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(4) ])->columns(5)
->columnSpanFull(), ->columnSpanFull(),
Grid::make() Grid::make()
->schema([ ->schema([
@@ -106,14 +117,14 @@ class Statistic extends BaseDashboard
return StatistikoDetail::where('txodds_id', $get('team_id'))->pluck('name', 'tm_player_id'); return StatistikoDetail::where('txodds_id', $get('team_id'))->pluck('name', 'tm_player_id');
}) })
->live(), ->live(),
Select::make('team_position') Select::make('player_on_field')
->prefixIcon('phosphor-map-pin') ->prefixIcon('phosphor-watch')
->default('all') ->default('all')
->selectablePlaceholder(false) ->selectablePlaceholder(false)
->options([ ->options([
'all' => 'All', 'all' => 'All',
'home' => 'Home', 'lineup' => 'Lineup',
'away' => 'Away', 'substituted' => 'Substituted',
]), ]),
Select::make('statistic_type') Select::make('statistic_type')
->prefixIcon('phosphor-cell-signal-full') ->prefixIcon('phosphor-cell-signal-full')
@@ -178,9 +189,11 @@ class Statistic extends BaseDashboard
protected function getFooterWidgets(): array protected function getFooterWidgets(): array
{ {
return [ return [
MedianAverageWidget::make(), MedianAverage::make(),
PunctualChart::make(), PunctualChart::make(),
MovingAverageChart::make(), MovingAverageChart::make(),
PunctualChartPlayer::make(),
// MovingAverageChartPlayer::make(),
]; ];
} }
@@ -1,9 +1,10 @@
<?php <?php
namespace App\Actions\Statistics; namespace App\Filament\Widgets\DB;
use App\Models\StatisticFixtures; use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent; use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
class LoadEvents class LoadEvents
{ {
@@ -21,6 +22,8 @@ class LoadEvents
$team_id = (int) $filter['team_id'] ?? 0; $team_id = (int) $filter['team_id'] ?? 0;
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
if (! $league_id) { if (! $league_id) {
return []; return [];
} }
@@ -58,6 +61,17 @@ class LoadEvents
$statistic_type = $filter['statistic_type'] ?? 0; $statistic_type = $filter['statistic_type'] ?? 0;
/**
* WITH PLAYER
*/
$tm_player_id = $filter['tm_player_id'];
if ($tm_player_id) {
$matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray();
} else {
$matches_played = false;
}
/** /**
* STATTISTIC DATA * STATTISTIC DATA
*/ */
@@ -65,7 +79,9 @@ class LoadEvents
case 'home': case 'home':
$res = StatistikoEvent::where('league_id', $league_id) $res = StatistikoEvent::where('league_id', $league_id)
->where('home_id', '=', $team_id) ->where('home_id', '=', $team_id)
->when($start, function ($query) use ($start) { ->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->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) {
return $query->where('starttime', '<=', $end); return $query->where('starttime', '<=', $end);
@@ -76,7 +92,9 @@ class LoadEvents
case 'away': case 'away':
$res = StatistikoEvent::where('league_id', $league_id) $res = StatistikoEvent::where('league_id', $league_id)
->where('away_id', '=', $team_id) ->where('away_id', '=', $team_id)
->when($start, function ($query) use ($start) { ->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->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) {
return $query->where('starttime', '<=', $end); return $query->where('starttime', '<=', $end);
@@ -89,7 +107,9 @@ class LoadEvents
->where(function ($query) use ($team_id) { ->where(function ($query) use ($team_id) {
$query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id); $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id);
}) })
->when($start, function ($query) use ($start) { ->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->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) {
return $query->where('starttime', '<=', $end); return $query->where('starttime', '<=', $end);
@@ -106,7 +126,7 @@ class LoadEvents
} }
foreach ($res as $value) { foreach ($res as $value) {
$labels[] = $value['starttime']->format('d. M.y'); $labels[] = $value['starttime']->format('d.M.y');
if ($team_position == 'home') { if ($team_position == 'home') {
@@ -1,9 +1,10 @@
<?php <?php
namespace App\Actions\Statistics; namespace App\Filament\Widgets\DB;
use App\Models\StatisticFixtures; use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent; use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
class LoadEventsAspGoal class LoadEventsAspGoal
{ {
@@ -67,12 +68,25 @@ class LoadEventsAspGoal
$total_range = [$exp_total - $accuracy, $exp_total + $accuracy]; $total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
} }
/**
* WITH PLAYER
*/
$tm_player_id = $filter['tm_player_id'];
if ($tm_player_id) {
$matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray();
} else {
$matches_played = false;
}
$similar_past_matches = $filter['similar_past_matches'] ?? 0; $similar_past_matches = $filter['similar_past_matches'] ?? 0;
switch ($similar_past_matches) { switch ($similar_past_matches) {
case 'league': case 'league':
$res = StatistikoEvent::when($league_id, function ($query) use ($league_id) { $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) {
return $query->where('league_id', $league_id); return $query->where('league_id', $league_id);
})->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->when($handicap_range, function ($query) use ($handicap_range) { })->when($handicap_range, function ($query) use ($handicap_range) {
return $query->whereBetween('exp_handicap', $handicap_range); return $query->whereBetween('exp_handicap', $handicap_range);
})->when($total_range, function ($query) use ($total_range) { })->when($total_range, function ($query) use ($total_range) {
@@ -88,6 +102,8 @@ class LoadEventsAspGoal
case 'all': case 'all':
$res = StatistikoEvent::when($handicap_range, function ($query) use ($handicap_range) { $res = StatistikoEvent::when($handicap_range, function ($query) use ($handicap_range) {
return $query->whereBetween('exp_handicap', $handicap_range); return $query->whereBetween('exp_handicap', $handicap_range);
})->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->when($total_range, function ($query) use ($total_range) { })->when($total_range, function ($query) use ($total_range) {
return $query->whereBetween('exp_total', $total_range); return $query->whereBetween('exp_total', $total_range);
})->when($start, function ($query) use ($start) { })->when($start, function ($query) use ($start) {
@@ -132,7 +148,7 @@ class LoadEventsAspGoal
} }
foreach ($res as $value) { foreach ($res as $value) {
$labels[] = $value['starttime']->format('d. M.y'); $labels[] = $value['starttime']->format('d.M.y');
// dd($filter); // dd($filter);
Whitespace-only changes.
@@ -0,0 +1,135 @@
<?php
namespace App\Filament\Widgets\DB;
use App\Models\StatistikoPlayer;
class LoadPunctualChartPlayer
{
public static function load($filter)
{
// dd($filter);
// "team_position" => "all"
// "statistic_type" => "gls"
// "similar_past_matches" => "none"
// "accuracy" => "0.5"
// "player_on_field" => "all"
// "league_id" => "26"
// "team_id" => "571991"
// "start_date" => null
// "end_date" => null
// "tm_player_id" => null
// 'gls' => 'Goals', // goals
// 'crn' => 'Corner',
// 'fls' => 'Fouls commited', // fouls
// 'ofs' => 'Offside', // offsides
// 'crd' => 'Cards',
// 'snt' => 'Shot on target', // shots_on_target
// 'tsh' => 'Total shots', // shots_off_target
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
if (! $league_id) {
return [];
}
if (! $team_id) {
return [];
}
if (! $tm_player_id) {
return [];
}
$team_position = $filter['team_position'];
$player_on_field = $filter['player_on_field'];
$res = StatistikoPlayer::with('event')->where('tm_player_id', $tm_player_id)
->when($team_position, function ($query) use ($team_id, $team_position) {
/**
* TEAM HOME/AWAY
*/
switch ($team_position) {
case 'home':
return $query->where('activeteam_id', $team_id);
break;
case 'away':
return $query->where('activeteam_id', '!=', $team_id);
break;
}
})->when($player_on_field, function ($query) use ($player_on_field) {
/**
* LINEUP
*/
switch ($player_on_field) {
case 'lineup':
return $query->where('lineup', 'T');
break;
case 'substituted':
return $query->where('lineup', 'P');
break;
}
})->get();
$statistic_type = $filter['statistic_type'] ?? 0;
// $fields = 'goals,fouls,offsides,shots_on_target,shots_off_target, subtype_event_during_the_match';
$labels = [];
foreach ($res as $key => $value) {
if (isset($value->event->starttime)) {
$labels[] = $value->event->starttime->format('d.M.y');
switch ($statistic_type) {
case 'gls':
$val = (int) $value['goals'];
break;
case 'crn':
$val = (int) 0;
break;
case 'fls':
$val = (int) $value['fouls'];
break;
case 'ofs':
$val = (int) $value['offsides'];
break;
case 'crd':
$val = (int) $value['crd_h'];
break;
case 'snt':
$val = (int) $value['shots_on_target'];
break;
case 'tsh':
$val = (int) $value['shots_off_target'];
break;
}
}
$datasets[] = $val;
}
$data = [
'datasets' => [
[
'label' => ucfirst($team_position),
'data' => $datasets,
'fill' => true,
'tension' => 0.5,
'borderColor' => '#36A2EB',
],
],
'labels' => $labels,
];
return $data;
}
}
@@ -1,6 +1,6 @@
<?php <?php
namespace App\Actions\Statistics; namespace App\Filament\Widgets\DB;
class MoveingAverage class MoveingAverage
{ {
@@ -1,6 +1,6 @@
<?php <?php
namespace App\Actions\Statistics; namespace App\Filament\Widgets\DB;
class StatisticType class StatisticType
{ {
@@ -2,13 +2,13 @@
namespace App\Filament\Widgets; namespace App\Filament\Widgets;
use App\Actions\Statistics\LoadEvents; use App\Filament\Widgets\DB\LoadEvents;
use App\Actions\Statistics\LoadEventsAspGoal; use App\Filament\Widgets\DB\LoadEventsAspGoal;
use Filament\Widgets\Concerns\InteractsWithPageFilters; use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget; use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat; use Filament\Widgets\StatsOverviewWidget\Stat;
class MedianAverageWidget extends StatsOverviewWidget class MedianAverage extends StatsOverviewWidget
{ {
use InteractsWithPageFilters; use InteractsWithPageFilters;
+4 -4
View File
@@ -2,9 +2,9 @@
namespace App\Filament\Widgets; namespace App\Filament\Widgets;
use App\Actions\Statistics\LoadEvents; use App\Filament\Widgets\DB\LoadEvents;
use App\Actions\Statistics\MoveingAverage; use App\Filament\Widgets\DB\MoveingAverage;
use App\Actions\Statistics\StatisticType; use App\Filament\Widgets\DB\StatisticType;
use Filament\Widgets\ChartWidget; use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters; use Filament\Widgets\Concerns\InteractsWithPageFilters;
@@ -26,7 +26,7 @@ class MovingAverageChart extends ChartWidget
public function getDescription(): ?string public function getDescription(): ?string
{ {
return 'Moving Average'; return 'Events Moving Average';
} }
protected function getData(): array protected function getData(): array
@@ -0,0 +1,48 @@
<?php
namespace App\Filament\Widgets;
use App\Actions\Statistics\LoadEvents;
use App\Actions\Statistics\StatisticType;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
class MovingAverageChartPlayer extends ChartWidget
{
use InteractsWithPageFilters;
protected ?string $pollingInterval = null;
public ?string $header;
protected ?array $options = [
'plugins' => [
'legend' => [
'display' => false,
],
],
];
public function getDescription(): ?string
{
return 'Player Moving Average';
}
protected function getData(): array
{
$this->heading = StatisticType::get($this->filters);
$data = LoadEvents::load($this->filters);
if ($data) {
// MoveingAveragePlayer::get($data);
}
return $data;
}
protected function getType(): string
{
return 'line';
}
}
+3 -4
View File
@@ -2,9 +2,8 @@
namespace App\Filament\Widgets; namespace App\Filament\Widgets;
// use App\Actions\Statistics\StatisticEvents; use App\Filament\Widgets\DB\LoadEvents;
use App\Actions\Statistics\LoadEvents; use App\Filament\Widgets\DB\StatisticType;
use App\Actions\Statistics\StatisticType;
use Filament\Widgets\ChartWidget; use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters; use Filament\Widgets\Concerns\InteractsWithPageFilters;
@@ -26,7 +25,7 @@ class PunctualChart extends ChartWidget
public function getDescription(): ?string public function getDescription(): ?string
{ {
return 'Punctual'; return 'Events Punctual';
} }
protected function getData(): array protected function getData(): array
@@ -0,0 +1,48 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Widgets\DB\LoadPunctualChartPlayer;
use App\Filament\Widgets\DB\StatisticType;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
class PunctualChartPlayer extends ChartWidget
{
use InteractsWithPageFilters;
protected ?string $pollingInterval = null;
public ?string $header;
protected ?array $options = [
'plugins' => [
'legend' => [
'display' => false,
],
],
];
public function getDescription(): ?string
{
return 'Player Punctual';
}
protected function getData(): array
{
if ($this->filters['statistic_type'] == 'crn') {
return [];
}
$this->heading = StatisticType::get($this->filters);
$data = LoadPunctualChartPlayer::load($this->filters);
return $data;
}
protected function getType(): string
{
return 'line';
}
}