From a4f7447fa7799d2d8ab4158b534a813160849e5d Mon Sep 17 00:00:00 2001 From: salam Date: Mon, 25 May 2026 16:52:36 +0200 Subject: [PATCH] wip --- app/Filament/Pages/Statistic.php | 3 +- app/Filament/Widgets/Data/LoadEvents.php | 56 +++++++++++++++++++----- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/app/Filament/Pages/Statistic.php b/app/Filament/Pages/Statistic.php index 08665d18..debab141 100644 --- a/app/Filament/Pages/Statistic.php +++ b/app/Filament/Pages/Statistic.php @@ -133,7 +133,8 @@ class Statistic extends BaseDashboard ->decimalPlaces(1) ->tooltips() ->range(minValue: 0, maxValue: 1) - ->pips(), + ->pips() + ->live(), // Select::make('accuracy') // ->disabled(fn (Get $get) => $get('similar_past_matches') == 'none') // ->default(0.5) diff --git a/app/Filament/Widgets/Data/LoadEvents.php b/app/Filament/Widgets/Data/LoadEvents.php index 16acabbb..360afd45 100644 --- a/app/Filament/Widgets/Data/LoadEvents.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -2,6 +2,7 @@ namespace App\Filament\Widgets\Data; +use App\Models\StatisticFixtures; use App\Models\StatistikoDetail; use App\Models\StatistikoEvent; use App\Models\StatistikoPlayer; @@ -38,6 +39,8 @@ class LoadEvents $accuracy = (float) $filter['accuracy']; + $similar_past_matches = $filter['similar_past_matches']; + if (! $league_id) { return []; } @@ -49,6 +52,27 @@ class LoadEvents $statistic_type = 'gls'; } + /** + * IF WITH SIMILAR_PAST_MATCHES + * + * 'none' => 'None', + * 'league' => 'League', + * 'all' => 'All Database', + */ + $handicap_range = 0; + $total_range = 0; + if ($similar_past_matches != 'none') { + $res = StatisticFixtures::where('id', (int) $match_id)->first(); + + $exp_handicap = $res->exp_away - $res->exp_home; + + $exp_total = $res->exp_away + $res->exp_home; + + $handicap_range = [$exp_handicap - $accuracy, $exp_handicap + $accuracy]; + + $total_range = [$exp_total - $accuracy, $exp_total + $accuracy]; + } + /** * IF WITH PLAYER */ @@ -78,19 +102,31 @@ class LoadEvents */ $res = StatistikoEvent::with('home') ->with('away') - ->where('league_id', $league_id) - ->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); + ->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, $team_position, $similar_past_matches) { + if ($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) { 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->where('starttime', '>=', $start); })->when($end, function ($query) use ($end) {