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
6 changes: 4 additions & 2 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +53,8 @@ protected function getHeaderWidgets(): array
{
return [
StatsOverviewWidget::make(),
RecentSpeedChartWidget::make(),
RecentDownloadChartWidget::make(),
RecentUploadChartWidget::make(),
RecentPingChartWidget::make(),
RecentJitterChartWidget::make(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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());
Expand All @@ -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')),
];
Expand All @@ -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,
],
],
];
Expand Down
15 changes: 13 additions & 2 deletions app/Filament/Widgets/RecentJitterChartWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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());
Expand Down Expand Up @@ -85,6 +85,17 @@ protected function getData(): array
];
}

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

protected function getType(): string
{
return 'line';
Expand Down
15 changes: 13 additions & 2 deletions app/Filament/Widgets/RecentPingChartWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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());
Expand Down Expand Up @@ -67,6 +67,17 @@ protected function getData(): array
];
}

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

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

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 RecentUploadChartWidget extends ChartWidget
{
protected static ?string $heading = 'Upload (Mbps)';

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', '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';
}
}
6 changes: 5 additions & 1 deletion resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
@endisset

<div class="col-span-full">
@livewire(\App\Filament\Widgets\RecentSpeedChartWidget::class)
@livewire(\App\Filament\Widgets\RecentDownloadChartWidget::class)
</div>

<div class="col-span-full">
@livewire(\App\Filament\Widgets\RecentUploadChartWidget::class)
</div>

<div class="col-span-full">
Expand Down