diff --git a/app/Filament/Imports/Helper/ImportDetails.php b/app/Filament/Imports/Helper/ImportDetails.php index 1e7dd088..eb594f51 100644 --- a/app/Filament/Imports/Helper/ImportDetails.php +++ b/app/Filament/Imports/Helper/ImportDetails.php @@ -11,42 +11,43 @@ class ImportDetails { public static function run(string $filePath): void { - $now = now()->format('Y-m-d H:i:s'); + StatistikoDetail::query()->update(['last_import' => 0]); SimpleExcelReader::create(storage_path('app/public/'.$filePath)) ->getRows() ->chunk(1000) - ->each(function (LazyCollection $chunk) use ($now) { + ->each(function (LazyCollection $chunk) { + $collection = []; foreach ($chunk as $row) { - - $row = array_values($row); - - if ($row[1] != '') { - StatistikoDetail::updateOrCreate( - [ - 'ss_player_id' => (int) $row[0], - ], - [ - 'ss_team_id' => (int) $row[1], - 'player_name' => $row[2], - 'ss_national_team_id' => (int) $row[3], - 'birthdate' => Carbon::parse($row[4])->format('Y-m-d'), - 'height' => (int) $row[5], - 'nationality' => $row[6], - 'position' => $row[7], - 'preferred_foot' => $row[8], - 'last_update' => Carbon::parse($row[9])->format('Y-m-d H:i:s'), - 'is_active' => 1, - 'created_at' => $now, - 'updated_at' => $now, - ] - ); - } + $row['is_active'] = 1; + $row['last_import'] = 1; + $row['birthdate'] = isset($row['birthday']) ? Carbon::parse($row['birthday'])->format('Y-m-d') : ''; + unset($row['birthday']); + $row['last_update'] = Carbon::parse($row['last_update'])->format('Y-m-d H:i:s'); + $collection[] = $row; } + + StatistikoDetail::upsert( + $collection, + uniqueBy: [ + 'ss_player_id', + ], + update: [ + 'ss_team_id', + 'player_name', + 'ss_national_team_id', + 'birthdate', + 'height', + 'nationality', + 'position', + 'preferred_foot', + 'last_update', + 'is_active', + 'last_import', + ]); }); - StatistikoDetail::where('updated_at', '!=', $now)->update(['is_active' => 0, 'ss_team_id' => 0]); - + StatistikoDetail::where('last_import', 0)->update(['is_active' => 0, 'ss_team_id' => 0]); } } diff --git a/app/Filament/Imports/Helper/ImportPlayer.php b/app/Filament/Imports/Helper/ImportPlayer.php index 32dbfb68..a9ec3916 100644 --- a/app/Filament/Imports/Helper/ImportPlayer.php +++ b/app/Filament/Imports/Helper/ImportPlayer.php @@ -111,6 +111,34 @@ class ImportPlayer $update_array ); } + + // $collection = []; + // foreach ($chunk as $row) { + // $update_array = []; + // foreach ($row as $name => $value) { + // switch ($name) { + // case 'SS_MATCH_ID': + // $update_array['match_id'] = (int) $value; + // break; + // case 'SS_PLAYER_ID': + // $update_array['ss_player_id'] = (int) $value; + // break; + // default: + // $name = strtolower($name); + // $update_array[$name] = $value; + // break; + // } + // } + // $collection[] = $update_array; + // } + + // StatistikoPlayer::upsert( + // $collection, + // uniqueBy: [ + // 'match_id', + // 'ss_player_id', + // ], + // update: $fieldnames); }); } } diff --git a/app/Filament/Widgets/PlayerPropsDrop.php b/app/Filament/Widgets/PlayerPropsDrop.php index 42f7034e..f9977c9f 100644 --- a/app/Filament/Widgets/PlayerPropsDrop.php +++ b/app/Filament/Widgets/PlayerPropsDrop.php @@ -506,11 +506,13 @@ 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)); + 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] = ($asp_team * $asp_team_riferimento) / $total_bettype; + $results[$key]['asp_player_'.$bettype] = ($value['asp_teorica_'.$bettype] * $asp_team_riferimento) / $total_bettype; } } diff --git a/app/Models/StatistikoDetail.php b/app/Models/StatistikoDetail.php index 3e7f4be9..bbba97a5 100644 --- a/app/Models/StatistikoDetail.php +++ b/app/Models/StatistikoDetail.php @@ -24,9 +24,8 @@ class StatistikoDetail extends Model 'position', 'preferred_foot', 'last_update', + 'last_import', 'is_active', - 'created_at', - 'updated_at', ]; protected $casts = [ diff --git a/composer.lock b/composer.lock index 9508264c..b8417439 100644 --- a/composer.lock +++ b/composer.lock @@ -4098,16 +4098,16 @@ }, { "name": "livewire/livewire", - "version": "v4.4.4", + "version": "v4.4.5", "source": { "type": "git", "url": "https://github.com/livewire/livewire.git", - "reference": "00bf1b9959807d7cbcf38fc088515a7261cb6fa8" + "reference": "10aa0b5ee44c99b5bce0f78ad265bbcf0e74abdc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/livewire/zipball/00bf1b9959807d7cbcf38fc088515a7261cb6fa8", - "reference": "00bf1b9959807d7cbcf38fc088515a7261cb6fa8", + "url": "https://api.github.com/repos/livewire/livewire/zipball/10aa0b5ee44c99b5bce0f78ad265bbcf0e74abdc", + "reference": "10aa0b5ee44c99b5bce0f78ad265bbcf0e74abdc", "shasum": "" }, "require": { @@ -4162,7 +4162,7 @@ "description": "A front-end framework for Laravel.", "support": { "issues": "https://github.com/livewire/livewire/issues", - "source": "https://github.com/livewire/livewire/tree/v4.4.4" + "source": "https://github.com/livewire/livewire/tree/v4.4.5" }, "funding": [ { @@ -4170,7 +4170,7 @@ "type": "github" } ], - "time": "2026-09-07T16:02:43+00:00" + "time": "2026-09-14T19:27:16+00:00" }, { "name": "maennchen/zipstream-php",