This commit is contained in:
salam committed 2026-05-23 08:38:34 +02:00
1 parent 2734b06350
commit fbaadcd248
9 files changed
+213 -219

No files matched your search

+8 -4
View File
@@ -4,9 +4,9 @@ namespace App\Filament\Pages;
use App\Actions\LoadStatisticFixturesLeaguesOptions;
use App\Filament\Widgets\ChartMovingAverageEvent;
use App\Filament\Widgets\ChartMovingAveragePlayer;
use App\Filament\Widgets\ChartPunctualEvent;
use App\Filament\Widgets\MovingAverageChartPlayer;
use App\Filament\Widgets\PunctualChartPlayer;
use App\Filament\Widgets\ChartPunctualPlayer;
use App\Filament\Widgets\StatsMedianAverage;
use App\Models\Element;
use App\Models\StatisticFixtures;
@@ -99,6 +99,7 @@ class Statistic extends BaseDashboard
DatePicker::make('start_date')
->native(false)
->prefixIcon('phosphor-calendar')
->live()
->suffixAction(
Action::make('clear_start')
->icon('phosphor-x')
@@ -108,6 +109,7 @@ class Statistic extends BaseDashboard
DatePicker::make('end_date')
->native(false)
->prefixIcon('phosphor-calendar')
->live()
->suffixAction(
Action::make('clear_end')
->icon('phosphor-x')
@@ -131,6 +133,7 @@ class Statistic extends BaseDashboard
->action(function (callable $set) {
$set('tm_player_id', null);
})
->color('gray')
->icon('phosphor-x'),
)
->preload()
@@ -140,6 +143,7 @@ class Statistic extends BaseDashboard
})
->live(),
Select::make('player_on_field')
->label('Time on field')
->prefixIcon('phosphor-watch')
->default('all')
->selectablePlaceholder(false)
@@ -224,8 +228,8 @@ class Statistic extends BaseDashboard
StatsMedianAverage::make(),
ChartPunctualEvent::make(),
ChartMovingAverageEvent::make(),
PunctualChartPlayer::make(),
MovingAverageChartPlayer::make(),
// ChartPunctualPlayer::make(),
// ChartMovingAveragePlayer::make(),
];
}
@@ -2,9 +2,9 @@
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\EventsLoad;
use App\Filament\Widgets\Data\HelperMoveingAverage;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\LoadEvents;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
@@ -33,7 +33,7 @@ class ChartMovingAverageEvent extends ChartWidget
{
$this->heading = HelperStatisticType::get($this->filters);
$data = EventsLoad::load($this->filters);
$data = LoadEvents::load($this->filters);
if ($data) {
HelperMoveingAverage::get($data);
@@ -4,11 +4,11 @@ namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperMoveingAverage;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\PlayerLoad;
use App\Filament\Widgets\Data\LoadPlayer;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
class MovingAverageChartPlayer extends ChartWidget
class ChartMovingAveragePlayer extends ChartWidget
{
use InteractsWithPageFilters;
@@ -31,9 +31,13 @@ class MovingAverageChartPlayer extends ChartWidget
protected function getData(): array
{
if ($this->filters['statistic_type'] == 'crn') {
return [];
}
$this->heading = HelperStatisticType::get($this->filters);
$data = PlayerLoad::load($this->filters);
$data = LoadPlayer::load($this->filters);
if ($data) {
HelperMoveingAverage::get($data);
+2 -2
View File
@@ -2,8 +2,8 @@
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\EventsLoad;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\LoadEvents;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
@@ -32,7 +32,7 @@ class ChartPunctualEvent extends ChartWidget
{
$this->heading = HelperStatisticType::get($this->filters);
$data = EventsLoad::load($this->filters);
$data = LoadEvents::load($this->filters);
return $data;
}
@@ -3,11 +3,11 @@
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\HelperStatisticType;
use App\Filament\Widgets\Data\PlayerLoad;
use App\Filament\Widgets\Data\LoadPlayer;
use Filament\Widgets\ChartWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
class PunctualChartPlayer extends ChartWidget
class ChartPunctualPlayer extends ChartWidget
{
use InteractsWithPageFilters;
@@ -36,7 +36,7 @@ class PunctualChartPlayer extends ChartWidget
$this->heading = HelperStatisticType::get($this->filters);
$data = PlayerLoad::load($this->filters);
$data = LoadPlayer::load($this->filters);
return $data;
}
+106 -72
View File
@@ -2,15 +2,14 @@
namespace App\Filament\Widgets\Data;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
class EventsLoadAspGoal
class LoadEventsAspGoal
{
public static function load($filter)
{
// dd($filter);
dd($filter);
$league_id = (int) $filter['league_id'] ?? 0;
@@ -23,27 +22,41 @@ class EventsLoadAspGoal
return [];
}
/**
* WITH PLAYER
*/
$tm_player_id = $filter['tm_player_id'];
if ($tm_player_id) {
$matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray();
} else {
$matches_played = false;
}
$team_position = $filter['team_position'];
/**
* ACCURACY DATA
* STATTISTIC DATA
*/
switch ($filter['team_position']) {
case 'home':
$res = StatisticFixtures::where('league_id', $league_id)->where('home_id', $team_id)->first();
break;
case 'away':
$res = StatisticFixtures::where('league_id', $league_id)->where('away_id', $team_id)->first();
break;
default:
$res = StatisticFixtures::where('league_id', $league_id)
->where(function ($query) use ($team_id) {
$query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id);
})->first();
break;
}
$res = StatistikoEvent::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);
}
})
->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->when($start, function ($query) use ($start) {
return $query->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})->first();
$start = $filter['start_date'] ?? 0;
@@ -81,63 +94,84 @@ class EventsLoadAspGoal
$similar_past_matches = $filter['similar_past_matches'] ?? 0;
switch ($similar_past_matches) {
case 'league':
$res = StatistikoEvent::when($league_id, function ($query) use ($league_id) {
$res = StatistikoEvent::when($league_id, function ($query) use ($league_id, $similar_past_matches) {
switch ($similar_past_matches) {
case 'league':
return $query->where('league_id', $league_id);
})->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->when($handicap_range, function ($query) use ($handicap_range) {
default:
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);
})
->get();
}
break;
case 'all':
$res = StatistikoEvent::when($handicap_range, function ($query) use ($handicap_range) {
return $query->whereBetween('exp_handicap', $handicap_range);
})->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->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);
})
->get();
})->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) {
return $query->where('starttime', '<=', $end);
})
->get();
break;
// case 'none':
// $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) {
// return $query->where('league_id', $league_id);
// })->when($team_id, function ($query) use ($team_id, $team_position) {
// switch ($team_position) {
// case 'home':
// return $query->where('home_id', $team_id);
// break;
// case 'away':
// return $query->where('away_id', $team_id);
// break;
// default:
// return $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id);
// break;
// }
// })->when($start, function ($query) use ($start) {
// return $query->where('starttime', '>=', $start);
// })->when($end, function ($query) use ($end) {
// return $query->where('starttime', '<=', $end);
// })
// ->get();
// switch ($similar_past_matches) {
// case 'league':
// $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) {
// return $query->where('league_id', $league_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) {
// return $query->where('starttime', '<=', $end);
// })
// ->get();
// break;
}
// break;
// case 'all':
// $res = StatistikoEvent::when($handicap_range, function ($query) use ($handicap_range) {
// return $query->whereBetween('exp_handicap', $handicap_range);
// })->when($matches_played, function ($query) use ($matches_played) {
// return $query->whereIn('match_id', $matches_played);
// })->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);
// })
// ->get();
// break;
// // case 'none':
// // $res = StatistikoEvent::when($league_id, function ($query) use ($league_id) {
// // return $query->where('league_id', $league_id);
// // })->when($team_id, function ($query) use ($team_id, $team_position) {
// // switch ($team_position) {
// // case 'home':
// // return $query->where('home_id', $team_id);
// // break;
// // case 'away':
// // return $query->where('away_id', $team_id);
// // break;
// // default:
// // return $query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id);
// // break;
// // }
// // })->when($start, function ($query) use ($start) {
// // return $query->where('starttime', '>=', $start);
// // })->when($end, function ($query) use ($end) {
// // return $query->where('starttime', '<=', $end);
// // })
// // ->get();
// // break;
// }
$datasets = [];
$labels = [];
@@ -2,11 +2,10 @@
namespace App\Filament\Widgets\Data;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
use App\Models\StatistikoPlayer;
use Illuminate\Support\Facades\Log;
class EventsLoad
class LoadEvents
{
public static $last_query = [];
@@ -14,12 +13,24 @@ class EventsLoad
{
// dd($filter);
if (self::$last_query) {
return self::$last_query;
}
$league_id = (int) $filter['league_id'] ?? 0;
$team_id = (int) $filter['team_id'] ?? 0;
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$similar_past_matches = $filter['similar_past_matches'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 0;
if (! $league_id) {
return [];
}
@@ -29,89 +40,34 @@ class EventsLoad
$team_position = $filter['team_position'];
/**
* ACCURACY DATA
*/
switch ($filter['team_position']) {
case 'home':
$res = StatisticFixtures::where('league_id', $league_id)->where('home_id', $team_id)->first();
break;
case 'away':
$res = StatisticFixtures::where('league_id', $league_id)->where('away_id', $team_id)->first();
break;
default:
$res = StatisticFixtures::where('league_id', $league_id)
->where(function ($query) use ($team_id) {
$query->where('home_id', '=', $team_id)->orWhere('away_id', '=', $team_id);
})->first();
break;
}
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
$similar_past_matches = $filter['similar_past_matches'] ?? 0;
$statistic_type = $filter['statistic_type'] ?? 0;
/**
* WITH PLAYER
*/
$tm_player_id = $filter['tm_player_id'];
if ($tm_player_id) {
$matches_played = StatistikoPlayer::where('tm_player_id', (int) $tm_player_id)->pluck('match_id')->toArray();
} else {
$matches_played = false;
}
/**
* STATTISTIC DATA
*/
switch ($filter['team_position']) {
case 'home':
$res = StatistikoEvent::where('league_id', $league_id)
->where('home_id', '=', $team_id)
->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->when($start, function ($query) use ($start) {
return $query->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})
->get();
break;
$res = StatistikoEvent::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);
}
})
->when($start, function ($query) use ($start) {
return $query->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})
->orderBy('starttime')
->get();
case 'away':
$res = StatistikoEvent::where('league_id', $league_id)
->where('away_id', '=', $team_id)
->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->when($start, function ($query) use ($start) {
return $query->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})
->get();
break;
// dd($res);
default:
$res = StatistikoEvent::where('league_id', $league_id)
->where(function ($query) use ($team_id) {
$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($start, function ($query) use ($start) {
return $query->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})->get();
break;
}
$total = count($res);
// Log::info($res);
// Log::info($total);
$datasets = [];
$labels = [];
@@ -243,6 +199,8 @@ class EventsLoad
'labels' => $labels,
];
self::$last_query = $data;
return $data;
}
}
@@ -2,9 +2,9 @@
namespace App\Filament\Widgets\Data;
use App\Models\StatistikoPlayer;
use App\Models\StatistikoEvent;
class PlayerLoad
class LoadPlayer
{
public static $last_query = [];
@@ -12,6 +12,10 @@ class PlayerLoad
{
// dd($filter);
if (self::$last_query) {
return self::$last_query;
}
// "team_position" => "all"
// "statistic_type" => "gls"
// "similar_past_matches" => "none"
@@ -37,6 +41,18 @@ class PlayerLoad
$tm_player_id = (int) $filter['tm_player_id'] ?? 0;
$team_position = $filter['team_position'];
$player_on_field = $filter['player_on_field'];
$statistic_type = $filter['statistic_type'] ?? 0;
$similar_past_matches = $filter['similar_past_matches'] ?? 0;
$start = $filter['start_date'] ?? 0;
$end = $filter['end_date'] ?? 0;
if (! $league_id) {
return [];
}
@@ -47,49 +63,28 @@ class PlayerLoad
return [];
}
$team_position = $filter['team_position'];
$player_on_field = $filter['player_on_field'];
if (self::$last_query) {
$res = self::$last_query;
} else {
$res = StatistikoPlayer::with('event')->where('tm_player_id', $tm_player_id)
->when($team_position, function ($query) use ($team_id, $team_position) {
/**
* TEAM HOME/AWAY
*/
switch ($team_position) {
case 'home':
return $query->where('activeteam_id', $team_id);
break;
case 'away':
return $query->where('activeteam_id', '!=', $team_id);
break;
}
})->when($player_on_field, function ($query) use ($player_on_field) {
/**
* LINEUP
*/
switch ($player_on_field) {
case 'lineup':
return $query->where('lineup', 'T');
break;
case 'substituted':
return $query->where('lineup', 'P');
break;
}
})->get();
self::$last_query = $res;
}
$statistic_type = $filter['statistic_type'] ?? 0;
// $fields = 'goals,fouls,offsides,shots_on_target,shots_off_target, subtype_event_during_the_match';
/**
* STATTISTIC DATA
*/
$res = StatistikoEvent::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);
}
})
->when($matches_played, function ($query) use ($matches_played) {
return $query->whereIn('match_id', $matches_played);
})->when($start, function ($query) use ($start) {
return $query->where('starttime', '>=', $start);
})->when($end, function ($query) use ($end) {
return $query->where('starttime', '<=', $end);
})->first();
$labels = [];
$datasets = [];
@@ -142,6 +137,8 @@ class PlayerLoad
'labels' => $labels,
];
self::$last_query = $data;
return $data;
}
}
+4 -7
View File
@@ -2,8 +2,7 @@
namespace App\Filament\Widgets;
use App\Filament\Widgets\Data\EventsLoad;
use App\Filament\Widgets\Data\EventsLoadAspGoal;
use App\Filament\Widgets\Data\LoadEvents;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
@@ -12,15 +11,13 @@ class StatsMedianAverage extends StatsOverviewWidget
{
use InteractsWithPageFilters;
protected ?string $pollingInterval = null;
protected function getStats(): array
{
$filters = $this->filters;
if ($filters['similar_past_matches'] == 'none') {
$data = EventsLoad::load($filters);
} else {
$data = EventsLoadAspGoal::load($filters);
}
$data = LoadEvents::load($filters);
if (! isset($data['datasets'][0])) {
return [];