check double upload player event wip

This commit is contained in:
salam committed 2026-07-15 12:29:48 +02:00
1 parent 9954f47139
commit fd7b8fadad
7 files changed
+74 -79

No files matched your search

@@ -60,25 +60,14 @@ class StatistikoImportsTable
Action::make('import')
->label('Import')
->color('success')
->tooltip('Import is much faster but does no check for doubles')
->tooltip('Update or create')
->icon('phosphor-database')
->action(fn ($record) => StatistikoImporter::run($record, 'import'))
->action(fn($record) => StatistikoImporter::run($record))
->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'),
@@ -2,11 +2,16 @@
namespace App\Filament\Clusters\StaticData\Resources\StatistikoPlayers\Tables;
use App\Models\StatistikoPlayer;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Checkbox;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class StatistikoPlayersTable
{
@@ -19,15 +24,46 @@ class StatistikoPlayersTable
TextColumn::make('details.name')
->label('Player')
->searchable()
->tooltip(fn ($record) => $record->details->full_name),
->tooltip(fn($record) => $record->details->full_name),
TextColumn::make('tm_player_id')->label('TM Id')->searchable(),
TextColumn::make('ss_player_id')->label('SS Id')->searchable(),
TextColumn::make('event.home.name')->searchable()->color('primary'),
TextColumn::make('event.away.name')->searchable()->color('success'),
])
->filters([
//
])
Filter::make('event_filters')
->schema([
Checkbox::make('find_double'),
])->query(function (Builder $query, array $data): Builder {
return $query->when(
$data['find_double'],
function (Builder $query) use ($data) {
$arr = [];
// $events = StatistikoPlayer::query()->select('match_id', 'ss_player_id')->get()->toArray();
// foreach ($events as $value) {
// $match_id = $value['match_id'];
// $ss_player_id = $value['ss_player_id'];
// if (in_array($ss_player_id, $arr[$value['match_id']]))
// $arr[$value['match_id']][] = $value['ss_player_id'];
// }
// dd($arr);
// dd($events);
// $doublEvents = array_diff_assoc(
// $events,
// array_unique($events)
// );
// $query->whereIn('match_id', $doublEvents)->orderBy('match_id');
}
);
})->indicateUsing(function (array $data): ?string {
if (! $data['find_double']) {
return null;
}
return 'Find Double';
}),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->recordActions([
EditAction::make(),
])
+7 -28
View File
@@ -9,47 +9,26 @@ use Spatie\SimpleExcel\SimpleExcelReader;
class ImportDetails
{
public static function run(string $filePath, string $importmode): void
public static function run(string $filePath): void
{
$now = now()->format('Y-m-d H:i:s');
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
SimpleExcelReader::create(storage_path('app/public/' . $filePath))
->getRows()
->chunk(1000)
->each(function (LazyCollection $chunk) use ($now, $importmode) {
->each(function (LazyCollection $chunk) use ($now) {
foreach ($chunk as $row) {
$row = array_values($row);
if ($importmode == 'update') {
StatistikoDetail::where('tm_player_id', $row[0])
->update(
if ($row[1] != '') {
StatistikoDetail::updateOrCreate(
[
'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,
'tm_player_id' => (int) $row[0],
],
['upsert' => true],
);
} else {
StatistikoDetail::insert(
[
'tm_player_id', $row[0],
'name' => $row[1],
'birthdate' => Carbon::parse($row[2])->toDateString(),
'height' => $row[3],
+2 -2
View File
@@ -9,14 +9,14 @@ use Spatie\SimpleExcel\SimpleExcelReader;
class ImportEvents
{
public static function run(string $filePath, string $importmode): void
public static function run(string $filePath): 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, $importmode) {
->each(function (LazyCollection $chunk) use ($now) {
foreach ($chunk as $row) {
+3 -17
View File
@@ -9,12 +9,12 @@ use Spatie\SimpleExcel\SimpleExcelReader;
class ImportFixtures
{
public static function run(string $filePath, string $importmode): void
public static function run(string $filePath): void
{
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
SimpleExcelReader::create(storage_path('app/public/' . $filePath))
->getRows()
->chunk(200)
->each(function (LazyCollection $chunk) use ($importmode) {
->each(function (LazyCollection $chunk) {
foreach ($chunk as $row) {
@@ -30,7 +30,6 @@ class ImportFixtures
6 => 1.035168989838
*/
if ($importmode == 'update') {
StatisticFixtures::updateOrCreate(
[
'sport_id' => (int) $row[0],
@@ -41,19 +40,6 @@ class ImportFixtures
],
['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],
]
);
}
}
});
}
+16 -11
View File
@@ -8,11 +8,11 @@ use Spatie\SimpleExcel\SimpleExcelReader;
class ImportPlayer
{
public static function run(string $filePath, string $importmode): void
public static function run(string $filePath): 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))
SimpleExcelReader::create(storage_path('app/public/' . $filePath))
->getRows()
->chunk(1000)
->each(function (LazyCollection $chunk) use ($fieldnames) {
@@ -21,21 +21,26 @@ class ImportPlayer
$row = array_values($row);
// print_r($row);
$update_array = [];
foreach ($fieldnames as $key => $name) {
$offset = (int) $key + 4;
$offset = (int) $key + 3;
$update_array[$name] = $row[$offset];
}
// dd($update_array);
StatistikoPlayer::updateOrCreate(
[
'sport_id' => (int) $row[0],
'match_id' => (int) $row[1],
'ss_player_id' => (int) $row[2],
],
$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]);
// 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]);
// if ($importmode == 'update') {
+5 -5
View File
@@ -19,7 +19,7 @@ class StatistikoImporter
public static int $startQueries;
public static function run(object $record, string $importmode): void
public static function run(object $record): void
{
error_reporting(E_ALL);
ini_set('display_errors', 1);
@@ -33,16 +33,16 @@ class StatistikoImporter
switch ($record['data_type']) {
case 'details':
ImportDetails::run($filePath, $importmode);
ImportDetails::run($filePath);
break;
case 'events':
ImportEvents::run($filePath, $importmode);
ImportEvents::run($filePath);
break;
case 'fixtures':
ImportFixtures::run($filePath, $importmode);
ImportFixtures::run($filePath);
break;
case 'player':
ImportPlayer::run($filePath, $importmode);
ImportPlayer::run($filePath);
break;
}