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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Charts\LoadEvents;
|
||||
|
||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LoadEventsQuery
|
||||
{
|
||||
public static function load(array $filter, array $handicap_range, array $total_range, 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'];
|
||||
$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'];
|
||||
$statistic_type = $filter['statistic_type'] ?? 'gls';
|
||||
$team_position = $filter['team_position'];
|
||||
$home_id = $match->home_id;
|
||||
$away_id = $match->away_id;
|
||||
|
||||
if ($statistic_type == 'none') {
|
||||
$statistic_type = 'gls';
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
// dd($team_id, $home_id, $away_id);
|
||||
$res = 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();
|
||||
|
||||
// dd($res);
|
||||
// dd($season, $league_id, $res);
|
||||
Log::info('season', $season);
|
||||
|
||||
$arr = [];
|
||||
foreach ($res as $value) {
|
||||
|
||||
$tmp = [];
|
||||
$tmp['match_id'] = $value->match_id;
|
||||
$tmp['sport_id'] = $value->sport_id;
|
||||
$tmp['league_id'] = $value->league_id;
|
||||
$tmp['home_id'] = $value->home_id;
|
||||
$tmp['away_id'] = $value->away_id;
|
||||
$tmp['starttime'] = $value->starttime;
|
||||
$tmp['season'] = $value->season;
|
||||
$tmp['exp_home'] = $value->exp_home;
|
||||
$tmp['exp_away'] = $value->exp_away;
|
||||
$tmp['exp_handicap'] = $value->exp_handicap;
|
||||
$tmp['exp_total'] = $value->exp_total;
|
||||
$tmp['result_code'] = $value->result_code;
|
||||
$tmp['home'] = $value->home->ss_team_name ?? 0;
|
||||
$tmp['away'] = $value->away->ss_team_name ?? 0;
|
||||
|
||||
switch ($statistic_type) {
|
||||
case 'gls':
|
||||
$tmp['val_home'] = $value->gls_h;
|
||||
$tmp['val_away'] = $value->gls_a;
|
||||
break;
|
||||
case 'crn':
|
||||
$tmp['val_home'] = $value->crn_h;
|
||||
$tmp['val_away'] = $value->crn_a;
|
||||
break;
|
||||
case 'fls':
|
||||
$tmp['val_home'] = $value->fls_h;
|
||||
$tmp['val_away'] = $value->fls_a;
|
||||
break;
|
||||
case 'ofs':
|
||||
$tmp['val_home'] = $value->ofs_h;
|
||||
$tmp['val_away'] = $value->ofs_a;
|
||||
break;
|
||||
case 'crd':
|
||||
$tmp['val_home'] = $value->crd_h;
|
||||
$tmp['val_away'] = $value->crd_a;
|
||||
break;
|
||||
case 'snt':
|
||||
$tmp['val_home'] = $value->snt_h;
|
||||
$tmp['val_away'] = $value->snt_a;
|
||||
break;
|
||||
case 'tsh':
|
||||
$tmp['val_home'] = $value->tsh_h;
|
||||
$tmp['val_away'] = $value->tsh_a;
|
||||
break;
|
||||
}
|
||||
|
||||
$arr['all'][] = $tmp;
|
||||
if ($value->home_id == $team_id) {
|
||||
$arr['home'][] = $tmp;
|
||||
}
|
||||
if ($value->away_id == $team_id) {
|
||||
$arr['away'][] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Charts\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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Charts\LoadEvents;
|
||||
|
||||
use App\Models\StatistikoConfig;
|
||||
|
||||
class LoadExpectations
|
||||
{
|
||||
public static function load(array $data, object $match, string $statistic_type)
|
||||
{
|
||||
|
||||
// dd($data, $match);
|
||||
|
||||
$config = StatistikoConfig::where('group', $statistic_type)->get();
|
||||
|
||||
$uba_home_made_total = 1;
|
||||
$uba_home_made_home = 1;
|
||||
$uba_home_got_total = 1;
|
||||
$uba_home_got_home = 1;
|
||||
$uba_away_made_total = 1;
|
||||
$uba_away_made_home = 1;
|
||||
$uba_away_got_total = 1;
|
||||
$uba_away_got_home = 1;
|
||||
|
||||
foreach ($config as $value) {
|
||||
$varname = str_replace($statistic_type.'_', '', $value->varname);
|
||||
switch ($varname) {
|
||||
case 'home_made_total':
|
||||
$uba_home_made_total = (float) $value->value;
|
||||
break;
|
||||
case 'home_made_home':
|
||||
$uba_home_made_home = (float) $value->value;
|
||||
break;
|
||||
case 'home_got_total':
|
||||
$uba_home_got_total = (float) $value->value;
|
||||
break;
|
||||
case 'home_got_home':
|
||||
$uba_home_got_home = (float) $value->value;
|
||||
break;
|
||||
case 'away_made_total':
|
||||
$uba_away_made_total = (float) $value->value;
|
||||
break;
|
||||
case 'away_made_home':
|
||||
$uba_away_made_home = (float) $value->value;
|
||||
break;
|
||||
case 'away_got_total':
|
||||
$uba_away_got_total = (float) $value->value;
|
||||
break;
|
||||
case 'away_got_home':
|
||||
$uba_away_got_home = (float) $value->value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$home_made_total = [];
|
||||
$home_made_home = [];
|
||||
$home_got_total = [];
|
||||
$home_got_home = [];
|
||||
|
||||
$away_made_total = [];
|
||||
$away_made_away = [];
|
||||
$away_got_total = [];
|
||||
$away_got_away = [];
|
||||
|
||||
$home_id = $match->home_id;
|
||||
$away_id = $match->away_id;
|
||||
foreach ($data as $value) {
|
||||
// HOME
|
||||
// if ($value['home_id'] == $home_id || $value['away_id'] == $home_id) {
|
||||
// $home_made_total[] = $value['val_home'];
|
||||
// $home_got_total[] = $value['val_away'];
|
||||
// }
|
||||
// if ($value['home_id'] == $home_id) {
|
||||
// $home_made_home[] = $value['val_home'];
|
||||
// $home_got_home[] = $value['val_away'];
|
||||
// }
|
||||
|
||||
// AWAY
|
||||
// if ($value['home_id'] == $away_id || $value['away_id'] == $away_id) {
|
||||
// $away_made_total[] = $value['val_away'];
|
||||
// $away_made_away[] = $value['val_home'];
|
||||
// }
|
||||
|
||||
// if ($value['away_id'] == $away_id) {
|
||||
// $away_made_away[] = $value['val_away'];
|
||||
// $away_got_away[] = $value['val_home'];
|
||||
// }
|
||||
|
||||
if ($value['home_id'] == $home_id) {
|
||||
$home_made_total[] = $value['val_home'];
|
||||
$home_made_home[] = $value['val_home'];
|
||||
$home_got_total[] = $value['val_away'];
|
||||
$home_got_home[] = $value['val_away'];
|
||||
} elseif ($value['away_id'] == $home_id) {
|
||||
$home_made_total[] = $value['val_away'];
|
||||
$home_got_total[] = $value['val_away'];
|
||||
} elseif ($value['home_id'] == $away_id) {
|
||||
$home_made_total[] = $value['val_away'];
|
||||
$home_got_total[] = $value['val_away'];
|
||||
} elseif ($value['away_id'] == $away_id) {
|
||||
$home_made_total[] = $value['val_home'];
|
||||
$home_made_home[] = $value['val_home'];
|
||||
$home_got_total[] = $value['val_away'];
|
||||
$home_got_home[] = $value['val_home'];
|
||||
}
|
||||
|
||||
if ($value['away_id'] == $away_id) {
|
||||
$away_made_total[] = $value['val_away'];
|
||||
$away_made_away[] = $value['val_away'];
|
||||
$away_got_total[] = $value['val_home'];
|
||||
$away_got_away[] = $value['val_home'];
|
||||
} elseif ($value['home_id'] == $away_id) {
|
||||
$away_made_total[] = $value['val_home'];
|
||||
$away_got_total[] = $value['val_home'];
|
||||
} elseif ($value['away_id'] == $home_id) {
|
||||
$away_made_total[] = $value['val_home'];
|
||||
$away_got_total[] = $value['val_home'];
|
||||
} elseif ($value['home_id'] == $home_id) {
|
||||
$away_made_total[] = $value['val_away'];
|
||||
$away_made_away[] = $value['val_away'];
|
||||
$away_got_total[] = $value['val_home'];
|
||||
$away_got_away[] = $value['val_away'];
|
||||
}
|
||||
}
|
||||
|
||||
$summe_home = array_sum($home_made_total) * $uba_home_made_total;
|
||||
$summe_home += array_sum($home_made_home) * $uba_home_made_home;
|
||||
$summe_home += array_sum($home_got_total) * $uba_home_got_total;
|
||||
$summe_home += array_sum($home_got_home) * $uba_home_got_home;
|
||||
$count_home = \count($home_made_total);
|
||||
$count_home += \count($home_made_home);
|
||||
$count_home += \count($home_got_total);
|
||||
$count_home += \count($home_got_home);
|
||||
|
||||
$count_home = ! $count_home ? 1 : $count_home;
|
||||
$aspettativa_home = round($summe_home / $count_home, 1);
|
||||
// dd($count_home, $summe_home, $aspettativa_home);
|
||||
|
||||
$summe_away = array_sum($away_made_total) * $uba_away_made_total;
|
||||
$summe_away += array_sum($away_made_away) * $uba_away_made_home;
|
||||
$summe_away += array_sum($away_got_total) * $uba_away_got_total;
|
||||
$summe_away += array_sum($away_got_away) * $uba_away_got_home;
|
||||
$count_away = \count($away_made_total);
|
||||
$count_away += \count($away_made_away);
|
||||
$count_away += \count($away_got_total);
|
||||
$count_away += \count($away_got_away);
|
||||
|
||||
$count_away = ! $count_away ? 1 : $count_away;
|
||||
$aspettativa_away = round($summe_away / $count_away, 1);
|
||||
|
||||
return ['home' => $aspettativa_home, 'away' => $aspettativa_away];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user