wip average all bettype in boxes

This commit is contained in:
salam committed 2026-09-25 09:51:50 +02:00
1 parent 1a46e5d887
commit fe4fa6e9cf
16 files changed
+1010 -135

No files matched your search

@@ -0,0 +1,57 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\StatistikoEvent;
class AverageLeagueSeason
{
public static function load(array &$expectations, array $filter)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$seasonmode = $filter['seasonmode'];
$active_season = GetSeason::active($seasonmode);
// Box 2
// average made and got for liga selected
// fixed to active season
$res = StatistikoEvent::where('league_id', $tournament_id)
->when($active_season, function ($query) use ($active_season) {
return $query->where('season', $active_season);
})->get();
$result = [];
if ($res) {
foreach ($res as $val) {
ExpectationAverage::filter($result, 'liga', 'gls', $val->gls_h, $val->gls_a);
ExpectationAverage::filter($result, 'liga', 'fls', $val->fls_h, $val->fls_a);
ExpectationAverage::filter($result, 'liga', 'ofs', $val->ofs_h, $val->ofs_a);
ExpectationAverage::filter($result, 'liga', 'crd', $val->crd_h, $val->crd_a);
ExpectationAverage::filter($result, 'liga', 'snt', $val->snt_h, $val->snt_a);
ExpectationAverage::filter($result, 'liga', 'tsh', $val->tsh_h, $val->tsh_a);
}
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
if ($result) {
foreach ($bets as $bet) {
$expectations[$bet.'_liga_season']['home'] = round(array_sum($result['liga'][$bet]['home']) / \count($result['liga'][$bet]['home']), 1);
$expectations[$bet.'_liga_season']['away'] = round(array_sum($result['liga'][$bet]['away']) / \count($result['liga'][$bet]['away']), 1);
}
} else {
foreach ($bets as $bet) {
$expectations[$bet.'_liga_season']['home'] = 0;
$expectations[$bet.'_liga_season']['away'] = 0;
}
}
$expectations['gls_liga_season']['name'] = 'Goals';
$expectations['fls_liga_season']['name'] = 'Fouls';
$expectations['ofs_liga_season']['name'] = 'Offsides';
$expectations['crd_liga_season']['name'] = 'Cards';
$expectations['snt_liga_season']['name'] = 'Shots on Target';
$expectations['tsh_liga_season']['name'] = 'Total Shots';
$expectations['active_season'] = $active_season;
}
}
}
@@ -0,0 +1,113 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\StatistikoEvent;
class AverageTeam
{
public static function load(array &$expectations, array $filter)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$team_position = $filter['team_position'];
$team_id = (int) $filter['team_id'] ?? 0;
$season = $filter['season'] ?? 0;
$season_or_date = $filter['season_or_date'] ?? 'season';
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$seasonmode = $filter['seasonmode'];
if ($season_or_date != 'season') {
$season = 0;
} else {
$end = 0;
$start = 0;
$season = GetSeason::load($season, $seasonmode);
}
$active_season = GetSeason::active($seasonmode);
// Average made and got for team selected
// Box 1
// for selected Date or Time or All
// Box 2
// fixed to active season
// Box 3 wie 2
// fixed to active season but all league
$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);
})->when($team_id, function ($query) use ($team_position, $team_id) {
switch ($team_position) {
case 'home':
return $query->where('home_id', $team_id);
case 'away':
return $query->where('away_id', $team_id);
default:
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
}
})->get();
$result = [];
if ($res) {
// 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 $val) {
if ($team_position == 'home' && $team_id == $val->home_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_h, $val->fls_a);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_h, $val->ofs_a);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_h, $val->crd_a);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_h, $val->snt_a);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_h, $val->tsh_a);
} elseif ($team_position == 'away' && $team_id == $val->away_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_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);
} else {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_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', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
if ($result) {
foreach ($bets as $bet) {
$expectations[$bet.'_team']['home'] = round(array_sum($result['team'][$bet]['home']) / \count($result['team'][$bet]['home']), 1);
$expectations[$bet.'_team']['away'] = round(array_sum($result['team'][$bet]['away']) / \count($result['team'][$bet]['away']), 1);
}
} else {
foreach ($bets as $bet) {
$expectations[$bet.'_team']['home'] = 0;
$expectations[$bet.'_team']['away'] = 0;
}
}
$expectations['gls_team']['name'] = 'Goals';
$expectations['fls_team']['name'] = 'Fouls';
$expectations['ofs_team']['name'] = 'Offsides';
$expectations['crd_team']['name'] = 'Cards';
$expectations['snt_team']['name'] = 'Shots on Target';
$expectations['tsh_team']['name'] = 'Total Shots';
}
}
}
@@ -0,0 +1,93 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\StatistikoEvent;
class AverageTeamSeason
{
public static function load(array &$expectations, array $filter)
{
$tournament_id = (int) $filter['league_id'] ?? 0;
$team_position = $filter['team_position'];
$team_id = (int) $filter['team_id'] ?? 0;
$seasonmode = $filter['seasonmode'];
$active_season = GetSeason::active($seasonmode);
// Box 2
// average made and got for team selected
// fixed to active season
$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_position, $team_id) {
switch ($team_position) {
case 'home':
return $query->where('home_id', $team_id);
case 'away':
return $query->where('away_id', $team_id);
default:
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
}
})->get();
$result = [];
if ($res) {
// 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 $val) {
if ($team_position == 'home' && $team_id == $val->home_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a);
ExpectationAverage::filter($result, 'team', 'fls', $val->fls_h, $val->fls_a);
ExpectationAverage::filter($result, 'team', 'ofs', $val->ofs_h, $val->ofs_a);
ExpectationAverage::filter($result, 'team', 'crd', $val->crd_h, $val->crd_a);
ExpectationAverage::filter($result, 'team', 'snt', $val->snt_h, $val->snt_a);
ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_h, $val->tsh_a);
} elseif ($team_position == 'away' && $team_id == $val->away_id) {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_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);
} else {
ExpectationAverage::filter($result, 'team', 'gls', $val->gls_a, $val->gls_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', '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['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;
}
}
}
@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
class ExpectationAverage
{
public static function filter(array &$result, string $type, string $bettype, float $val_home, float $val_away)
{
$result[$type][$bettype]['home'][] = (int) $val_home;
$result[$type][$bettype]['away'][] = (int) $val_away;
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Models\StatistikoConfig;
class ExpectationCalculation
{
public static function calc(array $expectations)
{
$summen = [];
$config = StatistikoConfig::pluck('value', 'varname');
foreach ($config as $name => $value) {
if (isset($expectations[$name])) {
$summen[$name]['sum'] = array_sum($expectations[$name]) * $value;
$summen[$name]['cnt'] = \count($expectations[$name]);
} else {
$summen[$name]['sum'] = 0;
$summen[$name]['cnt'] = 1;
}
}
$summen2 = [];
$bets = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
foreach ($bets as $name) {
$summen2[$name]['home']['sum'] = 0;
$summen2[$name]['home']['cnt'] = 0;
$summen2[$name]['away']['sum'] = 0;
$summen2[$name]['away']['cnt'] = 0;
}
foreach ($summen as $key => $value) {
foreach ($bets as $name) {
if (strpos($key, $name) !== false) {
if (strpos($key, 'home') !== false) {
$summen2[$name]['home']['sum'] += $value['sum'];
$summen2[$name]['home']['cnt'] += +$value['cnt'];
}
if (strpos($key, 'away') !== false) {
$summen2[$name]['away']['sum'] += $value['sum'];
$summen2[$name]['away']['cnt'] += +$value['cnt'];
}
}
}
}
$asp_result = [];
foreach ($summen2 as $bettype => $value) {
$asp_result[$bettype]['home'] = round($value['home']['sum'] / $value['home']['cnt'], 1);
$asp_result[$bettype]['away'] = round($value['away']['sum'] / $value['away']['cnt'], 1);
}
return $asp_result;
}
}
@@ -0,0 +1,46 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
class ExpectationCollecting
{
public static function sort(array &$result, string $type, int $home_id, int $away_id, float $val_home, float $val_away, object $match)
{
if ($home_id == $match->home_id) {
$result[$type.'_home_made_total'][] = $val_home;
$result[$type.'_home_made_home'][] = $val_home;
$result[$type.'_home_got_total'][] = $val_away;
$result[$type.'_home_got_home'][] = $val_away;
} elseif ($away_id == $match->home_id) {
$result[$type.'_home_made_total'][] = $val_away;
$result[$type.'_home_got_total'][] = $val_away;
} elseif ($home_id == $match->away_id) {
$result[$type.'_home_made_total'][] = $val_away;
$result[$type.'_home_got_total'][] = $val_away;
} elseif ($away_id == $match->away_id) {
$result[$type.'_home_made_total'][] = $val_home;
$result[$type.'_home_made_home'][] = $val_home;
$result[$type.'_home_got_total'][] = $val_away;
$result[$type.'_home_got_home'][] = $val_home;
}
if ($away_id == $match->away_id) {
$result[$type.'_away_made_total'][] = $val_away;
$result[$type.'_away_made_home'][] = $val_away;
$result[$type.'_away_got_total'][] = $val_home;
$result[$type.'_away_got_home'][] = $val_home;
} elseif ($home_id == $match->away_id) {
$result[$type.'_away_made_total'][] = $val_home;
$result[$type.'_away_got_total'][] = $val_home;
} elseif ($away_id == $match->home_id) {
$result[$type.'_away_made_total'][] = $val_home;
$result[$type.'_away_got_total'][] = $val_home;
} elseif ($home_id == $match->home_id) {
$result[$type.'_away_made_total'][] = $val_away;
$result[$type.'_away_made_home'][] = $val_away;
$result[$type.'_away_got_total'][] = $val_home;
$result[$type.'_away_got_home'][] = $val_away;
}
}
}
@@ -0,0 +1,143 @@
<?php
namespace App\Filament\Widgets\Data\LoadEvents;
use App\Filament\Pages\Selections\Helper\GetSeason;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
class LoadEventsQueryAll
{
public static function load(array $filter, object $match)
{
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$season = $filter['season'];
$seasonmode = $filter['seasonmode'];
$season_or_date = $filter['season_or_date'];
$accuracy = (float) $filter['accuracy'] ?? 0.5;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
if ($season_or_date == 'season') {
$start = 0;
$end = 0;
}
$ss_player_id = (int) $filter['ss_player_id'] ?? 0;
$player_on_field = $filter['player_on_field'] ?? 'all';
$similar_past_matches = $filter['similar_past_matches'];
$team_position = $filter['team_position'];
$home_id = $match->home_id;
$away_id = $match->away_id;
$handicap_range = [];
$total_range = [];
if ($similar_past_matches != 'none') {
$team_id = 0;
$team_position = '';
$exp_handicap = $match->exp_away - $match->exp_home;
$exp_total = $match->exp_away + $match->exp_home;
$handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy];
$total_range = [$exp_total - $accuracy, $exp_total + $accuracy];
}
if ($similar_past_matches != 'none') {
$team_position = '';
$team_id = 0;
$ss_player_id = 0;
}
// dd($season);
$season = GetSeason::load($season, $seasonmode);
/**
* IF WITH PLAYER
*/
$matches_played = [];
if ($ss_player_id) {
$matches_season = StatistikoEvent::where(function ($query) use ($team_id, $team_position) {
switch ($team_position) {
case 'home':
return $query->where('home_id', '=', $team_id);
case 'away':
return $query->where('away_id', '=', $team_id);
default:
return $query->where('home_id', '=', $team_id)
->orWhere('away_id', '=', $team_id);
}
})->pluck('match_id')->toArray();
$matches_played = StatistikoPlayer::query()
->whereIn('match_id', $matches_season)
->where('ss_player_id', $ss_player_id)
->when($player_on_field, function ($query) use ($player_on_field) {
// 'all' => 'All',
// 'lineup' => 'Lineup',
// 'substituted' => 'Substituted',
// 'notplayed' => 'Not Played',
switch ($player_on_field) {
case 'all':
return $query->where('minutes_played', '>', 0);
case 'lineup':
return $query->where('lineup', 'T')->where('minutes_played', '>', 0);
case 'substituted':
return $query->where('lineup', 'P')->where('minutes_played', '>', 0);
default:
return $query->where('minutes_played', '>', 0);
}
})
->pluck('match_id')->toArray();
if (! $matches_played) {
$matches_played[] = -1;
}
}
// dd($handicap_range, $total_range);
/**
* STATTISTIC DATA
*/
return StatistikoEvent::with('home')->with('away')
->where(function ($query) use ($league_id, $similar_past_matches) {
switch ($similar_past_matches) {
case 'none':
case 'league':
return $query->where('league_id', $league_id);
}
})
->where(function ($query) use ($team_id, $home_id, $away_id, $similar_past_matches) {
if ($similar_past_matches == 'none') {
if ($team_id) {
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
} else {
return $query->whereIn('home_id', [$home_id, $away_id])->orWhereIn('away_id', [$home_id, $away_id]);
}
}
})
->when($matches_played, function ($query) use ($matches_played, $player_on_field) {
if ($player_on_field == 'notplayed') {
return $query->whereNotIn('match_id', $matches_played);
} else {
return $query->whereIn('match_id', $matches_played);
}
})
->when($handicap_range, function ($query) use ($handicap_range) {
return $query->whereBetween('exp_handicap', $handicap_range);
})->when($total_range, function ($query) use ($total_range) {
return $query->whereBetween('exp_total', $total_range);
})
->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, $season_or_date, $similar_past_matches) {
if ($similar_past_matches == 'none' && $season_or_date == 'season') {
return $query->whereIn('season', $season);
}
})
->orderBy('starttime', 'ASC')
->get();
}
}