wiip
This commit is contained in:
1 parent
82f3654a05
commit
be4a08982e
8 files changed
+364
-326
No files matched your search
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Selections\Helper;
|
||||
|
||||
use App\Models\SofaScoreCategory;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
|
||||
class GetSeason
|
||||
{
|
||||
public static function load(array $season, int $sofascore_category_id)
|
||||
{
|
||||
if (!$season) {
|
||||
$season_mode = SofaScoreCategory::where('id', $sofascore_category_id)->value('season_mode');
|
||||
if ($season_mode == 'halfyear') {
|
||||
if ((int) date('m') > 7)
|
||||
$season[] = date('y') . '/' . date('y', strtotime('+1 year'));
|
||||
else
|
||||
$season[] = date('y', strtotime('-1 year')) . '/' . date('y');
|
||||
}
|
||||
}
|
||||
|
||||
return $season;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Pages\Selections;
|
||||
|
||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||
use App\Filament\Pages\Selections\LoadPositions;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
@@ -13,95 +14,102 @@ class LoadPlayer
|
||||
{
|
||||
$team_id = $get('team_id');
|
||||
|
||||
// $season = $get('season');
|
||||
|
||||
$team_position = $get('team_position');
|
||||
$sofascore_category_id = $get('sofascore_category_id');
|
||||
$season = $get('season');
|
||||
|
||||
// $season_or_date = $filter['season_or_date'] ?? 'season';
|
||||
$season = GetSeason::load($season, $sofascore_category_id);
|
||||
|
||||
// if ($season_or_date != 'season' or !count($season)) {
|
||||
// $season[] = date('Y');
|
||||
// }
|
||||
|
||||
$matches = 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 = 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_count = count($matches);
|
||||
|
||||
// dd($matches_count);
|
||||
|
||||
|
||||
$positions_map = LoadPositions::load();
|
||||
|
||||
// needs to run daily for pre-calculaton
|
||||
$player = SofaScorePlayerPerSeason::with('details')->where('ss_team_id', $team_id)->get();
|
||||
$player = SofaScorePlayerPerSeason::with('details')->where('ss_team_id', $team_id)->whereIn('season', $season)->get();
|
||||
|
||||
// dd($player);
|
||||
|
||||
$arr = [];
|
||||
foreach ($player as $val) {
|
||||
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
$events_played = $val->events_played_home;
|
||||
$minues_played = $val->minutes_played_home;
|
||||
break;
|
||||
case 'away':
|
||||
$events_played = $val->events_played_away;
|
||||
$minues_played = $val->minutes_played_away;
|
||||
break;
|
||||
default:
|
||||
$events_played = $val->events_played_home + $val->events_played_away;
|
||||
$minues_played = $val->minutes_played_home + $val->minutes_played_home;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($val->details) {
|
||||
|
||||
$colorlevel = round($matches_count / 3);
|
||||
|
||||
$preferred_foot = $val->details->preferred_foot;
|
||||
|
||||
$player_position = ' (Role ' . $val->details->position . ')';
|
||||
|
||||
if (in_array($val->details->position, $positions_map['MIDFIELD'])) {
|
||||
$position = 'MIDFIELD';
|
||||
} else if (in_array($val->details->position, $positions_map['DEFENCE'])) {
|
||||
$position = 'DEFENCE';
|
||||
} else if (in_array($val->details->position, $positions_map['ATTACK'])) {
|
||||
$position = 'ATTACK';
|
||||
} else if (in_array($val->details->position, $positions_map['GOALKEEPER'])) {
|
||||
$position = 'GOALKEEPER';
|
||||
$player_id = $val->ss_player_id;
|
||||
if (!isset($arr[$player_id])) {
|
||||
$arr[$player_id]['player_name'] = $val->details->player_name;
|
||||
$arr[$player_id]['events_played_home'] = $val->events_played_home;
|
||||
$arr[$player_id]['events_played_away'] = $val->events_played_away;
|
||||
$arr[$player_id]['minutes_played_home'] = $val->minutes_played_home;
|
||||
$arr[$player_id]['minutes_played_away'] = $val->minutes_played_away;
|
||||
$arr[$player_id]['preferred_foot'] = $val->details->preferred_foot ?? '';
|
||||
$arr[$player_id]['player_position'] = $val->details->position ?? '';
|
||||
$arr[$player_id]['color_level'] = round($matches_count / 3);
|
||||
} else {
|
||||
$player_position = $val->details->position;
|
||||
$position = 'NO SPECIFIC POSITION';
|
||||
}
|
||||
|
||||
$infostring = $events_played . ' Ev';
|
||||
if ($preferred_foot)
|
||||
$infostring .= ' - ' . $preferred_foot;
|
||||
if ($events_played)
|
||||
$infostring .= ' - ' . round($minues_played / $events_played) . 'min';
|
||||
|
||||
if ($events_played < $colorlevel) {
|
||||
$arr[$position][$val->ss_player_id] = '<span class="text-red-600 dark:text-red-500 cursor-pointer"><b>' . $val->details->player_name . '</b>' . $player_position . '<br>' . $infostring . '</span>';
|
||||
} else if ($events_played < $colorlevel * 2) {
|
||||
$arr[$position][$val->ss_player_id] = '<span class="text-blue-600 dark:text-blue-500 cursor-pointer"><b>' . $val->details->player_name . '</b>' . $player_position . '<br>' . $infostring . '</span>';
|
||||
} else {
|
||||
$arr[$position][$val->ss_player_id] = '<span class="text-green-600 dark:text-green-500 cursor-pointer"><b>' . $val->details->player_name . '</b>' . $player_position . '<br>' . $infostring . '</span>';
|
||||
$arr[$player_id]['events_played_home'] += $val->events_played_home;
|
||||
$arr[$player_id]['events_played_away'] += $val->events_played_away;
|
||||
$arr[$player_id]['minutes_played_home'] += $val->minutes_played_home;
|
||||
$arr[$player_id]['minutes_played_away'] += $val->minutes_played_away;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
|
||||
$result = [];
|
||||
foreach ($arr as $player_id => $val) {
|
||||
|
||||
switch ($team_position) {
|
||||
case 'home':
|
||||
$events_played = $val['events_played_home'];
|
||||
$minues_played = $val['minutes_played_home'];
|
||||
break;
|
||||
case 'away':
|
||||
$events_played = $val['events_played_away'];
|
||||
$minues_played = $val['minutes_played_away'];
|
||||
break;
|
||||
default:
|
||||
$events_played = $val['events_played_home'] + $val['events_played_away'];
|
||||
$minues_played = $val['minutes_played_home'] + $val['minutes_played_home'];
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$colorlevel = round($matches_count / 3);
|
||||
|
||||
if (in_array($val['player_position'], $positions_map['MIDFIELD'])) {
|
||||
$position = 'MIDFIELD';
|
||||
} else if (in_array($val['player_position'], $positions_map['DEFENCE'])) {
|
||||
$position = 'DEFENCE';
|
||||
} else if (in_array($val['player_position'], $positions_map['ATTACK'])) {
|
||||
$position = 'ATTACK';
|
||||
} else if (in_array($val['player_position'], $positions_map['GOALKEEPER'])) {
|
||||
$position = 'GOALKEEPER';
|
||||
} else {
|
||||
$player_position = $val['player_position'];
|
||||
$position = 'NO SPECIFIC POSITION';
|
||||
}
|
||||
|
||||
$infostring = $events_played . ' Ev';
|
||||
if ($val['preferred_foot'])
|
||||
$infostring .= ' - ' . $val['preferred_foot'];
|
||||
if ($events_played)
|
||||
$infostring .= ' - ' . round($minues_played / $events_played) . 'min';
|
||||
if ($colorlevel > 1 && $events_played < $colorlevel) {
|
||||
$result[$position][$player_id] = '<span class="text-red-600 dark:text-red-500 cursor-pointer"><b>' . $val['player_name'] . '</b> ' . $position . '<br>' . $infostring . '</span>';
|
||||
} else if ($events_played < $colorlevel * 2) {
|
||||
$result[$position][$player_id] = '<span class="text-blue-600 dark:text-blue-500 cursor-pointer"><b>' . $val['player_name'] . '</b> ' . $position . '<br>' . $infostring . '</span>';
|
||||
} else {
|
||||
$result[$position][$player_id] = '<span class="text-green-600 dark:text-green-500 cursor-pointer"><b>' . $val['player_name'] . '</b> ' . $position . '<br>' . $infostring . '</span>';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -250,6 +250,9 @@ class Statistic extends BaseDashboard
|
||||
->pipsFormatter(RawJs::make(<<<'JS'
|
||||
`${$value.toFixed(2)}`
|
||||
JS)),
|
||||
/************************
|
||||
* PLAYER
|
||||
************************/
|
||||
Select::make('ss_player_id')
|
||||
->live()
|
||||
->hiddenLabel()
|
||||
@@ -313,7 +316,7 @@ class Statistic extends BaseDashboard
|
||||
->columns(2)
|
||||
->hiddenLabel()
|
||||
->multiple()
|
||||
->placeholder('All Seasons')
|
||||
->placeholder('Current Season')
|
||||
->prefixIconColor('success')
|
||||
// ->prefixIconColor(fn(Get $get): string => $get('season') ? 'success' : 'primary')
|
||||
->hidden(fn(Get $get) => $get('season_or_date') == 'date')
|
||||
@@ -321,6 +324,9 @@ class Statistic extends BaseDashboard
|
||||
->preload()
|
||||
->options(function (Get $get) {
|
||||
return LoadSeasons::load($get('league_id'));
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('ss_player_id', null);
|
||||
}),
|
||||
DatePicker::make('start_date')
|
||||
->live()
|
||||
|
||||
@@ -42,9 +42,11 @@ class LoadEvents
|
||||
$total_range = [];
|
||||
$match = StatisticFixtures::with('home')->with('away')->where('id', (int) $match_id)->first();
|
||||
|
||||
if (! $match) {
|
||||
return [];
|
||||
}
|
||||
// dd($match);
|
||||
|
||||
// if (! $match) {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
if ($similar_past_matches != 'none') {
|
||||
|
||||
@@ -361,7 +363,7 @@ class LoadEvents
|
||||
];
|
||||
}
|
||||
|
||||
// Log::debug($results);
|
||||
// dd($data);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Widgets\Data\LoadEvents;
|
||||
|
||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\StatistikoPlayer;
|
||||
|
||||
@@ -12,14 +13,19 @@ class LoadEventsQuery
|
||||
$league_id = (int) $filter['league_id'] ?? 0;
|
||||
$team_id = (int) $filter['team_id'] ?? 0;
|
||||
$season = $filter['season'] ?? 0;
|
||||
$sofascore_category_id = $filter['sofascore_category_id'] ?? 0;
|
||||
$season_or_date = $filter['season_or_date'];
|
||||
$start = $filter['start_date'] ?? 0;
|
||||
$end = $filter['end_date'] ?? 0;
|
||||
if ($season_or_date == 'season') {
|
||||
$start = 0;
|
||||
$end = 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'];
|
||||
$season_or_date = $filter['season_or_date'] ?? 'season';
|
||||
$home_id = $match->home_id;
|
||||
$away_id = $match->away_id;
|
||||
|
||||
@@ -27,15 +33,9 @@ class LoadEventsQuery
|
||||
$statistic_type = 'gls';
|
||||
}
|
||||
|
||||
switch ($season_or_date) {
|
||||
case 'season':
|
||||
$start = 0;
|
||||
$end = 0;
|
||||
break;
|
||||
default:
|
||||
$season = 0;
|
||||
break;
|
||||
}
|
||||
$season = GetSeason::load($season, $sofascore_category_id);
|
||||
|
||||
// dd($season);
|
||||
|
||||
/**
|
||||
* IF WITH PLAYER
|
||||
@@ -107,13 +107,13 @@ class LoadEventsQuery
|
||||
}
|
||||
}
|
||||
})
|
||||
->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($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) {
|
||||
@@ -122,12 +122,15 @@ class LoadEventsQuery
|
||||
return $query->whereDate('starttime', '>=', $start);
|
||||
})->when($end, function ($query) use ($end) {
|
||||
return $query->whereDate('starttime', '<=', $end);
|
||||
})->when($season, function ($query) use ($season) {
|
||||
return $query->whereIn('season', $season);
|
||||
})->when($season, function ($query) use ($season, $season_or_date) {
|
||||
if ($season_or_date == 'season')
|
||||
return $query->whereIn('season', $season);
|
||||
})
|
||||
->orderBy('starttime', 'ASC')
|
||||
->get();
|
||||
|
||||
// dd($res);
|
||||
|
||||
$arr = [];
|
||||
foreach ($res as $value) {
|
||||
|
||||
|
||||
@@ -47,21 +47,14 @@ class LoadPlayer
|
||||
|
||||
$res = StatistikoPlayer::with('event')->where('ss_player_id', (int) $ss_player_id)->get();
|
||||
|
||||
// dd($res);
|
||||
|
||||
|
||||
$tmp = [];
|
||||
foreach ($res as $value) {
|
||||
|
||||
// dd($value);
|
||||
|
||||
$val = 0;
|
||||
$key = 0;
|
||||
|
||||
if (isset($value->event->starttime)) {
|
||||
|
||||
// $labels[] = $value->event->starttime->format('d.M.y');
|
||||
|
||||
$key = round($value->event->starttime->diffInDays(Carbon::now()));
|
||||
|
||||
switch ($statistic_type) {
|
||||
@@ -92,6 +85,7 @@ class LoadPlayer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
krsort($tmp);
|
||||
$dataset = [];
|
||||
$labels = [];
|
||||
|
||||
@@ -35,6 +35,7 @@ class StatsMedianAverage extends StatsOverviewWidget
|
||||
protected function getStats(): array
|
||||
{
|
||||
$data = LoadEvents::load($this->filters, false);
|
||||
|
||||
$team_id = (int) $this->filters['team_id'] ?? 0;
|
||||
|
||||
$season = $this->filters['season'] ?? 0;
|
||||
@@ -45,9 +46,9 @@ class StatsMedianAverage extends StatsOverviewWidget
|
||||
switch ($season_or_date) {
|
||||
case 'season':
|
||||
if ($season)
|
||||
$date_events = implode(',', $season);
|
||||
$date_events = implode(', ', $season);
|
||||
else
|
||||
$date_events = 'All Seasons';
|
||||
$date_events = 'Current Season';
|
||||
break;
|
||||
default:
|
||||
$start = $this->filters['start_date'] ?? 0;
|
||||
|
||||
Reference in new issue
Block a user