|
5 | 5 | use App\Events\ResultCreated; |
6 | 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
7 | 7 | use Illuminate\Database\Eloquent\Model; |
| 8 | +use Illuminate\Support\Arr; |
8 | 9 |
|
9 | 10 | class Result extends Model |
10 | 11 | { |
@@ -77,20 +78,21 @@ public function formatForInfluxDB2() |
77 | 78 | $data = json_decode($this->data, true); |
78 | 79 |
|
79 | 80 | 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, |
92 | 93 | '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'), |
94 | 96 | ]; |
95 | 97 | } |
96 | 98 |
|
|
0 commit comments