This commit is contained in:
salam committed 2026-07-27 18:36:54 +02:00
1 parent 332bdc9985
commit 3627a78989
2 files changed
+54 -52

No files matched your search

@@ -7,7 +7,7 @@ use App\Models\StatistikoEvent;
class LoadEventsAverages
{
public static function load(array &$data, array $filter,array $labels, array $events)
public static function load(array &$data, array $filter, array $labels, array $events)
{
$league_id = (int) $filter['league_id'] ?? 0;
@@ -46,7 +46,6 @@ class LoadEventsAverages
// quindi la media di questi 120 dati)
foreach ($res as $value) {
switch ($statistic_type) {
case 'gls':
$league_home[] = (int) $value['gls_h'];
@@ -78,135 +77,134 @@ class LoadEventsAverages
break;
}
if ($team_position == 'all' && ($team_id == $value['home_id'] or $team_id == $value['away_id'])) {
// dd($team_position, $team_id, $value);
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'];
$team_away[] = (int) $value['gls_a'];
} else {
$team_home[] = (int) $value['gls_a'];
$team_away[] =(int) $value['gls_h'];
$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'];
$team_away[] = (int) $value['crn_a'];
} else {
$team_home[] = (int) $value['crn_a'];
$team_away[] =(int) $value['crn_h'];
$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'];
$team_away[] = (int) $value['fls_a'];
} else {
$team_home[] = (int) $value['fls_a'];
$team_away[] =(int) $value['fls_h'];
$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'];
$team_away[] = (int) $value['ofs_a'];
} else {
$team_home[] = (int) $value['ofs_a'];
$team_away[] =(int) $value['ofs_h'];
$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'];
$team_away[] = (int) $value['crd_a'];
} else {
$team_home[] = (int) $value['crd_a'];
$team_away[] =(int) $value['crd_h'];
$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'];
$team_away[] = (int) $value['snt_a'];
} else {
$team_home[] = (int) $value['snt_a'];
$team_away[] =(int) $value['snt_h'];
$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'];
$team_away[] = (int) $value['tsh_a'];
} else {
$team_home[] = (int) $value['tsh_a'];
$team_away[] =(int) $value['tsh_h'];
$team_away[] = (int) $value['tsh_h'];
}
break;
}
}
else if ($team_position == 'home' && $team_id == $value['home_id']) {
}
} else if ($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'];
$team_away[] = (int) $value['gls_a'];
break;
case 'crn':
$team_home[] = (int) $value['crn_h'];
$team_away[] =(int) $value['crn_a'];
$team_away[] = (int) $value['crn_a'];
break;
case 'fls':
$team_home[] = (int) $value['fls_h'];
$team_away[] =(int) $value['fls_a'];
$team_away[] = (int) $value['fls_a'];
break;
case 'ofs':
$team_home[] = (int) $value['ofs_h'];
$team_away[] =(int) $value['ofs_a'];
$team_away[] = (int) $value['ofs_a'];
break;
case 'crd':
$team_home[] = (int) $value['crd_h'];
$team_away[] =(int) $value['crd_a'];
$team_away[] = (int) $value['crd_a'];
break;
case 'snt':
$team_home[] = (int) $value['snt_h'];
$team_away[] =(int) $value['snt_a'];
$team_away[] = (int) $value['snt_a'];
break;
case 'tsh':
$team_home[] = (int) $value['tsh_h'];
$team_away[] =(int) $value['tsh_a'];
$team_away[] = (int) $value['tsh_a'];
break;
}
}
else if ($team_position == 'away' && $team_id == $value['away_id']) {
} else if ($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'];
$team_away[] = (int) $value['gls_h'];
break;
case 'crn':
$team_home[] = (int) $value['crn_a'];
$team_away[] =(int) $value['crn_h'];
$team_away[] = (int) $value['crn_h'];
break;
case 'fls':
$team_home[] = (int) $value['fls_a'];
$team_away[] =(int) $value['fls_h'];
$team_away[] = (int) $value['fls_h'];
break;
case 'ofs':
$team_home[] = (int) $value['ofs_a'];
$team_away[] =(int) $value['ofs_h'];
$team_away[] = (int) $value['ofs_h'];
break;
case 'crd':
$team_home[] = (int) $value['crd_a'];
$team_away[] =(int) $value['crd_h'];
$team_away[] = (int) $value['crd_h'];
break;
case 'snt':
$team_home[] = (int) $value['snt_a'];
$team_away[] =(int) $value['snt_h'];
$team_away[] = (int) $value['snt_h'];
break;
case 'tsh':
$team_home[] = (int) $value['tsh_a'];
$team_away[] =(int) $value['tsh_h'];
$team_away[] = (int) $value['tsh_h'];
break;
}
}
@@ -219,22 +217,24 @@ class LoadEventsAverages
$average_league_home = 0;
$average_league_away = 0;
if ($team_id && $team_home){
// 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;
$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;