wip
This commit is contained in:
1 parent
7708a4a935
commit
43d1c091b3
9 files changed
+165
-344
No files matched your search
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||
use App\Filament\Pages\Selections\LoadPositions;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
use Livewire\Component;
|
||||
|
||||
@@ -22,129 +20,64 @@ class PlayerCalculator extends Component
|
||||
|
||||
public static function load(array $filters)
|
||||
{
|
||||
$team_position = $filters['team_position'];
|
||||
$season = $filters['season'];
|
||||
$seasonmode = $filters['seasonmode'];
|
||||
$team_id = (int) $filters['team_id'];
|
||||
$season = GetSeason::load($season, $seasonmode);
|
||||
|
||||
$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');
|
||||
|
||||
$positions_map = LoadPositions::load();
|
||||
|
||||
$player = SofaScorePlayerPerSeason::with('details')->where('ss_team_id', $team_id)->whereIn('season', $season)->get();
|
||||
|
||||
$arr = [];
|
||||
foreach ($player as $val) {
|
||||
if ($val->details && $val->details->is_active) {
|
||||
$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 {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
$player = SofaScorePlayerPerSeason::with('details')->where('season', '=', 'total')->where('ss_team_id', '=', $team_id)->get();
|
||||
|
||||
$result = [];
|
||||
foreach ($arr as $player_id => $val) {
|
||||
foreach ($player as $val) {
|
||||
$tmp = [];
|
||||
$tmp['id'] = $val->ss_player_id;
|
||||
$tmp['name'] = $val->details->player_name;
|
||||
$tmp['pos_ori'] = $val->details->position;
|
||||
$tmp['pos'] = '';
|
||||
$tmp['foot'] = $val->details->preferred_foot;
|
||||
$tmp['tot_evt'] = $val->total_events;
|
||||
$tmp['tot_min'] = $val->total_min;
|
||||
$tmp['ave_min'] = $val->average_min;
|
||||
$tmp['gls'] = $val->goals;
|
||||
$tmp['fls'] = $val->fouls;
|
||||
$tmp['ofs'] = $val->offsides;
|
||||
$tmp['crd'] = $val->cards;
|
||||
$tmp['snt'] = $val->shots_on_target;
|
||||
$tmp['tsh'] = $val->shots_off_target;
|
||||
|
||||
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'])) {
|
||||
$player_position = $val['player_position'];
|
||||
$position_area = 'midfield';
|
||||
$player_color = 'info';
|
||||
} elseif (in_array($val['player_position'], $positions_map['DEFENCE'])) {
|
||||
$player_position = $val['player_position'];
|
||||
$position_area = 'defence';
|
||||
$player_color = 'success';
|
||||
} elseif (in_array($val['player_position'], $positions_map['ATTACK'])) {
|
||||
$player_position = $val['player_position'];
|
||||
$position_area = 'attack';
|
||||
$player_color = 'warning';
|
||||
} elseif (in_array($val['player_position'], $positions_map['GOALKEEPER'])) {
|
||||
$player_position = $val['player_position'];
|
||||
$position_area = 'goalkeeper';
|
||||
$player_color = 'gray';
|
||||
} else {
|
||||
$player_position = 'NO SPECIFIC POSITION';
|
||||
$position_area = 'non';
|
||||
$player_color = 'danger';
|
||||
}
|
||||
|
||||
$everage_minutes = 0;
|
||||
$timed_color = '';
|
||||
if ($events_played) {
|
||||
$everage_minutes = round($minues_played / $events_played);
|
||||
if ($colorlevel > 1 && $events_played < $colorlevel) {
|
||||
$timed_color = 'danger';
|
||||
} elseif ($events_played < $colorlevel * 2) {
|
||||
$timed_color = 'info';
|
||||
$level = round($val->total_events / 3);
|
||||
if ($val->total_events) {
|
||||
if ($level > 1 && $val->total_events < $level) {
|
||||
$tmp['color_evt'] = 'danger';
|
||||
} elseif ($val->total_events < $level * 2) {
|
||||
$tmp['color_evt'] = 'info';
|
||||
} else {
|
||||
$timed_color = 'success';
|
||||
$tmp['color_evt'] = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'id' => $player_id,
|
||||
'name' => $val['player_name'],
|
||||
'preferred_foot' => $val['preferred_foot'],
|
||||
'player_position' => $player_position,
|
||||
'position_area' => $position_area,
|
||||
'player_color' => $player_color,
|
||||
'timed_color' => $timed_color,
|
||||
'events_played' => $events_played,
|
||||
'everage_minutes' => $everage_minutes,
|
||||
'position' => '',
|
||||
'active' => 0,
|
||||
'gls' => 0,
|
||||
'fls' => 0,
|
||||
'ofs' => 0,
|
||||
'snt' => 0,
|
||||
'tsh' => 0,
|
||||
'crd' => 0,
|
||||
];
|
||||
if (in_array($val->details->position, $positions_map['MIDFIELD'])) {
|
||||
$tmp['area'] = 'midfield';
|
||||
$tmp['color_pos'] = 'info';
|
||||
} elseif (in_array($val->details->position, $positions_map['DEFENCE'])) {
|
||||
$tmp['area'] = 'defence';
|
||||
$tmp['color_pos'] = 'success';
|
||||
} elseif (in_array($val->details->position, $positions_map['ATTACK'])) {
|
||||
$tmp['area'] = 'attack';
|
||||
$tmp['color_pos'] = 'warning';
|
||||
} elseif (in_array($val->details->position, $positions_map['GOALKEEPER'])) {
|
||||
$tmp['area'] = 'goalkeeper';
|
||||
$tmp['color_pos'] = 'gray';
|
||||
} else {
|
||||
$tmp['area'] = 'defence';
|
||||
$tmp['color_pos'] = 'success';
|
||||
}
|
||||
|
||||
$result[] = $tmp;
|
||||
}
|
||||
|
||||
$pos = array_column($result, 'player_position');
|
||||
$area = array_column($result, 'position_area');
|
||||
$pos = array_column($result, 'pos');
|
||||
$area = array_column($result, 'area');
|
||||
|
||||
array_multisort($area, SORT_ASC, $pos, SORT_ASC, $result);
|
||||
|
||||
return $result;
|
||||
|
||||
Reference in new issue
Block a user