Skip to content

Commit

Permalink
Failed speedtests (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Jan 12, 2023
1 parent 755ba47 commit 462bb59
Show file tree
Hide file tree
Showing 18 changed files with 269 additions and 232 deletions.
11 changes: 11 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -351,6 +352,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -558,6 +560,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -765,6 +768,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -972,6 +976,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -1179,6 +1184,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -1386,6 +1392,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -1593,6 +1600,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -1800,6 +1808,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -2007,6 +2016,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down Expand Up @@ -2214,6 +2224,7 @@
'Illuminate\Testing\ParallelTesting' => \Illuminate\Testing\ParallelTesting::class,
'Livewire\LivewireComponentsFinder' => \Livewire\LivewireComponentsFinder::class,
'Livewire\LivewireManager' => \Livewire\LivewireManager::class,
'NotificationChannels\Telegram\Telegram' => \NotificationChannels\Telegram\Telegram::class,
'NunoMaduro\Collision\Contracts\Provider' => \NunoMaduro\Collision\Provider::class,
'Spatie\FlareClient\Flare' => \Spatie\FlareClient\Flare::class,
'Spatie\Ignition\Config\IgnitionConfig' => \Spatie\Ignition\Config\IgnitionConfig::class,
Expand Down
6 changes: 0 additions & 6 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ protected function getActions(): array

public function getHeaderWidgets(): array
{
if (! $this->resultsCount) {
return [];
}

return [
StatsOverview::class,
];
Expand Down Expand Up @@ -85,8 +81,6 @@ public function queueSpeedtest(GeneralSettings $settings)
}

$speedtest = [
'enabled' => ! blank($settings->speedtest_schedule),
'schedule' => optional($settings)->speedtest_schedule,
'ookla_server_id' => $ookla_server_id,
];

Expand Down
138 changes: 113 additions & 25 deletions app/Filament/Resources/ResultResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
use App\Filament\Resources\ResultResource\Pages;
use App\Models\Result;
use App\Settings\GeneralSettings;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ViewColumn;
use Illuminate\Database\Eloquent\Builder;

class ResultResource extends Resource
{
Expand All @@ -21,6 +25,71 @@ class ResultResource extends Resource

protected static ?string $navigationLabel = 'Results';

public static function form(Form $form): Form
{
$settings = new GeneralSettings();

return $form
->schema([
Forms\Components\Grid::make([
'default' => 2,
'md' => 3,
])->schema([
Forms\Components\Grid::make([
'default' => 2,
'md' => 3,
])
->schema([
Forms\Components\TextInput::make('id')
->label('ID'),
Forms\Components\TextInput::make('created_at')
->label('Created')
->afterStateHydrated(function (TextInput $component, $state) use ($settings) {
$component->state(Carbon::parse($state)->format($settings->time_format ?? 'M j, Y G:i:s'));
})
->columnSpan(2),
Forms\Components\TextInput::make('server_id')
->label('Server ID'),
Forms\Components\TextInput::make('server_name')
->label('Server name')
->columnSpan(2),
Forms\Components\TextInput::make('server_host')
->label('Server host')
->columnSpan([
'default' => 2,
'md' => 3,
]),
Forms\Components\TextInput::make('download')
->label('Download (Mbps)')
->afterStateHydrated(function (TextInput $component, $state) {
$component->state(! blank($state) ? formatBits(formatBytestoBits($state), 3, false) : '');
}),
Forms\Components\TextInput::make('upload')
->label('Upload (Mbps)')
->afterStateHydrated(function (TextInput $component, $state) {
$component->state(! blank($state) ? formatBits(formatBytestoBits($state), 3, false) : '');
}),
Forms\Components\TextInput::make('ping')
->label('Ping (Ms)'),
])
->columnSpan(2),
Forms\Components\Card::make()
->schema([
Forms\Components\Checkbox::make('successful'),
Forms\Components\Checkbox::make('scheduled'),
])
->columns(1)
->columnSpan([
'default' => 2,
'md' => 1,
]),
]),
Forms\Components\Textarea::make('data')
->rows(10)
->columnSpan(2),
]);
}

public static function table(Table $table): Table
{
$settings = new GeneralSettings();
Expand All @@ -29,59 +98,78 @@ public static function table(Table $table): Table
->columns([
TextColumn::make('id')
->label('ID'),
TextColumn::make('server')
->getStateUsing(fn (Result $record): string|null => ! blank($record->server_id) ? $record->server_id.' ('.$record->server_name.')' : null)
->toggleable(),
IconColumn::make('successful')
->boolean()
->toggleable(),
IconColumn::make('scheduled')
->boolean()
->toggleable()
->toggledHiddenByDefault(),
ViewColumn::make('download')
->view('tables.columns.bits-column'),
ViewColumn::make('upload')
->view('tables.columns.bits-column'),
->toggleable(),
TextColumn::make('download')
->label('Download (Mbps)')
->getStateUsing(fn (Result $record): string|null => ! blank($record->download) ? formatBits(formatBytestoBits($record->download), 3, false) : null),
TextColumn::make('upload')
->label('Upload (Mbps)')
->getStateUsing(fn (Result $record): string|null => ! blank($record->upload) ? formatBits(formatBytestoBits($record->upload), 3, false) : null),
TextColumn::make('ping')
->label('Ping (Ms)')
->toggleable(),
TextColumn::make('download_jitter')
->getStateUsing(function (Result $record): string|null {
return json_decode($record->data, true)['download']['latency']['jitter'] ?? null;
})
->getStateUsing(fn (Result $record): string|null => json_decode($record->data, true)['download']['latency']['jitter'] ?? null)
->toggleable()
->toggledHiddenByDefault(),
TextColumn::make('upload_jitter')
->getStateUsing(function (Result $record): string|null {
return json_decode($record->data, true)['upload']['latency']['jitter'] ?? null;
})
->getStateUsing(fn (Result $record): string|null => json_decode($record->data, true)['upload']['latency']['jitter'] ?? null)
->toggleable()
->toggledHiddenByDefault(),
TextColumn::make('ping_jitter')
->getStateUsing(function (Result $record): string|null {
return json_decode($record->data, true)['ping']['jitter'] ?? null;
})
->getStateUsing(fn (Result $record): string|null => json_decode($record->data, true)['ping']['jitter'] ?? null)
->toggleable()
->toggledHiddenByDefault(),
ViewColumn::make('server_id')
->label('Server ID')
->view('tables.columns.server-column')
->toggleable(),
TextColumn::make('created_at')
->label('Created')
->dateTime($settings->time_format ?? 'M j, Y G:i:s')
->timezone($settings->timezone ?? 'UTC'),
->timezone($settings->timezone ?? 'UTC')
->sortable(),
])
->filters([
//
Tables\Filters\TernaryFilter::make('scheduled')
->placeholder('-')
->trueLabel('Only scheduled speedtests')
->falseLabel('Only manual speedtests')
->queries(
true: fn (Builder $query) => $query->where('scheduled', true),
false: fn (Builder $query) => $query->where('scheduled', false),
blank: fn (Builder $query) => $query,
),
Tables\Filters\TernaryFilter::make('successful')
->placeholder('-')
->trueLabel('Only successful speedtests')
->falseLabel('Only failed speedtests')
->queries(
true: fn (Builder $query) => $query->where('successful', true),
false: fn (Builder $query) => $query->where('successful', false),
blank: fn (Builder $query) => $query,
),
])
->actions([
Tables\Actions\ActionGroup::make([
Action::make('view result')
->label('View on Speedtest.net')
->icon('heroicon-o-link')
->url(fn (Result $record): string => $record->url)
->url(fn (Result $record): string|null => optional($record)->url)
->hidden(fn (Result $record): bool => ! $record->is_successful)
->openUrlInNewTab(),
// Tables\Actions\ViewAction::make(),
Tables\Actions\ViewAction::make(),
Tables\Actions\DeleteAction::make(),
]),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
])
->defaultSort('created_at', 'desc');
}

public static function getRelations(): array
Expand Down
6 changes: 0 additions & 6 deletions app/Filament/Resources/ResultResource/Pages/ListResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@

use App\Filament\Resources\ResultResource;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;

class ListResults extends ListRecords
{
protected static string $resource = ResultResource::class;

protected function getTableQuery(): Builder
{
return parent::getTableQuery()->orderBy('id', 'desc');
}

protected function getTablePollingInterval(): ?string
{
return '5s';
Expand Down
6 changes: 3 additions & 3 deletions app/Filament/Widgets/RecentJitterChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function getData(): array
'datasets' => [
[
'label' => 'Download',
'data' => $results->map(fn ($item) => $item->getJitterData()['download']),
'data' => $results->map(fn ($item) => $item->getJitterData()['download'] ?? 0),
'borderColor' => '#0ea5e9',
'backgroundColor' => '#0ea5e9',
'fill' => false,
Expand All @@ -58,7 +58,7 @@ protected function getData(): array
],
[
'label' => 'Upload',
'data' => $results->map(fn ($item) => $item->getJitterData()['upload']),
'data' => $results->map(fn ($item) => $item->getJitterData()['upload'] ?? 0),
'borderColor' => '#8b5cf6',
'backgroundColor' => '#8b5cf6',
'fill' => false,
Expand All @@ -67,7 +67,7 @@ protected function getData(): array
],
[
'label' => 'Ping',
'data' => $results->map(fn ($item) => $item->getJitterData()['ping']),
'data' => $results->map(fn ($item) => $item->getJitterData()['ping'] ?? 0),
'borderColor' => '#10b981',
'backgroundColor' => '#10b981',
'fill' => false,
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Widgets/RecentPingChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function getData(): array
'datasets' => [
[
'label' => 'Ping',
'data' => $results->map(fn ($item) => $item->ping),
'data' => $results->map(fn ($item) => $item->ping ?? 0),
'borderColor' => '#10b981',
'backgroundColor' => '#10b981',
'fill' => false,
Expand Down
Loading

0 comments on commit 462bb59

Please sign in to comment.