diff --git a/NOTES.md b/NOTES.md index 654169cd..cf24f135 100644 --- a/NOTES.md +++ b/NOTES.md @@ -27,4 +27,6 @@ https://icehouse-ventures.github.io/laravel-chartjs/ https://www.chartjs.org/docs/latest/configuration/interactions.html -https://www.sofascore.com/api/v1/unique-tournament/17/season/96668/standings/total \ No newline at end of file +https://www.sofascore.com/api/v1/unique-tournament/17/season/96668/standings/total + +/** @var \App\Models\User */ \ No newline at end of file diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/SofaScoreRosaResource.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/SofaScoreRosaResource.php index 97dad82c..f8d3e14b 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/SofaScoreRosaResource.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreRosas/SofaScoreRosaResource.php @@ -26,7 +26,7 @@ class SofaScoreRosaResource extends Resource protected static ?string $modelLabel = 'Teams'; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; public static function form(Schema $schema): Schema { diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/SofaScoreTaskResource.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/SofaScoreTaskResource.php index 84b35765..b124347d 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/SofaScoreTaskResource.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTasks/SofaScoreTaskResource.php @@ -26,7 +26,7 @@ class SofaScoreTaskResource extends Resource protected static ?int $navigationSort = 2; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; protected function isReadOnly(): bool { diff --git a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php index 94b87f12..2f14e155 100644 --- a/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php +++ b/app/Filament/Clusters/StaticData/Resources/SofaScoreTournaments/SofaScoreTournamentResource.php @@ -17,7 +17,7 @@ class SofaScoreTournamentResource extends Resource { protected static ?string $model = SofaScoreTournament::class; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; protected static ?string $cluster = StaticDataCluster::class; diff --git a/app/Filament/Clusters/StaticData/Resources/StatisticFixtures/StatisticFixturesResource.php b/app/Filament/Clusters/StaticData/Resources/StatisticFixtures/StatisticFixturesResource.php index d4155346..b8a6e96e 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatisticFixtures/StatisticFixturesResource.php +++ b/app/Filament/Clusters/StaticData/Resources/StatisticFixtures/StatisticFixturesResource.php @@ -20,7 +20,7 @@ class StatisticFixturesResource extends Resource protected static ?string $modelLabel = 'Fixtures'; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; protected static ?int $navigationSort = 5; diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/Pages/CreateStatistikoConfig.php b/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/Pages/CreateStatistikoConfig.php new file mode 100644 index 00000000..d7fa9628 --- /dev/null +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/Pages/CreateStatistikoConfig.php @@ -0,0 +1,11 @@ +components([ + TextInput::make('group') + ->required(), + TextInput::make('varname') + ->required(), + TextInput::make('team') + ->required(), + TextInput::make('name') + ->required(), + TextInput::make('value') + ->required(), + ]); + } +} diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/StatistikoConfigResource.php b/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/StatistikoConfigResource.php new file mode 100644 index 00000000..808b4971 --- /dev/null +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/StatistikoConfigResource.php @@ -0,0 +1,49 @@ + ListStatistikoConfigs::route('/'), + ]; + } + public static function getNavigationBadge(): ?string + { + return parent::getEloquentQuery()->count(); + } +} diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/Tables/StatistikoConfigsTable.php b/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/Tables/StatistikoConfigsTable.php new file mode 100644 index 00000000..a8393f0b --- /dev/null +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoConfigs/Tables/StatistikoConfigsTable.php @@ -0,0 +1,57 @@ +columns([ + TextColumn::make('group')->formatStateUsing(fn(string $state): string => match ($state) { + 'gls' => 'Goals', + 'crn' => 'Corner', + 'fls' => 'Fouls', + 'ofs' => 'Offside', + 'crd' => 'Cards', + 'snt' => 'Shots On Target', + 'tsh' => 'Total Shots', + }), + TextColumn::make('team')->badge() + ->color(fn(string $state): string => match ($state) { + 'home' => 'info', + 'away' => 'warning', + }), + TextColumn::make('varname') + ->formatStateUsing(fn(string $state): string => strtoupper($state)), + TextInputColumn::make('value') + ->prefix('xx.x') + ->type('number') + ->rules(['required', 'decimal:0.1,10']), + ]) + ->filters([ + SelectFilter::make('group') + ->options([ + 'gls' => 'Goals', + 'crn' => 'Corner', + 'fls' => 'Fouls Commited', + 'ofs' => 'Offside', + 'crd' => 'Cards', + 'snt' => 'Shots On Target', + 'tsh' => 'Total Shots', + ]), + SelectFilter::make('team') + ->options([ + 'home' => 'Home', + 'away' => 'Away', + ]) + ], layout: FiltersLayout::AboveContent) + ->deferFilters(false); + } +} diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoDetails/StatistikoDetailResource.php b/app/Filament/Clusters/StaticData/Resources/StatistikoDetails/StatistikoDetailResource.php index 22286956..5528cdd9 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoDetails/StatistikoDetailResource.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoDetails/StatistikoDetailResource.php @@ -20,7 +20,7 @@ class StatistikoDetailResource extends Resource protected static ?string $modelLabel = 'Details'; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; protected static ?string $cluster = StaticDataCluster::class; diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/StatistikoEventsResource.php b/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/StatistikoEventsResource.php index 65982900..c5d118d7 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/StatistikoEventsResource.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoEvents/StatistikoEventsResource.php @@ -20,7 +20,7 @@ class StatistikoEventsResource extends Resource protected static ?string $modelLabel = 'Events'; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; protected static ?int $navigationSort = 6; diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoImports/StatistikaImportResource.php b/app/Filament/Clusters/StaticData/Resources/StatistikoImports/StatistikaImportResource.php index 3c21423d..15fda088 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoImports/StatistikaImportResource.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoImports/StatistikaImportResource.php @@ -20,7 +20,7 @@ class StatistikaImportResource extends Resource protected static ?string $modelLabel = 'File Uploads'; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; protected static ?int $navigationSort = 1; diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/StatistikoPlayerResource.php b/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/StatistikoPlayerResource.php index 17492452..fa3ae6a1 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/StatistikoPlayerResource.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoPlayers/StatistikoPlayerResource.php @@ -20,7 +20,7 @@ class StatistikoPlayerResource extends Resource protected static ?string $modelLabel = 'Player'; - protected static string|UnitEnum|null $navigationGroup = 'SofaScore'; + protected static string|UnitEnum|null $navigationGroup = 'Statistiko'; protected static ?string $cluster = StaticDataCluster::class; diff --git a/app/Filament/Widgets/Data/LoadEvents.php b/app/Filament/Widgets/Data/LoadEvents.php index d19968ef..fa329a62 100644 --- a/app/Filament/Widgets/Data/LoadEvents.php +++ b/app/Filament/Widgets/Data/LoadEvents.php @@ -2,42 +2,27 @@ namespace App\Filament\Widgets\Data; -use Illuminate\Support\Carbon; -use App\Models\StatistikoEvent; -use App\Models\StatistikoDetail; -use App\Models\StatistikoPlayer; -use App\Models\StatisticFixtures; -use Illuminate\Support\Facades\Log; use App\Filament\Widgets\Data\LoadEvents\LoadEventsAverages; +use App\Filament\Widgets\Data\LoadEvents\LoadEventsQuery; +use App\Filament\Widgets\Data\LoadEvents\LoadExpectations; +use App\Models\StatisticFixtures; +use App\Models\StatistikoEvent; +use App\Models\StatistikoPlayer; +use Illuminate\Support\Carbon; class LoadEvents { 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; - $season_or_date = $filter['season_or_date'] ?? 'season'; - - $season = $filter['season'] ?? 0; - $ss_player_id = (int) $filter['ss_player_id'] ?? 0; - - $start = $filter['start_date'] ?? 0; - - $end = $filter['end_date'] ?? 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']; if (! $league_id) { @@ -68,8 +53,8 @@ class LoadEvents * 'league' => 'League', * 'all' => 'All Database', */ - $handicap_range = 0; - $total_range = 0; + $handicap_range = []; + $total_range = []; if ($similar_past_matches != 'none') { $team_position = ''; @@ -98,7 +83,6 @@ class LoadEvents $description = ''; if ($ss_player_id) { - $matches_season = StatistikoEvent::where(function ($query) use ($team_id, $team_position) { switch ($team_position) { case 'home': @@ -132,8 +116,6 @@ class LoadEvents }) ->pluck('match_id')->toArray(); - // $description = ' with ' . StatistikoDetail::where('ss_player_id', (int) $ss_player_id)->value('name') . ' (' . \count($matches_played) . ')'; - if (! $matches_played) { $matches_played[] = -1; } @@ -142,52 +124,7 @@ class LoadEvents /** * STATTISTIC DATA */ - $res = StatistikoEvent::with('home')->with('away') - ->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, $player_on_field) { - if ($player_on_field == 'notplayed') { - return $query->whereNotIn('match_id', $matches_played); - } else { - 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) { - return $query->where('starttime', '<=', $end); - })->when($season, function ($query) use ($season) { - return $query->whereIn('season', $season); - }) - ->orderBy('starttime', 'ASC') - ->get(); - - if ($res == null) { - return []; - } - - // Log::debug($res->toArray()); - + $res = LoadEventsQuery::load($filter, $matches_played, $handicap_range, $total_range); $dataset_home = []; $dataset_away = []; @@ -199,17 +136,22 @@ class LoadEvents $events = []; $results = ['w' => 0, 'd' => 0, 'l' => 0, 'w2' => 0, 'l2' => 0]; - // dd($res); + if (!\in_array($team_position, ['home', 'away'])) + $team_position = 'all'; - foreach ($res as $value) { + if (!isset($res[$team_position])) { + return []; + } - $labels[] = round($value['starttime']->diffInDays(Carbon::now())); + $expectations = LoadExpectations::load($res['all'], $match_id, $statistic_type); - // $labels[] = $value['starttime']->format('Y-m-d H:i'); + foreach ($res[$team_position] as $value) { - $playing_date[] = $value['starttime']->format('d. F Y H:i'); + $start = Carbon::createFromTimestamp($value['starttime']); + $labels[] = round($start->diffInDays(Carbon::now())); + $playing_date[] = $start->format('Y-m-d H:i'); - $results_per_event[] = $value['gls_h'] . ' : ' . $value['gls_a']; + $results_per_event[] = $value['val_home'] . ' : ' . $value['val_away']; if ($similar_past_matches != 'none') { switch ($value['result_code']) { @@ -225,38 +167,12 @@ class LoadEvents $results['w2']++; break; } - switch ($statistic_type) { - case 'gls': - $val_home = (int) $value['gls_h']; - $val_away = (int) $value['gls_a']; - $dataset_exp_home[] = (float) round($value['exp_home'], 1); - $dataset_exp_away[] = (float) round($value['exp_away'], 1); - break; - case 'crn': - $val_home = (int) $value['crn_h']; - $val_away = (int) $value['crn_a']; - break; - case 'fls': - $val_home = (int) $value['fls_h']; - $val_away = (int) $value['fls_a']; - break; - case 'ofs': - $val_home = (int) $value['ofs_h']; - $val_away = (int) $value['ofs_a']; - break; - case 'crd': - $val_home = (int) $value['crd_h']; - $val_away = (int) $value['crd_a']; - break; - case 'snt': - $val_home = (int) $value['snt_h']; - $val_away = (int) $value['snt_a']; - break; - case 'tsh': - $val_home = (int) $value['tsh_h']; - $val_away = (int) $value['tsh_a']; - break; - } + + $val_home = (int) $value['val_home']; + $val_away = (int) $value['val_away']; + + $dataset_exp_home[] = (float) round($value['exp_home'], 1); + $dataset_exp_away[] = (float) round($value['exp_away'], 1); } else { if ($team_position == 'home') { switch ($value['result_code']) { @@ -273,38 +189,11 @@ class LoadEvents break; } - switch ($statistic_type) { - case 'gls': - $val_home = (int) $value['gls_h']; - $val_away = (int) $value['gls_a']; - $dataset_exp_home[] = (float) round($value['exp_home'], 1); - $dataset_exp_away[] = (float) round($value['exp_away'], 1); - break; - case 'crn': - $val_home = (int) $value['crn_h']; - $val_away = (int) $value['crn_a']; - break; - case 'fls': - $val_home = (int) $value['fls_h']; - $val_away = (int) $value['fls_a']; - break; - case 'ofs': - $val_home = (int) $value['ofs_h']; - $val_away = (int) $value['ofs_a']; - break; - case 'crd': - $val_home = (int) $value['crd_h']; - $val_away = (int) $value['crd_a']; - break; - case 'snt': - $val_home = (int) $value['snt_h']; - $val_away = (int) $value['snt_a']; - break; - case 'tsh': - $val_home = (int) $value['tsh_h']; - $val_away = (int) $value['tsh_a']; - break; - } + $val_home = (int) $value['val_home']; + $val_away = (int) $value['val_away']; + + $dataset_exp_home[] = (float) round($value['exp_home'], 1); + $dataset_exp_away[] = (float) round($value['exp_away'], 1); } elseif ($team_position == 'away') { switch ($value['result_code']) { @@ -321,38 +210,11 @@ class LoadEvents break; } - switch ($statistic_type) { - case 'gls': - $val_home = (int) $value['gls_a']; - $val_away = (int) $value['gls_h']; - $dataset_exp_home[] = (float) round($value['exp_away'], 1); - $dataset_exp_away[] = (float) round($value['exp_home'], 1); - break; - case 'crn': - $val_home = (int) $value['crn_a']; - $val_away = (int) $value['crn_h']; - break; - case 'fls': - $val_home = (int) $value['fls_a']; - $val_away = (int) $value['fls_h']; - break; - case 'ofs': - $val_home = (int) $value['ofs_a']; - $val_away = (int) $value['ofs_h']; - break; - case 'crd': - $val_home = (int) $value['crd_a']; - $val_away = (int) $value['crd_h']; - break; - case 'snt': - $val_home = (int) $value['snt_a']; - $val_away = (int) $value['snt_h']; - break; - case 'tsh': - $val_home = (int) $value['tsh_a']; - $val_away = (int) $value['tsh_h']; - break; - } + $val_home = (int) $value['val_away']; + $val_away = (int) $value['val_home']; + + $dataset_exp_home[] = (float) round($value['exp_away'], 1); + $dataset_exp_away[] = (float) round($value['exp_home'], 1); } else { // dd($team_id, $value['home_id'], $value['away_id']); @@ -381,79 +243,21 @@ class LoadEvents break; } - switch ($statistic_type) { - case 'gls': - if ($team_id == $value['home_id']) { - $val_home = (int) $value['gls_h']; - $val_away = (int) $value['gls_a']; - $dataset_exp_home[] = (float) round($value['exp_home'], 1); - $dataset_exp_away[] = (float) round($value['exp_away'], 1); - } else { - $val_home = (int) $value['gls_a']; - $val_away = (int) $value['gls_h']; - $dataset_exp_home[] = (float) round($value['exp_away'], 1); - $dataset_exp_away[] = (float) round($value['exp_home'], 1); - } - break; - case 'crn': - if ($team_id == $value['home_id']) { - $val_home = (int) $value['crn_h']; - $val_away = (int) $value['crn_a']; - } else { - $val_home = (int) $value['crn_a']; - $val_away = (int) $value['crn_h']; - } - break; - case 'fls': - if ($team_id == $value['home_id']) { - $val_home = (int) $value['fls_h']; - $val_away = (int) $value['fls_a']; - } else { - $val_home = (int) $value['fls_a']; - $val_away = (int) $value['fls_h']; - } - break; - case 'ofs': - if ($team_id == $value['home_id']) { - $val_home = (int) $value['ofs_h']; - $val_away = (int) $value['ofs_a']; - } else { - $val_home = (int) $value['ofs_a']; - $val_away = (int) $value['ofs_h']; - } - break; - case 'crd': - if ($team_id == $value['home_id']) { - $val_home = (int) $value['crd_h']; - $val_away = (int) $value['crd_a']; - } else { - $val_home = (int) $value['crd_a']; - $val_away = (int) $value['crd_h']; - } - break; - case 'snt': - if ($team_id == $value['home_id']) { - $val_home = (int) $value['snt_h']; - $val_away = (int) $value['snt_a']; - } else { - $val_home = (int) $value['snt_a']; - $val_away = (int) $value['snt_h']; - } - break; - case 'tsh': - if ($team_id == $value['home_id']) { - $val_home = (int) $value['tsh_h']; - $val_away = (int) $value['tsh_a']; - } else { - $val_home = (int) $value['tsh_a']; - $val_away = (int) $value['tsh_h']; - } - break; + if ($team_id == $value['home_id']) { + $val_home = (int) $value['val_home']; + $val_away = (int) $value['val_away']; + $dataset_exp_home[] = (float) round($value['exp_home'], 1); + $dataset_exp_away[] = (float) round($value['exp_away'], 1); + } else { + $val_home = (int) $value['val_away']; + $val_away = (int) $value['val_home']; + $dataset_exp_home[] = (float) round($value['exp_away'], 1); + $dataset_exp_away[] = (float) round($value['exp_home'], 1); } } } if (isset($val_home) && isset($val_away)) { - $events[] = $value->home->ss_team_name . ' vs ' . $value->away->ss_team_name; + $events[] = $value['home'] . ' vs ' . $value['away']; $dataset_home[] = $val_home; $dataset_away[] = $val_away; } @@ -467,6 +271,7 @@ class LoadEvents $label2 = 'Against'; } + self::shortenEnding($labels, $dataset_home, $dataset_away); $data = [ @@ -507,6 +312,8 @@ class LoadEvents 'home_team' => $home_team, 'away_team' => $away_team, 'similar_past_matches' => $similar_past_matches, + 'expectations_home' => $expectations['home'], + 'expectations_away' => $expectations['away'], ]; if ($statistic_type == 'gls') { $data['datasets'][] = [ diff --git a/app/Filament/Widgets/Data/LoadEvents/LoadEventsQuery.php b/app/Filament/Widgets/Data/LoadEvents/LoadEventsQuery.php new file mode 100644 index 00000000..af8f7c06 --- /dev/null +++ b/app/Filament/Widgets/Data/LoadEvents/LoadEventsQuery.php @@ -0,0 +1,118 @@ +with('away') + ->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, $similar_past_matches) { + if ($similar_past_matches == 'none') { + 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); + } else { + 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) { + return $query->where('starttime', '<=', $end); + })->when($season, function ($query) use ($season) { + return $query->whereIn('season', $season); + }) + ->orderBy('starttime', 'ASC') + ->get(); + + $arr = []; + foreach ($res as $value) { + $tmp = []; + $tmp['match_id'] = $value->match_id; + $tmp['sport_id'] = $value->sport_id; + $tmp['league_id'] = $value->league_id; + $tmp['home_id'] = $value->home_id; + $tmp['away_id'] = $value->away_id; + $tmp['starttime'] = $value->starttime; + $tmp['season'] = $value->season; + $tmp['exp_home'] = $value->exp_home; + $tmp['exp_away'] = $value->exp_away; + $tmp['exp_handicap'] = $value->exp_handicap; + $tmp['exp_total'] = $value->exp_total; + $tmp['result_code'] = $value->result_code; + $tmp['home'] = $value->home->ss_team_name; + $tmp['away'] = $value->away->ss_team_name; + + switch ($statistic_type) { + case 'gls': + $tmp['val_home'] = $value->gls_h; + $tmp['val_away'] = $value->gls_a; + break; + case 'crn': + $tmp['val_home'] = $value->crn_h; + $tmp['val_away'] = $value->crn_a; + break; + case 'fls': + $tmp['val_home'] = $value->fls_h; + $tmp['val_away'] = $value->fls_a; + break; + case 'ofs': + $tmp['val_home'] = $value->ofs_h; + $tmp['val_away'] = $value->ofs_a; + break; + case 'crd': + $tmp['val_home'] = $value->crd_h; + $tmp['val_away'] = $value->crd_a; + break; + case 'snt': + $tmp['val_home'] = $value->snt_h; + $tmp['val_away'] = $value->snt_a; + break; + case 'tsh': + $tmp['val_home'] = $value->tsh_h; + $tmp['val_away'] = $value->tsh_a; + break; + } + + $arr['all'][] = $tmp; + if ($value->home_id == $team_id) + $arr['home'][] = $tmp; + if ($value->away_id == $team_id) + $arr['away'][] = $tmp; + } + + return $arr; + } +} diff --git a/app/Filament/Widgets/Data/LoadEvents/LoadExpectations.php b/app/Filament/Widgets/Data/LoadEvents/LoadExpectations.php new file mode 100644 index 00000000..188cb8ae --- /dev/null +++ b/app/Filament/Widgets/Data/LoadEvents/LoadExpectations.php @@ -0,0 +1,117 @@ +first(); + + $home_id = $match->home_id; + $away_id = $match->away_id; + + $config = StatistikoConfig::where('group', $statistic_type)->get(); + + $home_made_total = 1; + $home_made_home = 1; + $home_got_total = 1; + $home_got_home = 1; + $away_made_total = 1; + $away_made_home = 1; + $away_got_total = 1; + $away_got_home = 1; + + foreach ($config as $value) { + $varname = str_replace($statistic_type . '_', '', $value->varname); + switch ($varname) { + case 'home_made_total': + $home_made_total = (float) $value->value; + break; + case 'home_made_home': + $home_made_home = (float) $value->value; + break; + case 'home_got_total': + $home_got_total = (float) $value->value; + break; + case 'home_got_home': + $home_got_home = (float) $value->value; + break; + case 'away_made_total': + $away_made_total = (float) $value->value; + break; + case 'away_made_home': + $away_made_home = (float) $value->value; + break; + case 'away_got_total': + $away_got_total = (float) $value->value; + break; + case 'away_got_home': + $away_got_home = (float) $value->value; + break; + } + } + + $h_made_t = []; + $h_made_h = []; + $h_got_t = []; + $h_got_h = []; + + $a_made_t = []; + $a_made_a = []; + $a_got_t = []; + $a_got_a = []; + + foreach ($data as $value) { + // HOME + if ($value['home_id'] == $home_id || $value['away_id'] == $home_id) { + $h_made_t[] = $value['val_home']; + $h_got_t[] = $value['val_away']; + } + if ($value['home_id'] == $home_id) { + $h_made_h[] = $value['val_home']; + $h_got_h[] = $value['val_away']; + } + + // AWAY + if ($value['home_id'] == $away_id || $value['away_id'] == $away_id) { + $a_made_t[] = $value['val_away']; + $a_made_a[] = $value['val_home']; + } + + if ($value['away_id'] == $away_id) { + $a_made_a[] = $value['val_away']; + $a_got_a[] = $value['val_home']; + } + } + + $summe_home = array_sum($h_made_t) * $home_made_total; + $summe_home += array_sum($h_made_h) * $home_made_home; + $summe_home += array_sum($h_got_t) * $home_got_total; + $summe_home += array_sum($h_got_h) * $home_got_home; + $count_home = \count($h_made_t); + $count_home += \count($h_made_h); + $count_home += \count($h_got_t); + $count_home += \count($h_got_h); + + $count_home = !$count_home ? 1 : $count_home; + $aspettativa_home = round($summe_home / $count_home, 2); + + $summe_away = array_sum($a_made_t) * $away_made_total; + $summe_away += array_sum($a_made_a) * $away_made_home; + $summe_away += array_sum($a_got_t) * $away_got_total; + $summe_away += array_sum($a_got_a) * $away_got_home; + $count_away = \count($a_made_t); + $count_away += \count($a_made_a); + $count_away += \count($a_got_t); + $count_away += \count($a_got_a); + + $count_away = !$count_away ? 1 : $count_away; + $aspettativa_away = round($summe_away / $count_away, 2); + + return ['home' => $aspettativa_home, 'away' => $aspettativa_away]; + } +} diff --git a/app/Filament/Widgets/StatsMedianAverage.php b/app/Filament/Widgets/StatsMedianAverage.php index e30a8178..23b2ac86 100644 --- a/app/Filament/Widgets/StatsMedianAverage.php +++ b/app/Filament/Widgets/StatsMedianAverage.php @@ -9,7 +9,6 @@ use App\Utilities\Round; use Filament\Widgets\Concerns\InteractsWithPageFilters; use Filament\Widgets\StatsOverviewWidget; use Filament\Widgets\StatsOverviewWidget\Stat; -use Illuminate\Support\Facades\Log; use Illuminate\Support\HtmlString; use Livewire\Attributes\Reactive; @@ -101,8 +100,11 @@ class StatsMedianAverage extends StatsOverviewWidget $average_team_away = 0; $average_league_home = 0; $average_league_away = 0; + $expectations_home = 0; + $expectations_away = 0; - // Log::debug($data); + $expectations_home = $data['expectations_home'] ?? 0; + $expectations_away = $data['expectations_away'] ?? 0; foreach ($data['datasets'] as $value) { if ($value['label'] == 'Average Team') { @@ -119,37 +121,58 @@ class StatsMedianAverage extends StatsOverviewWidget $boxes = []; // BOX 1 - $boxes[] = Stat::make('Number', new HtmlString('