statistic on separate page wip
This commit is contained in:
1 parent
ad36ba555f
commit
422681df01
34 files changed
+660
-734
No files matched your search
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports\Helper;
|
||||
|
||||
use Filament\Notifications\Notification;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports\Helper;
|
||||
|
||||
use App\Models\StatistikoEvent;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Spatie\SimpleExcel\SimpleExcelReader;
|
||||
|
||||
class ImportPlayer
|
||||
{
|
||||
public static function importEvents(string $filePath, int $sport_id): 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, $sport_id) {
|
||||
|
||||
foreach ($chunk as $row) {
|
||||
|
||||
$row = array_values($row);
|
||||
|
||||
StatistikoEvent::where('sport_id', $sport_id)
|
||||
->where('league_id', $row[0])
|
||||
->where('home_id', $row[1])
|
||||
->where('away_id', $row[2])
|
||||
->where('starttime', Carbon::parse($row[3])->toIso8601String())
|
||||
->update(
|
||||
[
|
||||
'season' => $row[4],
|
||||
'gls_h' => $row[5],
|
||||
'gls_a' => $row[6],
|
||||
'crn_h' => $row[7],
|
||||
'crn_a' => $row[8],
|
||||
'fls_h' => $row[9],
|
||||
'fls_a' => $row[10],
|
||||
'ofs_h' => $row[11],
|
||||
'ofs_a' => $row[12],
|
||||
'snt_h' => $row[13],
|
||||
'snt_a' => $row[14],
|
||||
'tsh_h' => $row[15],
|
||||
'tsh_a' => $row[16],
|
||||
'crd_h' => $row[17],
|
||||
'crd_a' => $row[18],
|
||||
'expgoalshome_value' => $row[19],
|
||||
'expgoalsaway_value' => $row[20],
|
||||
'exp_handicap' => $row[21],
|
||||
'exp_total' => $row[22],
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
['upsert' => true],
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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, $sport_id): void
|
||||
{
|
||||
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
|
||||
->getRows()
|
||||
->chunk(200)
|
||||
->each(function (LazyCollection $chunk) use ($sport_id) {
|
||||
|
||||
foreach ($chunk as $row) {
|
||||
|
||||
$row = array_values($row);
|
||||
|
||||
/*
|
||||
0 => 87
|
||||
1 => 3614
|
||||
2 => 1491
|
||||
3 => DateTimeImmutable @1777334400 {#2722 ▶}
|
||||
4 => 0.90433699503783
|
||||
5 => 1.035168989838
|
||||
*/
|
||||
|
||||
StatisticFixtures::updateOrCreate(
|
||||
[
|
||||
'sport_id' => (int) $sport_id,
|
||||
'league_id' => (int) $row[0],
|
||||
'home_id' => (int) $row[1],
|
||||
'away_id' => (int) $row[2],
|
||||
'starttime' => Carbon::parse($row[3])->toDateString(),
|
||||
],
|
||||
['exp_home' => (float) $row[4], 'exp_away' => (float) $row[5]]
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports\Helper;
|
||||
|
||||
use App\Models\StatistikoPlayer;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Spatie\SimpleExcel\SimpleExcelReader;
|
||||
|
||||
class ImportPlayer
|
||||
{
|
||||
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);
|
||||
|
||||
StatistikoPlayer::where('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],
|
||||
'rigorist' => $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],
|
||||
);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user