wip pp filter
This commit is contained in:
1 parent
fc1e1b2832
commit
55f31acf2a
23 files changed
+1127
-329
No files matched your search
@@ -2,19 +2,24 @@
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\Boxes\LoadPlayerAverages;
|
||||
use App\Filament\Pages\Selections\LoadPositions;
|
||||
use App\Filament\Pages\Selections\LoadSeasons;
|
||||
use App\Filament\Widgets\PlayerProps\BoxNames;
|
||||
use App\Filament\Widgets\PlayerProps\Expectations;
|
||||
use App\Filament\Widgets\PlayerProps\LineUpMap;
|
||||
use App\Filament\Widgets\PlayerProps\PositionHirarchie;
|
||||
use App\Livewire\PlayerCalculator;
|
||||
use App\Models\ExpectedMinimumPosition;
|
||||
use App\Models\SofaScoreCategory;
|
||||
use App\Models\SofaScorePlayerPosition;
|
||||
use App\Models\SofaScoreRosa;
|
||||
use App\Models\SsLineupMemory;
|
||||
use App\Models\StatisticFixtures;
|
||||
use App\Models\StatistikoDetail;
|
||||
use App\Models\StatistikoEvent;
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Widgets\Widget;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -45,6 +50,16 @@ class PlayerPropsDrop extends Widget
|
||||
|
||||
public string $team_name = '';
|
||||
|
||||
public string $season_or_date = 'season';
|
||||
|
||||
public string $season_mode = '';
|
||||
|
||||
public array $season;
|
||||
|
||||
public string $start_date = '';
|
||||
|
||||
public string $end_date = '';
|
||||
|
||||
public int $team_id = 0;
|
||||
|
||||
public int $match_id = 0;
|
||||
@@ -59,6 +74,8 @@ class PlayerPropsDrop extends Widget
|
||||
{
|
||||
$this->activeBoxes = BoxNames::load();
|
||||
|
||||
$this->season_or_date = 'season';
|
||||
|
||||
$this->lineUpMap = LineUpMap::load();
|
||||
|
||||
$this->player_on_field_counter = 0;
|
||||
@@ -103,15 +120,79 @@ class PlayerPropsDrop extends Widget
|
||||
}
|
||||
|
||||
#[On('team-update')]
|
||||
public function syncData(?int $team_id)
|
||||
public function teamUpdate(int $team_id)
|
||||
{
|
||||
if ($team_id) {
|
||||
$this->team_id = $team_id;
|
||||
|
||||
$this->players = PlayerCalculator::load($team_id);
|
||||
$this->syncData();
|
||||
}
|
||||
|
||||
$this->team_name = SofaScoreRosa::where('ss_team_id', $team_id)->value('ss_team_name');
|
||||
public function syncData()
|
||||
{
|
||||
if ($this->team_id) {
|
||||
$this->players = [];
|
||||
|
||||
$positions_map = LoadPositions::load();
|
||||
|
||||
$players = $this->loadAverages();
|
||||
|
||||
foreach ($players as $val) {
|
||||
|
||||
$tmp = [];
|
||||
$tmp['id'] = $val['ss_player_id'];
|
||||
$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['color_evt'] = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
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'] = 4;
|
||||
} else {
|
||||
$tmp['area'] = 'defence';
|
||||
$tmp['color_pos'] = 'success';
|
||||
$tmp['order'] = 5;
|
||||
}
|
||||
|
||||
$this->players[] = $tmp;
|
||||
}
|
||||
|
||||
$this->team_name = SofaScoreRosa::where('ss_team_id', $this->team_id)->value('ss_team_name');
|
||||
|
||||
$this->team_id = $team_id;
|
||||
$this->loadPlacement();
|
||||
} else {
|
||||
$this->team_name = '';
|
||||
@@ -124,8 +205,14 @@ class PlayerPropsDrop extends Widget
|
||||
public function lineUpUpdate(int|string $activeLineUp)
|
||||
{
|
||||
$this->activeLineUp = $activeLineUp;
|
||||
|
||||
$this->lineup = $this->lineUpMap[$activeLineUp];
|
||||
|
||||
$this->loadPlacement();
|
||||
|
||||
$this->generateLineUp();
|
||||
|
||||
$this->calculateAspg();
|
||||
}
|
||||
|
||||
#[On('element-dropped-in-box')]
|
||||
@@ -168,6 +255,44 @@ class PlayerPropsDrop extends Widget
|
||||
}
|
||||
}
|
||||
|
||||
#[On('season_or_date-update')]
|
||||
public function setSeasonOrData(string $season_or_date)
|
||||
{
|
||||
$this->season_or_date = $season_or_date;
|
||||
|
||||
if ($this->player_on_field_counter >= 10) {
|
||||
$this->calculateAspg();
|
||||
}
|
||||
}
|
||||
|
||||
#[On('start_date-update')]
|
||||
public function setStartDate(string $start_date)
|
||||
{
|
||||
$this->start_date = $start_date;
|
||||
|
||||
if ($this->player_on_field_counter >= 10) {
|
||||
$this->calculateAspg();
|
||||
}
|
||||
}
|
||||
|
||||
#[On('end_date-update')]
|
||||
public function setEndDate(string $end_date)
|
||||
{
|
||||
$this->end_date = $end_date;
|
||||
|
||||
if ($this->player_on_field_counter >= 10) {
|
||||
$this->calculateAspg();
|
||||
}
|
||||
}
|
||||
|
||||
#[On('season_mode-update')]
|
||||
public function setSeason(string $country_id)
|
||||
{
|
||||
$season_mode = SofaScoreCategory::where('id', $country_id)->value('season_mode');
|
||||
$this->season_mode = $season_mode;
|
||||
$this->season = LoadSeasons::load($season_mode);
|
||||
}
|
||||
|
||||
public function loadPlacement()
|
||||
{
|
||||
$this->clearResultTable();
|
||||
@@ -377,6 +502,8 @@ class PlayerPropsDrop extends Widget
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Log::info($this->team_id, ['calculateAspg']);
|
||||
// Calcolare Aspettativa Team per GOALS
|
||||
// (il valore che appare quando viene selezionato un Evento): nell' esempio,
|
||||
// se scegliamo come Team il Remo (Home) il valore di riferimento sarà 1.2
|
||||
@@ -391,8 +518,16 @@ class PlayerPropsDrop extends Widget
|
||||
$asp_team = (float) $match->exp_away;
|
||||
$team_home_away = 'away';
|
||||
}
|
||||
$arr = [
|
||||
'team_id' => $this->team_id,
|
||||
'season_or_date' => $this->season_or_date,
|
||||
'season' => $this->season,
|
||||
'season_mode' => $this->season_mode,
|
||||
'start_date' => $this->end_date,
|
||||
'end_date' => $this->end_date,
|
||||
];
|
||||
|
||||
$players = LoadPlayerAverages::load($team_id, 'total');
|
||||
$players = $this->loadAverages();
|
||||
|
||||
$count_player = 0;
|
||||
foreach ($players as $ss_player_id => $value) {
|
||||
@@ -684,7 +819,16 @@ class PlayerPropsDrop extends Widget
|
||||
|
||||
public function prepareLineUp()
|
||||
{
|
||||
$players = LoadPlayerAverages::load($this->team_id, 'last180days');
|
||||
$arr = [
|
||||
'team_id' => $this->team_id,
|
||||
'season_or_date' => $this->season_or_date,
|
||||
'season' => $this->season,
|
||||
'season_mode' => $this->season_mode,
|
||||
'start_date' => $this->start_date,
|
||||
'end_date' => $this->end_date,
|
||||
];
|
||||
|
||||
$players = $this->loadAverages();
|
||||
|
||||
$arr = collect();
|
||||
foreach ($players as $value) {
|
||||
@@ -867,4 +1011,129 @@ class PlayerPropsDrop extends Widget
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loadAverages(): array
|
||||
{
|
||||
if (! $this->team_id) {
|
||||
return [];
|
||||
}
|
||||
// Log::debug('loadAverages', ['team_id' => $this->team_id]);
|
||||
|
||||
$players = StatistikoDetail::where('ss_team_id', $this->team_id)->where('is_active', 1)->get();
|
||||
|
||||
$player_ids = [];
|
||||
|
||||
foreach ($players as $player) {
|
||||
$player_ids[] = $player->ss_player_id;
|
||||
}
|
||||
|
||||
// Log::debug('loadAverages', ['player_ids' => $player_ids]);
|
||||
|
||||
$start_date = null;
|
||||
$end_date = null;
|
||||
if ($this->season_or_date == 'season') {
|
||||
$now = Carbon::now();
|
||||
if ($this->season_mode == 'halfyear') {
|
||||
if ((int) $now->month > 6) {
|
||||
$season_start = $now->startOfYear()->addMonths(7);
|
||||
} else {
|
||||
$season_start = $now->startOfYear()->subMonths(7);
|
||||
}
|
||||
} else {
|
||||
$season_start = $now->startOfYear();
|
||||
}
|
||||
} else {
|
||||
$season_start = '';
|
||||
$start_date = Carbon::parse($this->start_date);
|
||||
$end_date = Carbon::parse($this->end_date);
|
||||
// Log::debug('start end', [$start_date->format('Y-m-d').' - '.$end_date->format('Y-m-d')]);
|
||||
}
|
||||
|
||||
$match_ids = StatistikoEvent::when($start_date, function ($query) use ($start_date) {
|
||||
return $query->whereDate('starttime', '>', $start_date);
|
||||
})->when($end_date, function ($query) use ($end_date) {
|
||||
return $query->whereDate('starttime', '<', $end_date);
|
||||
})->when($season_start, function ($query) use ($season_start) {
|
||||
return $query->whereDate('starttime', '>', $season_start);
|
||||
})->pluck('match_id')->toArray();
|
||||
|
||||
// Log::debug('loadAverages', ['match_ids' => $match_ids]);
|
||||
|
||||
$res = StatistikoPlayer::with('details')
|
||||
->whereIn('ss_player_id', $player_ids)
|
||||
->whereIn('match_id', $match_ids)
|
||||
->get();
|
||||
|
||||
$arr = [];
|
||||
foreach ($res as $val) {
|
||||
|
||||
$ss_player_id = (int) $val->ss_player_id;
|
||||
$activeteam_id = (int) $val->activeteam_id;
|
||||
$minutes_played = (int) $val->minutes_played;
|
||||
$home_id = (int) $val->event->home_id;
|
||||
$away_id = (int) $val->event->away_id;
|
||||
|
||||
if (! isset($arr[$ss_player_id])) {
|
||||
self::array_template($arr, $ss_player_id);
|
||||
}
|
||||
|
||||
if ($activeteam_id == $home_id) {
|
||||
$arr[$ss_player_id]['events_played_home'] += 1;
|
||||
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
||||
$arr[$ss_player_id]['events_played_home'] += 1;
|
||||
$arr[$ss_player_id]['minutes_played_home'] += $minutes_played;
|
||||
} elseif ($activeteam_id == $away_id) {
|
||||
$arr[$ss_player_id]['events_played_away'] += 1;
|
||||
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
||||
$arr[$ss_player_id]['events_played_away'] += 1;
|
||||
$arr[$ss_player_id]['minutes_played_away'] += $minutes_played;
|
||||
}
|
||||
$cards = $val->card_yellow + $val->card_yellowred;
|
||||
|
||||
$arr[$ss_player_id]['ss_player_id'] = $ss_player_id;
|
||||
$arr[$ss_player_id]['total_events']++;
|
||||
$arr[$ss_player_id]['total_min'] += $minutes_played;
|
||||
$arr[$ss_player_id]['average_min'] = round($arr[$ss_player_id]['total_min'] / $arr[$ss_player_id]['total_events']);
|
||||
$arr[$ss_player_id]['goals'] += $val->goals;
|
||||
$arr[$ss_player_id]['fouls'] += $val->fouls;
|
||||
$arr[$ss_player_id]['cards'] += $cards;
|
||||
$arr[$ss_player_id]['offsides'] += $val->offsides;
|
||||
$arr[$ss_player_id]['shots_on_target'] += $val->shots_on_target;
|
||||
$arr[$ss_player_id]['shots_off_target'] += $val->shots_off_target;
|
||||
$arr[$ss_player_id]['shots_blocked'] += $val->shots_blocked;
|
||||
$arr[$ss_player_id]['total_shots'] += $val->shots_on_target + $val->shots_off_target + $val->shots_blocked;
|
||||
}
|
||||
|
||||
foreach ($players as $value) {
|
||||
if (isset($arr[$value->ss_player_id])) {
|
||||
$arr[$value->ss_player_id]['position'] = $value->position;
|
||||
$arr[$value->ss_player_id]['player_name'] = $value->player_name;
|
||||
$arr[$value->ss_player_id]['preferred_foot'] = $value->preferred_foot;
|
||||
}
|
||||
}
|
||||
|
||||
// Log::debug('loadAverages final', $arr);
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public static function array_template(array &$arr, int $ss_player_id)
|
||||
{
|
||||
$arr[$ss_player_id]['ss_player_id'] = 0;
|
||||
$arr[$ss_player_id]['total_events'] = 0;
|
||||
$arr[$ss_player_id]['total_min'] = 0;
|
||||
$arr[$ss_player_id]['average_min'] = 0;
|
||||
$arr[$ss_player_id]['events_played_home'] = 0;
|
||||
$arr[$ss_player_id]['events_played_away'] = 0;
|
||||
$arr[$ss_player_id]['minutes_played_home'] = 0;
|
||||
$arr[$ss_player_id]['minutes_played_away'] = 0;
|
||||
$arr[$ss_player_id]['goals'] = 0;
|
||||
$arr[$ss_player_id]['fouls'] = 0;
|
||||
$arr[$ss_player_id]['offsides'] = 0;
|
||||
$arr[$ss_player_id]['shots_on_target'] = 0;
|
||||
$arr[$ss_player_id]['shots_off_target'] = 0;
|
||||
$arr[$ss_player_id]['shots_blocked'] = 0;
|
||||
$arr[$ss_player_id]['total_shots'] = 0;
|
||||
$arr[$ss_player_id]['cards'] = 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user