Added YABs to Json output
Added YABs to Json output Cleaned up old unused functions
This commit is contained in:
parent
e46b7b3c63
commit
b9aed757ad
|
@ -159,4 +159,11 @@ class YabsController extends Controller
|
|||
return view('yabs.compare', compact('yabs1_data', 'yabs2_data'));
|
||||
}
|
||||
|
||||
public function yabsToJson(Yabs $yab): array
|
||||
{
|
||||
$all_yabs = Yabs::yabs($yab->id)[0];
|
||||
return Yabs::buildYabsArray($all_yabs);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -17,28 +17,10 @@ class Yabs extends Model
|
|||
|
||||
protected $fillable = ['id', 'server_id', 'has_ipv6', 'aes', 'vm', 'output_date', 'cpu_cores', 'cpu_freq', 'cpu_model', 'ram', 'ram_type', 'ram_mb', 'disk', 'disk_type', 'disk_gb', 'gb5_single', 'gb5_multi', 'gb5_id', '4k', '4k_type', '4k_as_mbps', '64k', '64k_type', '64k_as_mbps', '512k', '512k_type', '512k_as_mbps', '1m', '1m_type', '1m_as_mbps', 'location', 'send', 'send_type', 'send_as_mbps', 'receive', 'receive_type', 'receive_as_mbps'];
|
||||
|
||||
public static function networkSpeedsForServer(string $server_id)
|
||||
{
|
||||
return Cache::remember("network_speeds.$server_id", now()->addMonth(1), function () use ($server_id) {
|
||||
return json_decode(DB::table('network_speed')
|
||||
->where('network_speed.server_id', '=', $server_id)
|
||||
->get(), true);
|
||||
});
|
||||
}
|
||||
|
||||
public static function serverCompareNetwork(string $yabs_id)
|
||||
{
|
||||
return Cache::remember("compare_network_speeds.$yabs_id", now()->addMonth(1), function () use ($yabs_id) {
|
||||
return DB::table('network_speed')
|
||||
->where('id', '=', $yabs_id)
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
||||
public static function yabs(string $yabs_id)
|
||||
{
|
||||
return Cache::remember("yabs.$yabs_id", now()->addMonth(1), function () use ($yabs_id) {
|
||||
return self::where('id', $yabs_id)->with(['server', 'disk_speed', 'network_speed'])
|
||||
return self::where('id', $yabs_id)->with(['server', 'disk_speed', 'network_speed', 'server.location', 'server.provider'])
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
@ -46,7 +28,7 @@ class Yabs extends Model
|
|||
public static function allYabs()
|
||||
{
|
||||
return Cache::remember("all_yabs", now()->addMonth(1), function () {
|
||||
return self::with(['server', 'disk_speed', 'network_speed'])
|
||||
return self::with(['server', 'disk_speed', 'network_speed', 'server.location', 'server.provider'])
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
@ -66,4 +48,48 @@ class Yabs extends Model
|
|||
return $this->hasMany(NetworkSpeed::class, 'id', 'id');
|
||||
}
|
||||
|
||||
public static function buildYabsArray($data): array
|
||||
{
|
||||
$speed_tests = [];
|
||||
foreach ($data->network_speed as $ns) {
|
||||
$speed_tests[] = array(
|
||||
'location' => $ns->location,
|
||||
'send' => $ns->send.' '.$ns->send_type,
|
||||
'receive' => $ns->receive.' '.$ns->receive_type,
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'date_time' => $data->output_date,
|
||||
'location' => $data->server->location->name,
|
||||
'provider' => $data->server->provider->name,
|
||||
'cpu' => array(
|
||||
'cores' => $data->cpu_cores,
|
||||
'speed_mhz' => $data->cpu_freq,
|
||||
'model' => $data->cpu_model,
|
||||
'aes' => $data->aes === 1,
|
||||
'vm' => $data->vm === 1,
|
||||
'GB5_single' => $data->gb5_single,
|
||||
'GB5_multi' => $data->gb5_multi,
|
||||
),
|
||||
'ram' => array(
|
||||
'amount' => $data->ram.' '.$data->ram_type,
|
||||
'mb' => $data->ram_mb,
|
||||
),
|
||||
'disk' => array(
|
||||
'amount' => $data->disk.' '.$data->disk_type,
|
||||
'gb' => $data->disk_gb,
|
||||
'speed_tests' => array(
|
||||
'4k' => $data->disk_speed->d_4k.' '.$data->disk_speed->d_4k_type,
|
||||
'64k' => $data->disk_speed->d_64k.' '.$data->disk_speed->d_64k_type,
|
||||
'512k' => $data->disk_speed->d_512k.' '.$data->disk_speed->d_512k_type,
|
||||
'1m' => $data->disk_speed->d_1m.' '.$data->disk_speed->d_1m_type,
|
||||
),
|
||||
),
|
||||
'network' => array(
|
||||
'has_ipv6' => $data->has_ipv6 === 1,
|
||||
'speed_tests' => $speed_tests
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ Route::resource('shared', SharedController::class)->middleware(['auth']);
|
|||
|
||||
Route::resource('yabs', YabsController::class)->middleware(['auth']);
|
||||
|
||||
Route::get('yabs/{yab}/json', 'App\Http\Controllers\YabsController@yabsToJson')->middleware(['auth'])->name('yabs.json');
|
||||
|
||||
Route::get('yabs-compare-choose', 'App\Http\Controllers\YabsController@chooseYabsCompare')->middleware(['auth'])->name('yabs.compare-choose');
|
||||
|
||||
Route::get('yabs-compare/{yabs1}/{yabs2}', 'App\Http\Controllers\YabsController@compareYabs')->middleware(['auth'])->name('yabs.compare');
|
||||
|
|
Loading…
Reference in New Issue
Block a user