From a3628d66d81f67fe6094c0364241f39befd25554 Mon Sep 17 00:00:00 2001 From: Alex Justesen <1144087+alexjustesen@users.noreply.github.com> Date: Thu, 31 Jul 2025 19:13:45 -0400 Subject: [PATCH 1/3] add download and upload bytes --- app/Actions/Influxdb/v2/BuildPointData.php | 4 +-- app/Http/Resources/V1/ResultResource.php | 5 ++++ app/Jobs/Ookla/RunSpeedtestJob.php | 2 ++ database/factories/ResultFactory.php | 2 ++ ...7_31_225208_add_bytes_to_results_table.php | 29 +++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2025_07_31_225208_add_bytes_to_results_table.php diff --git a/app/Actions/Influxdb/v2/BuildPointData.php b/app/Actions/Influxdb/v2/BuildPointData.php index 7b2f0b3da..ae06e7f93 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('download_bytes', Number::castToType($result->data, 'download_bytes', 'float')) // TODO: this should be an integer in the next version. + ->addField('upload_bytes', Number::castToType($result->data, 'upload_bytes', 'float')) // TODO: this should be an integer in the next version. ->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 + { + // + } +}; From d7e87666b8c179d3cb48ab2ab6554a28f5f204bd Mon Sep 17 00:00:00 2001 From: Alex Justesen <1144087+alexjustesen@users.noreply.github.com> Date: Thu, 31 Jul 2025 19:24:08 -0400 Subject: [PATCH 2/3] rename download_bytes and upload_bytes fields to downloaded_bytes and uploaded_bytes --- app/Actions/Influxdb/v2/BuildPointData.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Actions/Influxdb/v2/BuildPointData.php b/app/Actions/Influxdb/v2/BuildPointData.php index ae06e7f93..fd66595fc 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('download_bytes', Number::castToType($result->data, 'download_bytes', 'float')) // TODO: this should be an integer in the next version. - ->addField('upload_bytes', Number::castToType($result->data, 'upload_bytes', 'float')) // TODO: this should be an integer in the next version. + ->addField('downloaded_bytes', Number::castToType($result->data, 'download_bytes', 'float')) + ->addField('uploadeded_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')); From eeae02c48b370d9a226ffa8e7a7415095f53d89f Mon Sep 17 00:00:00 2001 From: Alex Justesen <1144087+alexjustesen@users.noreply.github.com> Date: Thu, 31 Jul 2025 19:25:00 -0400 Subject: [PATCH 3/3] typo --- app/Actions/Influxdb/v2/BuildPointData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Actions/Influxdb/v2/BuildPointData.php b/app/Actions/Influxdb/v2/BuildPointData.php index fd66595fc..e135afdf0 100644 --- a/app/Actions/Influxdb/v2/BuildPointData.php +++ b/app/Actions/Influxdb/v2/BuildPointData.php @@ -51,7 +51,7 @@ public function handle(Result $result): Point ->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($result->data, 'download_bytes', 'float')) - ->addField('uploadeded_bytes', Number::castToType($result->data, 'upload_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'));