-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #521 from henrywhitaker3/alpha
Bunch of updates
- Loading branch information
Showing
50 changed files
with
28,318 additions
and
1,952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Actions; | ||
|
||
use App\Speedtest; | ||
use Cache; | ||
use Carbon\Carbon; | ||
use DB; | ||
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface; | ||
|
||
class GetFailedSpeedtestData implements ActionInterface | ||
{ | ||
/** | ||
* Run the action. | ||
* | ||
* @return mixed | ||
*/ | ||
public function run($days = 7) | ||
{ | ||
$ttl = Carbon::now()->addDays(1); | ||
|
||
return 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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Actions; | ||
|
||
use App\Helpers\SettingsHelper; | ||
use App\Helpers\SpeedtestHelper; | ||
use App\Speedtest; | ||
use DB; | ||
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface; | ||
|
||
class GetLatestSpeedtestData implements ActionInterface | ||
{ | ||
/** | ||
* Run the action. | ||
* | ||
* @return mixed | ||
*/ | ||
public function run() | ||
{ | ||
$data = SpeedtestHelper::latest(); | ||
|
||
$response = [ | ||
'data' => $data, | ||
]; | ||
|
||
if (SettingsHelper::get('show_average')) { | ||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload')) | ||
->where('failed', false) | ||
->first() | ||
->toArray(); | ||
$response['average'] = $avg; | ||
} | ||
|
||
if (SettingsHelper::get('show_max')) { | ||
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload')) | ||
->where('failed', false) | ||
->first() | ||
->toArray(); | ||
$response['maximum'] = $max; | ||
} | ||
|
||
if (SettingsHelper::get('show_min')) { | ||
$min = Speedtest::select(DB::raw('MIN(ping) as ping, MIN(download) as download, MIN(upload) as upload')) | ||
->where('failed', false) | ||
->first() | ||
->toArray(); | ||
$response['minimum'] = $min; | ||
} | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Actions; | ||
|
||
use App\Helpers\SettingsHelper; | ||
use App\Speedtest; | ||
use Cache; | ||
use Carbon\Carbon; | ||
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface; | ||
|
||
class GetSpeedtestTimeData implements ActionInterface | ||
{ | ||
/** | ||
* Run the action. | ||
* | ||
* @return mixed | ||
*/ | ||
public function run($days = 7) | ||
{ | ||
$ttl = Carbon::now()->addDays(1); | ||
|
||
return Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) { | ||
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value; | ||
|
||
if ($showFailed === true) { | ||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days)) | ||
->orderBy('created_at', 'asc') | ||
->get(); | ||
} | ||
|
||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days)) | ||
->where('failed', false) | ||
->orderBy('created_at', 'asc') | ||
->get(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Actions; | ||
|
||
use App\Helpers\SettingsHelper; | ||
use App\Interfaces\SpeedtestProvider; | ||
use App\Jobs\SpeedtestJob; | ||
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface; | ||
|
||
class QueueSpeedtest implements ActionInterface | ||
{ | ||
private SpeedtestProvider $speedtestProvider; | ||
|
||
/** | ||
* Create a new action instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(SpeedtestProvider $speedtestProvider) | ||
{ | ||
$this->speedtestProvider = $speedtestProvider; | ||
} | ||
|
||
/** | ||
* Run the action. | ||
* | ||
* @return mixed | ||
*/ | ||
public function run() | ||
{ | ||
SettingsHelper::loadIntegrationConfig(); | ||
|
||
SpeedtestJob::dispatch(false, config('integrations'), $this->speedtestProvider); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Casts; | ||
|
||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; | ||
|
||
class CommaSeparatedArrayCast implements CastsAttributes | ||
{ | ||
/** | ||
* Array of settings that should be cast | ||
*/ | ||
private array $shouldCast = [ | ||
'visible_columns', | ||
'hidden_columns', | ||
]; | ||
|
||
/** | ||
* Cast the given value. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param mixed $value | ||
* @param array $attributes | ||
* @return mixed | ||
*/ | ||
public function get($model, $key, $value, $attributes) | ||
{ | ||
if (!in_array($model->name, $this->shouldCast)) { | ||
return $value; | ||
} | ||
|
||
return explode(',', $value); | ||
} | ||
|
||
/** | ||
* Prepare the given value for storage. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @param string $key | ||
* @param mixed $value | ||
* @param array $attributes | ||
* @return mixed | ||
*/ | ||
public function set($model, $key, $value, $attributes) | ||
{ | ||
if (!in_array($model->name, $this->shouldCast)) { | ||
return $value; | ||
} | ||
|
||
return implode(',', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use Exception; | ||
|
||
class SpeedtestFailureException extends Exception | ||
{ | ||
// | ||
} |
Oops, something went wrong.