Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 206 additions & 86 deletions _ide_helper.php

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Filament\Pages;

use App\Filament\Widgets\RecentJitterChart;
use App\Filament\Widgets\RecentPingChart;
use App\Filament\Widgets\RecentSpeedChart;
use App\Filament\Widgets\StatsOverview;
use App\Jobs\ExecSpeedtest;
use App\Settings\GeneralSettings;
Expand All @@ -26,6 +29,9 @@ public function getHeaderWidgets(): array
{
return [
StatsOverview::class,
RecentSpeedChart::class,
RecentPingChart::class,
RecentJitterChart::class,
];
}

Expand Down
98 changes: 98 additions & 0 deletions app/Filament/Widgets/RecentJitterChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace App\Filament\Widgets;

use App\Models\Result;
use App\Settings\GeneralSettings;
use Filament\Widgets\LineChartWidget;

class RecentJitterChart extends LineChartWidget
{
protected int|string|array $columnSpan = 'full';

protected static ?string $maxHeight = '300px';

protected function getHeading(): string
{
return 'Jitter (ms)';
}

protected function getFilters(): ?array
{
return [
'today' => 'Today',
'week' => 'Last week',
'month' => 'Last month',
];
}

protected function getData(): array
{
$range = [];

$settings = new GeneralSettings();

switch ($this->filter) {
case 'today':
$range = [
['created_at', '>=', now()->startOfDay()],
['created_at', '<=', now()],
];
break;

case 'week':
$range = [
['created_at', '>=', now()->subWeek()],
['created_at', '<=', now()],
];
break;

case 'month':
$range = [
['created_at', '>=', now()->subMonth()],
['created_at', '<=', now()],
];
break;
}

$results = Result::query()
->select(['data', 'created_at'])
->where($range)
->get();

return [
'datasets' => [
[
'label' => 'Download',
'data' => $results->map(fn ($item) => json_decode($item->data)->download->latency->jitter),
'borderColor' => '#0ea5e9',
'backgroundColor' => '#0ea5e9',
],
[
'label' => 'Upload',
'data' => $results->map(fn ($item) => json_decode($item->data)->upload->latency->jitter),
'borderColor' => '#8b5cf6',
'backgroundColor' => '#8b5cf6',
],
[
'label' => 'Ping',
'data' => $results->map(fn ($item) => json_decode($item->data)->ping->jitter),
'borderColor' => '#10b981',
'backgroundColor' => '#10b981',
],
],
'labels' => $results->map(fn ($item) => $item->created_at->timezone($settings->timezone)->format('M d - G:i')),
];
}

protected static ?array $options = [
'plugins' => [
//
],
'scales' => [
'y' => [
'suggestedMin' => 0,
],
],
];
}
86 changes: 86 additions & 0 deletions app/Filament/Widgets/RecentPingChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Filament\Widgets;

use App\Models\Result;
use App\Settings\GeneralSettings;
use Filament\Widgets\LineChartWidget;

class RecentPingChart extends LineChartWidget
{
protected int|string|array $columnSpan = 'full';

protected static ?string $maxHeight = '300px';

protected function getHeading(): string
{
return 'Ping (ms)';
}

protected function getFilters(): ?array
{
return [
'today' => 'Today',
'week' => 'Last week',
'month' => 'Last month',
];
}

protected function getData(): array
{
$range = [];

$settings = new GeneralSettings();

switch ($this->filter) {
case 'today':
$range = [
['created_at', '>=', now()->startOfDay()],
['created_at', '<=', now()],
];
break;

case 'week':
$range = [
['created_at', '>=', now()->subWeek()],
['created_at', '<=', now()],
];
break;

case 'month':
$range = [
['created_at', '>=', now()->subMonth()],
['created_at', '<=', now()],
];
break;
}

$results = Result::query()
->select(['ping', 'created_at'])
->where($range)
->get();

return [
'datasets' => [
[
'label' => 'Ping',
'data' => $results->map(fn ($item) => $item->ping),
'borderColor' => '#10b981',
'backgroundColor' => '#10b981',
],
],
'labels' => $results->map(fn ($item) => $item->created_at->timezone($settings->timezone)->format('M d - G:i')),
];
}

protected static ?array $options = [
'plugins' => [
//
],
'scales' => [
'y' => [
'min' => 0,
],
],
];
}
92 changes: 92 additions & 0 deletions app/Filament/Widgets/RecentSpeedChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace App\Filament\Widgets;

use App\Models\Result;
use App\Settings\GeneralSettings;
use Filament\Widgets\LineChartWidget;

class RecentSpeedChart extends LineChartWidget
{
protected int|string|array $columnSpan = 'full';

protected static ?string $maxHeight = '300px';

protected function getHeading(): string
{
return 'Download / Upload (mbps)';
}

protected function getFilters(): ?array
{
return [
'today' => 'Today',
'week' => 'Last week',
'month' => 'Last month',
];
}

protected function getData(): array
{
$range = [];

$settings = new GeneralSettings();

switch ($this->filter) {
case 'today':
$range = [
['created_at', '>=', now()->startOfDay()],
['created_at', '<=', now()],
];
break;

case 'week':
$range = [
['created_at', '>=', now()->subWeek()],
['created_at', '<=', now()],
];
break;

case 'month':
$range = [
['created_at', '>=', now()->subMonth()],
['created_at', '<=', now()],
];
break;
}

$results = Result::query()
->select(['download', 'upload', 'created_at'])
->where($range)
->get();

return [
'datasets' => [
[
'label' => 'Download',
'data' => $results->map(fn ($item) => formatBits(formatBytesToBits($item->download), 2, false)),
'borderColor' => '#0ea5e9',
'backgroundColor' => '#0ea5e9',
],
[
'label' => 'Upload',
'data' => $results->map(fn ($item) => formatBits(formatBytesToBits($item->upload), 2, false)),
'borderColor' => '#8b5cf6',
'backgroundColor' => '#8b5cf6',
],
],
'labels' => $results->map(fn ($item) => $item->created_at->timezone($settings->timezone)->format('M d - G:i')),
];
}

protected static ?array $options = [
'plugins' => [
//
],
'scales' => [
'y' => [
'min' => 0,
],
],
];
}
Loading