diff --git a/app/Filament/Resources/ResultResource.php b/app/Filament/Resources/ResultResource.php index ff26a0186..d8fdc55ef 100644 --- a/app/Filament/Resources/ResultResource.php +++ b/app/Filament/Resources/ResultResource.php @@ -140,6 +140,7 @@ public static function form(Form $form): Form Forms\Components\Placeholder::make('server_host') ->content(fn (Result $result): ?string => $result->server_host), Forms\Components\Checkbox::make('scheduled'), + Forms\Components\Checkbox::make('healthy'), ]) ->columns(1) ->columnSpan([ @@ -315,6 +316,11 @@ public static function table(Table $table): Table ->toggleable() ->toggledHiddenByDefault() ->alignment(Alignment::Center), + Tables\Columns\IconColumn::make('healthy') + ->boolean() + ->toggleable() + ->toggledHiddenByDefault() + ->alignment(Alignment::Center), Tables\Columns\TextColumn::make('created_at') ->dateTime(config('app.datetime_format')) ->timezone(config('app.display_timezone')) @@ -347,7 +353,7 @@ public static function table(Table $table): Table }) ->attribute('data->interface->externalIp'), Tables\Filters\TernaryFilter::make('scheduled') - ->placeholder('-') + ->nullable() ->trueLabel('Only scheduled speedtests') ->falseLabel('Only manual speedtests') ->queries( @@ -358,6 +364,10 @@ public static function table(Table $table): Table Tables\Filters\SelectFilter::make('status') ->multiple() ->options(ResultStatus::class), + Tables\Filters\TernaryFilter::make('healthy') + ->nullable() + ->trueLabel('Only healthy speedtests') + ->falseLabel('Only unhealthy speedtests'), ]) ->actions([ Tables\Actions\ActionGroup::make([ diff --git a/app/Jobs/CheckAndUpdateBenchmarkResult.php b/app/Jobs/CheckAndUpdateBenchmarkResult.php new file mode 100644 index 000000000..7716017db --- /dev/null +++ b/app/Jobs/CheckAndUpdateBenchmarkResult.php @@ -0,0 +1,69 @@ +batch()->cancelled()) { + return; + } + + // Retrieve the benchmarks from the result + $benchmarks = $this->result->benchmarks; + + // Process the benchmarks (assuming you have download, upload, ping types) + $types = ['download', 'upload', 'ping']; + + foreach ($types as $type) { + $value = $this->result->{$type}; + + // Retrieve the benchmark settings for the given type + $benchmark = Arr::get($benchmarks, $type); + + // Only check the benchmark if the value and benchmark are valid + if ($benchmark && $value !== null) { + if ($type === 'ping') { + // Use the ping method for the ping benchmark + $passed = Benchmark::ping($value, $benchmark); + } else { + // Use the bitrate method for download/upload benchmarks + $passed = Benchmark::bitrate($value, $benchmark); + } + + // Invert the result logic here: + $passedStatus = ! $passed ? 'true' : 'false'; + + // If the result has changed, update the passed status + if (Arr::get($benchmarks, "$type.passed") !== $passedStatus) { + $benchmarks[$type]['passed'] = $passedStatus; + } + } + } + + // After processing, update the result with the modified benchmarks + $this->result->benchmarks = $benchmarks; + $this->result->save(); + } +} diff --git a/app/Jobs/Ookla/ProcessSpeedtestBatch.php b/app/Jobs/Ookla/ProcessSpeedtestBatch.php index 59709bd06..09577e463 100644 --- a/app/Jobs/Ookla/ProcessSpeedtestBatch.php +++ b/app/Jobs/Ookla/ProcessSpeedtestBatch.php @@ -2,6 +2,7 @@ namespace App\Jobs\Ookla; +use App\Jobs\CheckAndUpdateBenchmarkResult; use App\Jobs\CheckForInternetConnectionJob; use App\Jobs\SkipSpeedtestJob; use App\Models\Result; @@ -35,6 +36,7 @@ public function handle(): void new SelectSpeedtestServerJob($this->result), new RunSpeedtestJob($this->result), new BenchmarkSpeedtestJob($this->result), + new CheckAndUpdateBenchmarkResult($this->result), new CompleteSpeedtestJob($this->result), ], ])->catch(function (Batch $batch, ?Throwable $e) {