wip order classes
This commit is contained in:
1 parent
fe4fa6e9cf
commit
7bf4258c4a
29 files changed
+140
-124
No files matched your search
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Charts\LoadEvents;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
|
||||
class LoadEventsAverages
|
||||
{
|
||||
public static function load(array &$data, array $filter, array $labels, array $events)
|
||||
{
|
||||
$tournament_id = (int) $filter['league_id'] ?? 0;
|
||||
$team_position = $filter['team_position'];
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
$statistic_type = $filter['statistic_type'] ?? 'gls';
|
||||
$season = $filter['season'] ?? 0;
|
||||
$season_or_date = $filter['season_or_date'] ?? 'season';
|
||||
$start = $filter['start_date'] ?? 0;
|
||||
$end = $filter['end_date'] ?? 0;
|
||||
|
||||
if ($season_or_date != 'season') {
|
||||
$season = 0;
|
||||
} else {
|
||||
$end = 0;
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
$res = StatistikoEvent::where('league_id', $tournament_id)
|
||||
->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) {
|
||||
return $query->whereIn('season', $season);
|
||||
})
|
||||
->orderBy('starttime', 'ASC')
|
||||
->get();
|
||||
|
||||
// dd($res);
|
||||
|
||||
if ($res) {
|
||||
|
||||
$team_home = [];
|
||||
$team_away = [];
|
||||
$league_home = [];
|
||||
$league_away = [];
|
||||
|
||||
// 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)
|
||||
|
||||
// 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-...,
|
||||
// quindi la media di questi 120 dati)
|
||||
|
||||
foreach ($res as $value) {
|
||||
switch ($statistic_type) {
|
||||
case 'gls':
|
||||
$league_home[] = (int) $value['gls_h'];
|
||||
$league_away[] = (int) $value['gls_a'];
|
||||
break;
|
||||
case 'crn':
|
||||
$league_home[] = (int) $value['crn_h'];
|
||||
$league_away[] = (int) $value['crn_a'];
|
||||
break;
|
||||
case 'fls':
|
||||
$league_home[] = (int) $value['fls_h'];
|
||||
$league_away[] = (int) $value['fls_a'];
|
||||
break;
|
||||
case 'ofs':
|
||||
$league_home[] = (int) $value['ofs_h'];
|
||||
$league_away[] = (int) $value['ofs_a'];
|
||||
break;
|
||||
case 'crd':
|
||||
$league_home[] = (int) $value['crd_h'];
|
||||
$league_away[] = (int) $value['crd_a'];
|
||||
break;
|
||||
case 'snt':
|
||||
$league_home[] = (int) $value['snt_h'];
|
||||
$league_away[] = (int) $value['snt_a'];
|
||||
break;
|
||||
case 'tsh':
|
||||
$league_home[] = (int) $value['tsh_h'];
|
||||
$league_away[] = (int) $value['tsh_a'];
|
||||
break;
|
||||
}
|
||||
|
||||
if ((! $team_position || $team_position == 'all') && ($team_id == $value['home_id'] or $team_id == $value['away_id'])) {
|
||||
switch ($statistic_type) {
|
||||
case 'gls':
|
||||
if ($team_id == $value['home_id']) {
|
||||
$team_home[] = (int) $value['gls_h'];
|
||||
$team_away[] = (int) $value['gls_a'];
|
||||
} else {
|
||||
$team_home[] = (int) $value['gls_a'];
|
||||
$team_away[] = (int) $value['gls_h'];
|
||||
}
|
||||
break;
|
||||
case 'crn':
|
||||
if ($team_id == $value['home_id']) {
|
||||
$team_home[] = (int) $value['crn_h'];
|
||||
$team_away[] = (int) $value['crn_a'];
|
||||
} else {
|
||||
$team_home[] = (int) $value['crn_a'];
|
||||
$team_away[] = (int) $value['crn_h'];
|
||||
}
|
||||
break;
|
||||
case 'fls':
|
||||
if ($team_id == $value['home_id']) {
|
||||
$team_home[] = (int) $value['fls_h'];
|
||||
$team_away[] = (int) $value['fls_a'];
|
||||
} else {
|
||||
$team_home[] = (int) $value['fls_a'];
|
||||
$team_away[] = (int) $value['fls_h'];
|
||||
}
|
||||
break;
|
||||
case 'ofs':
|
||||
if ($team_id == $value['home_id']) {
|
||||
$team_home[] = (int) $value['ofs_h'];
|
||||
$team_away[] = (int) $value['ofs_a'];
|
||||
} else {
|
||||
$team_home[] = (int) $value['ofs_a'];
|
||||
$team_away[] = (int) $value['ofs_h'];
|
||||
}
|
||||
break;
|
||||
case 'crd':
|
||||
if ($team_id == $value['home_id']) {
|
||||
$team_home[] = (int) $value['crd_h'];
|
||||
$team_away[] = (int) $value['crd_a'];
|
||||
} else {
|
||||
$team_home[] = (int) $value['crd_a'];
|
||||
$team_away[] = (int) $value['crd_h'];
|
||||
}
|
||||
break;
|
||||
case 'snt':
|
||||
if ($team_id == $value['home_id']) {
|
||||
$team_home[] = (int) $value['snt_h'];
|
||||
$team_away[] = (int) $value['snt_a'];
|
||||
} else {
|
||||
$team_home[] = (int) $value['snt_a'];
|
||||
$team_away[] = (int) $value['snt_h'];
|
||||
}
|
||||
break;
|
||||
case 'tsh':
|
||||
if ($team_id == $value['home_id']) {
|
||||
$team_home[] = (int) $value['tsh_h'];
|
||||
$team_away[] = (int) $value['tsh_a'];
|
||||
} else {
|
||||
$team_home[] = (int) $value['tsh_a'];
|
||||
$team_away[] = (int) $value['tsh_h'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
} elseif ($team_position == 'home' && $team_id == $value['home_id']) {
|
||||
switch ($statistic_type) {
|
||||
case 'gls':
|
||||
$team_home[] = (int) $value['gls_h'];
|
||||
$team_away[] = (int) $value['gls_a'];
|
||||
break;
|
||||
case 'crn':
|
||||
$team_home[] = (int) $value['crn_h'];
|
||||
$team_away[] = (int) $value['crn_a'];
|
||||
break;
|
||||
case 'fls':
|
||||
$team_home[] = (int) $value['fls_h'];
|
||||
$team_away[] = (int) $value['fls_a'];
|
||||
break;
|
||||
case 'ofs':
|
||||
$team_home[] = (int) $value['ofs_h'];
|
||||
$team_away[] = (int) $value['ofs_a'];
|
||||
break;
|
||||
case 'crd':
|
||||
$team_home[] = (int) $value['crd_h'];
|
||||
$team_away[] = (int) $value['crd_a'];
|
||||
break;
|
||||
case 'snt':
|
||||
$team_home[] = (int) $value['snt_h'];
|
||||
$team_away[] = (int) $value['snt_a'];
|
||||
break;
|
||||
case 'tsh':
|
||||
$team_home[] = (int) $value['tsh_h'];
|
||||
$team_away[] = (int) $value['tsh_a'];
|
||||
break;
|
||||
}
|
||||
} elseif ($team_position == 'away' && $team_id == $value['away_id']) {
|
||||
switch ($statistic_type) {
|
||||
case 'gls':
|
||||
$team_home[] = (int) $value['gls_a'];
|
||||
$team_away[] = (int) $value['gls_h'];
|
||||
break;
|
||||
case 'crn':
|
||||
$team_home[] = (int) $value['crn_a'];
|
||||
$team_away[] = (int) $value['crn_h'];
|
||||
break;
|
||||
case 'fls':
|
||||
$team_home[] = (int) $value['fls_a'];
|
||||
$team_away[] = (int) $value['fls_h'];
|
||||
break;
|
||||
case 'ofs':
|
||||
$team_home[] = (int) $value['ofs_a'];
|
||||
$team_away[] = (int) $value['ofs_h'];
|
||||
break;
|
||||
case 'crd':
|
||||
$team_home[] = (int) $value['crd_a'];
|
||||
$team_away[] = (int) $value['crd_h'];
|
||||
break;
|
||||
case 'snt':
|
||||
$team_home[] = (int) $value['snt_a'];
|
||||
$team_away[] = (int) $value['snt_h'];
|
||||
break;
|
||||
case 'tsh':
|
||||
$team_home[] = (int) $value['tsh_a'];
|
||||
$team_away[] = (int) $value['tsh_h'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$average_team = 0;
|
||||
$average_team_home = 0;
|
||||
$average_team_away = 0;
|
||||
$average_league = 0;
|
||||
$average_league_home = 0;
|
||||
$average_league_away = 0;
|
||||
|
||||
// dd($team_home);
|
||||
|
||||
if ($team_id && $team_home) {
|
||||
|
||||
$sum = array_sum($team_home) + array_sum($team_away);
|
||||
|
||||
$count = count($team_home) + count($team_away);
|
||||
|
||||
$average_team = round($sum / $count, 1);
|
||||
|
||||
$average_team_home = round(array_sum($team_home) / count($team_home), 1);
|
||||
|
||||
$average_team_away = round(array_sum($team_away) / count($team_away), 1);
|
||||
|
||||
$average_league_home = $league_home ? round(array_sum($league_home) / \count($league_home), 1) : 0;
|
||||
|
||||
$average_league_away = $league_away ? round(array_sum($league_away) / \count($league_away), 1) : 0;
|
||||
|
||||
$media_league = array_merge($league_away, $league_home);
|
||||
|
||||
$average_league = $media_league ? round(array_sum($media_league) / \count($media_league), 1) : 0;
|
||||
}
|
||||
|
||||
$data_team = array_fill(0, count($labels), $average_team);
|
||||
$data_league = array_fill(0, count($labels), $average_league);
|
||||
|
||||
$data['datasets'][] = [
|
||||
'label' => 'Average Team',
|
||||
'events' => $events,
|
||||
'data' => $data_team,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#ad46ff',
|
||||
'backgroundColor' => '#ad46ff',
|
||||
'borderDash' => [5, 5],
|
||||
'pointStyle' => false,
|
||||
'hidden' => false,
|
||||
'average_team_home' => $average_team_home,
|
||||
'average_team_away' => $average_team_away,
|
||||
];
|
||||
$data['datasets'][] = [
|
||||
'label' => 'Average League',
|
||||
'events' => $events,
|
||||
'data' => $data_league,
|
||||
'tension' => 0.5,
|
||||
'borderColor' => '#00bba7',
|
||||
'backgroundColor' => '#00bba7',
|
||||
'borderDash' => [5, 5],
|
||||
'pointStyle' => false,
|
||||
'hidden' => false,
|
||||
'average_league_home' => $average_league_home,
|
||||
'average_league_away' => $average_league_away,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user