wip del err

This commit is contained in:
salam committed 2026-10-04 15:22:39 +02:00
1 parent 812736ca9a
commit 9bcd4432c6
1210 files changed
-220941

No files matched your search

@@ -1,58 +0,0 @@
<?php
namespace App\Filament\Imports\Helper;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\HtmlString;
class ImportBenchmark
{
public static float $benchmarkStartTime;
public static int $benchmarkStartMemory;
public static int $startRowCount;
public static int $startQueries;
public static function start(string $table): void
{
self::$startRowCount = DB::connection('mongodb')->table($table)->count();
self::$benchmarkStartTime = microtime(true);
self::$benchmarkStartMemory = memory_get_usage();
DB::connection('mongodb')->enableQueryLog();
}
public static function end(string $table): void
{
$executionTime = microtime(true) - self::$benchmarkStartTime;
$memoryUsage = round((memory_get_usage() - self::$benchmarkStartMemory) / 1024 / 1024, 2);
$logs = DB::connection('mongodb')->getQueryLog();
$queriesCount = \count($logs);
// Get row count after we've stopped tracking queries
$rowDiff = DB::connection('mongodb')->table($table)->count() - self::$startRowCount;
$formattedTime = match (true) {
$executionTime >= 60 => sprintf('%dm %ds', floor($executionTime / 60), $executionTime % 60),
$executionTime >= 1 => round($executionTime, 2).'s',
default => round($executionTime * 1000).'ms',
};
$str = '⚡ TIME: '.$formattedTime;
$str .= '<br/>MEM: '.$memoryUsage.'MB';
$str .= '<br/>SQL: '.number_format($queriesCount);
$str .= '<br/>ROWS: '.number_format($rowDiff);
$recipient = Auth::user();
Notification::make()
->success()
->title('Import compleated')
->body(new HtmlString($str))
->sendToDatabase($recipient);
}
}
@@ -1,55 +0,0 @@
<?php
namespace App\Filament\Imports\Helper;
use App\Models\StatistikoDetail;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;
use Spatie\SimpleExcel\SimpleExcelReader;
class ImportDetails
{
public static function run(string $filePath): void
{
StatistikoDetail::query()->update(['last_import' => 'no']);
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
->getRows()
->chunk(1000)
->each(function (LazyCollection $chunk) {
$collection = [];
foreach ($chunk as $row) {
if ($row['player_name'] != '') {
$row['is_active'] = 1;
$row['last_import'] = 'yes';
$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('last_import', 'no')->update(['is_active' => 0, 'ss_team_id' => 0]);
}
}
@@ -1,74 +0,0 @@
<?php
namespace App\Filament\Imports\Helper;
use App\Models\StatistikoEvent;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;
use Spatie\SimpleExcel\SimpleExcelReader;
class ImportEvents
{
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) {
foreach ($chunk as $row) {
$row = array_values($row);
/**
* must be != null
* exp_home, exp_away, exp_handicap, exp_total
*/
if (
(float) $row[21] != 0
&& (float) $row[22] != 0
&& (float) $row[23] != 0
&& (float) $row[24] != 0
&& (string) $row[25] != ''
) {
StatistikoEvent::updateOrCreate(
[
'match_id' => (int) $row[0],
],
[
'sport_id' => (int) $row[1],
'league_id' => (int) $row[2],
'home_id' => (int) $row[3],
'away_id' => (int) $row[4],
'starttime' => Carbon::parse($row[5])->toIso8601String(),
'season' => (string) $row[6],
'gls_h' => (int) $row[7],
'gls_a' => (int) $row[8],
'crn_h' => (int) $row[9],
'crn_a' => (int) $row[10],
'fls_h' => (int) $row[11],
'fls_a' => (int) $row[12],
'ofs_h' => (int) $row[13],
'ofs_a' => (int) $row[14],
'snt_h' => (int) $row[15],
'snt_a' => (int) $row[16],
'tsh_h' => (int) $row[17],
'tsh_a' => (int) $row[18],
'crd_h' => (int) $row[19],
'crd_a' => (int) $row[20],
'exp_home' => (float) $row[21],
'exp_away' => (float) $row[22],
'exp_handicap' => (float) $row[23],
'exp_total' => (float) $row[24],
'result_code' => (string) $row[25], // w, d, l
'created_at' => $now,
'updated_at' => $now,
]
);
}
}
});
}
}
@@ -1,46 +0,0 @@
<?php
namespace App\Filament\Imports\Helper;
use App\Models\StatisticFixtures;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;
use Spatie\SimpleExcel\SimpleExcelReader;
class ImportFixtures
{
public static function run(string $filePath): void
{
SimpleExcelReader::create(storage_path('app/public/' . $filePath))
->getRows()
->chunk(200)
->each(function (LazyCollection $chunk) {
foreach ($chunk as $row) {
$row = array_values($row);
/*
0 => 1
1 => 87
2 => 3614
3 => 1491
4 => DateTimeImmutable @1777334400 {#2722 ▶}
5 => 0.90433699503783
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]]
);
}
});
}
}
@@ -1,144 +0,0 @@
<?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);
});
}
}