Files
Alex Justesen 96ad94f734 [Chore] Refactored benchmarking results (#1835)
* [Feature] Added Check benchmark for healthy (#1816)

* Add Check and update benchmarsk state process

* Add helper and result resource

* Add filter

* Fix result table

* replace placeholder

* Use Helpers\Benchmark

---------

Co-authored-by: Alex Justesen <alexjustesen@users.noreply.github.com>

* moved skipspeedtestjob to ookla namespace

* consolidated benchmark jobs

* fixed typo

* benchmark helper should be truthy

---------

Co-authored-by: Sven van Ginkel <svenvanginkel@icloud.com>
2024-11-26 18:07:30 -05:00

41 lines
913 B
PHP

<?php
namespace App\Helpers;
use Illuminate\Support\Arr;
class Benchmark
{
/**
* Validate if the bitrate passes the benchmark.
*/
public static function bitrate(float|int $bytes, array $benchmark): bool
{
$value = Arr::get($benchmark, 'value');
$unit = Arr::get($benchmark, 'unit');
// Pass the benchmark if the value or unit is empty.
if (blank($value) || blank($unit)) {
return true;
}
return Bitrate::bytesToBits($bytes) >= Bitrate::normalizeToBits($value.$unit);
}
/**
* Validate if the ping passes the benchmark.
*/
public static function ping(float|int $ping, array $benchmark): bool
{
$value = Arr::get($benchmark, 'value');
// Pass the benchmark if the value is empty.
if (blank($value)) {
return true;
}
return $ping < $value;
}
}