diff --git a/app/Filament/Pages/Dashboard.php b/app/Filament/Pages/Dashboard.php index 590f2828d..46aa2489e 100644 --- a/app/Filament/Pages/Dashboard.php +++ b/app/Filament/Pages/Dashboard.php @@ -3,9 +3,10 @@ namespace App\Filament\Pages; use App\Console\Commands\RunOoklaSpeedtest; +use App\Filament\Widgets\RecentDownloadChartWidget; use App\Filament\Widgets\RecentJitterChartWidget; use App\Filament\Widgets\RecentPingChartWidget; -use App\Filament\Widgets\RecentSpeedChartWidget; +use App\Filament\Widgets\RecentUploadChartWidget; use App\Filament\Widgets\StatsOverviewWidget; use App\Settings\GeneralSettings; use Filament\Actions\Action; @@ -52,7 +53,8 @@ protected function getHeaderWidgets(): array { return [ StatsOverviewWidget::make(), - RecentSpeedChartWidget::make(), + RecentDownloadChartWidget::make(), + RecentUploadChartWidget::make(), RecentPingChartWidget::make(), RecentJitterChartWidget::make(), ]; diff --git a/app/Filament/Widgets/RecentSpeedChartWidget.php b/app/Filament/Widgets/RecentDownloadChartWidget.php similarity index 66% rename from app/Filament/Widgets/RecentSpeedChartWidget.php rename to app/Filament/Widgets/RecentDownloadChartWidget.php index 751a9f3d3..a9640c889 100644 --- a/app/Filament/Widgets/RecentSpeedChartWidget.php +++ b/app/Filament/Widgets/RecentDownloadChartWidget.php @@ -3,18 +3,19 @@ namespace App\Filament\Widgets; use App\Enums\ResultStatus; +use App\Helpers\Number; use App\Helpers\TimeZoneHelper; use App\Models\Result; use App\Settings\GeneralSettings; use Filament\Widgets\ChartWidget; -class RecentSpeedChartWidget extends ChartWidget +class RecentDownloadChartWidget extends ChartWidget { - protected static ?string $heading = 'Download / Upload'; + protected static ?string $heading = 'Download (Mbps)'; protected int|string|array $columnSpan = 'full'; - protected static ?string $maxHeight = '300px'; + protected static ?string $maxHeight = '250px'; public ?string $filter = '24h'; @@ -37,7 +38,7 @@ protected function getData(): array $settings = new GeneralSettings(); $results = Result::query() - ->select(['id', 'download', 'upload', 'created_at']) + ->select(['id', 'download', 'created_at']) ->where('status', '=', ResultStatus::Completed) ->when($this->filter == '24h', function ($query) { $query->where('created_at', '>=', now()->subDay()); @@ -55,22 +56,13 @@ protected function getData(): array 'datasets' => [ [ 'label' => 'Download', - 'data' => $results->map(fn ($item) => ! blank($item->download) ? toBits(convertSize($item->download), 2) : 0), + 'data' => $results->map(fn ($item) => ! blank($item->download) ? Number::bitsToMagnitude(bits: $item->download_bits, precision: 2, magnitude: 'mbit') : 0), 'borderColor' => '#0ea5e9', 'backgroundColor' => '#0ea5e9', 'fill' => false, 'cubicInterpolationMode' => 'monotone', 'tension' => 0.4, ], - [ - 'label' => 'Upload', - 'data' => $results->map(fn ($item) => ! blank($item->upload) ? toBits(convertSize($item->upload), 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')), ]; @@ -79,19 +71,14 @@ protected function getData(): array protected function getOptions(): array { return [ - 'scales' => [ - 'x' => [ - 'display' => true, - 'title' => [ - 'display' => true, - ], + 'plugins' => [ + 'legend' => [ + 'display' => false, ], + ], + 'scales' => [ 'y' => [ - 'display' => true, - 'title' => [ - 'display' => true, - 'text' => 'Mbps', - ], + 'beginAtZero' => true, ], ], ]; diff --git a/app/Filament/Widgets/RecentJitterChartWidget.php b/app/Filament/Widgets/RecentJitterChartWidget.php index e9e34f423..03d0e09be 100644 --- a/app/Filament/Widgets/RecentJitterChartWidget.php +++ b/app/Filament/Widgets/RecentJitterChartWidget.php @@ -14,7 +14,7 @@ class RecentJitterChartWidget extends ChartWidget protected int|string|array $columnSpan = 'full'; - protected static ?string $maxHeight = '300px'; + protected static ?string $maxHeight = '250px'; public ?string $filter = '24h'; @@ -37,7 +37,7 @@ protected function getData(): array $settings = new GeneralSettings(); $results = Result::query() - ->select(['data', 'created_at']) + ->select(['id', 'data', 'created_at']) ->where('status', '=', ResultStatus::Completed) ->when($this->filter == '24h', function ($query) { $query->where('created_at', '>=', now()->subDay()); @@ -85,6 +85,17 @@ protected function getData(): array ]; } + protected function getOptions(): array + { + return [ + 'scales' => [ + 'y' => [ + 'beginAtZero' => true, + ], + ], + ]; + } + protected function getType(): string { return 'line'; diff --git a/app/Filament/Widgets/RecentPingChartWidget.php b/app/Filament/Widgets/RecentPingChartWidget.php index 3a467c8c0..068cfd5ba 100644 --- a/app/Filament/Widgets/RecentPingChartWidget.php +++ b/app/Filament/Widgets/RecentPingChartWidget.php @@ -14,7 +14,7 @@ class RecentPingChartWidget extends ChartWidget protected int|string|array $columnSpan = 'full'; - protected static ?string $maxHeight = '300px'; + protected static ?string $maxHeight = '250px'; public ?string $filter = '24h'; @@ -37,7 +37,7 @@ protected function getData(): array $settings = new GeneralSettings(); $results = Result::query() - ->select(['ping', 'created_at']) + ->select(['id', 'ping', 'created_at']) ->where('status', '=', ResultStatus::Completed) ->when($this->filter == '24h', function ($query) { $query->where('created_at', '>=', now()->subDay()); @@ -67,6 +67,17 @@ protected function getData(): array ]; } + protected function getOptions(): array + { + return [ + 'scales' => [ + 'y' => [ + 'beginAtZero' => true, + ], + ], + ]; + } + protected function getType(): string { return 'line'; diff --git a/app/Filament/Widgets/RecentUploadChartWidget.php b/app/Filament/Widgets/RecentUploadChartWidget.php new file mode 100644 index 000000000..aab60eaab --- /dev/null +++ b/app/Filament/Widgets/RecentUploadChartWidget.php @@ -0,0 +1,91 @@ + 'Last 24h', + 'week' => 'Last week', + 'month' => 'Last month', + ]; + } + + protected function getData(): array + { + $settings = new GeneralSettings(); + + $results = Result::query() + ->select(['id', 'upload', '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' => 'Upload', + 'data' => $results->map(fn ($item) => ! blank($item->upload) ? Number::bitsToMagnitude(bits: $item->upload_bits, precision: 2, magnitude: 'mbit') : 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 [ + 'plugins' => [ + 'legend' => [ + 'display' => false, + ], + ], + 'scales' => [ + 'y' => [ + 'beginAtZero' => true, + ], + ], + ]; + } + + protected function getType(): string + { + return 'line'; + } +} diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index fe5219f90..3a73b77f9 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -11,7 +11,11 @@ @endisset