update import opetion by upload
This commit is contained in:
1 parent
37d28eec21
commit
0221ace4d2
15 files changed
+194
-253
No files matched your search
@@ -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 .= '<br/>SQL: '.number_format($queriesCount);
|
||||
$str .= '<br/>ROWS: '.number_format($rowDiff);
|
||||
|
||||
$recipient = auth()->user();
|
||||
$recipient = Auth::user();
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
|
||||
@@ -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],
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user