wip generate positions in PP

This commit is contained in:
salam committed 2026-10-09 22:47:37 +02:00
1 parent 01b62be635
commit 8ae58d2e2a
7 files changed
+210 -9

No files matched your search

-1
View File
@@ -20,7 +20,6 @@ use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\Utilities\Set; use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema; use Filament\Schemas\Schema;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Livewire\Attributes\On; use Livewire\Attributes\On;
class PlayerProps extends Page implements HasForms class PlayerProps extends Page implements HasForms
@@ -58,9 +58,7 @@ class ExpectationsTeam
$expectations = ExpectationCalculationMethodB::calc($tmp); $expectations = ExpectationCalculationMethodB::calc($tmp);
} }
// dd($expectations); ExpectationsMinMax::calc($expectations, $match);
ExpectationsMinMax::calc($expectations, $league_id);
$expectations['gls']['name'] = 'Goals'; $expectations['gls']['name'] = 'Goals';
$expectations['crn']['name'] = 'Corner'; $expectations['crn']['name'] = 'Corner';
@@ -6,7 +6,7 @@ use App\Models\StatistikoEvent;
class ExpectationsMinMax class ExpectationsMinMax
{ {
public static function calc(array &$expectations, int $league_id) public static function calc(array &$expectations, object $match)
{ {
/** /**
* get min and max for each bettype from all DB for liga * get min and max for each bettype from all DB for liga
@@ -15,7 +15,7 @@ class ExpectationsMinMax
$bets = ['crn', 'fls', 'ofs', 'crd', 'snt', 'tsh']; $bets = ['crn', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
$Y = 0.25; $Y = 0.25;
$res = StatistikoEvent::where('league_id', $league_id)->get(); $res = StatistikoEvent::where('league_id', $match->league_id)->get();
$count = $res->count(); $count = $res->count();
$data = []; $data = [];
@@ -75,5 +75,24 @@ class ExpectationsMinMax
$expectations[$key]['away'] = $final[$key]['min']; $expectations[$key]['away'] = $final[$key]['min'];
} }
} }
// GOALS with asp from fixtures
$gls_home_max = $match->exp_home * (1 + ($Y / 2));
$gls_home_min = $match->exp_home * (1 - ($Y / 2));
$gls_away_max = $match->exp_away * (1 + ($Y / 2));
$gls_away_min = $match->exp_away * (1 - ($Y / 2));
if ($expectations['gls']['home'] > $gls_home_max) {
$expectations['gls']['home'] = $gls_home_max;
}
if ($expectations['gls']['away'] > $gls_away_max) {
$expectations['gls']['away'] = $gls_away_max;
}
if ($expectations['gls']['home'] < $gls_home_min) {
$expectations['gls']['home'] = $gls_home_min;
}
if ($expectations['gls']['away'] < $gls_away_min) {
$expectations['gls']['away'] = $gls_away_min;
}
} }
} }
@@ -58,4 +58,65 @@ class LineUpMap
'541+' => [2, 9, 16, 23, 30, 4, 11, 25, 32, 21], '541+' => [2, 9, 16, 23, 30, 4, 11, 25, 32, 21],
]; ];
} }
public static function get(string $key)
{
$lup = [
'3313' => [9, 16, 23, 11, 18, 25, 19, 6, 34, 21],
'3331' => [9, 16, 23, 17, 11, 25, 12, 19, 26, 21],
'3331-' => [9, 16, 23, 10, 18, 24, 12, 19, 26, 21],
'3331+' => [9, 16, 23, 11, 18, 25, 12, 19, 26, 21],
'3412-' => [9, 16, 23, 4, 10, 24, 32, 19, 20, 21],
'3412+' => [9, 16, 23, 4, 11, 25, 32, 19, 20, 21],
'3421-' => [9, 16, 23, 4, 10, 24, 32, 12, 26, 21],
'3421+' => [9, 16, 23, 4, 11, 25, 32, 12, 26, 21],
'343-' => [9, 16, 23, 4, 10, 24, 32, 6, 34, 21],
'343+' => [9, 16, 23, 4, 11, 25, 32, 6, 34, 21],
'3511' => [9, 16, 23, 4, 11, 17, 25, 32, 19, 21],
'3511-' => [9, 16, 23, 4, 10, 18, 24, 32, 19, 21],
'3511+' => [9, 16, 23, 4, 11, 18, 25, 32, 19, 21],
'352' => [9, 16, 23, 4, 11, 17, 25, 32, 20, 21],
'352-' => [9, 16, 23, 4, 10, 18, 24, 32, 20, 21],
'352+' => [9, 16, 23, 4, 11, 18, 25, 32, 20, 21],
'4132' => [2, 9, 23, 30, 17, 12, 19, 26, 20, 21],
'4213-' => [2, 9, 23, 30, 10, 24, 19, 6, 34, 21],
'4213+' => [2, 9, 23, 30, 11, 25, 19, 6, 34, 21],
'4222' => [2, 9, 23, 30, 10, 24, 12, 26, 20, 21],
'4231' => [2, 9, 23, 30, 10, 24, 12, 19, 26, 21],
'424' => [2, 9, 23, 30, 10, 24, 6, 34, 20, 21],
'4312' => [2, 9, 23, 30, 17, 11, 25, 19, 20, 21],
'4312-' => [2, 9, 23, 30, 10, 18, 24, 19, 20, 21],
'4312+' => [2, 9, 23, 30, 11, 18, 25, 19, 20, 21],
'4321' => [2, 9, 23, 30, 17, 11, 25, 12, 26, 21],
'4321-' => [2, 9, 23, 30, 10, 18, 24, 12, 26, 21],
'4321+' => [2, 9, 23, 30, 11, 18, 25, 12, 26, 21],
'433' => [2, 9, 23, 30, 17, 11, 25, 6, 34, 21],
'433-' => [2, 9, 23, 30, 10, 18, 24, 6, 34, 21],
'433+' => [2, 9, 23, 30, 11, 18, 25, 6, 34, 21],
'4411-' => [2, 9, 23, 30, 4, 10, 24, 32, 19, 21],
'4411+' => [2, 9, 23, 30, 4, 11, 25, 32, 19, 21],
'442' => [2, 9, 23, 30, 4, 17, 18, 32, 20, 21],
'442-' => [2, 9, 23, 30, 4, 10, 24, 32, 20, 21],
'442+' => [2, 9, 23, 30, 4, 11, 25, 32, 20, 21],
'451' => [2, 9, 23, 30, 4, 17, 11, 25, 32, 21],
'451-' => [2, 9, 23, 30, 4, 10, 18, 24, 32, 21],
'451+' => [2, 9, 23, 30, 4, 11, 18, 25, 32, 21],
'523-' => [2, 9, 16, 23, 30, 10, 24, 6, 34, 21],
'523+' => [2, 9, 16, 23, 30, 11, 25, 6, 34, 21],
'5311' => [2, 9, 16, 23, 30, 17, 11, 25, 19, 21],
'5311-' => [2, 9, 16, 23, 30, 10, 18, 24, 19, 21],
'5311+' => [2, 9, 16, 23, 30, 11, 18, 25, 19, 21],
'532' => [2, 9, 16, 23, 30, 17, 11, 25, 20, 21],
'532-' => [2, 9, 16, 23, 30, 10, 18, 24, 20, 21],
'532+' => [2, 9, 16, 23, 30, 11, 18, 25, 20, 21],
'541-' => [2, 9, 16, 23, 30, 4, 10, 24, 32, 21],
'541+' => [2, 9, 16, 23, 30, 4, 11, 25, 32, 21],
];
if (isset($lup[$key])) {
return $lup[$key];
}
return [];
}
} }
@@ -0,0 +1,25 @@
<?php
namespace App\Filament\Widgets\PlayerProps;
class PositionHirarchie
{
public static function load()
{
return [
// 'DC' => ['DC'],
'DR' => ['MR', 'DC'],
'DL' => ['ML', 'DC'],
'SW' => ['DC'],
'MR' => ['DR', 'RW'],
'ML' => ['DL', 'LW'],
// 'MC' => ['MC'],
'DM' => ['MC'],
'AM' => ['LW', 'RW', 'MC'],
'LW' => ['AM', 'ST'],
'RW' => ['AM', 'ST'],
// 'ST' => ['ST'],
'SS' => ['ST'],
];
}
}
+99 -2
View File
@@ -5,6 +5,7 @@ namespace App\Filament\Widgets;
use App\Filament\Widgets\PlayerProps\BoxNames; use App\Filament\Widgets\PlayerProps\BoxNames;
use App\Filament\Widgets\PlayerProps\Expectations; use App\Filament\Widgets\PlayerProps\Expectations;
use App\Filament\Widgets\PlayerProps\LineUpMap; use App\Filament\Widgets\PlayerProps\LineUpMap;
use App\Filament\Widgets\PlayerProps\PositionHirarchie;
use App\Livewire\PlayerCalculator; use App\Livewire\PlayerCalculator;
use App\Models\ExpectedMinimumPosition; use App\Models\ExpectedMinimumPosition;
use App\Models\SofaScorePlayerPerSeason; use App\Models\SofaScorePlayerPerSeason;
@@ -44,7 +45,7 @@ class PlayerPropsDrop extends Widget
public int $team_id = 0; public int $team_id = 0;
public int $match_id; public int $match_id = 0;
public int $player_on_field_counter; public int $player_on_field_counter;
@@ -614,8 +615,9 @@ class PlayerPropsDrop extends Widget
$this->players[$k]['active'] = $result['active']; $this->players[$k]['active'] = $result['active'];
$pos = $this->players[$k]['pos']; $pos = $this->players[$k]['pos'];
if (!$pos) if (! $pos) {
$pos = $this->players[$k]['pos_ori']; $pos = $this->players[$k]['pos_ori'];
}
$tamx = number_format($map[$pos]['gls'], 3); $tamx = number_format($map[$pos]['gls'], 3);
$final = number_format($result['asp_player_goals'], 3); $final = number_format($result['asp_player_goals'], 3);
@@ -672,4 +674,99 @@ class PlayerPropsDrop extends Widget
return false; return false;
} }
public function prepareLineUp()
{
$players = SofaScorePlayerPerSeason::with('details')->where('season', 'total')->where('ss_team_id', $this->team_id)->get();
$arr = collect();
foreach ($players as $value) {
if ($value?->details->position ?? 0) {
$arr->push([
'id' => $value->ss_player_id,
'min' => $value->total_min,
'pos' => $value->details->position,
]);
}
}
return $arr;
}
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) {
$players = $this->prepareLineUp();
$hirarchy = PositionHirarchie::load();
$places = LineUpMap::get($this->activeLineUp);
$lineup = [];
$id_used = [];
foreach ($places as $k => $place) {
$position = $this->activeBoxes[$place];
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortBy('min')->first();
if (isset($fitered['id'])) {
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
$id_used[] = $fitered['id'];
} else {
if (isset($hirarchy[$position])) {
$position = $hirarchy[$position][0];
$fitered = $players->where('pos', $position)->sortBy('min')->first();
if (isset($fitered['id'])) {
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
$id_used[] = $fitered['id'];
} elseif (isset($hirarchy[$position][1])) {
$position = $hirarchy[$position][1];
$fitered = $players->where('pos', $position)->sortBy('min')->first();
if (isset($fitered['id'])) {
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
$id_used[] = $fitered['id'];
} elseif (isset($hirarchy[$position][2])) {
$position = $hirarchy[$position][2];
$fitered = $players->where('pos', $position)->sortBy('min')->first();
if (isset($fitered['id'])) {
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
$id_used[] = $fitered['id'];
}
}
}
}
}
}
$this->clearResultTable();
$this->player_on_field_counter = 0;
foreach ($this->players as $k => $record) {
$id = $record['id'];
if (isset($lineup[$id])) {
$this->boxes[$lineup[$id]['place']] = $record;
$this->players[$k]['active'] = 1;
$this->players[$k]['pos'] = $lineup[$id]['position'];
$this->player_on_field_counter++;
}
}
$this->calculateAspg();
}
}
} }
@@ -6,6 +6,9 @@
<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-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">
<x-slot name="trigger"> <x-slot name="trigger">
<x-filament::button icon="phosphor-question-mark" tooltip="Lineup code explanation" /> <x-filament::button icon="phosphor-question-mark" tooltip="Lineup code explanation" />
@@ -22,7 +25,6 @@
</div> </div>
</x-slot> </x-slot>
</x-filament::modal> </x-filament::modal>
<x-filament::button icon="phosphor-x" tooltip="Clear all" wire:click="clearResultTable()" />
<x-filament::button icon="phosphor-arrows-clockwise" tooltip="Reload" wire:click="loadPlacement()" /> <x-filament::button icon="phosphor-arrows-clockwise" tooltip="Reload" wire:click="loadPlacement()" />
{{-- <x-filament::button icon="phosphor-calculator" tooltip="Calculate" wire:click="calculateAspg(1)" /> --}} {{-- <x-filament::button icon="phosphor-calculator" tooltip="Calculate" wire:click="calculateAspg(1)" /> --}}
<x-filament::button icon="phosphor-copy" color="success" <x-filament::button icon="phosphor-copy" color="success"