find pest positions
This commit is contained in:
1 parent
c0c4373ba0
commit
d6fe50e69a
3 files changed
+106
-16
No files matched your search
@@ -205,6 +205,12 @@ class PlayerProps extends Page implements HasForms
|
|||||||
$this->players = $players;
|
$this->players = $players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[On('update-lineup')]
|
||||||
|
public function updateLineup(string $lineup_name)
|
||||||
|
{
|
||||||
|
$this->filterData['lineup'] = $lineup_name;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getFooterWidgets(): array
|
protected function getFooterWidgets(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -694,18 +694,6 @@ class PlayerPropsDrop extends Widget
|
|||||||
|
|
||||||
public function generateLineUp(): void
|
public function generateLineUp(): void
|
||||||
{
|
{
|
||||||
// {
|
|
||||||
// "975216": 6,
|
|
||||||
// "1122806": 9,
|
|
||||||
// "1003010": 11,
|
|
||||||
// "881215": 16,
|
|
||||||
// "158277": 18,
|
|
||||||
// "221636": 19,
|
|
||||||
// "2282985": 21,
|
|
||||||
// "1631268": 23,
|
|
||||||
// "1064039": 25,
|
|
||||||
// "922559": 34
|
|
||||||
// }
|
|
||||||
if ($this->activeLineUp && $this->team_id) {
|
if ($this->activeLineUp && $this->team_id) {
|
||||||
|
|
||||||
$players = $this->prepareLineUp();
|
$players = $this->prepareLineUp();
|
||||||
@@ -728,19 +716,19 @@ class PlayerPropsDrop extends Widget
|
|||||||
} else {
|
} else {
|
||||||
if (isset($hirarchy[$position])) {
|
if (isset($hirarchy[$position])) {
|
||||||
$position = $hirarchy[$position][0];
|
$position = $hirarchy[$position][0];
|
||||||
$fitered = $players->where('pos', $position)->sortByDesc('min')->first();
|
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||||
if (isset($fitered['id'])) {
|
if (isset($fitered['id'])) {
|
||||||
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
||||||
$id_used[] = $fitered['id'];
|
$id_used[] = $fitered['id'];
|
||||||
} elseif (isset($hirarchy[$position][1])) {
|
} elseif (isset($hirarchy[$position][1])) {
|
||||||
$position = $hirarchy[$position][1];
|
$position = $hirarchy[$position][1];
|
||||||
$fitered = $players->where('pos', $position)->sortByDesc('min')->first();
|
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||||
if (isset($fitered['id'])) {
|
if (isset($fitered['id'])) {
|
||||||
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
||||||
$id_used[] = $fitered['id'];
|
$id_used[] = $fitered['id'];
|
||||||
} elseif (isset($hirarchy[$position][2])) {
|
} elseif (isset($hirarchy[$position][2])) {
|
||||||
$position = $hirarchy[$position][2];
|
$position = $hirarchy[$position][2];
|
||||||
$fitered = $players->where('pos', $position)->sortByDesc('min')->first();
|
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||||
if (isset($fitered['id'])) {
|
if (isset($fitered['id'])) {
|
||||||
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
||||||
$id_used[] = $fitered['id'];
|
$id_used[] = $fitered['id'];
|
||||||
@@ -762,7 +750,9 @@ class PlayerPropsDrop extends Widget
|
|||||||
foreach ($this->players as $k => $record) {
|
foreach ($this->players as $k => $record) {
|
||||||
$id = $record['id'];
|
$id = $record['id'];
|
||||||
if (isset($lineup[$id])) {
|
if (isset($lineup[$id])) {
|
||||||
|
|
||||||
$this->boxes[$lineup[$id]['place']] = $record;
|
$this->boxes[$lineup[$id]['place']] = $record;
|
||||||
|
|
||||||
$this->players[$k]['active'] = 1;
|
$this->players[$k]['active'] = 1;
|
||||||
$this->players[$k]['pos'] = $lineup[$id]['position'];
|
$this->players[$k]['pos'] = $lineup[$id]['position'];
|
||||||
|
|
||||||
@@ -778,4 +768,97 @@ class PlayerPropsDrop extends Widget
|
|||||||
$this->storePlacement();
|
$this->storePlacement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function majorFormations(): array
|
||||||
|
{
|
||||||
|
// 343+
|
||||||
|
// 352
|
||||||
|
// 433+
|
||||||
|
// 442+
|
||||||
|
// 4231
|
||||||
|
// 4321+
|
||||||
|
// 4312+
|
||||||
|
// 4411+
|
||||||
|
return [
|
||||||
|
'343+' => [9, 16, 23, 4, 11, 25, 32, 6, 34, 21],
|
||||||
|
'352' => [9, 16, 23, 4, 11, 17, 25, 32, 20, 21],
|
||||||
|
'433+' => [2, 9, 23, 30, 11, 18, 25, 6, 34, 21],
|
||||||
|
'442+' => [2, 9, 23, 30, 4, 11, 25, 32, 20, 21],
|
||||||
|
'4231' => [2, 9, 23, 30, 10, 24, 12, 19, 26, 21],
|
||||||
|
'4321+' => [2, 9, 23, 30, 11, 18, 25, 12, 26, 21],
|
||||||
|
'4312+' => [2, 9, 23, 30, 11, 18, 25, 19, 20, 21],
|
||||||
|
'4411+' => [2, 9, 23, 30, 4, 11, 25, 32, 19, 21],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateBestLineUp(): void
|
||||||
|
{
|
||||||
|
if (! $this->team_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$all_lineups = [];
|
||||||
|
|
||||||
|
$players = $this->prepareLineUp();
|
||||||
|
|
||||||
|
$hirarchy = PositionHirarchie::load();
|
||||||
|
|
||||||
|
$major_formations = self::majorFormations();
|
||||||
|
|
||||||
|
foreach ($major_formations as $formation_name => $formation_positions) {
|
||||||
|
|
||||||
|
$lineup = [];
|
||||||
|
|
||||||
|
$id_used = [];
|
||||||
|
|
||||||
|
foreach ($formation_positions as $place) {
|
||||||
|
|
||||||
|
$position = $this->activeBoxes[$place];
|
||||||
|
|
||||||
|
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||||
|
|
||||||
|
if (isset($player['id'])) {
|
||||||
|
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||||
|
$id_used[] = $player['id'];
|
||||||
|
} else {
|
||||||
|
if (isset($hirarchy[$position])) {
|
||||||
|
$position = $hirarchy[$position][0];
|
||||||
|
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||||
|
if (isset($player['id'])) {
|
||||||
|
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||||
|
$id_used[] = $player['id'];
|
||||||
|
} elseif (isset($hirarchy[$position][1])) {
|
||||||
|
$position = $hirarchy[$position][1];
|
||||||
|
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||||
|
if (isset($player['id'])) {
|
||||||
|
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||||
|
$id_used[] = $player['id'];
|
||||||
|
} elseif (isset($hirarchy[$position][2])) {
|
||||||
|
$position = $hirarchy[$position][2];
|
||||||
|
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||||
|
if (isset($player['id'])) {
|
||||||
|
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||||
|
$id_used[] = $player['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$all_lineups[$formation_name] = $lineup;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = [];
|
||||||
|
foreach ($all_lineups as $formation_name => $lineup) {
|
||||||
|
$tmp[$formation_name] = array_sum(array_column($lineup, 'min'));
|
||||||
|
}
|
||||||
|
$formation_name = array_search(max($tmp), $tmp);
|
||||||
|
|
||||||
|
$this->dispatch('update-lineup', $formation_name);
|
||||||
|
|
||||||
|
$this->lineUpUpdate($formation_name);
|
||||||
|
|
||||||
|
$this->generateLineUp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,8 @@
|
|||||||
<div class="text-3xl font-bold"> {{ $team_name }} <span
|
<div class="text-3xl font-bold"> {{ $team_name }} <span
|
||||||
class="text-sm font-light">({{ $player_on_field_counter }})</span></div>
|
class="text-sm font-light">({{ $player_on_field_counter }})</span></div>
|
||||||
<div class="flex gap-3">
|
<div class="flex gap-3">
|
||||||
<x-filament::button icon="phosphor-user-switch" tooltip="Create Lienup" wire:click="generateLineUp()"/>
|
<x-filament::button icon="phosphor-user-circle-check" color="success" tooltip="Find best formation and create lineup" wire:click="generateBestLineUp()"/>
|
||||||
|
<x-filament::button icon="phosphor-user-switch" tooltip="Create lineup for selected formation" wire:click="generateLineUp()"/>
|
||||||
<x-filament::button icon="phosphor-x" tooltip="Clear all" wire:click="clearResultTable()" />
|
<x-filament::button icon="phosphor-x" tooltip="Clear all" wire:click="clearResultTable()" />
|
||||||
|
|
||||||
<x-filament::modal id="custom-view-modal" slide-over width="xl">
|
<x-filament::modal id="custom-view-modal" slide-over width="xl">
|
||||||
|
|||||||
Reference in new issue
Block a user