Updated site to v1.5.5

This commit is contained in:
Henry Whitaker
2020-06-20 18:26:12 +01:00
parent d7d6cebcc6
commit 258b6f1c8a
28 changed files with 680 additions and 594 deletions

View File

@@ -13,6 +13,13 @@ use JsonException;
use SimpleXMLElement;
class SpeedtestHelper {
/**
* Runs/processes speedtest output to created a Speedtest object
*
* @param boolean|string $output If false, new speedtest runs. If anything else, will try to parse as JSON for speedtest results.
* @return \App\Speedtest|boolean
*/
public static function runSpeedtest($output = false)
{
if($output === false) {
@@ -25,6 +32,10 @@ class SpeedtestHelper {
'ping' => $output['ping']['latency'],
'download' => SpeedtestHelper::convert($output['download']['bandwidth']),
'upload' => SpeedtestHelper::convert($output['upload']['bandwidth']),
'server_id' => $output['server']['id'],
'server_name' => $output['server']['name'],
'server_host' => $output['server']['host'] . ':' . $output['server']['port'],
'url' => $output['result']['url'],
]);
} catch(JsonException $e) {
Log::error('Failed to parse speedtest JSON');
@@ -36,6 +47,11 @@ class SpeedtestHelper {
return (isset($test)) ? $test : false;
}
/**
* Gets the output of executing speedtest binary.
*
* @return boolean|string
*/
public static function output()
{
$server = SettingsHelper::get('server')['value'];
@@ -54,10 +70,21 @@ class SpeedtestHelper {
return shell_exec('HOME=/config && ' . $binPath . ' -f json');
}
/**
* Converts bytes/s to Mbps
*
* @param int|float $bytes
* @return int|float
*/
public static function convert($bytes) {
return ( $bytes * 8 ) / 1000000;
}
/**
* Returns the latest speedtest object.
*
* @return boolean|\App\Speedtest
*/
public static function latest()
{
$data = Speedtest::latest()->get();
@@ -69,6 +96,12 @@ class SpeedtestHelper {
return $data->first();
}
/**
* Parses network speeds and return converted to Mbps
*
* @param array $input
* @return array
*/
public static function parseUnits($input)
{
$input = explode(' ', $input);