wip fix
This commit is contained in:
1 parent
9bcd4432c6
commit
6f92f9e1d5
1209 files changed
+220940
No files matched your search
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports\Helper;
|
||||
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Spatie\SimpleExcel\SimpleExcelReader;
|
||||
|
||||
class ImportPlayer
|
||||
{
|
||||
public static function run(string $filePath): void
|
||||
{
|
||||
$fieldnames = [
|
||||
'sport_id',
|
||||
'match_id',
|
||||
'ss_player_id',
|
||||
'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',
|
||||
'tm_player_id',
|
||||
];
|
||||
|
||||
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
|
||||
->getRows()
|
||||
->chunk(1000)
|
||||
->each(function (LazyCollection $chunk) use ($fieldnames) {
|
||||
|
||||
foreach ($chunk as $row) {
|
||||
|
||||
$row = array_values($row);
|
||||
|
||||
$match_id = 0;
|
||||
$ss_player_id = 0;
|
||||
|
||||
$update_array = [];
|
||||
foreach ($fieldnames as $key => $name) {
|
||||
if ($key == 1) {
|
||||
$match_id = (int) $row[$key];
|
||||
} elseif ($key == 2) {
|
||||
$ss_player_id = (int) $row[$key];
|
||||
} else {
|
||||
$update_array[$name] = $row[$key];
|
||||
}
|
||||
}
|
||||
|
||||
StatistikoPlayer::updateOrCreate(
|
||||
[
|
||||
'match_id' => $match_id,
|
||||
'ss_player_id' => $ss_player_id,
|
||||
],
|
||||
$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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user