diff --git a/app/Filament/Widgets/Data/LoadEvents.php b/app/Filament/Widgets/Data/LoadEvents.php index ac5b2cad..32d1d412 100644 --- a/app/Filament/Widgets/Data/LoadEvents.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -18,10 +18,8 @@ class LoadEvents $match_id = (int) $filter['match_id'] ?? 0; $team_id = (int) $filter['team_id'] ?? 0; $season_or_date = $filter['season_or_date'] ?? 'season'; - $ss_player_id = (int) $filter['ss_player_id'] ?? 0; $statistic_type = $filter['statistic_type'] ?? 'gls'; $team_position = $filter['team_position']; - $player_on_field = $filter['player_on_field'] ?? 'all'; $accuracy = (float) $filter['accuracy'] ?? 0.5; $similar_past_matches = $filter['similar_past_matches']; @@ -76,56 +74,12 @@ class LoadEvents $away_team = 'Against'; } - /** - * IF WITH PLAYER - */ - $matches_played = []; - $description = ''; - - 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; - } - } - $match = StatisticFixtures::where('id', $match_id)->first(); /** * STATTISTIC DATA */ - $res = LoadEventsQuery::load($filter, $matches_played, $handicap_range, $total_range, $match); + $res = LoadEventsQuery::load($filter, $handicap_range, $total_range, $match); + $dataset_home = []; $dataset_away = []; @@ -137,11 +91,8 @@ class LoadEvents $events = []; $results = ['w' => 0, 'd' => 0, 'l' => 0, 'w2' => 0, 'l2' => 0]; - if (!\in_array($team_position, ['home', 'away'])) + if (!$team_id || !\in_array($team_position, ['home', 'away'])) { $team_position = 'all'; - - if (!isset($res[$team_position])) { - return []; } $expectations = LoadExpectations::load($res['all'], $match, $statistic_type); diff --git a/app/Filament/Widgets/Data/LoadEvents/LoadEventsQuery.php b/app/Filament/Widgets/Data/LoadEvents/LoadEventsQuery.php index 7fc3dc5a..242a70d7 100644 --- a/app/Filament/Widgets/Data/LoadEvents/LoadEventsQuery.php +++ b/app/Filament/Widgets/Data/LoadEvents/LoadEventsQuery.php @@ -3,19 +3,22 @@ namespace App\Filament\Widgets\Data\LoadEvents; use App\Models\StatistikoEvent; +use App\Models\StatistikoPlayer; class LoadEventsQuery { - public static function load(array $filter, array $matches_played, array $handicap_range, array $total_range, object $match) + 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'] ?? 0; $start = $filter['start_date'] ?? 0; $end = $filter['end_date'] ?? 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; @@ -23,6 +26,50 @@ class LoadEventsQuery $statistic_type = 'gls'; } + /** + * 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; + } + } + /** * STATTISTIC DATA */ @@ -61,6 +108,8 @@ class LoadEventsQuery ->orderBy('starttime', 'ASC') ->get(); + // dd($res); + $arr = []; foreach ($res as $value) { $tmp = []; diff --git a/app/Filament/Widgets/StatsMedianAverage.php b/app/Filament/Widgets/StatsMedianAverage.php index 25aebef2..6be511ad 100644 --- a/app/Filament/Widgets/StatsMedianAverage.php +++ b/app/Filament/Widgets/StatsMedianAverage.php @@ -44,6 +44,7 @@ class StatsMedianAverage extends StatsOverviewWidget return []; } + $statistic_type = HelperStatisticType::get($this->filters); if (! isset($data['datasets'][0])) { @@ -124,46 +125,6 @@ class StatsMedianAverage extends StatsOverviewWidget } $boxes = []; - // BOX 1 - $boxes[] = Stat::make('Total', new HtmlString('
' . $total_home . '
')) - ->description('Events') - ->extraAttributes([ - 'class' => 'box-info', - ]); - // ->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); - - // BOX 2 - $boxes[] = Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team, $value_home, $value_away)) - ->description('Team ' . $team_position) - ->extraAttributes([ - 'class' => 'box-success', - ]); - // ->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]); - - // BOX 3 - // Log::debug([$average_team_home, $average_team_away]); - $boxes[] = Stat::make('Average ' . $statistic_type, self::template('av_team_home', 'av_team_away', $home_team, $away_team, $average_team_home, $average_team_away)) - ->description('Team Season') - ->extraAttributes([ - 'class' => 'box-success', - ]); - // ->extraAttributes(['x-init' => "animate('av_team_home', $average_team_home); animate('av_team_away', $average_team_away)"]); - - // BOX 4 - $boxes[] = Stat::make('Average ' . $statistic_type, self::template('av_league_home', 'av_league_away', 'Home', 'Away', $average_league_home, $average_league_away)) - ->description('League Season') - ->extraAttributes([ - 'class' => 'box-success', - ]); - // ->extraAttributes(['x-init' => "animate('av_league_home', $average_league_home); animate('av_league_away', $average_league_away)"]); - - // BOX 5 - $boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost)) - ->description($team_position) - ->extraAttributes([ - 'class' => 'box-purple', - ]); - // ->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]); // BOX 6 $boxes[] = Stat::make($statistic_type, self::template('expectations_home', 'expectations_away', 'Home', 'Away', $expectations_home, $expectations_away)) @@ -172,6 +133,49 @@ class StatsMedianAverage extends StatsOverviewWidget 'class' => 'box-yellow', ]); + if ($team_id) { + // BOX 1 + $boxes[] = Stat::make('Total', new HtmlString('
' . $total_home . '
')) + ->description('Events') + ->extraAttributes([ + 'class' => 'box-info', + ]); + // ->extraAttributes(['x-init' => "animate('number-of-events', $total_home, 0)"]); + + // BOX 2 + $boxes[] = Stat::make('Average ' . $statistic_type, self::template('avhome', 'avaway', $home_team, $away_team, $value_home, $value_away)) + ->description('Team ' . $team_position) + ->extraAttributes([ + 'class' => 'box-success', + ]); + // ->extraAttributes(['x-init' => "animate('avhome', $value_home); animate('avaway', $value_away)"]); + + // BOX 3 + // Log::debug([$average_team_home, $average_team_away]); + $boxes[] = Stat::make('Average ' . $statistic_type, self::template('av_team_home', 'av_team_away', $home_team, $away_team, $average_team_home, $average_team_away)) + ->description('Team Season') + ->extraAttributes([ + 'class' => 'box-success', + ]); + // ->extraAttributes(['x-init' => "animate('av_team_home', $average_team_home); animate('av_team_away', $average_team_away)"]); + + // BOX 4 + $boxes[] = Stat::make('Average ' . $statistic_type, self::template('av_league_home', 'av_league_away', 'Home', 'Away', $average_league_home, $average_league_away)) + ->description('League Season') + ->extraAttributes([ + 'class' => 'box-success', + ]); + // ->extraAttributes(['x-init' => "animate('av_league_home', $average_league_home); animate('av_league_away', $average_league_away)"]); + + // BOX 5 + $boxes[] = Stat::make('Odds', self::templateOdds($data, $win, $draw, $lost)) + ->description($team_position) + ->extraAttributes([ + 'class' => 'box-purple', + ]); + // ->extraAttributes(['x-init' => "animate('mehome', $median_home); animate('meaway', $median_away, 0)"]); + } + $this->columns = [ 'default' => 1, 'sm' => 2,