diff --git a/app/Actions/Influxdb/v2/BuildPointData.php b/app/Actions/Influxdb/v2/BuildPointData.php index 9bead5a7a..508b86e94 100644 --- a/app/Actions/Influxdb/v2/BuildPointData.php +++ b/app/Actions/Influxdb/v2/BuildPointData.php @@ -48,7 +48,9 @@ public function handle(Result $result): Point ->addField('upload_latency_avg', Number::castToType(Arr::get($result->data, 'upload.latency.iqm'), 'float')) ->addField('upload_latency_high', Number::castToType(Arr::get($result->data, 'upload.latency.high'), 'float')) ->addField('upload_latency_low', Number::castToType(Arr::get($result->data, 'upload.latency.low'), 'float')) - ->addField('packet_loss', Number::castToType(Arr::get($result->data, 'packetLoss'), 'float')); + ->addField('packet_loss', Number::castToType(Arr::get($result->data, 'packetLoss'), 'float')) + ->addField('downloaded_bytes', Number::castToType($result->downloaded_bytes, 'int')) + ->addField('uploaded_bytes', Number::castToType($result->uploaded_bytes, 'int')); return $point; } diff --git a/app/Filament/Exports/ResultExporter.php b/app/Filament/Exports/ResultExporter.php index ab844ec99..c81e86afc 100644 --- a/app/Filament/Exports/ResultExporter.php +++ b/app/Filament/Exports/ResultExporter.php @@ -113,6 +113,10 @@ public static function getColumns(): array return $record->download_latency_iqm; }) ->enabledByDefault(false), + ExportColumn::make('downloaded_bytes') + ->enabledByDefault(false), + ExportColumn::make('uploaded_bytes') + ->enabledByDefault(false), ExportColumn::make('result_url') ->state(function (Result $record) { return $record->result_url; diff --git a/app/Filament/Resources/ResultResource.php b/app/Filament/Resources/ResultResource.php index 9e768b1bf..08069103c 100644 --- a/app/Filament/Resources/ResultResource.php +++ b/app/Filament/Resources/ResultResource.php @@ -20,6 +20,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; use Illuminate\Support\HtmlString; +use Illuminate\Support\Number as LaravelNumber; class ResultResource extends Resource { @@ -83,6 +84,11 @@ public static function form(Form $form): Form ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), + Forms\Components\TextInput::make('downloaded_bytes') + ->label('Downloaded bytes') + ->afterStateHydrated(function (TextInput $component, Result $record) { + $component->state(! blank($record->downloaded_bytes) ? LaravelNumber::fileSize(bytes: $record->downloaded_bytes, precision: 2) : ''); + }), Forms\Components\TextInput::make('data.upload.latency.jitter') ->label('Upload Jitter') ->formatStateUsing(function ($state) { @@ -103,6 +109,11 @@ public static function form(Form $form): Form ->formatStateUsing(function ($state) { return number_format((float) $state, 0, '.', '').' ms'; }), + Forms\Components\TextInput::make('uploaded_bytes') + ->label('Uploaded bytes') + ->afterStateHydrated(function (TextInput $component, Result $record) { + $component->state(! blank($record->downloaded_bytes) ? LaravelNumber::fileSize(bytes: $record->uploaded_bytes, precision: 2) : ''); + }), Forms\Components\TextInput::make('data.ping.jitter') ->label('Ping Jitter') ->formatStateUsing(function ($state) { @@ -196,9 +207,17 @@ public static function table(Table $table): Table Tables\Columns\TextColumn::make('download') ->getStateUsing(fn (Result $record): ?string => ! blank($record->download) ? Number::toBitRate(bits: $record->download_bits, precision: 2) : null) ->sortable(), + Tables\Columns\TextColumn::make('downloaded_bytes') + ->toggleable() + ->getStateUsing(fn (Result $record): ?string => ! blank($record->download) ? LaravelNumber::fileSize(bytes: $record->downloaded_bytes, precision: 2) : null) + ->sortable(), Tables\Columns\TextColumn::make('upload') ->getStateUsing(fn (Result $record): ?string => ! blank($record->upload) ? Number::toBitRate(bits: $record->upload_bits, precision: 2) : null) ->sortable(), + Tables\Columns\TextColumn::make('uploaded_bytes') + ->toggleable() + ->getStateUsing(fn (Result $record): ?string => ! blank($record->download) ? LaravelNumber::fileSize(bytes: $record->uploaded_bytes, precision: 2) : null) + ->sortable(), Tables\Columns\TextColumn::make('ping') ->toggleable() ->sortable() diff --git a/app/Http/Resources/V1/ResultResource.php b/app/Http/Resources/V1/ResultResource.php index e4b1aacad..10ac8ed65 100644 --- a/app/Http/Resources/V1/ResultResource.php +++ b/app/Http/Resources/V1/ResultResource.php @@ -20,7 +20,9 @@ public function toArray(Request $request): array 'service' => $this->service, 'ping' => $this->ping, 'download' => $this->download, + 'downloaded_bytes' => $this->downloaded_bytes, 'upload' => $this->upload, + 'uploaded_bytes' => $this->uploaded_bytes, 'download_bits' => $this->when($this->download, fn (): int|float => Bitrate::bytesToBits($this->download)), 'upload_bits' => $this->when($this->upload, fn (): int|float => Bitrate::bytesToBits($this->upload)), 'download_bits_human' => $this->when($this->download, fn (): string => Bitrate::formatBits(Bitrate::bytesToBits($this->download)).'ps'), diff --git a/app/Jobs/Ookla/RunSpeedtestJob.php b/app/Jobs/Ookla/RunSpeedtestJob.php index 058c73363..e88a49c7a 100644 --- a/app/Jobs/Ookla/RunSpeedtestJob.php +++ b/app/Jobs/Ookla/RunSpeedtestJob.php @@ -89,7 +89,9 @@ public function handle(): void $this->result->update([ 'ping' => Arr::get($output, 'ping.latency'), 'download' => Arr::get($output, 'download.bandwidth'), + 'downloaded_bytes' => Arr::get($output, 'download.bytes'), 'upload' => Arr::get($output, 'upload.bandwidth'), + 'uploaded_bytes' => Arr::get($output, 'upload.bytes'), 'data' => $output, ]); } diff --git a/database/factories/ResultFactory.php b/database/factories/ResultFactory.php index 9fa2375ba..8de01da01 100644 --- a/database/factories/ResultFactory.php +++ b/database/factories/ResultFactory.php @@ -44,7 +44,9 @@ public function definition(): array 'service' => ResultService::Faker, 'ping' => Arr::get($output, 'ping.latency'), 'download' => Arr::get($output, 'download.bandwidth'), + 'downloaded_bytes' => Arr::get($output, 'download.bytes'), 'upload' => Arr::get($output, 'upload.bandwidth'), + 'uploaded_bytes' => Arr::get($output, 'upload.bytes'), 'data' => $output, 'status' => ResultStatus::Completed, 'scheduled' => false, diff --git a/database/migrations/2025_04_16_000050_update_results_table.php b/database/migrations/2025_04_16_000050_update_results_table.php new file mode 100644 index 000000000..01de010e8 --- /dev/null +++ b/database/migrations/2025_04_16_000050_update_results_table.php @@ -0,0 +1,27 @@ +unsignedBigInteger('downloaded_bytes')->nullable()->after('download'); + $table->unsignedBigInteger('uploaded_bytes')->nullable()->after('upload'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +};