diff --git a/app/Actions/Influxdb/v2/BuildPointData.php b/app/Actions/Influxdb/v2/BuildPointData.php index 7b2f0b3da..e135afdf0 100644 --- a/app/Actions/Influxdb/v2/BuildPointData.php +++ b/app/Actions/Influxdb/v2/BuildPointData.php @@ -50,8 +50,8 @@ 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('downloaded_bytes', Number::castToType(Arr::get($result->data, 'downloaded_bytes'), 'float')) - ->addField('uploaded_bytes', Number::castToType(Arr::get($result->data, 'uploaded_bytes'), 'float')) + ->addField('downloaded_bytes', Number::castToType($result->data, 'download_bytes', 'float')) + ->addField('uploaded_bytes', Number::castToType($result->data, 'upload_bytes', 'float')) ->addField('packet_loss', Number::castToType(Arr::get($result->data, 'packetLoss'), 'float')) ->addField('log_message', Arr::get($result->data, 'message')); diff --git a/app/Http/Resources/V1/ResultResource.php b/app/Http/Resources/V1/ResultResource.php index e4b1aacad..e00710297 100644 --- a/app/Http/Resources/V1/ResultResource.php +++ b/app/Http/Resources/V1/ResultResource.php @@ -5,6 +5,7 @@ use App\Helpers\Bitrate; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use Illuminate\Support\Number; class ResultResource extends JsonResource { @@ -25,6 +26,10 @@ public function toArray(Request $request): array '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'), 'upload_bits_human' => $this->when($this->upload, fn (): string => Bitrate::formatBits(Bitrate::bytesToBits($this->upload)).'ps'), + 'download_bytes' => $this->download_bytes, + 'upload_bytes' => $this->upload_bytes, + 'download_bytes_human' => $this->when($this->download_bytes, fn (): string => Number::fileSize($this->download_bytes)), + 'upload_bytes_human' => $this->when($this->upload_bytes, fn (): string => Number::fileSize($this->upload_bytes)), 'benchmarks' => $this->benchmarks, 'healthy' => $this->healthy, 'status' => $this->status, diff --git a/app/Jobs/Ookla/RunSpeedtestJob.php b/app/Jobs/Ookla/RunSpeedtestJob.php index 058c73363..486faab6f 100644 --- a/app/Jobs/Ookla/RunSpeedtestJob.php +++ b/app/Jobs/Ookla/RunSpeedtestJob.php @@ -90,6 +90,8 @@ public function handle(): void 'ping' => Arr::get($output, 'ping.latency'), 'download' => Arr::get($output, 'download.bandwidth'), 'upload' => Arr::get($output, 'upload.bandwidth'), + 'download_bytes' => Arr::get($output, 'download.bytes'), + 'upload_bytes' => Arr::get($output, 'upload.bytes'), 'data' => $output, ]); } diff --git a/database/factories/ResultFactory.php b/database/factories/ResultFactory.php index 9fa2375ba..fb338571b 100644 --- a/database/factories/ResultFactory.php +++ b/database/factories/ResultFactory.php @@ -45,6 +45,8 @@ public function definition(): array 'ping' => Arr::get($output, 'ping.latency'), 'download' => Arr::get($output, 'download.bandwidth'), 'upload' => Arr::get($output, 'upload.bandwidth'), + 'download_bytes' => Arr::get($output, 'download.bytes'), + 'upload_bytes' => Arr::get($output, 'upload.bytes'), 'data' => $output, 'status' => ResultStatus::Completed, 'scheduled' => false, diff --git a/database/migrations/2025_07_31_225208_add_bytes_to_results_table.php b/database/migrations/2025_07_31_225208_add_bytes_to_results_table.php new file mode 100644 index 000000000..6a9fa87a7 --- /dev/null +++ b/database/migrations/2025_07_31_225208_add_bytes_to_results_table.php @@ -0,0 +1,29 @@ +after('upload', function (Blueprint $table) { + $table->unsignedBigInteger('download_bytes')->nullable(); + $table->unsignedBigInteger('upload_bytes')->nullable(); + }); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +};