removed precalculation
This commit is contained in:
1 parent
f6f5dd0c7c
commit
838d6419f4
11 files changed
+214
-680
No files matched your search
@@ -3,8 +3,7 @@
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Filament\Pages\Selections\LoadPositions;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use App\Models\StatistikoDetail;
|
||||
use App\Filament\Widgets\Boxes\LoadPlayerAverages;
|
||||
use Livewire\Component;
|
||||
|
||||
class PlayerCalculator extends Component
|
||||
@@ -13,86 +12,76 @@ class PlayerCalculator extends Component
|
||||
{
|
||||
$positions_map = LoadPositions::load();
|
||||
|
||||
$team_player_ids = StatistikoDetail::where('ss_team_id', $team_id)->pluck('ss_player_id')->toArray();
|
||||
|
||||
$players = SofaScorePlayerPerSeason::with('details')->where('season', 'total')->whereIn('ss_player_id', $team_player_ids)->get();
|
||||
$players = LoadPlayerAverages::load($team_id, 'total');
|
||||
|
||||
$result = [];
|
||||
foreach ($players as $val) {
|
||||
if ($val->details != null && $val->details->is_active) {
|
||||
|
||||
$tmp = [];
|
||||
$tmp['id'] = $val->ss_player_id;
|
||||
if (! isset($val->details)) {
|
||||
$tmp['name'] = $val->ss_player_id;
|
||||
$tmp['pos_ori'] = 'GK';
|
||||
$tmp['foot'] = 'Both';
|
||||
$tmp = [];
|
||||
$tmp['id'] = $val['ss_player_id'];
|
||||
if (! isset($val->details)) {
|
||||
$tmp['name'] = $val['ss_player_id'];
|
||||
$tmp['pos_ori'] = 'GK';
|
||||
$tmp['foot'] = 'Both';
|
||||
} else {
|
||||
$tmp['name'] = $val['player_name'];
|
||||
$tmp['pos_ori'] = $val['position'];
|
||||
$tmp['foot'] = $val['preferred_foot'];
|
||||
}
|
||||
$tmp['pos'] = '';
|
||||
$tmp['active'] = 0;
|
||||
$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'];
|
||||
|
||||
$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 {
|
||||
$tmp['name'] = $val->details->player_name;
|
||||
$tmp['pos_ori'] = $val->details->position;
|
||||
$tmp['foot'] = $val->details->preferred_foot;
|
||||
$tmp['color_evt'] = 'success';
|
||||
}
|
||||
$tmp['pos'] = '';
|
||||
$tmp['active'] = 0;
|
||||
$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;
|
||||
}
|
||||
|
||||
$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 {
|
||||
$tmp['color_evt'] = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
if (! isset($val->details)) {
|
||||
if (! isset($val->details)) {
|
||||
$tmp['area'] = 'goalkeeper';
|
||||
$tmp['color_pos'] = 'gray';
|
||||
$tmp['order'] = 5;
|
||||
} else {
|
||||
if (in_array($val['position'], $positions_map['MIDFIELD'])) {
|
||||
$tmp['area'] = 'midfield';
|
||||
$tmp['color_pos'] = 'info';
|
||||
$tmp['order'] = 2;
|
||||
} elseif (in_array($val['position'], $positions_map['DEFENCE'])) {
|
||||
$tmp['area'] = 'defence';
|
||||
$tmp['color_pos'] = 'success';
|
||||
$tmp['order'] = 1;
|
||||
} elseif (in_array($val['position'], $positions_map['ATTACK'])) {
|
||||
$tmp['area'] = 'attack';
|
||||
$tmp['color_pos'] = 'warning';
|
||||
$tmp['order'] = 3;
|
||||
} elseif (in_array($val['position'], $positions_map['GOALKEEPER'])) {
|
||||
$tmp['area'] = 'goalkeeper';
|
||||
$tmp['color_pos'] = 'gray';
|
||||
$tmp['order'] = 5;
|
||||
$tmp['order'] = 4;
|
||||
} else {
|
||||
if (in_array($val->details->position, $positions_map['MIDFIELD'])) {
|
||||
$tmp['area'] = 'midfield';
|
||||
$tmp['color_pos'] = 'info';
|
||||
$tmp['order'] = 2;
|
||||
} elseif (in_array($val->details->position, $positions_map['DEFENCE'])) {
|
||||
$tmp['area'] = 'defence';
|
||||
$tmp['color_pos'] = 'success';
|
||||
$tmp['order'] = 1;
|
||||
} elseif (in_array($val->details->position, $positions_map['ATTACK'])) {
|
||||
$tmp['area'] = 'attack';
|
||||
$tmp['color_pos'] = 'warning';
|
||||
$tmp['order'] = 3;
|
||||
} elseif (in_array($val->details->position, $positions_map['GOALKEEPER'])) {
|
||||
$tmp['area'] = 'goalkeeper';
|
||||
$tmp['color_pos'] = 'gray';
|
||||
$tmp['order'] = 4;
|
||||
} else {
|
||||
$tmp['area'] = 'defence';
|
||||
$tmp['color_pos'] = 'success';
|
||||
$tmp['order'] = 5;
|
||||
}
|
||||
$tmp['area'] = 'defence';
|
||||
$tmp['color_pos'] = 'success';
|
||||
$tmp['order'] = 5;
|
||||
}
|
||||
|
||||
$result[] = $tmp;
|
||||
}
|
||||
|
||||
$result[] = $tmp;
|
||||
}
|
||||
|
||||
// dd($result);
|
||||
|
||||
// $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