Expectations finale

This commit is contained in:
salam committed 2026-09-17 20:03:06 +02:00
1 parent 2c641b5507
commit bbd6251020
3 files changed
+267 -74

No files matched your search

+16 -5
View File
@@ -119,7 +119,11 @@ class PlayerProps extends Page implements HasForms
})
->afterStateUpdated(function (callable $set, $state) {
$set('tid', null);
$this->dispatch('match-update', match_id: $state);
if ($state) {
$this->dispatch('match-update', match_id: $state);
} else {
$this->dispatch('clear-all');
}
})
->placeholder('Events'),
@@ -142,7 +146,9 @@ class PlayerProps extends Page implements HasForms
}
})
->placeholder('Team')->afterStateUpdated(function ($state) {
$this->dispatch('team-update', team_id: $state);
if ($state) {
$this->dispatch('team-update', team_id: $state);
}
}),
Select::make('lineup')
->live()
@@ -175,10 +181,15 @@ class PlayerProps extends Page implements HasForms
}
#[On('team-update')]
public function syncData(int $team_id)
public function syncData(?int $team_id)
{
$this->team_id = $team_id;
$this->clientLineUps = SsLineupMemory::where('team_id', $team_id)->where('client_id', Auth::user()->client_id)->pluck('lineup')->toArray();
if ($team_id) {
$this->team_id = $team_id;
$this->clientLineUps = SsLineupMemory::where('team_id', $team_id)->where('client_id', Auth::user()->client_id)->pluck('lineup')->toArray();
} else {
$this->players = [];
$this->dispatch('clear-all');
}
}
#[On('update-players')]
+222 -50
View File
@@ -2,74 +2,246 @@
namespace App\Filament\Widgets\PlayerProps;
use App\Models\StatistikoConfig;
use App\Models\StatisticFixtures;
use App\Models\StatistikoEvent;
class Expectations
{
public static function load(int $team_id, int $count_player)
public static function load(StatisticFixtures $match)
{
$bettypes = ['gls', 'fls', 'ofs', 'crd', 'snt', 'tsh'];
$data = StatistikoEvent::where(function ($query) use ($team_id) {
return $query->orWhere('home_id', $team_id)
->orWhere('away_id', '=', $team_id);
$home_id = $match->home_id;
$away_id = $match->away_id;
$data = StatistikoEvent::where(function ($query) use ($home_id, $away_id) {
return $query->whereIn('home_id', [$home_id, $away_id])->orWhereIn('away_id', [$home_id, $away_id]);
})->get();
$count_events = $data->count();
$count_events = ! $count_events ? 1 : $count_events;
$config = StatistikoConfig::pluck('value', 'varname')->toArray();
$work = [];
foreach ($config as $key => $value) {
$work[$key] = 0;
}
$bettypes = ['gls', 'fls', 'crn', 'ofs', 'crd', 'snt', 'tsh'];
foreach ($data as $value) {
foreach ($bettypes as $type) {
if ($value['home_id'] == $team_id) {
$work[$type.'_home_made_total'] += $value[$type.'_h'];
// $work[$type.'_home_made_home'] += $value[$type.'_h'];
$work[$type.'_home_got_total'] += $value[$type.'_a'];
// $work[$type.'_home_got_home'] += $value[$type.'_a'];
} elseif ($value['away_id'] == $team_id) {
$work[$type.'_away_made_total'] += $value[$type.'_a'];
// $work[$type.'_away_made_home'] += $value[$type.'_a'];
$work[$type.'_away_got_total'] += $value[$type.'_h'];
// $work[$type.'_away_got_home'] += $value[$type.'_h'];
if ($value['home_id'] == $home_id) {
$work[$type]['home_made_total'][] = $value[$type.'_h'];
$work[$type]['home_made_home'][] = $value[$type.'_h'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
$work[$type]['home_got_home'][] = $value[$type.'_a'];
} elseif ($value['away_id'] == $home_id) {
$work[$type]['home_made_total'][] = $value[$type.'_a'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
} elseif ($value['home_id'] == $away_id) {
$work[$type]['home_made_total'][] = $value[$type.'_a'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
} elseif ($value['away_id'] == $away_id) {
$work[$type]['home_made_total'][] = $value[$type.'_h'];
$work[$type]['home_made_home'][] = $value[$type.'_h'];
$work[$type]['home_got_total'][] = $value[$type.'_a'];
$work[$type]['home_got_home'][] = $value[$type.'_h'];
}
if ($value['away_id'] == $away_id) {
$work[$type]['away_made_total'][] = $value[$type.'_a'];
$work[$type]['away_made_away'][] = $value[$type.'_a'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
$work[$type]['away_got_away'][] = $value[$type.'_a'];
} elseif ($value['away_id'] == $home_id) {
$work[$type]['away_made_total'][] = $value[$type.'_h'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
} elseif ($value['home_id'] == $away_id) {
$work[$type]['away_made_total'][] = $value[$type.'_h'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
} elseif ($value['away_id'] == $away_id) {
$work[$type]['away_made_total'][] = $value[$type.'_a'];
$work[$type]['away_made_away'][] = $value[$type.'_a'];
$work[$type]['away_got_total'][] = $value[$type.'_h'];
$work[$type]['away_got_away'][] = $value[$type.'_a'];
}
}
}
$config = StatistikoConfig::pluck('value', 'varname')->toArray();
foreach ($config as $key => $value) {
$work[$key] = $work[$key] * $value;
$num_home_crd = 0;
$num_away_crd = 0;
$num_home_gls = 0;
$num_away_gls = 0;
$num_home_fls = 0;
$num_away_fls = 0;
$num_home_ofs = 0;
$num_away_ofs = 0;
$num_home_snt = 0;
$num_away_snt = 0;
$num_home_tsh = 0;
$num_away_tsh = 0;
$bettypes = ['gls', 'crd', 'fls', 'ofs', 'snt', 'tsh'];
foreach ($work as $type => $value) {
switch ($type) {
case 'gls':
$sum_home_gls = array_sum($value['home_made_total']);
$num_home_gls = \count($value['home_made_total']);
$sum_home_gls += array_sum($value['home_made_home']);
$num_home_gls += \count($value['home_made_home']);
$sum_home_gls += array_sum($value['home_got_total']);
$num_home_gls += \count($value['home_got_total']);
$sum_home_gls += array_sum($value['home_got_home']);
$num_home_gls += \count($value['home_got_home']);
$sum_away_gls = array_sum($value['away_made_total']);
$num_away_gls = \count($value['away_made_total']);
$sum_away_gls += array_sum($value['away_made_away']);
$num_away_gls += \count($value['away_made_away']);
$sum_away_gls += array_sum($value['away_got_total']);
$num_away_gls += \count($value['away_got_total']);
$sum_away_gls += array_sum($value['away_got_away']);
$num_away_gls += \count($value['away_got_away']);
break;
case 'crd':
$sum_home_crd = array_sum($value['home_made_total']);
$num_home_crd = \count($value['home_made_total']);
$sum_home_crd += array_sum($value['home_made_home']);
$num_home_crd += \count($value['home_made_home']);
$sum_home_crd += array_sum($value['home_got_total']);
$num_home_crd += \count($value['home_got_total']);
$sum_home_crd += array_sum($value['home_got_home']);
$num_home_crd += \count($value['home_got_home']);
$sum_away_crd = array_sum($value['away_made_total']);
$num_away_crd = \count($value['away_made_total']);
$sum_away_crd += array_sum($value['away_made_away']);
$num_away_crd += \count($value['away_made_away']);
$sum_away_crd += array_sum($value['away_got_total']);
$num_away_crd += \count($value['away_got_total']);
$sum_away_crd += array_sum($value['away_got_away']);
$num_away_crd += \count($value['away_got_away']);
break;
case 'fls':
$sum_home_fls = array_sum($value['home_made_total']);
$num_home_fls = \count($value['home_made_total']);
$sum_home_fls += array_sum($value['home_made_home']);
$num_home_fls += \count($value['home_made_home']);
$sum_home_fls += array_sum($value['home_got_total']);
$num_home_fls += \count($value['home_got_total']);
$sum_home_fls += array_sum($value['home_got_home']);
$num_home_fls += \count($value['home_got_home']);
$sum_away_fls = array_sum($value['away_made_total']);
$num_away_fls = \count($value['away_made_total']);
$sum_away_fls += array_sum($value['away_made_away']);
$num_away_fls += \count($value['away_made_away']);
$sum_away_fls += array_sum($value['away_got_total']);
$num_away_fls += \count($value['away_got_total']);
$sum_away_fls += array_sum($value['away_got_away']);
$num_away_fls += \count($value['away_got_away']);
break;
case 'ofs':
$sum_home_ofs = array_sum($value['home_made_total']);
$num_home_ofs = \count($value['home_made_total']);
$sum_home_ofs += array_sum($value['home_made_home']);
$num_home_ofs += \count($value['home_made_home']);
$sum_home_ofs += array_sum($value['home_got_total']);
$num_home_ofs += \count($value['home_got_total']);
$sum_home_ofs += array_sum($value['home_got_home']);
$num_home_ofs += \count($value['home_got_home']);
$sum_away_ofs = array_sum($value['away_made_total']);
$num_away_ofs = \count($value['away_made_total']);
$sum_away_ofs += array_sum($value['away_made_away']);
$num_away_ofs += \count($value['away_made_away']);
$sum_away_ofs += array_sum($value['away_got_total']);
$num_away_ofs += \count($value['away_got_total']);
$sum_away_ofs += array_sum($value['away_got_away']);
$num_away_ofs += \count($value['away_got_away']);
break;
case 'snt':
$sum_home_snt = array_sum($value['home_made_total']);
$num_home_snt = \count($value['home_made_total']);
$sum_home_snt += array_sum($value['home_made_home']);
$num_home_snt += \count($value['home_made_home']);
$sum_home_snt += array_sum($value['home_got_total']);
$num_home_snt += \count($value['home_got_total']);
$sum_home_snt += array_sum($value['home_got_home']);
$num_home_snt += \count($value['home_got_home']);
$sum_away_snt = array_sum($value['away_made_total']);
$num_away_snt = \count($value['away_made_total']);
$sum_away_snt += array_sum($value['away_made_away']);
$num_away_snt += \count($value['away_made_away']);
$sum_away_snt += array_sum($value['away_got_total']);
$num_away_snt += \count($value['away_got_total']);
$sum_away_snt += array_sum($value['away_got_away']);
$num_away_snt += \count($value['away_got_away']);
break;
case 'tsh':
$sum_home_tsh = array_sum($value['home_made_total']);
$num_home_tsh = \count($value['home_made_total']);
$sum_home_tsh += array_sum($value['home_made_home']);
$num_home_tsh += \count($value['home_made_home']);
$sum_home_tsh += array_sum($value['home_got_total']);
$num_home_tsh += \count($value['home_got_total']);
$sum_home_tsh += array_sum($value['home_got_home']);
$num_home_tsh += \count($value['home_got_home']);
$sum_away_tsh = array_sum($value['away_made_total']);
$num_away_tsh = \count($value['away_made_total']);
$sum_away_tsh += array_sum($value['away_made_away']);
$num_away_tsh += \count($value['away_made_away']);
$sum_away_tsh += array_sum($value['away_got_total']);
$num_away_tsh += \count($value['away_got_total']);
$sum_away_tsh += array_sum($value['away_got_away']);
$num_away_tsh += \count($value['away_got_away']);
break;
}
}
$aspettativa = [];
foreach ($work as $key => $value) {
if ($value) {
$aspettativa[$key] = round($value /= $count_events, 1);
}
}
$aspettativa['home']['gls'] = round($sum_home_gls / $num_home_gls, 1);
$aspettativa['home']['crd'] = round($sum_home_crd / $num_home_crd, 1);
$aspettativa['home']['fls'] = round($sum_home_fls / $num_home_fls, 1);
$aspettativa['home']['ofs'] = round($sum_home_ofs / $num_home_ofs, 1);
$aspettativa['home']['snt'] = round($sum_home_snt / $num_home_snt, 1);
$aspettativa['home']['tsh'] = round($sum_home_tsh / $num_home_tsh, 1);
$finals = [];
foreach ($bettypes as $type) {
$finals[$type]['home'] = 0;
$finals[$type]['away'] = 0;
}
foreach ($aspettativa as $key => $value) {
foreach ($bettypes as $type) {
if (strpos($key, $type) !== false) {
if (strpos($key, 'home') !== false) {
$finals[$type]['home'] += $value;
}
if (strpos($key, 'away') !== false) {
$finals[$type]['away'] += $value;
}
}
}
}
$aspettativa['away']['gls'] = round($sum_away_gls / $sum_away_gls, 1);
$aspettativa['away']['crd'] = round($sum_away_crd / $num_away_crd, 1);
$aspettativa['away']['fls'] = round($sum_away_fls / $num_away_fls, 1);
$aspettativa['away']['ofs'] = round($sum_away_ofs / $num_away_ofs, 1);
$aspettativa['away']['snt'] = round($sum_away_snt / $num_away_snt, 1);
$aspettativa['away']['tsh'] = round($sum_away_tsh / $num_away_tsh, 1);
return $finals;
return $aspettativa;
}
}
+29 -19
View File
@@ -86,22 +86,32 @@ class PlayerPropsDrop extends Widget
#[On('match-update')]
public function matchUpdate(?int $match_id)
{
$this->clearResultTable();
$this->team_name = '';
$this->match_id = 0;
$this->players = [];
for ($i = 1; $i <= 35; $i++) {
$this->boxes[$i] = [];
}
if ($match_id) {
$this->match_id = $match_id;
} else {
$this->team_name = '';
}
$this->dispatch('update-players', players: $this->players);
}
#[On('team-update')]
public function syncData(int $team_id)
public function syncData(?int $team_id)
{
$this->players = PlayerCalculator::load($team_id);
$this->team_name = SofaScoreRosa::where('ss_team_id', $team_id)->value('ss_team_name');
$this->team_id = $team_id;
$this->loadPlacement();
if ($team_id) {
$this->players = PlayerCalculator::load($team_id);
$this->team_name = SofaScoreRosa::where('ss_team_id', $team_id)->value('ss_team_name');
$this->team_id = $team_id;
$this->loadPlacement();
} else {
$this->team_name = '';
$this->clearResultTable();
$this->players = [];
}
}
#[On('lineup-update')]
@@ -365,14 +375,14 @@ class PlayerPropsDrop extends Widget
// (il valore che appare quando viene selezionato un Evento): nell' esempio,
// se scegliamo come Team il Remo (Home) il valore di riferimento sarà 1.2
$team_id = $this->team_id;
$res = StatisticFixtures::where('id', $this->match_id)->first();
$match = StatisticFixtures::where('id', $this->match_id)->first();
$asp_team = 0;
$team_home_away = 'home';
if ((int) $res->home_id == (int) $team_id) {
$asp_team = (float) $res->exp_home;
if ((int) $match->home_id == (int) $team_id) {
$asp_team = (float) $match->exp_home;
$team_home_away = 'home';
} elseif ((int) $res->away_id == (int) $team_id) {
$asp_team = (float) $res->exp_away;
} elseif ((int) $match->away_id == (int) $team_id) {
$asp_team = (float) $match->exp_away;
$team_home_away = 'away';
}
@@ -512,7 +522,7 @@ class PlayerPropsDrop extends Widget
}
}
$asp_team_all = Expectations::load($team_id, $count_player);
$asp_team_all = Expectations::load($match);
// Aspettativa Team di Riferimento
// (ATR) = Aspettativa Team * Numero di Giocatori di Team in Rosters (esclusi i portieri) / 10.
@@ -536,31 +546,31 @@ class PlayerPropsDrop extends Widget
$results[$key]['asp_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
break;
case 'cards':
$asp_team_riferimento = (float) $asp_team_all['crd'][$team_home_away] * $count_player / 10;
$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_player_'.$bettype] = $value['asp_teorica_'.$bettype] * $asp_team_riferimento / $total_bettype;
$results[$key]['asp_total_'.$bettype] = $total_bettype;
break;
case 'fouls':
$asp_team_riferimento = (float) $asp_team_all['fls'][$team_home_away] * $count_player / 10;
$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;
break;
case 'offsides':
$asp_team_riferimento = (float) $asp_team_all['ofs'][$team_home_away] * $count_player / 10;
$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;
break;
case 'total_shots':
$asp_team_riferimento = (float) $asp_team_all['tsh'][$team_home_away] * $count_player / 10;
$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;
break;
case 'shots_on_target':
$asp_team_riferimento = (float) $asp_team_all['snt'][$team_home_away] * $count_player / 10;
$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;