Skip to content

Commit a0ed543

Browse files
authored
null safe model helper for chart data (alexjustesen#218)
1 parent 2fc6f52 commit a0ed543

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

app/Filament/Widgets/RecentJitterChart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ protected function getData(): array
6464
'datasets' => [
6565
[
6666
'label' => 'Download',
67-
'data' => $results->map(fn ($item) => json_decode($item->data)->download->latency->jitter),
67+
'data' => $results->map(fn ($item) => $item->getJitterData()['download']),
6868
'borderColor' => '#0ea5e9',
6969
'backgroundColor' => '#0ea5e9',
7070
],
7171
[
7272
'label' => 'Upload',
73-
'data' => $results->map(fn ($item) => json_decode($item->data)->upload->latency->jitter),
73+
'data' => $results->map(fn ($item) => $item->getJitterData()['upload']),
7474
'borderColor' => '#8b5cf6',
7575
'backgroundColor' => '#8b5cf6',
7676
],
7777
[
7878
'label' => 'Ping',
79-
'data' => $results->map(fn ($item) => json_decode($item->data)->ping->jitter),
79+
'data' => $results->map(fn ($item) => $item->getJitterData()['ping']),
8080
'borderColor' => '#10b981',
8181
'backgroundColor' => '#10b981',
8282
],

app/Models/Result.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,15 @@ public function formatForInfluxDB2()
7878
'packet_loss' => (float) $data['packetLoss'] ?? null, // optional, because apparently the cli doesn't always have this metric
7979
];
8080
}
81+
82+
public function getJitterData(): array
83+
{
84+
$data = json_decode($this->data, true);
85+
86+
return [
87+
'download' => $data['download']['latency']['jitter'] ?? null,
88+
'upload' => $data['upload']['latency']['jitter'] ?? null,
89+
'ping' => $data['ping']['jitter'] ?? null,
90+
];
91+
}
8192
}

app/Providers/FilamentServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function boot()
3232
return true;
3333
});
3434

35-
FilamentVersions::addItem('Speedtest Tracker', 'v0.7.0');
35+
FilamentVersions::addItem('Speedtest Tracker', 'v0.7.1');
3636

3737
Filament::serving(function () {
3838
Filament::registerNavigationGroups([

0 commit comments

Comments
 (0)