wip average all bettype in boxes
This commit is contained in:
1 parent
1a46e5d887
commit
fe4fa6e9cf
16 files changed
+1010
-135
No files matched your search
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets\Data;
|
||||
|
||||
use App\Filament\Widgets\Data\LoadEvents\AverageLeagueSeason;
|
||||
use App\Filament\Widgets\Data\LoadEvents\AverageTeam;
|
||||
use App\Filament\Widgets\Data\LoadEvents\AverageTeamSeason;
|
||||
use App\Filament\Widgets\Data\LoadEvents\ExpectationCalculation;
|
||||
use App\Filament\Widgets\Data\LoadEvents\ExpectationCollecting;
|
||||
use App\Filament\Widgets\Data\LoadEvents\LoadEventsQueryAll;
|
||||
use App\Models\StatisticFixtures;
|
||||
use App\Utilities\Round;
|
||||
|
||||
class LoadEventsBoxes
|
||||
{
|
||||
public static function load(array $filter, bool $hasdots)
|
||||
{
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
$match_id = (int) $filter['match_id'] ?? 0;
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
$team_position = $filter['team_position'];
|
||||
$similar_past_matches = $filter['similar_past_matches'];
|
||||
|
||||
if (! $league_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $match_id) {
|
||||
return [];
|
||||
}
|
||||
if (! $team_id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
|
||||
|
||||
if (! $match) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($similar_past_matches != 'none') {
|
||||
$team_id = 0;
|
||||
$team_position = '';
|
||||
$home_team = $match->home->ss_team_name;
|
||||
$away_team = $match->away->ss_team_name;
|
||||
} else {
|
||||
$home_team = 'In Favour';
|
||||
$away_team = 'Against';
|
||||
}
|
||||
|
||||
/**
|
||||
* STATTISTIC DATA
|
||||
*/
|
||||
$res = LoadEventsQueryAll::load($filter, $match);
|
||||
if (! $res) {
|
||||
return [];
|
||||
}
|
||||
$tmp = [];
|
||||
foreach ($res as $value) {
|
||||
ExpectationCollecting::sort($tmp, 'gls', $value->home_id, $value->away_id, $value->gls_h, $value->gls_a, $match);
|
||||
ExpectationCollecting::sort($tmp, 'fls', $value->home_id, $value->away_id, $value->fls_h, $value->fls_a, $match);
|
||||
ExpectationCollecting::sort($tmp, 'ofs', $value->home_id, $value->away_id, $value->ofs_h, $value->ofs_a, $match);
|
||||
ExpectationCollecting::sort($tmp, 'crd', $value->home_id, $value->away_id, $value->crd_h, $value->crd_a, $match);
|
||||
ExpectationCollecting::sort($tmp, 'snt', $value->home_id, $value->away_id, $value->snt_h, $value->snt_a, $match);
|
||||
ExpectationCollecting::sort($tmp, 'tsh', $value->home_id, $value->away_id, $value->tsh_h, $value->tsh_a, $match);
|
||||
ExpectationCollecting::sort($tmp, 'crn', $value->home_id, $value->away_id, $value->crn_h, $value->crn_a, $match);
|
||||
}
|
||||
$expectations = ExpectationCalculation::calc($tmp);
|
||||
$expectations['gls']['name'] = 'Goals';
|
||||
$expectations['fls']['name'] = 'Fouls';
|
||||
$expectations['ofs']['name'] = 'Offsides';
|
||||
$expectations['crd']['name'] = 'Cards';
|
||||
$expectations['snt']['name'] = 'Shots on Target';
|
||||
$expectations['tsh']['name'] = 'Total Shots';
|
||||
$expectations['home'] = $home_team;
|
||||
$expectations['away'] = $away_team;
|
||||
|
||||
$expectations += ['win_count' => 0, 'draw_count' => 0, 'lost_count' => 0];
|
||||
$count_events = 0;
|
||||
foreach ($res as $value) {
|
||||
// dd($value);
|
||||
if ($team_id && $team_position == 'home') {
|
||||
$count_events++;
|
||||
switch ($value['result_code']) {
|
||||
case '1':
|
||||
$expectations['win_count']++;
|
||||
break;
|
||||
case 'X':
|
||||
$expectations['draw_count']++;
|
||||
break;
|
||||
case '2':
|
||||
$expectations['lost_count']++;
|
||||
break;
|
||||
}
|
||||
|
||||
} elseif ($team_id && $team_position == 'away') {
|
||||
$count_events++;
|
||||
switch ($value['result_code']) {
|
||||
case '1':
|
||||
$expectations['win_count']++;
|
||||
break;
|
||||
case 'X':
|
||||
$expectations['draw_count']++;
|
||||
break;
|
||||
case '2':
|
||||
$expectations['lost_count']++;
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
$count_events++;
|
||||
switch ($value['result_code']) {
|
||||
case '1':
|
||||
$expectations['win_count']++;
|
||||
break;
|
||||
case 'X':
|
||||
$expectations['draw_count']++;
|
||||
break;
|
||||
case '2':
|
||||
$expectations['lost_count']++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$expectations['win_odd'] = $expectations['win_count'] ? number_format(Round::odd($count_events / $expectations['win_count']), 2) : 0;
|
||||
$expectations['draw_odd'] = $expectations['draw_count'] ? number_format(Round::odd($count_events / $expectations['draw_count']), 2) : 0;
|
||||
$expectations['lost_odd'] = $expectations['lost_count'] ? number_format(Round::odd($count_events / $expectations['lost_count']), 2) : 0;
|
||||
$expectations['count_events'] = $count_events;
|
||||
|
||||
if ($team_id == $match->home_id) {
|
||||
$expectations['active_team'] = $match->home->ss_team_name;
|
||||
} else {
|
||||
$expectations['active_team'] = $match->away->ss_team_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* LEAGUE AVERAGES
|
||||
*/
|
||||
if ($team_id != 0 && $similar_past_matches == 'none') {
|
||||
AverageTeam::load($expectations, $filter);
|
||||
AverageTeamSeason::load($expectations, $filter);
|
||||
AverageLeagueSeason::load($expectations, $filter);
|
||||
}
|
||||
|
||||
return $expectations;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user