Files
nuhodds_fi4/app/Filament/Widgets/Boxes/AverageTeamSeason.php
T
2026-10-10 15:59:48 +02:00

65 lines
2.9 KiB
PHP

<?php
namespace App\Filament\Widgets\Boxes;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Filament\Widgets\Boxes\Helper\ExpectationAverage;
use App\Models\StatistikoEvent;
class AverageTeamSeason
{
/**
* BOX 5 - AVERAGE WITH TEAM FIXED TO ACTIVE SEASON
*/
public static function load(array &$expectations, array $filter, object $match)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$seasonmode = $filter['seasonmode'];
$active_season = GetSeason::active($seasonmode);
$res = StatistikoEvent::where('league_id', $tournament_id)
->when($active_season, function ($query) use ($active_season) {
return $query->where('season', $active_season);
})->when($team_id, function ($query) use ($team_id) {
return $query->orWhere('home_id', $team_id)->orWhere('away_id', '=', $team_id);
})->get();
if ($res) {
$result = [];
foreach ($res as $val) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_h);
ExpectationAverage::filter($result, 'team', 'crn', $val->crn_a, $val->crn_h);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_a, $val->fls_h);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_a, $val->ofs_h);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_a, $val->crd_h);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h);
}
$bets = ['gls', 'crn', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
if ($result) {
foreach ($bets as $bet) {
$expectations[$bet.'_team_season']['home'] = round(array_sum($result['team'][$bet]['home']) / \count($result['team'][$bet]['home']), 1);
$expectations[$bet.'_team_season']['away'] = round(array_sum($result['team'][$bet]['away']) / \count($result['team'][$bet]['away']), 1);
}
} else {
foreach ($bets as $bet) {
$expectations[$bet.'_team_season']['home'] = 0;
$expectations[$bet.'_team_season']['away'] = 0;
}
}
$expectations['gls_team_season']['name'] = 'Goals';
$expectations['crn_team_season']['name'] = 'Corner';
$expectations['fls_team_season']['name'] = 'Fouls';
$expectations['ofs_team_season']['name'] = 'Offsides';
$expectations['crd_team_season']['name'] = 'Cards';
$expectations['snt_team_season']['name'] = 'Shots on Target';
$expectations['tsh_team_season']['name'] = 'Total Shots';
$expectations['active_season'] = $active_season;
}
}
}