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
24 changes: 24 additions & 0 deletions app/Filament/Exports/ResultExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ public static function getColumns(): array
->state(function (Result $record): ?string {
return $record->ping_jitter;
}),
ExportColumn::make('upload_latency_high')
->state(function (Result $record): ?string {
return $record->upload_latency_high;
}),
ExportColumn::make('upload_latency_low')
->state(function (Result $record): ?string {
return $record->upload_latency_low;
}),
ExportColumn::make('upload_latency_avg')
->state(function (Result $record): ?string {
return $record->upload_latency_iqm;
}),
ExportColumn::make('download_latency_high')
->state(function (Result $record): ?string {
return $record->download_latency_high;
}),
ExportColumn::make('download_latency_low')
->state(function (Result $record): ?string {
return $record->download_latency_low;
}),
ExportColumn::make('download_latency_avg')
->state(function (Result $record): ?string {
return $record->download_latency_iqm;
}),
ExportColumn::make('comments')
->enabledByDefault(false),
// ExportColumn::make('status'), // TODO: enable status when upgrading to PHP v8.3: https://php.watch/versions/8.3/dynamic-class-const-enum-member-syntax-support
Expand Down
4 changes: 4 additions & 0 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use App\Actions\Speedtests\RunOoklaSpeedtest;
use App\Filament\Widgets\RecentDownloadChartWidget;
use App\Filament\Widgets\RecentDownloadLatencyChartWidget;
use App\Filament\Widgets\RecentJitterChartWidget;
use App\Filament\Widgets\RecentPingChartWidget;
use App\Filament\Widgets\RecentUploadChartWidget;
use App\Filament\Widgets\RecentUploadLatencyChartWidget;
use App\Filament\Widgets\StatsOverviewWidget;
use App\Settings\GeneralSettings;
use Filament\Actions\Action;
Expand Down Expand Up @@ -67,6 +69,8 @@ protected function getHeaderWidgets(): array
RecentUploadChartWidget::make(),
RecentPingChartWidget::make(),
RecentJitterChartWidget::make(),
RecentUploadLatencyChartWidget::make(),
RecentDownloadLatencyChartWidget::make(),
];
}
}
48 changes: 48 additions & 0 deletions app/Filament/Resources/ResultResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,20 @@ public static function form(Form $form): Form
->label('Ping (ms)'),
Forms\Components\TextInput::make('data.download.latency.jitter')
->label('Download Jitter (ms)'),
Forms\Components\TextInput::make('data.download.latency.high')
->label('Download Latency High'),
Forms\Components\TextInput::make('data.download.latency.low')
->label('Download Latency low'),
Forms\Components\TextInput::make('data.download.latency.iqm')
->label('Download Latency iqm'),
Forms\Components\TextInput::make('data.upload.latency.jitter')
->label('Upload Jitter (ms)'),
Forms\Components\TextInput::make('data.upload.latency.high')
->label('Upload Latency High'),
Forms\Components\TextInput::make('data.upload.latency.low')
->label('Upload Latency low'),
Forms\Components\TextInput::make('data.upload.latency.iqm')
->label('Upload Latency iqm'),
Forms\Components\TextInput::make('data.ping.jitter')
->label('Ping Jitter (ms)'),
Forms\Components\TextInput::make('data.packetLoss')
Expand Down Expand Up @@ -151,12 +163,48 @@ public static function table(Table $table): Table
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->download->latency->jitter', $direction);
}),
Tables\Columns\TextColumn::make('download_latency_high')
->toggleable()
->toggledHiddenByDefault()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->download->latency->high', $direction);
}),
Tables\Columns\TextColumn::make('download_latency_low')
->toggleable()
->toggledHiddenByDefault()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->download->latency->low', $direction);
}),
Tables\Columns\TextColumn::make('download_latency_iqm')
->toggleable()
->toggledHiddenByDefault()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->download->latency->iqm', $direction);
}),
Tables\Columns\TextColumn::make('upload_jitter')
->toggleable()
->toggledHiddenByDefault()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->upload->latency->jitter', $direction);
}),
Tables\Columns\TextColumn::make('upload_latency_high')
->toggleable()
->toggledHiddenByDefault()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->upload->latency->high', $direction);
}),
Tables\Columns\TextColumn::make('upload_latency_low')
->toggleable()
->toggledHiddenByDefault()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->upload->latency->low', $direction);
}),
Tables\Columns\TextColumn::make('upload_latency_iqm')
->toggleable()
->toggledHiddenByDefault()
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderBy('data->upload->latency->iqm', $direction);
}),
Tables\Columns\TextColumn::make('ping_jitter')
->toggleable()
->toggledHiddenByDefault()
Expand Down
103 changes: 103 additions & 0 deletions app/Filament/Widgets/RecentDownloadLatencyChartWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace App\Filament\Widgets;

use App\Enums\ResultStatus;
use App\Helpers\TimeZoneHelper;
use App\Models\Result;
use App\Settings\GeneralSettings;
use Filament\Widgets\ChartWidget;

class RecentDownloadLatencyChartWidget extends ChartWidget
{
protected static ?string $heading = 'Download Latency';

protected int|string|array $columnSpan = 'full';

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

public ?string $filter = '24h';

protected function getPollingInterval(): ?string
{
return config('speedtest.dashboard_polling');
}

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

protected function getData(): array
{
$settings = new GeneralSettings();

$results = Result::query()
->select(['id', 'data', 'created_at'])
->where('status', '=', ResultStatus::Completed)
->when($this->filter == '24h', function ($query) {
$query->where('created_at', '>=', now()->subDay());
})
->when($this->filter == 'week', function ($query) {
$query->where('created_at', '>=', now()->subWeek());
})
->when($this->filter == 'month', function ($query) {
$query->where('created_at', '>=', now()->subMonth());
})
->orderBy('created_at')
->get();

return [
'datasets' => [
[
'label' => 'Average (ms)',
'data' => $results->map(fn ($item) => $item->download_latency_iqm ? number_format($item->pdownload_latency_iqm, 2) : 0),
'borderColor' => '#10b981',
'backgroundColor' => '#10b981',
'fill' => false,
'cubicInterpolationMode' => 'monotone',
'tension' => 0.4,
],
[
'label' => 'High (ms)',
'data' => $results->map(fn ($item) => $item->download_latency_high ? number_format($item->download_latency_high, 2) : 0),
'borderColor' => '#0ea5e9',
'backgroundColor' => '#0ea5e9',
'fill' => false,
'cubicInterpolationMode' => 'monotone',
'tension' => 0.4,
],
[
'label' => 'Low (ms)',
'data' => $results->map(fn ($item) => $item->download_latency_low ? number_format($item->download_latency_low, 2) : 0),
'borderColor' => '#8b5cf6',
'backgroundColor' => '#8b5cf6',
'fill' => false,
'cubicInterpolationMode' => 'monotone',
'tension' => 0.4,
],
],
'labels' => $results->map(fn ($item) => $item->created_at->timezone(TimeZoneHelper::displayTimeZone($settings))->format('M d - G:i')),
];
}

protected function getOptions(): array
{
return [
'scales' => [
'y' => [
'beginAtZero' => true,
],
],
];
}

protected function getType(): string
{
return 'line';
}
}
103 changes: 103 additions & 0 deletions app/Filament/Widgets/RecentUploadLatencyChartWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace App\Filament\Widgets;

use App\Enums\ResultStatus;
use App\Helpers\TimeZoneHelper;
use App\Models\Result;
use App\Settings\GeneralSettings;
use Filament\Widgets\ChartWidget;

class RecentUploadLatencyChartWidget extends ChartWidget
{
protected static ?string $heading = 'Upload Latency';

protected int|string|array $columnSpan = 'full';

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

public ?string $filter = '24h';

protected function getPollingInterval(): ?string
{
return config('speedtest.dashboard_polling');
}

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

protected function getData(): array
{
$settings = new GeneralSettings();

$results = Result::query()
->select(['id', 'data', 'created_at'])
->where('status', '=', ResultStatus::Completed)
->when($this->filter == '24h', function ($query) {
$query->where('created_at', '>=', now()->subDay());
})
->when($this->filter == 'week', function ($query) {
$query->where('created_at', '>=', now()->subWeek());
})
->when($this->filter == 'month', function ($query) {
$query->where('created_at', '>=', now()->subMonth());
})
->orderBy('created_at')
->get();

return [
'datasets' => [
[
'label' => 'Average (ms)',
'data' => $results->map(fn ($item) => $item->upload_latency_iqm ? number_format($item->upload_latency_iqm, 2) : 0),
'borderColor' => '#10b981',
'backgroundColor' => '#10b981',
'fill' => false,
'cubicInterpolationMode' => 'monotone',
'tension' => 0.4,
],
[
'label' => 'High (ms)',
'data' => $results->map(fn ($item) => $item->upload_latency_high ? number_format($item->upload_latency_high, 2) : 0),
'borderColor' => '#0ea5e9',
'backgroundColor' => '#0ea5e9',
'fill' => false,
'cubicInterpolationMode' => 'monotone',
'tension' => 0.4,
],
[
'label' => 'Low (ms)',
'data' => $results->map(fn ($item) => $item->upload_latency_low ? number_format($item->upload_latency_low, 2) : 0),
'borderColor' => '#8b5cf6',
'backgroundColor' => '#8b5cf6',
'fill' => false,
'cubicInterpolationMode' => 'monotone',
'tension' => 0.4,
],
],
'labels' => $results->map(fn ($item) => $item->created_at->timezone(TimeZoneHelper::displayTimeZone($settings))->format('M d - G:i')),
];
}

protected function getOptions(): array
{
return [
'scales' => [
'y' => [
'beginAtZero' => true,
],
],
];
}

protected function getType(): string
{
return 'line';
}
}
Loading