diff --git a/app/Filament/Widgets/Boxes/ExpectationsTeam.php b/app/Filament/Widgets/Boxes/ExpectationsTeam.php index f88d958d..b1fdefda 100644 --- a/app/Filament/Widgets/Boxes/ExpectationsTeam.php +++ b/app/Filament/Widgets/Boxes/ExpectationsTeam.php @@ -6,6 +6,7 @@ use App\Filament\Widgets\Boxes\Helper\ExpectationCalculation; use App\Filament\Widgets\Boxes\Helper\ExpectationCollecting; use App\Filament\Widgets\Boxes\Helper\ExpectationCounting; use App\Filament\Widgets\Charts\LoadEvents\LoadEventsQueryAll; +use App\Filament\Widgets\Charts\LoadEvents\LoadEventsQueryTP; use App\Utilities\Round; use Illuminate\Support\Facades\Log; @@ -31,9 +32,12 @@ class ExpectationsTeam } $res = LoadEventsQueryAll::load($filter, $match); - $count_events_selection = $res->count(); - $count_events = ExpectationCounting::count($team_position, $team_id, $res); + $res_tp = LoadEventsQueryTP::load($filter, $match); + + $count_tp = $res_tp->count(); + + // $count_events = ExpectationCounting::count($team_position, $team_id, $res); // Log::debug('count_events ' . $count_events); @@ -62,10 +66,10 @@ class ExpectationsTeam $expectations['tsh']['name'] = 'Total Shots'; $expectations['home'] = $home_team; $expectations['away'] = $away_team; - $expectations['count_events'] = $count_events; + $expectations['count_events'] = $count_tp; $expectations += ['win_count' => 0, 'draw_count' => 0, 'lost_count' => 0]; - foreach ($res as $value) { + foreach ($res_tp as $value) { if ($team_id && $team_position == 'home') { switch ($value['result_code']) { case '1': @@ -105,8 +109,8 @@ class ExpectationsTeam } } - $expectations['win_odd'] = $expectations['win_count'] ? number_format(Round::odd($count_events_selection / $expectations['win_count']), 2) : 0; - $expectations['draw_odd'] = $expectations['draw_count'] ? number_format(Round::odd($count_events_selection / $expectations['draw_count']), 2) : 0; - $expectations['lost_odd'] = $expectations['lost_count'] ? number_format(Round::odd($count_events_selection / $expectations['lost_count']), 2) : 0; + $expectations['win_odd'] = $expectations['win_count'] ? number_format(Round::odd($count_tp / $expectations['win_count']), 2) : 0; + $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; } } diff --git a/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQueryAll.php b/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQueryAll.php index 9db29ecb..7187034e 100644 --- a/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQueryAll.php +++ b/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQueryAll.php @@ -48,19 +48,6 @@ class LoadEventsQueryAll $matches_played = []; if ($ss_player_id) { - // $matches_season = StatistikoEvent::whereIn('season', $season) - // ->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_season = StatistikoEvent::whereIn('season', $season) ->where(function ($query) use ($team_id) { return $query->where('home_id', '=', $team_id) @@ -111,19 +98,6 @@ class LoadEventsQueryAll return $query->where('home_id', '=', $team_id) ->orWhere('away_id', '=', $team_id); }) - // ->where(function ($query) use ($team_id, $similar_past_matches, $team_position) { - // if ($team_id && $similar_past_matches == 'none') { - // 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); - // } - // } - // }) ->when($matches_played, function ($query) use ($matches_played, $player_on_field) { if ($player_on_field == 'notplayed') { return $query->whereNotIn('match_id', $matches_played); diff --git a/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQuerySPM.php b/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQueryTP.php similarity index 85% rename from app/Filament/Widgets/Charts/LoadEvents/LoadEventsQuerySPM.php rename to app/Filament/Widgets/Charts/LoadEvents/LoadEventsQueryTP.php index 466d293b..46352371 100644 --- a/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQuerySPM.php +++ b/app/Filament/Widgets/Charts/LoadEvents/LoadEventsQueryTP.php @@ -6,7 +6,7 @@ use App\Filament\Pages\Selections\Helper\GetSeason; use App\Models\StatistikoEvent; use App\Models\StatistikoPlayer; -class LoadEventsQuerySPM +class LoadEventsQueryTP { public static function load(array $filter, object $match) { @@ -26,8 +26,6 @@ class LoadEventsQuerySPM $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 = []; @@ -63,6 +61,12 @@ class LoadEventsQuerySPM } })->pluck('match_id')->toArray(); + $matches_season = StatistikoEvent::whereIn('season', $season) + ->where(function ($query) use ($team_id) { + 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) @@ -103,13 +107,16 @@ class LoadEventsQuerySPM 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]); + ->where(function ($query) use ($team_id, $similar_past_matches, $team_position) { + if ($team_id && $similar_past_matches == 'none') { + 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); } } })