Convert sequelpro xml to yaml for import

This commit is contained in:
Nabeel Shahzad 2018-02-21 15:02:24 -06:00
parent 713fd66da6
commit a18c00ee95
2 changed files with 625 additions and 56 deletions

View File

@ -9,10 +9,11 @@ use App\Models\Pirep;
use App\Models\User; use App\Models\User;
use DB; use DB;
use PDO; use PDO;
use Symfony\Component\Yaml\Yaml;
class DevCommands extends BaseCommand class DevCommands extends BaseCommand
{ {
protected $signature = 'phpvms {cmd}'; protected $signature = 'phpvms {cmd} {param?}';
protected $description = 'Developer commands'; protected $description = 'Developer commands';
/** /**
@ -32,6 +33,7 @@ class DevCommands extends BaseCommand
'clear-users' => 'clearUsers', 'clear-users' => 'clearUsers',
'compile-assets' => 'compileAssets', 'compile-assets' => 'compileAssets',
'db-attrs' => 'dbAttrs', 'db-attrs' => 'dbAttrs',
'xml-to-yaml' => 'xmlToYaml',
]; ];
if(!array_key_exists($command, $commands)) { if(!array_key_exists($command, $commands)) {
@ -106,4 +108,43 @@ class DevCommands extends BaseCommand
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulate_prepares); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulate_prepares);
} }
/**
* Convert the sequelpro xml export to yaml
*/
protected function xmlToYaml()
{
$file = $this->argument('param');
$this->info('Reading '. $file);
$xml_str = file_get_contents($file);
$xml = new \SimpleXMLElement($xml_str);
$yaml = [];
$table_name = (string) $xml->database->table_data['name'];
$this->info('Writing table "'.$table_name.'"');
$count = 0;
$yaml[$table_name] = [];
foreach ($xml->database->table_data->row as $row) {
$yaml_row = [];
foreach($row->field as $field) {
$fname = (string) $field['name'];
$fvalue = (string) $field;
$yaml_row[$fname] = $fvalue;
}
if($yaml_row['pirep_id'] === 'pirepid_2')
$yaml[$table_name][] = $yaml_row;
++$count;
}
$this->info('Exporting '.$count.' rows');
$file_name = $table_name.'.yml';
file_put_contents(storage_path($file_name), Yaml::dump($yaml, 4, 2));
$this->info('Writing yaml to storage: '. $file_name);
}
} }

View File

@ -178,7 +178,15 @@ airports:
timezone: Europe/London timezone: Europe/London
lat: 51.4775 lat: 51.4775
lon: -0.4614 lon: -0.4614
- id: LGRP
iata: RHO
icao: LGRP
name: Diagoras Airport
location: Rhodos
country: Greece
timezone: Europe/Athens
lat: 36.4054
lon: 28.0862
# #
aircraft: aircraft:
- id: 1 - id: 1
@ -269,8 +277,8 @@ flights:
airline_id: 1 airline_id: 1
flight_number: 6028 flight_number: 6028
route_code: A route_code: A
dpt_airport_id: KIAH dpt_airport_id: LGRP
arr_airport_id: KAUS arr_airport_id: LGRP
dpt_time: 9AM CST dpt_time: 9AM CST
arr_time: 1030AM CST arr_time: 1030AM CST
route: PITZZ4 MNURE WLEEE4 route: PITZZ4 MNURE WLEEE4
@ -307,56 +315,6 @@ user_bids:
user_id: 1 user_id: 1
flight_id: flightid_3 flight_id: flightid_3
acars:
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: TNV
lat: 30.28852
lon: -96.058239
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: IAH
lat: 29.95691
lon: -95.345719
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: LCH
lat: 30.14151
lon: -93.105569
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: MEI
lat: 32.37843
lon: -88.804267
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: ATL
lat: 33.62907
lon: -84.435064
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: SIE
lat: 39.0955
lon: -74.800344
created_at: now
updated_at: now
pireps: pireps:
- id: pirepid_1 - id: pirepid_1
user_id: 1 user_id: 1
@ -378,8 +336,8 @@ pireps:
flight_id: flightid_2 flight_id: flightid_2
flight_number: 101 flight_number: 101
aircraft_id: 1 aircraft_id: 1
dpt_airport_id: KJFK dpt_airport_id: LGRP
arr_airport_id: KAUS arr_airport_id: LGRP
flight_time: 180 # 6 hours flight_time: 180 # 6 hours
state: 1 state: 1
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3 route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
@ -431,3 +389,573 @@ pirep_comments:
comment: Another comment comment: Another comment
created_at: now created_at: now
updated_at: now updated_at: now
acars:
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: TNV
lat: 30.28852
lon: -96.058239
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: IAH
lat: 29.95691
lon: -95.345719
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: LCH
lat: 30.14151
lon: -93.105569
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: MEI
lat: 32.37843
lon: -88.804267
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: ATL
lat: 33.62907
lon: -84.435064
created_at: now
updated_at: now
- pirep_id: pirepid_1
type: 1
nav_type: 2
name: SIE
lat: 39.0955
lon: -74.800344
created_at: now
updated_at: now
-
id: 7e5Q5wlxBpxe
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4314'
lon: '28.1399'
heading: '251'
altitude: '1040'
vs: '-950'
gs: '62'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:06:36'
updated_at: '2018-02-21 20:06:36'
-
id: 9aAN5XQ7y6Ob
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4169'
lon: '28.1202'
heading: '238'
altitude: '350'
vs: '-200'
gs: '58'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:08:06'
updated_at: '2018-02-21 20:08:06'
-
id: aADPEZ6kR81e
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Brakes are Released'
lat: '36.4004'
lon: '28.0689'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:02:47'
updated_at: '2018-02-21 20:02:47'
-
id: aOYypxgnx1Nd
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Brakes are On'
lat: '36.4004'
lon: '28.0689'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:02:37'
updated_at: '2018-02-21 20:02:37'
-
id: azpKgO7O4r2d
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4097'
lon: '28.1016'
heading: '255'
altitude: '120'
vs: '-250'
gs: '61'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:09:06'
updated_at: '2018-02-21 20:09:06'
-
id: b826rZMqoKLe
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4159'
lon: '28.1218'
heading: '70'
altitude: '1370'
vs: '700'
gs: '92'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:05:06'
updated_at: '2018-02-21 20:05:06'
-
id: bDk9KjqgQxka
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4010'
lon: '28.0711'
heading: '70'
altitude: '20'
vs: '0'
gs: '52'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:03:06'
updated_at: '2018-02-21 20:03:06'
-
id: bmZQWxqo2D0d
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Airborne and Beacons are off'
lat: '36.4018'
lon: '28.0739'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:03:15'
updated_at: '2018-02-21 20:03:15'
-
id: bo2QWzjqBg3a
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: "Landed @ 59 Knots with -90 Vertical Speed With a heading of 251 and with 1.2416 G Force\nArrival Weather: KJFK 211951Z 19007KT 10SM FEW033 FEW070 FEW270 18/12 A3022 RMK AO2 SLP233 T01780122"
lat: '36.4075'
lon: '28.0929'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:09:33'
updated_at: '2018-02-21 20:09:33'
-
id: bqxYWBQ0yrpa
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Engine 1 Started'
lat: '36.4004'
lon: '28.0689'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:02:38'
updated_at: '2018-02-21 20:02:38'
-
id: bW67AJQwJRWa
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Flaps 3 Selected at 1360ft and 101kts'
lat: '36.4287'
lon: '28.1486'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:06:10'
updated_at: '2018-02-21 20:06:10'
-
id: bYEvDL73AmMb
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4042'
lon: '28.0820'
heading: '70'
altitude: '200'
vs: '-50'
gs: '78'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:03:36'
updated_at: '2018-02-21 20:03:36'
-
id: dG65NmMk1N8b
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4124'
lon: '28.1113'
heading: '241'
altitude: '230'
vs: '-250'
gs: '62'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:08:36'
updated_at: '2018-02-21 20:08:36'
-
id: dNk9owOZwGLe
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4117'
lon: '28.1075'
heading: '70'
altitude: '990'
vs: '650'
gs: '88'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:04:36'
updated_at: '2018-02-21 20:04:36'
-
id: dR6ovAlxj1Ed
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Airborne and Navigation Lights are off'
lat: '36.4020'
lon: '28.0744'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:03:16'
updated_at: '2018-02-21 20:03:16'
-
id: e73LqZ9Z87we
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Flaps 2 Selected at 20ft and 0kts'
lat: '36.4004'
lon: '28.0689'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:02:48'
updated_at: '2018-02-21 20:02:48'
-
id: e9rQvZ9095Da
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Flaps 0 Selected at 190ft and 69kts'
lat: '36.4037'
lon: '28.0802'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:03:32'
updated_at: '2018-02-21 20:03:32'
-
id: egJLWonpgwZd
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4203'
lon: '28.1366'
heading: '70'
altitude: '1500'
vs: '-150'
gs: '97'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:05:36'
updated_at: '2018-02-21 20:05:36'
-
id: egJLWonx6p3d
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4274'
lon: '28.1487'
heading: '6'
altitude: '1390'
vs: '-450'
gs: '102'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:06:06'
updated_at: '2018-02-21 20:06:06'
-
id: egJLWopjvKDd
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Beacon lights are off and engine is started'
lat: '36.4004'
lon: '28.0689'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:02:39'
updated_at: '2018-02-21 20:02:39'
-
id: ejRqWrYE8Nye
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4080'
lon: '28.0949'
heading: '70'
altitude: '640'
vs: '400'
gs: '81'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:04:06'
updated_at: '2018-02-21 20:04:06'
-
id: erkRWD2wROBa
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: "Took off @ 68 Knots and Flaps at Position 2 With a heading of 70 Degrees \nDeparture Weather KAUS 211953Z 35018KT 2SM R17L/3500VP6000FT -RA BR OVC010 05/05 A3017 RMK AO2 SFC VIS 2 1/2 SLP216"
lat: '36.4018'
lon: '28.0736'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:03:14'
updated_at: '2018-02-21 20:03:14'
-
id: erkRWDmNz92a
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4216'
lon: '28.1277'
heading: '210'
altitude: '440'
vs: '-250'
gs: '55'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:07:36'
updated_at: '2018-02-21 20:07:36'
-
id: kazvG4B4z0Oa
pirep_id: pirepid_2
type: '2'
nav_type: ''
order: '0'
name: ''
log: 'Landing light OFF Below FL100'
lat: '36.4022'
lon: '28.0750'
heading: ''
altitude: ''
vs: ''
gs: ''
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:03:17'
updated_at: '2018-02-21 20:03:17'
-
id: wdL7o1YlAZjb
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4263'
lon: '28.1347'
heading: '183'
altitude: '660'
vs: '-500'
gs: '56'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:07:06'
updated_at: '2018-02-21 20:07:06'
-
id: zbq7vpVrwB2e
pirep_id: pirepid_2
type: '0'
nav_type: ''
order: '0'
name: ''
log: ''
lat: '36.4072'
lon: '28.0917'
heading: '252'
altitude: '20'
vs: '0'
gs: '58'
transponder: ''
autopilot: ''
fuel_flow: ''
sim_time: ''
created_at: '2018-02-21 20:09:36'
updated_at: '2018-02-21 20:09:36'