This commit is contained in:
salam committed 2026-09-15 18:04:33 +02:00
1 parent b5054e6ae2
commit fa13ef40b0
2 files changed
+112 -791

No files matched your search

+112 -37
View File
@@ -8,6 +8,7 @@ use App\Models\SofaScorePlayerPosition;
use App\Models\SofaScoreRosa;
use App\Models\SsLineupMemory;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
use Filament\Notifications\Notification;
use Filament\Widgets\Widget;
use Illuminate\Support\Facades\Auth;
@@ -262,9 +263,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`)");
@@ -284,7 +285,7 @@ class PlayerPropsDrop extends Widget
return;
}
$header = ['name', 'foot', 'events', 'average min', 'position', 'on field', 'gls', 'fls', 'ofs', 'snt', 'tsh', 'crd'];
$copystring = implode(';', $header) . "\n";
$copystring = implode(';', $header)."\n";
foreach ($this->players as $row) {
$tmp = [];
$tmp[] = $row['name'];
@@ -304,7 +305,7 @@ class PlayerPropsDrop extends Widget
$tmp[] = $row['tsh'];
$tmp[] = $row['crd'];
$copystring .= implode(';', $tmp) . "\n";
$copystring .= implode(';', $tmp)."\n";
}
$this->js("navigator.clipboard.writeText(`$copystring`)");
@@ -357,6 +358,8 @@ class PlayerPropsDrop extends Widget
}
}
$asp_team_others = $this->loadOthers($count_player, $team_id);
// Aspettativa Team di Riferimento
// (ATR) = Aspettativa Team * Numero di Giocatori di Team in Rosters (esclusi i portieri) / 10.
// Ad esempio per Remo (supponiamo 24 giocatori nel Roster esclusi i portieri): ATR = 1.2 * 24 / 10 = 2.88
@@ -416,7 +419,6 @@ class PlayerPropsDrop extends Widget
// Somma Minuti Giocati da Player (SMG) nel DB
$tmp['somma_minuti'] = $val->total_min;
$tmp['shots_on_target'] = $val->shots_on_target;
$tmp['shots_off_target'] = $val->shots_off_target;
$tmp['shots_blocked'] = $val->shots_blocked;
@@ -435,68 +437,68 @@ 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;
switch ($bettype) {
case 'goals':
if ($val->total_min < $this->y_value || $val->goals == 0) {
$tmp['asp_gioco_' . $bettype] = $asp_statistica;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
$tmp['asp_gioco_'.$bettype] = $asp_statistica;
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
} else {
$asp_gioco = $val->goals / $val->total_min * 90;
$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':
if ($val->total_min < $this->y_value || $val->cards == 0) {
$tmp['asp_gioco_' . $bettype] = $asp_statistica;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
$tmp['asp_gioco_'.$bettype] = $asp_statistica;
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
} else {
$asp_gioco = $val->cards / $val->total_min * 90;
$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':
if ($val->total_min < $this->y_value || $val->fouls == 0) {
$tmp['asp_gioco_' . $bettype] = $asp_statistica;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
$tmp['asp_gioco_'.$bettype] = $asp_statistica;
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
} else {
$asp_gioco = $val->fouls / $val->total_min * 90;
$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':
if ($val->total_min < $this->y_value || $val->offsides == 0) {
$tmp['asp_gioco_' . $bettype] = $asp_statistica;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
$tmp['asp_gioco_'.$bettype] = $asp_statistica;
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
} else {
$asp_gioco = $val->offsides / $val->total_min * 90;
$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':
if ($val->total_min < $this->y_value || $val->total_shots == 0) {
$tmp['asp_gioco_' . $bettype] = $asp_statistica;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
$tmp['asp_gioco_'.$bettype] = $asp_statistica;
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
} else {
$asp_gioco = $val->total_shots / $val->total_min * 90;
$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':
if ($val->total_min < $this->y_value || $val->shots_on_target == 0) {
$tmp['asp_gioco_' . $bettype] = $asp_statistica;
$tmp['asp_teorica_' . $bettype] = $asp_statistica;
$tmp['asp_gioco_'.$bettype] = $asp_statistica;
$tmp['asp_teorica_'.$bettype] = $asp_statistica;
} else {
$asp_gioco = $val->shots_on_target / $val->total_min * 90;
$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;
}
@@ -510,17 +512,48 @@ class PlayerPropsDrop extends Widget
}
// Log::debug('results', $results);
// dd($asp_team_others);
// "asp_riferimento_goals" => 4.4
// "asp_riferimento_fouls" => 42.2
// "asp_riferimento_offside" => 2.0
// "asp_riferimento_card" => 8.8
// "asp_riferimento_snt" => 15.4
// "asp_riferimento_tsh" => 42.6
$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) {
// Aspettativa per Player: AP = AT * ATR / TOT AT
$results[$key]['asp_total_' . $bettype] = $total_bettype;
// $results[$key]['asp_player_'.$bettype] = ((float) $value['asp_team'] * (float) $value['asp_teorica_'.$bettype]) / $total_bettype;
// $results[$key]['asp_player_'.$bettype] = ($asp_team * $asp_team_riferimento) / $total_bettype;
$results[$key]['asp_player_' . $bettype] = ($value['asp_teorica_' . $bettype] * $asp_team_riferimento) / $total_bettype;
switch ($bettype) {
case 'goals':
// Aspettativa per Player: AP = AT * ATR / TOT AT
$results[$key]['asp_total_'.$bettype] = $total_bettype;
// $results[$key]['asp_player_'.$bettype] = ((float) $value['asp_team'] * (float) $value['asp_teorica_'.$bettype]) / $total_bettype;
// $results[$key]['asp_player_'.$bettype] = ($asp_team * $asp_team_riferimento) / $total_bettype;
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
break;
case 'cards':
$results[$key]['asp_total_'.$bettype] = $total_bettype;
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_others['asp_riferimento_card'] / $total_bettype;
break;
case 'fouls':
$results[$key]['asp_total_'.$bettype] = $total_bettype;
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_others['asp_riferimento_fouls'] / $total_bettype;
break;
case 'offsides':
$results[$key]['asp_total_'.$bettype] = $total_bettype;
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_others['asp_riferimento_offside'] / $total_bettype;
break;
case 'total_shots':
$results[$key]['asp_total_'.$bettype] = $total_bettype;
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_others['asp_riferimento_tsh'] / $total_bettype;
break;
case 'shots_on_target':
$results[$key]['asp_total_'.$bettype] = $total_bettype;
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_others['asp_riferimento_snt'] / $total_bettype;
break;
}
}
}
@@ -555,6 +588,48 @@ class PlayerPropsDrop extends Widget
return false;
}
public function loadOthers(int $count_player, int $team_id)
{
$arr = [];
$arr['goals'] = 0;
$arr['fouls'] = 0;
$arr['offside'] = 0;
$arr['card'] = 0;
$arr['snt'] = 0;
$arr['tsh'] = 0;
$res = StatistikoEvent::where(function ($query) use ($team_id) {
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
})->get();
$count_events = \count($res);
foreach ($res as $value) {
if ($value->home_id == $team_id) {
$arr['goals'] += $value->gls_h;
$arr['fouls'] += $value->fls_h;
$arr['offside'] += $value->ofs_h;
$arr['card'] += $value->crd_h;
$arr['snt'] += $value->snt_h;
$arr['tsh'] += $value->tsh_h;
} elseif ($value->away_id == $team_id) {
$arr['goals'] += $value->gls_a;
$arr['fouls'] += $value->fls_a;
$arr['offside'] += $value->ofs_a;
$arr['card'] += $value->crd_a;
$arr['snt'] += $value->snt_a;
$arr['tsh'] += $value->tsh_a;
}
}
foreach ($arr as $name => $value) {
$arr['asp_riferimento_'.$name] = (float) round($value / $count_events * $count_player / 10, 1);
}
return $arr;
}
private function boxNames(): array
{
return [2 => 'DR', 4 => 'MR', 6 => 'LW', 9 => 'DC', 10 => 'DM', 11 => 'MC', 12 => 'AM', 15 => 'SW', 16 => 'DC', 17 => 'DM', 18 => 'MC', 19 => 'AM', 20 => 'SM', 21 => 'ST', 23 => 'DC', 24 => 'DM', 25 => 'MC', 26 => 'AM', 30 => 'DL', 32 => 'ML', 34 => 'RW'];