Skip to content

Commit 1fec5d0

Browse files
authored
Add download and upload bytes (alexjustesen#2301)
Co-authored-by: Alex Justesen <[email protected]>
1 parent f4be64a commit 1fec5d0

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

app/Actions/Influxdb/v2/BuildPointData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function handle(Result $result): Point
5050
->addField('upload_latency_avg', Number::castToType(Arr::get($result->data, 'upload.latency.iqm'), 'float'))
5151
->addField('upload_latency_high', Number::castToType(Arr::get($result->data, 'upload.latency.high'), 'float'))
5252
->addField('upload_latency_low', Number::castToType(Arr::get($result->data, 'upload.latency.low'), 'float'))
53-
->addField('downloaded_bytes', Number::castToType(Arr::get($result->data, 'downloaded_bytes'), 'float'))
54-
->addField('uploaded_bytes', Number::castToType(Arr::get($result->data, 'uploaded_bytes'), 'float'))
53+
->addField('downloaded_bytes', Number::castToType($result->data, 'download_bytes', 'float'))
54+
->addField('uploaded_bytes', Number::castToType($result->data, 'upload_bytes', 'float'))
5555
->addField('packet_loss', Number::castToType(Arr::get($result->data, 'packetLoss'), 'float'))
5656
->addField('log_message', Arr::get($result->data, 'message'));
5757

app/Http/Resources/V1/ResultResource.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Helpers\Bitrate;
66
use Illuminate\Http\Request;
77
use Illuminate\Http\Resources\Json\JsonResource;
8+
use Illuminate\Support\Number;
89

910
class ResultResource extends JsonResource
1011
{
@@ -25,6 +26,10 @@ public function toArray(Request $request): array
2526
'upload_bits' => $this->when($this->upload, fn (): int|float => Bitrate::bytesToBits($this->upload)),
2627
'download_bits_human' => $this->when($this->download, fn (): string => Bitrate::formatBits(Bitrate::bytesToBits($this->download)).'ps'),
2728
'upload_bits_human' => $this->when($this->upload, fn (): string => Bitrate::formatBits(Bitrate::bytesToBits($this->upload)).'ps'),
29+
'download_bytes' => $this->download_bytes,
30+
'upload_bytes' => $this->upload_bytes,
31+
'download_bytes_human' => $this->when($this->download_bytes, fn (): string => Number::fileSize($this->download_bytes)),
32+
'upload_bytes_human' => $this->when($this->upload_bytes, fn (): string => Number::fileSize($this->upload_bytes)),
2833
'benchmarks' => $this->benchmarks,
2934
'healthy' => $this->healthy,
3035
'status' => $this->status,

app/Jobs/Ookla/RunSpeedtestJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public function handle(): void
9090
'ping' => Arr::get($output, 'ping.latency'),
9191
'download' => Arr::get($output, 'download.bandwidth'),
9292
'upload' => Arr::get($output, 'upload.bandwidth'),
93+
'download_bytes' => Arr::get($output, 'download.bytes'),
94+
'upload_bytes' => Arr::get($output, 'upload.bytes'),
9395
'data' => $output,
9496
]);
9597
}

database/factories/ResultFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function definition(): array
4545
'ping' => Arr::get($output, 'ping.latency'),
4646
'download' => Arr::get($output, 'download.bandwidth'),
4747
'upload' => Arr::get($output, 'upload.bandwidth'),
48+
'download_bytes' => Arr::get($output, 'download.bytes'),
49+
'upload_bytes' => Arr::get($output, 'upload.bytes'),
4850
'data' => $output,
4951
'status' => ResultStatus::Completed,
5052
'scheduled' => false,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('results', function (Blueprint $table) {
15+
$table->after('upload', function (Blueprint $table) {
16+
$table->unsignedBigInteger('download_bytes')->nullable();
17+
$table->unsignedBigInteger('upload_bytes')->nullable();
18+
});
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*/
25+
public function down(): void
26+
{
27+
//
28+
}
29+
};

0 commit comments

Comments
 (0)