diff --git a/app/Filament/Widgets/RecentDownloadChartWidget.php b/app/Filament/Widgets/RecentDownloadChartWidget.php index 5d4ba1279..4600a3f21 100644 --- a/app/Filament/Widgets/RecentDownloadChartWidget.php +++ b/app/Filament/Widgets/RecentDownloadChartWidget.php @@ -3,6 +3,7 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Helpers\Average; use App\Helpers\Number; use App\Models\Result; use Filament\Widgets\ChartWidget; @@ -53,12 +54,24 @@ protected function getData(): array [ 'label' => 'Download', 'data' => $results->map(fn ($item) => ! blank($item->download) ? Number::bitsToMagnitude(bits: $item->download_bits, precision: 2, magnitude: 'mbit') : null), - 'borderColor' => '#0ea5e9', - 'backgroundColor' => '#0ea5e9', - 'pointBackgroundColor' => '#0ea5e9', + 'borderColor' => 'rgba(14, 165, 233)', + 'backgroundColor' => 'rgba(14, 165, 233, 0.1)', + 'pointBackgroundColor' => 'rgba(14, 165, 233)', + 'fill' => true, + 'cubicInterpolationMode' => 'monotone', + 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, + ], + [ + 'label' => 'Average', + 'data' => array_fill(0, count($results), Average::averageDownload($results)), + 'borderColor' => 'rgb(243, 7, 6, 1)', + 'pointBackgroundColor' => 'rgb(243, 7, 6, 1)', 'fill' => false, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'borderDash' => [5, 5], + 'pointRadius' => 0, ], ], 'labels' => $results->map(fn ($item) => $item->created_at->timezone(config('app.display_timezone'))->format(config('app.chart_datetime_format'))), @@ -70,12 +83,19 @@ protected function getOptions(): array return [ 'plugins' => [ 'legend' => [ - 'display' => false, + 'display' => true, + + ], + 'tooltip' => [ + 'enabled' => true, + 'mode' => 'index', + 'intersect' => false, + 'position' => 'nearest', ], ], 'scales' => [ 'y' => [ - 'beginAtZero' => true, + 'beginAtZero' => config('app.chart_begin_at_zero'), ], ], ]; diff --git a/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php b/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php index e588ac38e..b5040abc9 100644 --- a/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php +++ b/app/Filament/Widgets/RecentDownloadLatencyChartWidget.php @@ -52,32 +52,35 @@ protected function getData(): array [ 'label' => 'Average (ms)', 'data' => $results->map(fn ($item) => $item->download_latency_iqm), - 'borderColor' => '#10b981', - 'backgroundColor' => '#10b981', - 'pointBackgroundColor' => '#10b981', - 'fill' => false, + 'borderColor' => 'rgba(16, 185, 129)', + 'backgroundColor' => 'rgba(16, 185, 129, 0.1)', + 'pointBackgroundColor' => 'rgba(16, 185, 129)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], [ 'label' => 'High (ms)', 'data' => $results->map(fn ($item) => $item->download_latency_high), - 'borderColor' => '#0ea5e9', - 'backgroundColor' => '#0ea5e9', - 'pointBackgroundColor' => '#0ea5e9', - 'fill' => false, + 'borderColor' => 'rgba(14, 165, 233)', + 'backgroundColor' => 'rgba(14, 165, 233, 0.1)', + 'pointBackgroundColor' => 'rgba(14, 165, 233)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], [ 'label' => 'Low (ms)', 'data' => $results->map(fn ($item) => $item->download_latency_low), - 'borderColor' => '#8b5cf6', - 'backgroundColor' => '#8b5cf6', - 'pointBackgroundColor' => '#8b5cf6', - 'fill' => false, + 'borderColor' => 'rgba(139, 92, 246)', + 'backgroundColor' => 'rgba(139, 92, 246, 0.1)', + 'pointBackgroundColor' => 'rgba(139, 92, 246)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], ], 'labels' => $results->map(fn ($item) => $item->created_at->timezone(config('app.display_timezone'))->format(config('app.chart_datetime_format'))), @@ -87,9 +90,20 @@ protected function getData(): array protected function getOptions(): array { return [ + 'plugins' => [ + 'legend' => [ + 'display' => true, + ], + 'tooltip' => [ + 'enabled' => true, + 'mode' => 'index', + 'intersect' => false, + 'position' => 'nearest', + ], + ], 'scales' => [ 'y' => [ - 'beginAtZero' => true, + 'beginAtZero' => config('app.chart_begin_at_zero'), ], ], ]; diff --git a/app/Filament/Widgets/RecentJitterChartWidget.php b/app/Filament/Widgets/RecentJitterChartWidget.php index b0bfc1fea..5db523eca 100644 --- a/app/Filament/Widgets/RecentJitterChartWidget.php +++ b/app/Filament/Widgets/RecentJitterChartWidget.php @@ -52,32 +52,35 @@ protected function getData(): array [ 'label' => 'Download (ms)', 'data' => $results->map(fn ($item) => $item->download_jitter), - 'borderColor' => '#0ea5e9', - 'backgroundColor' => '#0ea5e9', - 'pointBackgroundColor' => '#0ea5e9', - 'fill' => false, + 'borderColor' => 'rgba(14, 165, 233)', + 'backgroundColor' => 'rgba(14, 165, 233, 0.1)', + 'pointBackgroundColor' => 'rgba(14, 165, 233)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], [ 'label' => 'Upload (ms)', 'data' => $results->map(fn ($item) => $item->upload_jitter), - 'borderColor' => '#8b5cf6', - 'backgroundColor' => '#8b5cf6', - 'pointBackgroundColor' => '#8b5cf6', - 'fill' => false, + 'borderColor' => 'rgba(139, 92, 246)', + 'backgroundColor' => 'rgba(139, 92, 246, 0.1)', + 'pointBackgroundColor' => 'rgba(139, 92, 246)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], [ 'label' => 'Ping (ms)', 'data' => $results->map(fn ($item) => $item->ping_jitter), - 'borderColor' => '#10b981', - 'backgroundColor' => '#10b981', - 'pointBackgroundColor' => '#10b981', - 'fill' => false, + 'borderColor' => 'rgba(16, 185, 129)', + 'backgroundColor' => 'rgba(16, 185, 129, 0.1)', + 'pointBackgroundColor' => 'rgba(16, 185, 129)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], ], 'labels' => $results->map(fn ($item) => $item->created_at->timezone(config('app.display_timezone'))->format(config('app.chart_datetime_format'))), @@ -87,9 +90,20 @@ protected function getData(): array protected function getOptions(): array { return [ + 'plugins' => [ + 'legend' => [ + 'display' => true, + ], + 'tooltip' => [ + 'enabled' => true, + 'mode' => 'index', + 'intersect' => false, + 'position' => 'nearest', + ], + ], 'scales' => [ 'y' => [ - 'beginAtZero' => true, + 'beginAtZero' => config('app.chart_begin_at_zero'), ], ], ]; diff --git a/app/Filament/Widgets/RecentPingChartWidget.php b/app/Filament/Widgets/RecentPingChartWidget.php index f0b9781f7..240710057 100644 --- a/app/Filament/Widgets/RecentPingChartWidget.php +++ b/app/Filament/Widgets/RecentPingChartWidget.php @@ -3,6 +3,7 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Helpers\Average; use App\Models\Result; use Filament\Widgets\ChartWidget; @@ -50,14 +51,26 @@ protected function getData(): array return [ 'datasets' => [ [ - 'label' => 'Ping (ms)', + 'label' => 'Ping', 'data' => $results->map(fn ($item) => $item->ping), - 'borderColor' => '#10b981', - 'backgroundColor' => '#10b981', - 'pointBackgroundColor' => '#10b981', + 'borderColor' => 'rgba(16, 185, 129)', + 'backgroundColor' => 'rgba(16, 185, 129, 0.1)', + 'pointBackgroundColor' => 'rgba(16, 185, 129)', + 'fill' => true, + 'cubicInterpolationMode' => 'monotone', + 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, + ], + [ + 'label' => 'Average', + 'data' => array_fill(0, count($results), Average::averagePing($results)), + 'borderColor' => 'rgb(243, 7, 6, 1)', + 'pointBackgroundColor' => 'rgb(243, 7, 6, 1)', 'fill' => false, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'borderDash' => [5, 5], + 'pointRadius' => 0, ], ], 'labels' => $results->map(fn ($item) => $item->created_at->timezone(config('app.display_timezone'))->format(config('app.chart_datetime_format'))), @@ -69,12 +82,18 @@ protected function getOptions(): array return [ 'plugins' => [ 'legend' => [ - 'display' => false, + 'display' => true, + ], + 'tooltip' => [ + 'enabled' => true, + 'mode' => 'index', + 'intersect' => false, + 'position' => 'nearest', ], ], 'scales' => [ 'y' => [ - 'beginAtZero' => true, + 'beginAtZero' => config('app.chart_begin_at_zero'), ], ], ]; diff --git a/app/Filament/Widgets/RecentUploadChartWidget.php b/app/Filament/Widgets/RecentUploadChartWidget.php index c31345c8b..00d07a098 100644 --- a/app/Filament/Widgets/RecentUploadChartWidget.php +++ b/app/Filament/Widgets/RecentUploadChartWidget.php @@ -3,6 +3,7 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Helpers\Average; use App\Helpers\Number; use App\Models\Result; use Filament\Widgets\ChartWidget; @@ -53,12 +54,24 @@ protected function getData(): array [ 'label' => 'Upload', 'data' => $results->map(fn ($item) => ! blank($item->upload) ? Number::bitsToMagnitude(bits: $item->upload_bits, precision: 2, magnitude: 'mbit') : null), - 'borderColor' => '#8b5cf6', - 'backgroundColor' => '#8b5cf6', - 'pointBackgroundColor' => '#8b5cf6', + 'borderColor' => 'rgba(139, 92, 246)', + 'backgroundColor' => 'rgba(139, 92, 246, 0.1)', + 'pointBackgroundColor' => 'rgba(139, 92, 246)', + 'fill' => true, + 'cubicInterpolationMode' => 'monotone', + 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, + ], + [ + 'label' => 'Average', + 'data' => array_fill(0, count($results), Average::averageUpload($results)), + 'borderColor' => 'rgb(243, 7, 6, 1)', + 'pointBackgroundColor' => 'rgb(243, 7, 6, 1)', 'fill' => false, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'borderDash' => [5, 5], + 'pointRadius' => 0, ], ], 'labels' => $results->map(fn ($item) => $item->created_at->timezone(config('app.display_timezone'))->format(config('app.chart_datetime_format'))), @@ -70,12 +83,18 @@ protected function getOptions(): array return [ 'plugins' => [ 'legend' => [ - 'display' => false, + 'display' => true, + ], + 'tooltip' => [ + 'enabled' => true, + 'mode' => 'index', + 'intersect' => false, + 'position' => 'nearest', ], ], 'scales' => [ 'y' => [ - 'beginAtZero' => true, + 'beginAtZero' => config('app.chart_begin_at_zero'), ], ], ]; diff --git a/app/Filament/Widgets/RecentUploadLatencyChartWidget.php b/app/Filament/Widgets/RecentUploadLatencyChartWidget.php index 956092b37..9397f8c52 100644 --- a/app/Filament/Widgets/RecentUploadLatencyChartWidget.php +++ b/app/Filament/Widgets/RecentUploadLatencyChartWidget.php @@ -52,32 +52,35 @@ protected function getData(): array [ 'label' => 'Average (ms)', 'data' => $results->map(fn ($item) => $item->upload_latency_iqm), - 'borderColor' => '#10b981', - 'backgroundColor' => '#10b981', - 'pointBackgroundColor' => '#10b981', - 'fill' => false, + 'borderColor' => 'rgba(16, 185, 129)', + 'backgroundColor' => 'rgba(16, 185, 129, 0.1)', + 'pointBackgroundColor' => 'rgba(16, 185, 129)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], [ 'label' => 'High (ms)', 'data' => $results->map(fn ($item) => $item->upload_latency_high), - 'borderColor' => '#0ea5e9', - 'backgroundColor' => '#0ea5e9', - 'pointBackgroundColor' => '#0ea5e9', - 'fill' => false, + 'borderColor' => 'rgba(14, 165, 233)', + 'backgroundColor' => 'rgba(14, 165, 233, 0.1)', + 'pointBackgroundColor' => 'rgba(14, 165, 233)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], [ 'label' => 'Low (ms)', 'data' => $results->map(fn ($item) => $item->upload_latency_low), - 'borderColor' => '#8b5cf6', - 'backgroundColor' => '#8b5cf6', - 'pointBackgroundColor' => '#8b5cf6', - 'fill' => false, + 'borderColor' => 'rgba(139, 92, 246)', + 'backgroundColor' => 'rgba(139, 92, 246, 0.1)', + 'pointBackgroundColor' => 'rgba(139, 92, 246)', + 'fill' => true, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, + 'pointRadius' => count($results) <= 24 ? 3 : 0, ], ], 'labels' => $results->map(fn ($item) => $item->created_at->timezone(config('app.display_timezone'))->format(config('app.chart_datetime_format'))), @@ -87,9 +90,20 @@ protected function getData(): array protected function getOptions(): array { return [ + 'plugins' => [ + 'legend' => [ + 'display' => true, + ], + 'tooltip' => [ + 'enabled' => true, + 'mode' => 'index', + 'intersect' => false, + 'position' => 'nearest', + ], + ], 'scales' => [ 'y' => [ - 'beginAtZero' => true, + 'beginAtZero' => config('app.chart_begin_at_zero'), ], ], ]; diff --git a/app/Helpers/Average.php b/app/Helpers/Average.php new file mode 100644 index 000000000..c93d2d5cd --- /dev/null +++ b/app/Helpers/Average.php @@ -0,0 +1,44 @@ +map(function ($item) use ($magnitude, $precision) { + return ! blank($item->download) + ? Number::bitsToMagnitude(bits: $item->download_bits, precision: $precision, magnitude: $magnitude) + : 0; + })->avg(), + $precision + ); + } + + public static function averageUpload(Collection $results, int $precision = 2, string $magnitude = 'mbit'): float + { + return round( + $results->map(function ($item) use ($magnitude, $precision) { + return ! blank($item->upload) + ? Number::bitsToMagnitude(bits: $item->upload_bits, precision: $precision, magnitude: $magnitude) + : 0; + })->avg(), + $precision + ); + } + + public static function averagePing(Collection $results, int $precision = 2): float + { + $avgPing = $results->filter(function ($item) { + return ! blank($item->ping); + })->avg('ping'); + + return round($avgPing, $precision); + } +} diff --git a/app/Livewire/Topbar/RunSpeedtestAction.php b/app/Livewire/Topbar/RunSpeedtestAction.php index fc58a0a5b..e1b0ee5c6 100644 --- a/app/Livewire/Topbar/RunSpeedtestAction.php +++ b/app/Livewire/Topbar/RunSpeedtestAction.php @@ -22,7 +22,7 @@ class RunSpeedtestAction extends Component implements HasActions, HasForms public function dashboardAction(): Action { return Action::make('home') - ->label('Dashboard') + ->label('Public Dashboard') ->icon('heroicon-o-chart-bar') ->iconPosition(IconPosition::Before) ->color('gray') diff --git a/config/app.php b/config/app.php index 60b38f700..8f63418fa 100644 --- a/config/app.php +++ b/config/app.php @@ -6,6 +6,8 @@ 'env' => env('APP_ENV', 'production'), + 'chart_begin_at_zero' => env('CHART_BEGIN_AT_ZERO', true), + 'chart_datetime_format' => env('CHART_DATETIME_FORMAT', 'M. j - G:i'), 'datetime_format' => env('DATETIME_FORMAT', 'M. jS, Y g:ia'), diff --git a/config/speedtest.php b/config/speedtest.php index 4649a7daa..6a8b40284 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -4,9 +4,9 @@ return [ - 'build_date' => Carbon::parse('2024-11-26'), + 'build_date' => Carbon::parse('2024-11-27'), - 'build_version' => 'v0.24.2', + 'build_version' => 'v0.24.3', /** * General settings.