diff --git a/app/Filament/Widgets/PlayerPropsDrop.php b/app/Filament/Widgets/PlayerPropsDrop.php index ef5654ba..2980e772 100644 --- a/app/Filament/Widgets/PlayerPropsDrop.php +++ b/app/Filament/Widgets/PlayerPropsDrop.php @@ -6,6 +6,7 @@ use App\Filament\Widgets\PlayerProps\BoxNames; use App\Filament\Widgets\PlayerProps\Expectations; use App\Filament\Widgets\PlayerProps\LineUpMap; use App\Livewire\PlayerCalculator; +use App\Models\ExpectedMinimumPosition; use App\Models\SofaScorePlayerPerSeason; use App\Models\SofaScorePlayerPosition; use App\Models\SofaScoreRosa; @@ -296,9 +297,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`)"); @@ -318,7 +319,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']; @@ -338,7 +339,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`)"); @@ -453,8 +454,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); @@ -469,61 +470,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; } @@ -545,7 +546,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) { @@ -556,38 +557,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; } } @@ -599,12 +600,48 @@ class PlayerPropsDrop extends Widget foreach ($results as $key => $result) { if ((int) $player['id'] == (int) $result['id']) { $this->players[$k]['active'] = $result['active']; - $this->players[$k]['gls'] = number_format($result['asp_player_goals'], 3); - $this->players[$k]['fls'] = number_format($result['asp_player_fouls'], 3); - $this->players[$k]['ofs'] = number_format($result['asp_player_offsides'], 3); - $this->players[$k]['snt'] = number_format($result['asp_player_total_shots'], 3); - $this->players[$k]['tsh'] = number_format($result['asp_player_shots_on_target'], 3); - $this->players[$k]['crd'] = number_format($result['asp_player_cards'], 3); + + $min = ExpectedMinimumPosition::where('position', $this->players[$k]['pos'])->where('gls', '>', $result['asp_player_goals'])->first(); + if ($min) { + $this->players[$k]['gls'] = number_format($min->gls, 3); + } else { + $this->players[$k]['gls'] = number_format($result['asp_player_goals'], 3); + } + + $min = ExpectedMinimumPosition::where('position', $this->players[$k]['pos'])->where('fls', '>', $result['asp_player_fouls'])->first(); + if ($min) { + $this->players[$k]['fls'] = number_format($min->fls, 3); + } else { + $this->players[$k]['fls'] = number_format($result['asp_player_fouls'], 3); + } + + $min = ExpectedMinimumPosition::where('position', $this->players[$k]['pos'])->where('ofs', '>', $result['asp_player_offsides'])->first(); + if ($min) { + $this->players[$k]['ofs'] = number_format($min->fls, 3); + } else { + $this->players[$k]['ofs'] = number_format($result['asp_player_offsides'], 3); + } + + $min = ExpectedMinimumPosition::where('position', $this->players[$k]['pos'])->where('snt', '>', $result['asp_player_shots_on_target'])->first(); + if ($min) { + $this->players[$k]['snt'] = number_format($min->fls, 3); + } else { + $this->players[$k]['snt'] = number_format($result['asp_player_total_shots'], 3); + } + + $min = ExpectedMinimumPosition::where('position', $this->players[$k]['pos'])->where('tsh', '>', $result['asp_player_total_shots'])->first(); + if ($min) { + $this->players[$k]['tsh'] = number_format($min->fls, 3); + } else { + $this->players[$k]['tsh'] = number_format($result['asp_player_shots_on_target'], 3); + } + + $min = ExpectedMinimumPosition::where('position', $this->players[$k]['pos'])->where('crd', '>', $result['asp_player_cards'])->first(); + if ($min) { + $this->players[$k]['crd'] = number_format($min->fls, 3); + } else { + $this->players[$k]['crd'] = number_format($result['asp_player_cards'], 3); + } } } } diff --git a/app/Models/ExpectiveApproach.php b/app/Models/ExpectedMinimumPosition.php similarity index 60% rename from app/Models/ExpectiveApproach.php rename to app/Models/ExpectedMinimumPosition.php index 3007e432..93b4daf3 100644 --- a/app/Models/ExpectiveApproach.php +++ b/app/Models/ExpectedMinimumPosition.php @@ -4,4 +4,4 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; -class ExpectiveApproach extends Model {} +class ExpectedMinimumPosition extends Model {} diff --git a/database/migrations/2026_09_17_093035_create_expective_approaches_table.php b/database/migrations/2026_09_17_093035_create_expective_approaches_table.php deleted file mode 100644 index 4b9f7320..00000000 --- a/database/migrations/2026_09_17_093035_create_expective_approaches_table.php +++ /dev/null @@ -1,36 +0,0 @@ -id(); - $table->string('position'); - $table->decimal('goals', 4, 3)->default(0); - $table->decimal('assists', 4, 3)->default(0); - $table->decimal('cards', 4, 3)->default(0); - $table->decimal('fouls', 4, 3)->default(0); - $table->decimal('was_fould', 4, 3)->default(0); - $table->decimal('offsides', 4, 3)->default(0); - $table->decimal('total_shots', 4, 3)->default(0); - $table->decimal('shots_on_target', 4, 3)->default(0); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('expective_approaches'); - } -}; diff --git a/database/migrations/2026_09_18_173601_create_expected_minimum_positions_table.php b/database/migrations/2026_09_18_173601_create_expected_minimum_positions_table.php new file mode 100644 index 00000000..8027aae5 --- /dev/null +++ b/database/migrations/2026_09_18_173601_create_expected_minimum_positions_table.php @@ -0,0 +1,35 @@ +id(); + $table->string('position'); + $table->decimal('gls', 4, 3)->default(0); + $table->decimal('crd', 4, 3)->default(0); + $table->decimal('fls', 4, 3)->default(0); + $table->decimal('ofs', 4, 3)->default(0); + $table->decimal('tsh', 4, 3)->default(0); + $table->decimal('snt', 4, 3)->default(0); + $table->decimal('wlf', 4, 3)->default(0); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('expected_minimum_positions'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index b90c8cd6..8b6630e1 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -27,7 +27,8 @@ class DatabaseSeeder extends Seeder AlarmLevelSeeder::class, OddsNameSeeder::class, AddByMethodSeeder::class, - StatistikoConfigSeeder::class + StatistikoConfigSeeder::class, + ExpectedMinimumPositionSeeder::class, ]); } } diff --git a/database/seeders/ExpectedMinimumPositionSeeder.php b/database/seeders/ExpectedMinimumPositionSeeder.php new file mode 100644 index 00000000..98bfcb05 --- /dev/null +++ b/database/seeders/ExpectedMinimumPositionSeeder.php @@ -0,0 +1,34 @@ +