Skip to content

Commit 07214d5

Browse files
authored
[Feature] Refactored format data for InfluxDB (alexjustesen#721)
1 parent 11457a9 commit 07214d5

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

app/Models/Result.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Events\ResultCreated;
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
77
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Support\Arr;
89

910
class Result extends Model
1011
{
@@ -77,20 +78,21 @@ public function formatForInfluxDB2()
7778
$data = json_decode($this->data, true);
7879

7980
return [
80-
'id' => (int) $this->id,
81-
'ping' => (float) $this->ping,
82-
'download' => (int) $this->download,
83-
'upload' => (int) $this->upload,
84-
'download_bits' => (int) $this->download * 8,
85-
'upload_bits' => (int) $this->upload * 8,
86-
'ping_jitter' => (float) $data['ping']['jitter'] ?? null,
87-
'download_jitter' => (float) $data['download']['latency']['jitter'] ?? null,
88-
'upload_jitter' => (float) $data['upload']['latency']['jitter'] ?? null,
89-
'server_id' => (int) $this->server_id,
90-
'server_host' => $this->server_host,
91-
'server_name' => $this->server_name,
81+
'id' => $this->id,
82+
'ping' => $this?->ping,
83+
'download' => $this?->download,
84+
'upload' => $this?->upload,
85+
'download_bits' => $this->download ? $this->download * 8 : null,
86+
'upload_bits' => $this->upload ? $this->upload * 8 : null,
87+
'ping_jitter' => Arr::get($data, 'ping.jitter'),
88+
'download_jitter' => Arr::get($data, 'download.latency.jitter'),
89+
'upload_jitter' => Arr::get($data, 'upload.latency.jitter'),
90+
'server_id' => $this?->server_id,
91+
'server_host' => $this?->server_host,
92+
'server_name' => $this?->server_name,
9293
'scheduled' => $this->scheduled,
93-
'packet_loss' => array_key_exists('packetLoss', $data) ? (float) $data['packetLoss'] : null, // optional, because apparently the cli doesn't always have this metric
94+
'successful' => $this->successful,
95+
'packet_loss' => Arr::get($data, 'packetLoss'),
9496
];
9597
}
9698

0 commit comments

Comments
 (0)