diff --git a/app/Console/Commands/NavdataCommand.php b/app/Console/Commands/NavdataCommand.php new file mode 100644 index 00000000..908d05af --- /dev/null +++ b/app/Console/Commands/NavdataCommand.php @@ -0,0 +1,197 @@ +error('WPNAVAID.txt not found in storage/navdata'); + return false; + } + + $this->info('Importing navaids (WPNAVAID.txt) ...'); + $generator = $this->readFile($file_path); + + $imported = 0; + foreach($generator as $line) { + $navaid = [ + 'id' => trim(substr($line, 24, 4)), // ident column + 'name' => trim(substr($line, 0, 24)), + 'type' => trim(substr($line, 29, 4)), + 'lat' => trim(substr($line, 33, 9)), + 'lon' => trim(substr($line, 44, 10)), + 'freq' => trim(substr($line, 54, 6)), + 'class' => trim($line[60]), + ]; + + switch($navaid['type']) + { + case 'ILS': + $navaid['type'] = NavaidType::LOC; + break; + case 'ILSDME': + $navaid['type'] = NavaidType::LOC_DME; + break; + case 'NDB': + case 'NDBM': + case 'NDBO': + case 'MARI': + $navaid['type'] = NavaidType::NDB; + break; + case 'VOR': + $navaid['type'] = NavaidType::VOR; + break; + case 'VORD': + $navaid['type'] = NavaidType::VOR_DME; + break; + default: + $navaid['type'] = NavaidType::UNKNOWN; + break; + } + + Navdata::updateOrCreate(['id' => $navaid['id']], $navaid); + + $imported++; + if($imported % 100 === 0) { + $this->info('Imported ' . $imported . ' entries...'); + } + } + + $this->info('Imported a total of ' . $imported . ' nav aids'); + } + + /** + * + */ + public function read_wp_nav_fix() + { + /* + * ....,....1....,....2....,...3....,....4....,.... + * 5.8750W 8750W-87.000000 -50.000000 + * GAREP GAREP 37.619689 128.073419 + * CIHAD CIHAD 37.619719 -86.013228 + * FOLAB FOLAB 37.619931 -87.359411 + * KEKAD KEKAD 37.620000 67.518333 + * NIKDE NIKDE 37.620567-122.563328 + * ZUMAS ZUMAS 37.620575-113.167747 + * NNNNN NNNNN dd.dddddd dd.dddddd + * Col 1-5 & 25-30 Fix Name + * dd.dddddd Col 32-40 Latitude degrees (-Lat for South, sign Col 31) + * ddd.dddddd Col 41-51 Longitude degrees (-Lon for West, decimal always Col 45) + * Note: The duplicate name fields may be the result how the FAA + * provides data, where there are many more fixes defined than provide + * in the airac data. For example, most terminal data is not included. + * This data includes airway crossing, radar service boundaries, etc. + */ + + $file_path = storage_path('/navdata/WPNAVFIX.txt'); + if(!file_exists($file_path)) { + $this->error('WPNAVFIX.txt not found in storage/navdata'); + return false; + } + + $this->info('Importing navaids (WPNAVFIX.txt) ...'); + $generator = $this->readFile($file_path); + + $imported = 0; + foreach ($generator as $line) { + $navfix = [ + 'id' => trim(substr($line, 0, 4)), // ident column + 'name' => trim(substr($line, 24, 6)), + 'type' => NavaidType::FIX, + 'lat' => trim(substr($line, 30, 10)), + 'lon' => trim(substr($line, 40, 11)), + ]; + + switch ($navfix['type']) { + default: + $navfix['type'] = NavaidType::UNKNOWN; + break; + } + + Navdata::updateOrCreate(['id' => $navfix['id']], $navfix); + + $imported++; + if ($imported % 100 === 0) { + $this->info('Imported ' . $imported . ' entries...'); + } + } + + $this->info('Imported a total of ' . $imported . ' nav fixes'); + } + + public function handle() + { + $this->info('Emptying the current navdata...'); + Navdata::query()->truncate(); + + $this->info('Looking for nav files...'); + $this->read_wp_nav_aid(); + $this->read_wp_nav_fix(); + } +} diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php deleted file mode 100644 index 893a0346..00000000 --- a/app/Console/Commands/Test.php +++ /dev/null @@ -1,22 +0,0 @@ -bigIncrements('id'); - $table->string('name', 10); - $table->string('title', 25); - $table->string('airway', 7)->nullable(); - $table->string('airway_type', 1)->nullable(); - $table->bigInteger('seq')->nullable(); - $table->string('loc', 4)->nullable(); + Schema::create('navdata', function (Blueprint $table) { + $table->string('id', 4); + $table->string('name', 24); + $table->unsignedInteger('type'); $table->float('lat', 7, 4)->default(0.0); $table->float('lon', 7, 4)->default(0.0); - $table->string('freq', 7); - $table->integer('type'); + $table->string('freq', 7)->nullable(); + $table->index('id'); $table->index('name'); - $table->index('airway'); }); } @@ -42,6 +37,6 @@ class CreateNavdataTables extends Migration */ public function down() { - Schema::dropIfExists('navpoints'); + Schema::dropIfExists('navdata'); } } diff --git a/app/Models/Airport.php b/app/Models/Airport.php index c5c603fb..0d38bc0b 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -28,7 +28,7 @@ class Airport extends Model ]; protected $casts = [ - 'id' => 'string', + ]; /** diff --git a/app/Models/Enums/Days.php b/app/Models/Enums/Days.php index b1bec568..d06f6997 100644 --- a/app/Models/Enums/Days.php +++ b/app/Models/Enums/Days.php @@ -5,16 +5,19 @@ namespace App\Models\Enums; - +/** + * Class Days + * @package App\Models\Enums + */ class Days extends EnumBase { - const MONDAY = 1; - const TUESDAY = 2; - const WEDNESDAY = 4; - const THURSDAY = 8; - const FRIDAY = 16; - const SATURDAY = 32; - const SUNDAY = 64; + const MONDAY = 1 << 0; + const TUESDAY = 1 << 1; + const WEDNESDAY = 1 << 2; + const THURSDAY = 1 << 3; + const FRIDAY = 1 << 4; + const SATURDAY = 1 << 5; + const SUNDAY = 1 << 6; protected static $labels = [ Days::MONDAY => 'system.days.mon', diff --git a/app/Models/Enums/NavaidType.php b/app/Models/Enums/NavaidType.php new file mode 100644 index 00000000..3be72575 --- /dev/null +++ b/app/Models/Enums/NavaidType.php @@ -0,0 +1,45 @@ + 'VOR', + NavaidType::VOR_DME => 'VOR DME', + NavaidType::LOC => 'Localizer', + NavaidType::LOC_DME => 'Localizer DME', + NavaidType::NDB => 'Non-directional Beacon', + NavaidType::TACAN => 'TACAN', + NavaidType::UNKNOWN => 'Unknown', + NavaidType::ANY_VOR => 'VOR', + NavaidType::ANY_LOC => 'Localizer', + ]; +} diff --git a/app/Models/Navdata.php b/app/Models/Navdata.php new file mode 100644 index 00000000..4aa3faf3 --- /dev/null +++ b/app/Models/Navdata.php @@ -0,0 +1,26 @@ + 'string', + 'type' => 'integer', + ]; +} diff --git a/app/Models/Navpoint.php b/app/Models/Navpoint.php deleted file mode 100644 index abf61008..00000000 --- a/app/Models/Navpoint.php +++ /dev/null @@ -1,10 +0,0 @@ -