mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 13:23:04 +01:00
Fix tests and update version number
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Speedtest Tracker
|
||||
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||
|
||||
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.
|
||||
|
||||
|
||||
@@ -228,4 +228,42 @@ class SpeedtestHelper
|
||||
|
||||
throw new InvalidArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a percentage rate of failure by days
|
||||
*
|
||||
* @param integer $days number of days to get rate for
|
||||
* @return integer percentage fail rate
|
||||
*/
|
||||
public static function failureRate(int $days)
|
||||
{
|
||||
$ttl = Carbon::now()->addDays(1);
|
||||
$rate = Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
|
||||
$range = [
|
||||
Carbon::today()
|
||||
];
|
||||
for ($i = 0; $i < ($days - 1); $i++) {
|
||||
$prev = end($range);
|
||||
$new = $prev->copy()->subDays(1);
|
||||
array_push($range, $new);
|
||||
}
|
||||
|
||||
$rate = [];
|
||||
|
||||
foreach ($range as $day) {
|
||||
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
|
||||
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];
|
||||
|
||||
array_push($rate, [
|
||||
'date' => $day->toDateString(),
|
||||
'success' => $success,
|
||||
'failure' => $fail,
|
||||
]);
|
||||
}
|
||||
|
||||
return array_reverse($rate);
|
||||
});
|
||||
|
||||
return $rate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class OoklaTester implements SpeedtestProvider
|
||||
'scheduled' => $scheduled,
|
||||
]);
|
||||
|
||||
throw new SpeedtestFailureException((string)$output);
|
||||
throw new SpeedtestFailureException(json_encode($output));
|
||||
}
|
||||
|
||||
Cache::flush();
|
||||
|
||||
@@ -7,7 +7,7 @@ return [
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'version' => '1.11.0',
|
||||
'version' => '1.11.1',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -9,7 +9,7 @@ class CheckOutputTest extends TestCase
|
||||
{
|
||||
private OoklaTester $speedtestProvider;
|
||||
|
||||
public function __construct()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->speedtestProvider = new OoklaTester();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Tests\Unit\Helpers\SpeedtestHelper;
|
||||
|
||||
use App\Exceptions\SpeedtestFailureException;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Utils\OoklaTester;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use JsonException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SpeedtestTest extends TestCase
|
||||
@@ -58,11 +58,11 @@ class SpeedtestTest extends TestCase
|
||||
*/
|
||||
public function testInvaidJson()
|
||||
{
|
||||
$this->expectException(SpeedtestFailureException::class);
|
||||
|
||||
$json = '{hi: hi}';
|
||||
|
||||
$o = $this->speedtestProvider->run($json);
|
||||
|
||||
$this->assertFalse($o);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,10 +72,10 @@ class SpeedtestTest extends TestCase
|
||||
*/
|
||||
public function testIncompleteJson()
|
||||
{
|
||||
$this->expectException(SpeedtestFailureException::class);
|
||||
|
||||
$json = '{"hi": "hi"}';
|
||||
|
||||
$o = $this->speedtestProvider->run($json);
|
||||
|
||||
$this->assertFalse($o);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user