wip generate positions in PP
This commit is contained in:
1 parent
01b62be635
commit
8ae58d2e2a
7 files changed
+261
-60
No files matched your search
@@ -5,6 +5,7 @@ namespace App\Filament\Widgets;
|
||||
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\SofaScorePlayerPerSeason;
|
||||
@@ -44,7 +45,7 @@ class PlayerPropsDrop extends Widget
|
||||
|
||||
public int $team_id = 0;
|
||||
|
||||
public int $match_id;
|
||||
public int $match_id = 0;
|
||||
|
||||
public int $player_on_field_counter;
|
||||
|
||||
@@ -297,9 +298,9 @@ class PlayerPropsDrop extends Widget
|
||||
foreach ($this->calculationVariables as $row) {
|
||||
if ($copystring == '') {
|
||||
$keys = array_keys($row);
|
||||
$copystring .= implode(';', $keys) . "\n";
|
||||
$copystring .= implode(';', $keys)."\n";
|
||||
}
|
||||
$copystring .= implode(';', $row) . "\n";
|
||||
$copystring .= implode(';', $row)."\n";
|
||||
}
|
||||
$this->js("navigator.clipboard.writeText(`$copystring`)");
|
||||
|
||||
@@ -319,7 +320,7 @@ class PlayerPropsDrop extends Widget
|
||||
return;
|
||||
}
|
||||
$header = ['name', 'foot', 'events', 'average min', 'position', 'on field', 'gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
|
||||
$copystring = implode(';', $header) . "\n";
|
||||
$copystring = implode(';', $header)."\n";
|
||||
foreach ($this->players as $row) {
|
||||
$tmp = [];
|
||||
$tmp[] = $row['name'];
|
||||
@@ -339,7 +340,7 @@ class PlayerPropsDrop extends Widget
|
||||
$tmp[] = $row['snt'];
|
||||
$tmp[] = $row['tsh'];
|
||||
|
||||
$copystring .= implode(';', $tmp) . "\n";
|
||||
$copystring .= implode(';', $tmp)."\n";
|
||||
}
|
||||
$this->js("navigator.clipboard.writeText(`$copystring`)");
|
||||
|
||||
@@ -454,8 +455,8 @@ class PlayerPropsDrop extends Widget
|
||||
$bettypes = ['goals', 'cards', 'fouls', 'offsides', 'total_shots', 'shots_on_target'];
|
||||
foreach ($bettypes as $bettype) {
|
||||
|
||||
$asp_statistica = (float) SofaScorePlayerPosition::where('ss_code', $position)->value('exp_' . $bettype);
|
||||
$tmp['asp_statistica_' . $bettype] = $asp_statistica;
|
||||
$asp_statistica = (float) SofaScorePlayerPosition::where('ss_code', $position)->value('exp_'.$bettype);
|
||||
$tmp['asp_statistica_'.$bettype] = $asp_statistica;
|
||||
|
||||
// if ($val->ss_player_id == 243651)
|
||||
// dd($val, $asp_statistica);
|
||||
@@ -470,61 +471,61 @@ class PlayerPropsDrop extends Widget
|
||||
case 'goals':
|
||||
$asp_gioco = $val->goals / $val->total_min * 90;
|
||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
||||
$tmp['asp_gioco_' . $bettype] = 0;
|
||||
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
|
||||
$tmp['asp_gioco_'.$bettype] = 0;
|
||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||
} else {
|
||||
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
$tmp['asp_gioco_'.$bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_'.$bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
}
|
||||
break;
|
||||
case 'cards':
|
||||
$asp_gioco = $val->cards / $val->total_min * 90;
|
||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
||||
$tmp['asp_gioco_' . $bettype] = 0;
|
||||
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
|
||||
$tmp['asp_gioco_'.$bettype] = 0;
|
||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||
} else {
|
||||
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
$tmp['asp_gioco_'.$bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_'.$bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
}
|
||||
break;
|
||||
case 'fouls':
|
||||
$asp_gioco = $val->fouls / $val->total_min * 90;
|
||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
||||
$tmp['asp_gioco_' . $bettype] = 0;
|
||||
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
|
||||
$tmp['asp_gioco_'.$bettype] = 0;
|
||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||
} else {
|
||||
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
$tmp['asp_gioco_'.$bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_'.$bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
}
|
||||
break;
|
||||
case 'offsides':
|
||||
$asp_gioco = $val->offsides / $val->total_min * 90;
|
||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
||||
$tmp['asp_gioco_' . $bettype] = 0;
|
||||
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
|
||||
$tmp['asp_gioco_'.$bettype] = 0;
|
||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||
} else {
|
||||
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
$tmp['asp_gioco_'.$bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_'.$bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
}
|
||||
break;
|
||||
case 'total_shots':
|
||||
$asp_gioco = $val->total_shots / $val->total_min * 90;
|
||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
||||
$tmp['asp_gioco_' . $bettype] = 0;
|
||||
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
|
||||
$tmp['asp_gioco_'.$bettype] = 0;
|
||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||
} else {
|
||||
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
$tmp['asp_gioco_'.$bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_'.$bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
}
|
||||
break;
|
||||
case 'shots_on_target':
|
||||
$asp_gioco = $val->shots_on_target / $val->total_min * 90;
|
||||
if ($asp_gioco == 0 || $val->total_min < $this->y_value) {
|
||||
$tmp['asp_gioco_' . $bettype] = 0;
|
||||
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
|
||||
$tmp['asp_gioco_'.$bettype] = 0;
|
||||
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
|
||||
} else {
|
||||
$tmp['asp_gioco_' . $bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_' . $bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
$tmp['asp_gioco_'.$bettype] = $asp_gioco;
|
||||
$tmp['asp_teorica_'.$bettype] = ($this->x_value * $asp_gioco + $asp_statistica) / (1 + $this->x_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -546,7 +547,7 @@ class PlayerPropsDrop extends Widget
|
||||
$bettypes = ['goals', 'cards', 'fouls', 'offsides', 'total_shots', 'shots_on_target'];
|
||||
foreach ($bettypes as $bettype) {
|
||||
|
||||
$total_bettype = array_sum(array_column($results, 'asp_teorica_' . $bettype));
|
||||
$total_bettype = array_sum(array_column($results, 'asp_teorica_'.$bettype));
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
switch ($bettype) {
|
||||
@@ -557,38 +558,38 @@ class PlayerPropsDrop extends Widget
|
||||
|
||||
$asp_team_riferimento = (float) $asp_team * $count_player / 10;
|
||||
$results[$key]['asp_riferimento_goals'] = $asp_team_riferimento;
|
||||
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
|
||||
$results[$key]['asp_total_' . $bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
|
||||
$results[$key]['asp_total_'.$bettype] = $total_bettype;
|
||||
break;
|
||||
case 'cards':
|
||||
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['crd'] * $count_player / 10;
|
||||
$results[$key]['asp_team_riferimento_card'] = $asp_team_riferimento;
|
||||
$results[$key]['asp_total_' . $bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
|
||||
$results[$key]['asp_total_'.$bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
|
||||
break;
|
||||
case 'fouls':
|
||||
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['fls'] * $count_player / 10;
|
||||
$results[$key]['asp_team_riferimento_fouls'] = $asp_team_riferimento;
|
||||
$results[$key]['asp_total_' . $bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
|
||||
$results[$key]['asp_total_'.$bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
|
||||
break;
|
||||
case 'offsides':
|
||||
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['ofs'] * $count_player / 10;
|
||||
$results[$key]['asp_team_riferimento_offside'] = $asp_team_riferimento;
|
||||
$results[$key]['asp_total_' . $bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
|
||||
$results[$key]['asp_total_'.$bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
|
||||
break;
|
||||
case 'total_shots':
|
||||
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['tsh'] * $count_player / 10;
|
||||
$results[$key]['asp_team_riferimento_tsh'] = $asp_team_riferimento;
|
||||
$results[$key]['asp_total_' . $bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
|
||||
$results[$key]['asp_total_'.$bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
|
||||
break;
|
||||
case 'shots_on_target':
|
||||
$asp_team_riferimento = (float) $asp_team_all[$team_home_away]['snt'] * $count_player / 10;
|
||||
$results[$key]['asp_team_riferimento_snt'] = $asp_team_riferimento;
|
||||
$results[$key]['asp_total_' . $bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_' . $bettype] = $value['asp_teorica_' . $bettype] * $asp_team_riferimento / $total_bettype;
|
||||
$results[$key]['asp_total_'.$bettype] = $total_bettype;
|
||||
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -614,8 +615,9 @@ class PlayerPropsDrop extends Widget
|
||||
$this->players[$k]['active'] = $result['active'];
|
||||
|
||||
$pos = $this->players[$k]['pos'];
|
||||
if (!$pos)
|
||||
if (! $pos) {
|
||||
$pos = $this->players[$k]['pos_ori'];
|
||||
}
|
||||
|
||||
$tamx = number_format($map[$pos]['gls'], 3);
|
||||
$final = number_format($result['asp_player_goals'], 3);
|
||||
@@ -672,4 +674,99 @@ class PlayerPropsDrop extends Widget
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user