mirror of
https://github.com/alexjustesen/speedtest-tracker.git
synced 2026-06-23 06:20:09 +00:00
96ad94f734
* [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>
41 lines
913 B
PHP
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;
|
|
}
|
|
}
|