update livemap to use rivets.js bindings for data updates
This commit is contained in:
@@ -97,6 +97,26 @@ class PirepController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the active PIREPs
|
||||
* @param $id
|
||||
* @return PirepResource
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$active = [];
|
||||
$pireps = $this->acarsRepo->getPositions();
|
||||
foreach($pireps as $pirep) {
|
||||
if(\count($pirep->position) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$active[] = $pirep;
|
||||
}
|
||||
|
||||
return PirepResource::collection(collect($active));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return PirepResource
|
||||
|
||||
@@ -25,6 +25,7 @@ class PositionRequest extends FormRequest
|
||||
'positions' => 'required|array',
|
||||
'positions.*.lat' => 'required|numeric',
|
||||
'positions.*.lon' => 'required|numeric',
|
||||
'positions.*.status' => 'nullable',
|
||||
'positions.*.altitude' => 'nullable|numeric',
|
||||
'positions.*.heading' => 'nullable|numeric|between:0,360',
|
||||
'positions.*.vs' => 'nullable',
|
||||
|
||||
@@ -25,6 +25,7 @@ class PrefileRequest extends FormRequest
|
||||
'arr_airport_id' => 'required',
|
||||
'source_name' => 'required',
|
||||
|
||||
'status' => 'nullable',
|
||||
'level' => 'nullable|numeric',
|
||||
'flight_type' => 'nullable',
|
||||
'route_code' => 'nullable',
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Support\Units\Distance;
|
||||
use App\Support\Units\Fuel;
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
class Acars extends Resource
|
||||
@@ -14,6 +16,16 @@ class Acars extends Resource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
$obj = parent::toArray($request);
|
||||
|
||||
if ($this->distance instanceof Distance) {
|
||||
$obj['distance'] = $this->distance->units;
|
||||
}
|
||||
|
||||
if ($this->fuel instanceof Fuel) {
|
||||
$obj['fuel'] = $this->fuel->units;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ class Pirep extends Resource
|
||||
{
|
||||
$pirep = parent::toArray($request);
|
||||
|
||||
$pirep['ident'] = $this->ident;
|
||||
|
||||
if ($this->distance instanceof Distance) {
|
||||
$pirep['distance'] = $this->distance->units;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class AcarsRepository extends Repository
|
||||
*/
|
||||
public function getPositions()
|
||||
{
|
||||
return Pirep::with(['airline', 'position'])
|
||||
return Pirep::with(['airline', 'position', 'aircraft'])
|
||||
->where(['state' => PirepState::IN_PROGRESS])
|
||||
->get();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
Route::group([], function () {
|
||||
Route::get('acars', 'AcarsController@index');
|
||||
Route::get('pireps', 'PirepController@index');
|
||||
Route::get('pireps/{pirep_id}', 'PirepController@get');
|
||||
Route::get('pireps/{pirep_id}/acars/geojson', 'PirepController@acars_geojson');
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class DatabaseService extends Service
|
||||
*/
|
||||
protected function time(): string
|
||||
{
|
||||
return Carbon::now('UTC')->format('Y-m-d H:i:s');
|
||||
return Carbon::now('UTC'); //->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,6 @@ class DatabaseService extends Service
|
||||
public function seed_from_yaml_file($yaml_file, $ignore_errors = false): array
|
||||
{
|
||||
$yml = file_get_contents($yaml_file);
|
||||
|
||||
return $this->seed_from_yaml($yml, $ignore_errors);
|
||||
}
|
||||
|
||||
@@ -61,39 +60,56 @@ class DatabaseService extends Service
|
||||
$imported[$table] = 0;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
# see if this table uses a UUID as the PK
|
||||
# if no ID is specified
|
||||
if (in_array($table, $this->uuid_tables)) {
|
||||
if (!array_key_exists('id', $row)) {
|
||||
$row['id'] = Uuid::generate()->string;
|
||||
}
|
||||
}
|
||||
|
||||
# encrypt any password fields
|
||||
if (array_key_exists('password', $row)) {
|
||||
$row['password'] = bcrypt($row['password']);
|
||||
}
|
||||
|
||||
# if any time fields are == to "now", then insert the right time
|
||||
foreach ($this->time_fields as $tf) {
|
||||
if (array_key_exists($tf, $row) && strtolower($row[$tf]) === 'now') {
|
||||
$row[$tf] = $this->time();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::table($table)->insert($row);
|
||||
++$imported[$table];
|
||||
} catch (QueryException $e) {
|
||||
$row = $this->insert_row($table, $row);
|
||||
} catch(QueryException $e) {
|
||||
if ($ignore_errors) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
++$imported[$table];
|
||||
}
|
||||
}
|
||||
|
||||
return $imported;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $table
|
||||
* @param $row
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function insert_row($table, $row) {
|
||||
# see if this table uses a UUID as the PK
|
||||
# if no ID is specified
|
||||
if (\in_array($table, $this->uuid_tables, true)) {
|
||||
if (!array_key_exists('id', $row)) {
|
||||
$row['id'] = Uuid::generate()->string;
|
||||
}
|
||||
}
|
||||
|
||||
# encrypt any password fields
|
||||
if (array_key_exists('password', $row)) {
|
||||
$row['password'] = bcrypt($row['password']);
|
||||
}
|
||||
|
||||
# if any time fields are == to "now", then insert the right time
|
||||
foreach($row as $column => $value) {
|
||||
if(strtolower($value) === 'now') {
|
||||
$row[$column] = $this->time();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
DB::table($table)->insert($row);
|
||||
} catch (QueryException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user