wip player app
This commit is contained in:
1 parent
f9712cbd25
commit
6b1a68e738
13 files changed
+537
-311
No files matched your search
@@ -7,7 +7,6 @@ use App\Filament\Pages\Selections\LoadPositions;
|
||||
use App\Models\SofaScorePlayerCache;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
|
||||
class LoadPlayer
|
||||
{
|
||||
@@ -18,7 +17,7 @@ class LoadPlayer
|
||||
$hash = hash('crc32', $team_id . $team_position . $sofascore_category_id . serialize($season));
|
||||
$cached_players = SofaScorePlayerCache::where('hash', $hash)->value('players');
|
||||
if ($cached_players) {
|
||||
return $cached_players;
|
||||
// return $cached_players;
|
||||
}
|
||||
|
||||
$matches = StatistikoEvent::whereIn('season', $season)
|
||||
@@ -93,7 +92,6 @@ class LoadPlayer
|
||||
} else if (in_array($val['player_position'], $positions_map['GOALKEEPER'])) {
|
||||
$position = 'GOALKEEPER';
|
||||
} else {
|
||||
$player_position = $val['player_position'];
|
||||
$position = 'NO SPECIFIC POSITION';
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,8 @@ class Statistic extends BaseDashboard
|
||||
->modalSubmitAction(false) // Hides the submit button
|
||||
->modalCancelAction(false) // Optional: hides the cancel button too
|
||||
->label('Calculate')
|
||||
->stickyModalHeader()
|
||||
->modalHeading('Calculate Player ASG')
|
||||
->icon('icon-player')
|
||||
->color(fn(): string => $this->filters['team_id'] ? 'primary' : 'gray')
|
||||
->disabled(fn(): string => $this->filters['team_id'] ? false : true)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Livewire\Mapper;
|
||||
|
||||
class LoadPositions
|
||||
class LoadGridPositions
|
||||
{
|
||||
|
||||
public static function load()
|
||||
@@ -2,25 +2,140 @@
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Filament\Pages\Selections\LoadPlayer;
|
||||
use App\Livewire\Mapper\LoadPositions;
|
||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||
use App\Filament\Pages\Selections\LoadPositions;
|
||||
use App\Livewire\Mapper\LoadGridPositions;
|
||||
use App\Models\SofaScorePlayerPerSeason;
|
||||
use App\Models\StatistikoEvent;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
use Livewire\Component;
|
||||
|
||||
class PlayerCalculator extends Component
|
||||
{
|
||||
use InteractsWithPageFilters;
|
||||
public $player = [];
|
||||
public $positions = [];
|
||||
public $grid = [];
|
||||
|
||||
public function mount(array $filters)
|
||||
{
|
||||
$this->positions = LoadPositions::load();
|
||||
$pos = array_chunk(LoadGridPositions::load(), 5);
|
||||
$pla = array_chunk(self::load($filters), 5);
|
||||
|
||||
$i = 1;
|
||||
while ($v = array_shift($pos)) {
|
||||
array_splice($pla, $i, 0, [$v]);
|
||||
$i += 2;
|
||||
}
|
||||
$this->grid = $pla;
|
||||
// dd($this->grid);
|
||||
}
|
||||
|
||||
public static function load(array $filters)
|
||||
{
|
||||
$team_position = $filters['team_position'];
|
||||
$sofascore_category_id = $filters['sofascore_category_id'];
|
||||
$season = $filters['season'];
|
||||
$seasonmode = $filters['seasonmode'];
|
||||
$team_id = $filters['team_id'];
|
||||
$this->player = LoadPlayer::load($team_id, $team_position, $sofascore_category_id, $season, $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) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$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 {
|
||||
$position = 'NO SPECIFIC POSITION';
|
||||
}
|
||||
|
||||
$name = $val['player_name'];
|
||||
$preferred_foot = $val['preferred_foot'] ?? '-';
|
||||
$everage_minutes = round($minues_played / $events_played) . ' min';
|
||||
if ($colorlevel > 1 && $events_played < $colorlevel) {
|
||||
$color = 'danger';
|
||||
} else if ($events_played < $colorlevel * 2) {
|
||||
$color = 'info';
|
||||
} else {
|
||||
$color = 'success';
|
||||
}
|
||||
|
||||
$result[] = [
|
||||
'player_id' => $player_id,
|
||||
'name' => $name,
|
||||
'position' => $position,
|
||||
'color' => $color,
|
||||
'info' => 'Ev ' . $events_played . ', ' . $preferred_foot . ', ' . $everage_minutes,
|
||||
];
|
||||
}
|
||||
|
||||
$maxlength = 35;
|
||||
$len = count($result);
|
||||
if ($len < $maxlength) {
|
||||
$result += array_fill($len, $maxlength - $len, [0, 0, 0, 0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
FilamentAsset::register([
|
||||
Css::make('font-stylesheet', __DIR__ . '/../../resources/css/font.css'),
|
||||
Js::make('example-external-script', 'https://cdn.jsdelivr.net/npm/interactjs@latest'),
|
||||
Js::make('number-animator', __DIR__ . '/../../resources/js/number-animator.js'),
|
||||
Js::make('dragndrop', __DIR__ . '/../../resources/js/dragndrop.js'),
|
||||
]);
|
||||
|
||||
FilamentView::registerRenderHook(
|
||||
|
||||
Reference in new issue
Block a user