diff --git a/app/Filament/Clusters/StaticData/Resources/Players/Pages/CreatePlayer.php b/app/Filament/Clusters/StaticData/Resources/Players/Pages/CreatePlayer.php deleted file mode 100644 index 06e4802f..00000000 --- a/app/Filament/Clusters/StaticData/Resources/Players/Pages/CreatePlayer.php +++ /dev/null @@ -1,11 +0,0 @@ -label('New') - ->icon('phosphor-plus'), - ImportAction::make('importPlayer') - ->icon('phosphor-upload') - ->label('Import') - ->modalDescription('Separator comma ",", First line: "name,tm_player_id"') - ->importer(PlayerImporter::class), - ]; - } -} diff --git a/app/Filament/Clusters/StaticData/Resources/Players/PlayerResource.php b/app/Filament/Clusters/StaticData/Resources/Players/PlayerResource.php deleted file mode 100644 index f69cf98c..00000000 --- a/app/Filament/Clusters/StaticData/Resources/Players/PlayerResource.php +++ /dev/null @@ -1,46 +0,0 @@ - ListPlayers::route('/'), - ]; - } - - public static function getNavigationBadge(): ?string - { - return parent::getEloquentQuery()->count(); - } -} diff --git a/app/Filament/Clusters/StaticData/Resources/Players/Schemas/PlayerForm.php b/app/Filament/Clusters/StaticData/Resources/Players/Schemas/PlayerForm.php deleted file mode 100644 index 3d80169c..00000000 --- a/app/Filament/Clusters/StaticData/Resources/Players/Schemas/PlayerForm.php +++ /dev/null @@ -1,19 +0,0 @@ -components([ - TextInput::make('name'), - TextInput::make('tm_player_id')->afterLabel(['Must be unique']), - TextInput::make('ss_player_id')->afterLabel(['Must be unique']), - ]); - } -} diff --git a/app/Filament/Clusters/StaticData/Resources/Players/Tables/PlayersTable.php b/app/Filament/Clusters/StaticData/Resources/Players/Tables/PlayersTable.php deleted file mode 100644 index 914affaa..00000000 --- a/app/Filament/Clusters/StaticData/Resources/Players/Tables/PlayersTable.php +++ /dev/null @@ -1,35 +0,0 @@ -striped() - ->columns([ - Stack::make([ - TextColumn::make('name') - ->searchable(), - TextColumn::make('tm_player_id') - ->badge() - ->searchable(), - ]), - ]) - ->contentGrid([ - 'md' => 3, - 'xl' => 5, - ]) - ->recordActions([ - EditAction::make()->hiddenLabel(), - DeleteAction::make()->hiddenLabel(), - ]); - } -} diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Schemas/StatistikoImportForm.php b/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Schemas/StatistikoImportForm.php index bcc16499..c8533796 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Schemas/StatistikoImportForm.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Schemas/StatistikoImportForm.php @@ -17,10 +17,10 @@ class StatistikoImportForm ->required() ->allowHtml() ->options([ - 'details' => 'Details', - 'events' => 'Events', - 'fixtures' => 'Fixtures', - 'player' => 'Player', + 'details' => 'Player Details', + 'player' => 'Player History', + 'fixtures' => 'Fixtures Upcoming', + 'events' => 'Events History', ]), FileUpload::make('file_name') diff --git a/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Tables/StatistikoImportsTable.php b/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Tables/StatistikoImportsTable.php index 7721f813..036d4533 100644 --- a/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Tables/StatistikoImportsTable.php +++ b/app/Filament/Clusters/StaticData/Resources/StatistikoImports/Tables/StatistikoImportsTable.php @@ -25,13 +25,12 @@ class StatistikoImportsTable ->columns([ SelectColumn::make('data_type') ->native(false) - ->width('2rem') ->allowOptionsHtml() ->options([ - 'details' => 'Details', - 'events' => 'Events', - 'fixtures' => 'Fixtures', - 'player' => 'Player', + 'details' => 'Player Details', + 'player' => 'Player History', + 'fixtures' => 'Fixtures Upcoming', + 'events' => 'Events History', ]), TextColumn::make('file_name_original') ->searchable() @@ -58,15 +57,28 @@ class StatistikoImportsTable ->deferFilters(false) ->recordActions([ ActionGroup::make([ - Action::make('Import') - ->label('Import to DB') + Action::make('import') + ->label('Import') + ->color('success') + ->tooltip('Import is much faster but does no check for doubles') ->icon('phosphor-database') - ->action(fn ($record) => StatistikoImporter::run($record)) + ->action(fn ($record) => StatistikoImporter::run($record, 'import')) ->successNotification( Notification::make() ->info() ->title('Import started') ), + Action::make('update') + ->label('Update') + ->color('info') + ->tooltip('Compares ervery row in database and takes time') + ->icon('phosphor-database') + ->action(fn ($record) => StatistikoImporter::run($record, 'update')) + ->successNotification( + Notification::make() + ->info() + ->title('Update started') + ), DeleteAction::make() ->successNotificationTitle('File deleted') ->label('Delete file'), diff --git a/app/Filament/Imports/Helper/ImportBenchmark.php b/app/Filament/Imports/Helper/ImportBenchmark.php index 3bd2eb4f..bab1e59c 100644 --- a/app/Filament/Imports/Helper/ImportBenchmark.php +++ b/app/Filament/Imports/Helper/ImportBenchmark.php @@ -3,6 +3,7 @@ namespace App\Filament\Imports\Helper; use Filament\Notifications\Notification; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\HtmlString; @@ -46,7 +47,7 @@ class ImportBenchmark $str .= '
SQL: '.number_format($queriesCount); $str .= '
ROWS: '.number_format($rowDiff); - $recipient = auth()->user(); + $recipient = Auth::user(); Notification::make() ->success() diff --git a/app/Filament/Imports/Helper/ImportDetails.php b/app/Filament/Imports/Helper/ImportDetails.php index 6fd760b4..721da70b 100644 --- a/app/Filament/Imports/Helper/ImportDetails.php +++ b/app/Filament/Imports/Helper/ImportDetails.php @@ -9,22 +9,47 @@ use Spatie\SimpleExcel\SimpleExcelReader; class ImportDetails { - public static function run(string $filePath): void + public static function run(string $filePath, string $importmode): void { $now = now()->format('Y-m-d H:i:s'); SimpleExcelReader::create(storage_path('app/public/'.$filePath)) ->getRows() ->chunk(1000) - ->each(function (LazyCollection $chunk) use ($now) { + ->each(function (LazyCollection $chunk) use ($now, $importmode) { foreach ($chunk as $row) { $row = array_values($row); - StatistikoDetail::where('tm_player_id', $row[0]) - ->update( + if ($importmode == 'update') { + StatistikoDetail::where('tm_player_id', $row[0]) + ->update( + [ + 'name' => $row[1], + 'birthdate' => Carbon::parse($row[2])->toDateString(), + 'height' => $row[3], + 'nationality' => $row[4], + 'position' => $row[5], + 'sport_radar_id' => $row[6], + 'id_squadra_tm' => $row[7], + 'full_name' => $row[8], + 'no_specialities' => $row[9], + 'txodds_id' => $row[10], + 'national_team_id' => $row[11], + 'last_update' => Carbon::parse($row[12])->toDateString(), + 'league_code' => $row[13], + 'team_code' => $row[14], + 'team_name' => $row[15], + 'created_at' => $now, + 'updated_at' => $now, + ], + ['upsert' => true], + ); + } else { + StatistikoDetail::insert( [ + 'tm_player_id', $row[0], 'name' => $row[1], 'birthdate' => Carbon::parse($row[2])->toDateString(), 'height' => $row[3], @@ -42,10 +67,9 @@ class ImportDetails 'team_name' => $row[15], 'created_at' => $now, 'updated_at' => $now, - ], - ['upsert' => true], + ] ); - + } } }); } diff --git a/app/Filament/Imports/Helper/ImportEvents.php b/app/Filament/Imports/Helper/ImportEvents.php index f168bab4..79a4194e 100644 --- a/app/Filament/Imports/Helper/ImportEvents.php +++ b/app/Filament/Imports/Helper/ImportEvents.php @@ -9,37 +9,71 @@ use Spatie\SimpleExcel\SimpleExcelReader; class ImportEvents { - public static function run(string $filePath): void + public static function run(string $filePath, string $importmode): void { $now = now()->format('Y-m-d H:i:s'); SimpleExcelReader::create(storage_path('app/public/'.$filePath)) ->getRows() ->chunk(1000) - ->each(function (LazyCollection $chunk) use ($now) { + ->each(function (LazyCollection $chunk) use ($now, $importmode) { foreach ($chunk as $row) { $row = array_values($row); - dd($row); + if ($importmode == 'update') { - /* - 0 => 14082828 - 1 => 1 - 2 => 12 - 3 => 1661 - 4 => 4781 - */ + /* + 0 => 14082828 + 1 => 1 + 2 => 12 + 3 => 1661 + 4 => 4781 + */ - StatistikoEvent::where('match_id', $row[0]) - ->where('sport_id', $row[1]) - ->where('league_id', $row[2]) - ->where('home_id', $row[3]) - ->where('away_id', $row[4]) - ->where('starttime', Carbon::parse($row[5])->toIso8601String()) - ->update( + StatistikoEvent::where('match_id', $row[0]) + ->where('sport_id', $row[1]) + ->where('league_id', $row[2]) + ->where('home_id', $row[3]) + ->where('away_id', $row[4]) + ->where('starttime', Carbon::parse($row[5])->toIso8601String()) + ->update( + [ + 'season' => $row[6], + 'gls_h' => $row[7], + 'gls_a' => $row[8], + 'crn_h' => $row[9], + 'crn_a' => $row[10], + 'fls_h' => $row[11], + 'fls_a' => $row[12], + 'ofs_h' => $row[13], + 'ofs_a' => $row[14], + 'snt_h' => $row[15], + 'snt_a' => $row[16], + 'tsh_h' => $row[17], + 'tsh_a' => $row[18], + 'crd_h' => $row[19], + 'crd_a' => $row[20], + 'exp_home' => $row[21], + 'exp_away' => $row[22], + 'exp_handicap' => $row[23], + 'exp_total' => $row[24], + 'result_code' => $row[25], // w, d, l + 'created_at' => $now, + 'updated_at' => $now, + ], + ['upsert' => true], + ); + } else { + StatistikoEvent::import( [ + 'match_id', $row[0], + 'sport_id', $row[1], + 'league_id', $row[2], + 'home_id', $row[3], + 'away_id', $row[4], + 'starttime', Carbon::parse($row[5])->toIso8601String(), 'season' => $row[6], 'gls_h' => $row[7], 'gls_a' => $row[8], @@ -62,9 +96,9 @@ class ImportEvents 'result_code' => $row[25], // w, d, l 'created_at' => $now, 'updated_at' => $now, - ], - ['upsert' => true], + ] ); + } } }); } diff --git a/app/Filament/Imports/Helper/ImportFixtures.php b/app/Filament/Imports/Helper/ImportFixtures.php index 0ac65e9c..2f4d211d 100644 --- a/app/Filament/Imports/Helper/ImportFixtures.php +++ b/app/Filament/Imports/Helper/ImportFixtures.php @@ -9,12 +9,12 @@ use Spatie\SimpleExcel\SimpleExcelReader; class ImportFixtures { - public static function run(string $filePath): void + public static function run(string $filePath, string $importmode): void { SimpleExcelReader::create(storage_path('app/public/'.$filePath)) ->getRows() ->chunk(200) - ->each(function (LazyCollection $chunk) { + ->each(function (LazyCollection $chunk) use ($importmode) { foreach ($chunk as $row) { @@ -30,16 +30,30 @@ class ImportFixtures 6 => 1.035168989838 */ - StatisticFixtures::updateOrCreate( - [ - 'sport_id' => (int) $row[0], - 'league_id' => (int) $row[1], - 'home_id' => (int) $row[2], - 'away_id' => (int) $row[3], - 'starttime' => Carbon::parse($row[4])->toDateTimeString(), - ], - ['exp_home' => (float) $row[5], 'exp_away' => (float) $row[6]] - ); + if ($importmode == 'update') { + StatisticFixtures::updateOrCreate( + [ + 'sport_id' => (int) $row[0], + 'league_id' => (int) $row[1], + 'home_id' => (int) $row[2], + 'away_id' => (int) $row[3], + 'starttime' => Carbon::parse($row[4])->toDateTimeString(), + ], + ['exp_home' => (float) $row[5], 'exp_away' => (float) $row[6]] + ); + } else { + StatisticFixtures::insert( + [ + 'sport_id' => (int) $row[0], + 'league_id' => (int) $row[1], + 'home_id' => (int) $row[2], + 'away_id' => (int) $row[3], + 'starttime' => Carbon::parse($row[4])->toDateTimeString(), + 'exp_home' => (float) $row[5], + 'exp_away' => (float) $row[6], + ] + ); + } } }); } diff --git a/app/Filament/Imports/Helper/ImportPlayer.php b/app/Filament/Imports/Helper/ImportPlayer.php index 879d72e9..3ef4e0e6 100644 --- a/app/Filament/Imports/Helper/ImportPlayer.php +++ b/app/Filament/Imports/Helper/ImportPlayer.php @@ -8,14 +8,14 @@ use Spatie\SimpleExcel\SimpleExcelReader; class ImportPlayer { - public static function run(string $filePath): void + public static function run(string $filePath, string $importmode): void { $fieldnames = ['activeteam_id', 'playersubstitute_id', 'goals', 'assists', 'own_goals', 'shots_on_target', 'shots_off_target', 'shots_blocked', 'fouls', 'was_fouled', 'offsides', 'possessions_lost', 'total_tackles', 'touches', 'total_cross', 'cross_done', 'total_dribbles', 'dribbles_won', 'total_ground_duels', 'total_ground_duels_won', 'total_aerial_duels', 'total_duels_aerial_won', 'total_pass', 'pass', 'total_long_balls', 'long_balls', 'blocked_shots', 'clearances', 'dribbled_past', 'hit_woodwork', 'interceptions', 'key_pass', 'last_man_tackle', 'dispossessed', 'clearance_off_line', 'bcc', 'bcm', 'errors_lead_to_a_goal', 'errors_lead_to_a_shot', 'penalty_committed', 'penalty_miss', 'penalty_save', 'penalty_won', 'saves', 'saves_from_in_box', 'total_runs_out', 'runs_out', 'punches', 'good_high_claim', 'minutes_played', 'lineup', 'minute_event_during_the_match', 'type_event_during_the_match', 'description_event_during_the_match', 'subtype_event_during_the_match', 'card_yellow', 'card_yellowred', 'card_red', 'ingamepenalty_missed', 'penaltyshoutout_scored', 'penaltyshoutout_missed', 'player_position', 'playerrating_value']; SimpleExcelReader::create(storage_path('app/public/'.$filePath)) ->getRows() ->chunk(1000) - ->each(function (LazyCollection $chunk) use ($fieldnames) { + ->each(function (LazyCollection $chunk) use ($fieldnames, $importmode) { foreach ($chunk as $row) { @@ -23,19 +23,29 @@ class ImportPlayer // print_r($row); - $update_array = []; - foreach ($fieldnames as $key => $name) { - $offset = (int) $key + 4; - $update_array[$name] = $row[$offset]; + if ($importmode == 'update') { + + $update_array = []; + foreach ($fieldnames as $key => $name) { + $offset = (int) $key + 4; + $update_array[$name] = $row[$offset]; + } + + // dd($update_array); + + StatistikoPlayer::where('sport_id', (int) $row[0]) + ->where('match_id', (int) $row[1]) + ->where('ss_player_id', (int) $row[2]) + ->where('tm_player_id', (int) $row[3]) + ->update($update_array, ['upsert' => true]); + } else { + $insert_array = []; + foreach ($fieldnames as $key => $name) { + $insert_array[$name] = $row[$key]; + } + + StatistikoPlayer::insert($insert_array); } - - // dd($update_array); - - StatistikoPlayer::where('sport_id', (int) $row[0]) - ->where('match_id', (int) $row[1]) - ->where('ss_player_id', (int) $row[2]) - ->where('tm_player_id', (int) $row[3]) - ->update($update_array, ['upsert' => true]); } }); } diff --git a/app/Filament/Imports/StatistikoImporter.php b/app/Filament/Imports/StatistikoImporter.php index 4f27bc6c..3a36542c 100644 --- a/app/Filament/Imports/StatistikoImporter.php +++ b/app/Filament/Imports/StatistikoImporter.php @@ -19,30 +19,30 @@ class StatistikoImporter public static int $startQueries; - public static function run($record): void + public static function run(object $record, string $importmode): void { error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('max_execution_time', -1); - $table = $record['data_type']; + $table = $record->data_type; - $filePath = $record['file_name']; + $filePath = $record->file_name; ImportBenchmark::start($table); switch ($record['data_type']) { case 'details': - ImportDetails::run($filePath); + ImportDetails::run($filePath, $importmode); break; case 'events': - ImportEvents::run($filePath); + ImportEvents::run($filePath, $importmode); break; case 'fixtures': - ImportFixtures::run($filePath); + ImportFixtures::run($filePath, $importmode); break; case 'player': - ImportPlayer::run($filePath); + ImportPlayer::run($filePath, $importmode); break; } diff --git a/composer.lock b/composer.lock index 56f8f9ce..20456c29 100644 --- a/composer.lock +++ b/composer.lock @@ -2196,25 +2196,26 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.10.6", + "version": "7.11.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "e7412b3180912c01650cc66647f18c1d1cbe9b94" + "reference": "c987f8ce84b8434fa430795eca0f3430663da72b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e7412b3180912c01650cc66647f18c1d1cbe9b94", - "reference": "e7412b3180912c01650cc66647f18c1d1cbe9b94", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/c987f8ce84b8434fa430795eca0f3430663da72b", + "reference": "c987f8ce84b8434fa430795eca0f3430663da72b", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^2.3", - "guzzlehttp/psr7": "^2.8", + "guzzlehttp/promises": "^2.5", + "guzzlehttp/psr7": "^2.11", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" + "symfony/deprecation-contracts": "^2.5 || ^3.0", + "symfony/polyfill-php80": "^1.24" }, "provide": { "psr/http-client-implementation": "1.0" @@ -2303,7 +2304,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.10.6" + "source": "https://github.com/guzzle/guzzle/tree/7.11.0" }, "funding": [ { @@ -2319,24 +2320,25 @@ "type": "tidelift" } ], - "time": "2026-06-01T13:06:22+00:00" + "time": "2026-06-02T12:40:51+00:00" }, { "name": "guzzlehttp/promises", - "version": "2.4.1", + "version": "2.5.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "09e8a212562fb1fb6a512c4156ed71525969d6c2" + "reference": "4360e982f87f5f258bf872d094647791db2f4c8e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/09e8a212562fb1fb6a512c4156ed71525969d6c2", - "reference": "09e8a212562fb1fb6a512c4156ed71525969d6c2", + "url": "https://api.github.com/repos/guzzle/promises/zipball/4360e982f87f5f258bf872d094647791db2f4c8e", + "reference": "4360e982f87f5f258bf872d094647791db2f4c8e", "shasum": "" }, "require": { - "php": "^7.2.5 || ^8.0" + "php": "^7.2.5 || ^8.0", + "symfony/deprecation-contracts": "^2.5 || ^3.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", @@ -2386,7 +2388,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.4.1" + "source": "https://github.com/guzzle/promises/tree/2.5.0" }, "funding": [ { @@ -2402,27 +2404,29 @@ "type": "tidelift" } ], - "time": "2026-05-20T22:57:30+00:00" + "time": "2026-06-02T12:23:43+00:00" }, { "name": "guzzlehttp/psr7", - "version": "2.10.4", + "version": "2.11.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "d2a1a094e396da8957e797489fddaf860c340cfc" + "reference": "bbb5e61349fa5cb822b3e87842b951088b76b81f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/d2a1a094e396da8957e797489fddaf860c340cfc", - "reference": "d2a1a094e396da8957e797489fddaf860c340cfc", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/bbb5e61349fa5cb822b3e87842b951088b76b81f", + "reference": "bbb5e61349fa5cb822b3e87842b951088b76b81f", "shasum": "" }, "require": { "php": "^7.2.5 || ^8.0", "psr/http-factory": "^1.0", "psr/http-message": "^1.1 || ^2.0", - "ralouphie/getallheaders": "^3.0" + "ralouphie/getallheaders": "^3.0", + "symfony/deprecation-contracts": "^2.5 || ^3.0", + "symfony/polyfill-php80": "^1.24" }, "provide": { "psr/http-factory-implementation": "1.0", @@ -2503,7 +2507,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.10.4" + "source": "https://github.com/guzzle/psr7/tree/2.11.0" }, "funding": [ { @@ -2519,7 +2523,7 @@ "type": "tidelift" } ], - "time": "2026-05-29T12:59:07+00:00" + "time": "2026-06-02T12:30:48+00:00" }, { "name": "guzzlehttp/uri-template",