diff --git a/app/Filament/Widgets/Boxes/AverageTeam.php b/app/Filament/Widgets/Boxes/AverageTeam.php index 8e05358c..ab4fd253 100644 --- a/app/Filament/Widgets/Boxes/AverageTeam.php +++ b/app/Filament/Widgets/Boxes/AverageTeam.php @@ -64,8 +64,6 @@ class AverageTeam foreach ($res as $val) { - // dd($team_position, $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', 'crn', $val->crn_h, $val->crn_a); @@ -100,14 +98,6 @@ class AverageTeam ExpectationAverage::filter($result, 'team', 'snt', $val->snt_a, $val->snt_h); ExpectationAverage::filter($result, 'team', 'tsh', $val->tsh_a, $val->tsh_h); } - - // ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a); - // ExpectationAverage::filter($result, 'team', 'crn', $val->crn_h, $val->crn_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); } } diff --git a/app/Filament/Widgets/Boxes/AverageTeamSeason.php b/app/Filament/Widgets/Boxes/AverageTeamSeason.php index 2603dffe..315d7ba2 100644 --- a/app/Filament/Widgets/Boxes/AverageTeamSeason.php +++ b/app/Filament/Widgets/Boxes/AverageTeamSeason.php @@ -14,15 +14,24 @@ class AverageTeamSeason public static function load(array &$expectations, array $filter, object $match) { $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); + $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); + ->when($season, function ($query) use ($season) { + return $query->where('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(); if ($res) { @@ -30,13 +39,41 @@ class AverageTeamSeason $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); + if ($team_position == 'home' && $team_id == $val->home_id) { + ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a); + ExpectationAverage::filter($result, 'team', 'crn', $val->crn_h, $val->crn_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', '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); + } else { + if ($team_id == $val->home_id) { + ExpectationAverage::filter($result, 'team', 'gls', $val->gls_h, $val->gls_a); + ExpectationAverage::filter($result, 'team', 'crn', $val->crn_h, $val->crn_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_id == $val->away_id) { + 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']; @@ -58,7 +95,7 @@ class AverageTeamSeason $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; + $expectations['active_season'] = $season; } } } diff --git a/app/Filament/Widgets/Boxes/ExpectationsTeam.php b/app/Filament/Widgets/Boxes/ExpectationsTeam.php index 7df4a840..e5256962 100644 --- a/app/Filament/Widgets/Boxes/ExpectationsTeam.php +++ b/app/Filament/Widgets/Boxes/ExpectationsTeam.php @@ -20,7 +20,6 @@ class ExpectationsTeam * STATTISTIC DATA */ $team_id = (int) $filter['team_id'] ?? 0; - $league_id = (int) $filter['league_id'] ?? 0; $team_position = $filter['team_position']; $similar_past_matches = $filter['similar_past_matches']; @@ -40,7 +39,7 @@ class ExpectationsTeam return []; } - $tmp = []; + $tmp = self::template(); foreach ($res as $value) { // dd($match->home_id, $match->away_id, $value); ExpectationCollecting::sort($similar_past_matches, $tmp, 'gls', $value->home_id, $value->away_id, $value->gls_h, $value->gls_a, $match); @@ -52,14 +51,15 @@ class ExpectationsTeam ExpectationCollecting::sort($similar_past_matches, $tmp, 'crn', $value->home_id, $value->away_id, $value->crn_h, $value->crn_a, $match); } - if (self::$collectionMethod == 'A') { - $expectations = ExpectationMethodA::calc($tmp); - } else { - $expectations = ExpectationMethodB::calc($tmp); + if ($expectations) { + if (self::$collectionMethod == 'A') { + $expectations = ExpectationMethodA::calc($tmp); + } else { + $expectations = ExpectationMethodB::calc($tmp); + } + ExpectationsMinMax::calc($expectations, $match); } - ExpectationsMinMax::calc($expectations, $match); - $expectations['gls']['name'] = 'Goals'; $expectations['crn']['name'] = 'Corner'; $expectations['fls']['name'] = 'Fouls'; @@ -120,4 +120,23 @@ class ExpectationsTeam $expectations['draw_odd'] = $expectations['draw_count'] ? number_format(Round::odd($count_tp / $expectations['draw_count']), 2) : 0; $expectations['lost_odd'] = $expectations['lost_count'] ? number_format(Round::odd($count_tp / $expectations['lost_count']), 2) : 0; } + + public static function template() + { + $arr = []; + $bets = ['gls', 'crn', 'fls', 'ofs', 'crd', 'snt', 'tsh']; + foreach ($bets as $bet) { + foreach (['team_home', 'team_away'] as $team) { + foreach (['scored', 'conceded'] as $sc) { + foreach (['home', 'away'] as $ha) { + foreach (['evt', 'sum'] as $es) { + $arr[$bet][$team][$sc][$ha][$es] = 0; + } + } + } + } + } + + return $arr; + } } diff --git a/app/Filament/Widgets/Boxes/Helper/ExpectationMethodB.php b/app/Filament/Widgets/Boxes/Helper/ExpectationMethodB.php index a1b0218e..9a8c09d9 100644 --- a/app/Filament/Widgets/Boxes/Helper/ExpectationMethodB.php +++ b/app/Filament/Widgets/Boxes/Helper/ExpectationMethodB.php @@ -13,28 +13,32 @@ class ExpectationMethodB $result = []; foreach ($expectations as $bettype => $data) { - $result[$bettype]['home'] = round(( - $data['team_home']['scored']['home']['sum'] * $cfHA + - $data['team_home']['scored']['away']['sum'] + - $data['team_away']['conceded']['away']['sum'] * $cfHA + - $data['team_away']['conceded']['home']['sum'] - ) / ( - $data['team_home']['scored']['home']['evt'] * $cfHA + - $data['team_home']['scored']['away']['evt'] + - $data['team_away']['conceded']['home']['evt'] + - $data['team_away']['conceded']['away']['evt'] * $cfHA - ), 1); - $result[$bettype]['away'] = round(( - $data['team_home']['conceded']['home']['sum'] * $cfHA + - $data['team_home']['conceded']['away']['sum'] + - $data['team_away']['scored']['away']['sum'] * $cfHA + - $data['team_away']['scored']['home']['sum'] - ) / ( - $data['team_home']['conceded']['home']['evt'] * $cfHA + - $data['team_home']['conceded']['away']['evt'] + - $data['team_away']['scored']['home']['evt'] + - $data['team_away']['scored']['away']['evt'] * $cfHA - ), 1); + if ($data['team_home']['scored']['home']['evt'] && $data['team_away']['scored']['home']['evt']) { + $result[$bettype]['home'] = round(( + $data['team_home']['scored']['home']['sum'] * $cfHA + + $data['team_home']['scored']['away']['sum'] + + $data['team_away']['conceded']['away']['sum'] * $cfHA + + $data['team_away']['conceded']['home']['sum'] + ) / ( + $data['team_home']['scored']['home']['evt'] * $cfHA + + $data['team_home']['scored']['away']['evt'] + + $data['team_away']['conceded']['home']['evt'] + + $data['team_away']['conceded']['away']['evt'] * $cfHA + ), 1); + } + if ($data['team_home']['scored']['home']['evt'] && $data['team_away']['scored']['home']['evt']) { + $result[$bettype]['away'] = round(( + $data['team_home']['conceded']['home']['sum'] * $cfHA + + $data['team_home']['conceded']['away']['sum'] + + $data['team_away']['scored']['away']['sum'] * $cfHA + + $data['team_away']['scored']['home']['sum'] + ) / ( + $data['team_home']['conceded']['home']['evt'] * $cfHA + + $data['team_home']['conceded']['away']['evt'] + + $data['team_away']['scored']['home']['evt'] + + $data['team_away']['scored']['away']['evt'] * $cfHA + ), 1); + } } return $result; diff --git a/app/Filament/Widgets/Boxes/Helper/ExpectationsMinMax.php b/app/Filament/Widgets/Boxes/Helper/ExpectationsMinMax.php index 7bc47b54..6e0736be 100644 --- a/app/Filament/Widgets/Boxes/Helper/ExpectationsMinMax.php +++ b/app/Filament/Widgets/Boxes/Helper/ExpectationsMinMax.php @@ -62,17 +62,19 @@ class ExpectationsMinMax } foreach ($bets as $key) { - if ($expectations[$key]['home'] > $final[$key]['max']) { - $expectations[$key]['home'] = $final[$key]['max']; - } - if ($expectations[$key]['away'] > $final[$key]['max']) { - $expectations[$key]['away'] = $final[$key]['max']; - } - if ($expectations[$key]['home'] < $final[$key]['min']) { - $expectations[$key]['home'] = $final[$key]['min']; - } - if ($expectations[$key]['away'] < $final[$key]['min']) { - $expectations[$key]['away'] = $final[$key]['min']; + if (isset($expectations[$key])) { + if ($expectations[$key]['home'] > $final[$key]['max']) { + $expectations[$key]['home'] = $final[$key]['max']; + } + if ($expectations[$key]['away'] > $final[$key]['max']) { + $expectations[$key]['away'] = $final[$key]['max']; + } + if ($expectations[$key]['home'] < $final[$key]['min']) { + $expectations[$key]['home'] = $final[$key]['min']; + } + if ($expectations[$key]['away'] < $final[$key]['min']) { + $expectations[$key]['away'] = $final[$key]['min']; + } } } @@ -82,17 +84,19 @@ class ExpectationsMinMax $gls_away_max = $match->exp_away * (1 + ($Y / 2)); $gls_away_min = $match->exp_away * (1 - ($Y / 2)); - if ($expectations['gls']['home'] > $gls_home_max) { - $expectations['gls']['home'] = $gls_home_max; - } - if ($expectations['gls']['away'] > $gls_away_max) { - $expectations['gls']['away'] = $gls_away_max; - } - if ($expectations['gls']['home'] < $gls_home_min) { - $expectations['gls']['home'] = $gls_home_min; - } - if ($expectations['gls']['away'] < $gls_away_min) { - $expectations['gls']['away'] = $gls_away_min; + if (isset($expectations['gls'])) { + if ($expectations['gls']['home'] > $gls_home_max) { + $expectations['gls']['home'] = $gls_home_max; + } + if ($expectations['gls']['away'] > $gls_away_max) { + $expectations['gls']['away'] = $gls_away_max; + } + if ($expectations['gls']['home'] < $gls_home_min) { + $expectations['gls']['home'] = $gls_home_min; + } + if ($expectations['gls']['away'] < $gls_away_min) { + $expectations['gls']['away'] = $gls_away_min; + } } } } diff --git a/app/Filament/Widgets/Boxes/LoadEventsBoxes.php b/app/Filament/Widgets/Boxes/LoadEventsBoxes.php index 9560cab7..170d5526 100644 --- a/app/Filament/Widgets/Boxes/LoadEventsBoxes.php +++ b/app/Filament/Widgets/Boxes/LoadEventsBoxes.php @@ -26,7 +26,7 @@ class LoadEventsBoxes return []; } - $expectations = []; + $expectations = self::template(); ExpectationsTeam::load($expectations, $filter, $match); @@ -47,4 +47,23 @@ class LoadEventsBoxes return $expectations; } + + public static function template() + { + $arr = []; + $bets = ['gls', 'crn', 'fls', 'ofs', 'crd', 'snt', 'tsh']; + foreach ($bets as $bet) { + foreach (['team_home', 'team_away'] as $team) { + foreach (['scored', 'conceded'] as $sc) { + foreach (['home', 'away'] as $ha) { + foreach (['evt', 'sum'] as $es) { + $arr[$bet][$team][$sc][$ha][$es] = 0; + } + } + } + } + } + + return $arr; + } } diff --git a/app/Filament/Widgets/BoxesBettypeAll.php b/app/Filament/Widgets/BoxesBettypeAll.php index 961fcc95..15db2ddd 100644 --- a/app/Filament/Widgets/BoxesBettypeAll.php +++ b/app/Filament/Widgets/BoxesBettypeAll.php @@ -144,8 +144,8 @@ class BoxesBettypeAll extends StatsOverviewWidget // $str .= '