Skip to content

Commit

Permalink
[Feature] Refactored format data for InfluxDB (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Sep 4, 2023
1 parent 11457a9 commit 07214d5
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app/Models/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Events\ResultCreated;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;

class Result extends Model
{
Expand Down Expand Up @@ -77,20 +78,21 @@ public function formatForInfluxDB2()
$data = json_decode($this->data, true);

return [
'id' => (int) $this->id,
'ping' => (float) $this->ping,
'download' => (int) $this->download,
'upload' => (int) $this->upload,
'download_bits' => (int) $this->download * 8,
'upload_bits' => (int) $this->upload * 8,
'ping_jitter' => (float) $data['ping']['jitter'] ?? null,
'download_jitter' => (float) $data['download']['latency']['jitter'] ?? null,
'upload_jitter' => (float) $data['upload']['latency']['jitter'] ?? null,
'server_id' => (int) $this->server_id,
'server_host' => $this->server_host,
'server_name' => $this->server_name,
'id' => $this->id,
'ping' => $this?->ping,
'download' => $this?->download,
'upload' => $this?->upload,
'download_bits' => $this->download ? $this->download * 8 : null,
'upload_bits' => $this->upload ? $this->upload * 8 : null,
'ping_jitter' => Arr::get($data, 'ping.jitter'),
'download_jitter' => Arr::get($data, 'download.latency.jitter'),
'upload_jitter' => Arr::get($data, 'upload.latency.jitter'),
'server_id' => $this?->server_id,
'server_host' => $this?->server_host,
'server_name' => $this?->server_name,
'scheduled' => $this->scheduled,
'packet_loss' => array_key_exists('packetLoss', $data) ? (float) $data['packetLoss'] : null, // optional, because apparently the cli doesn't always have this metric
'successful' => $this->successful,
'packet_loss' => Arr::get($data, 'packetLoss'),
];
}

Expand Down

0 comments on commit 07214d5

Please sign in to comment.