-
Notifications
You must be signed in to change notification settings - Fork 6
#659 Realops Pre-file/Export Buttons #837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kjporter
wants to merge
15
commits into
main
Choose a base branch
from
realops-prefile-button-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
547b395
Add Preferred Routes
kjporter 680a2de
Add Aircraft Types
kjporter c8d3186
Add Aircraft Types
kjporter 6ed30ef
Integrate Pre-File Logic
kjporter 64d4552
Add format references
kjporter c77d095
Update field label
kjporter c9156a3
Update filter label
kjporter 76a34d5
Removes Aircraft table, adds aircraft JSON support
kjporter 06ab73a
Merge branch 'main' into realops-prefile-button-v2
kjporter 4e04f51
Update realops.blade.php
kjporter 7e291f7
Merge branch 'main' into realops-prefile-button-v2
kjporter 1fef616
Fix ETE and null aircraft bugs
kjporter 8369996
Merge branch 'main' into realops-prefile-button-v2
kjporter 4aa9ab0
Merge branch 'main' into realops-prefile-button-v2
kjporter 612978e
Update PreferredRoute.php
kjporter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,28 @@ | ||
| <?php | ||
|
|
||
| namespace App; | ||
|
|
||
| use Illuminate\Support\Collection; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class Aircraft { | ||
|
|
||
| public static $data; | ||
| private static $initialized = false; | ||
| const FILENAME = 'private/aircraft.json'; | ||
|
|
||
| public static function init() { | ||
| if (self::$initialized) { | ||
| return 1; | ||
| } | ||
| if (Storage::disk('local')->exists(self::FILENAME)) { | ||
| self::$data = Collection::fromJson(Storage::disk('local')->get(self::FILENAME)); | ||
| } | ||
| } | ||
|
|
||
| public static function fetch($acid) { | ||
| $ac = self::$data->where('ac_type', $acid)->first(); | ||
| return (is_null($ac)) ? null : (object) $ac; | ||
| } | ||
| } | ||
| Aircraft::init(); | ||
This file contains hidden or 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,149 @@ | ||
| <?php | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use GuzzleHttp\Client; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\Storage; | ||
| use Symfony\Component\Console\Helper\ProgressIndicator; | ||
| use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
|
||
| class UpdateFAA extends Command { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'FAA:update-faa'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'Updates FAA-specific datafiles'; | ||
|
|
||
| const FAA_DATA_URL = 'https://www.fly.faa.gov/rmt/data_file/'; | ||
| private $routes = [ | ||
| [ | ||
| 'name' => 'PRD', | ||
| 'model' => 'App\PreferredRoute', | ||
| 'file' => 'prefroutes_db.csv' | ||
| ] | ||
| ]; | ||
| private ProgressIndicator $progressIndicator; | ||
| private $path; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle() { | ||
| $this->info('Updating FAA-specific datafiles'); | ||
| $this->path = Storage::disk('local')->path('private/'); | ||
| $this->setup_progress_indicator(); | ||
| $this->update_routes(); | ||
| } | ||
|
|
||
| private function update_routes(): void { | ||
| foreach ($this->routes as $route) { | ||
| $route = (object) $route; | ||
| $this->progressIndicator->start("Fetching $route->name info from FAA server..."); | ||
| $this->call_api(SELF::FAA_DATA_URL . $route->file, $this->path, strtolower($route->name) . '_new.csv'); | ||
| $this->progressIndicator->finish("Fetching $route->name info from FAA server... done"); | ||
|
|
||
| // Update table | ||
| $this->progressIndicator->start("Updating $route->name table..."); | ||
| if (($handle = fopen($this->path . strtolower($route->name) . '_new.csv', "r")) !== false) { | ||
| $route->model::truncate(); | ||
| while (($rte_line = fgetcsv($handle, null, ",")) !== false) { | ||
| if (!is_array($rte_line)) { | ||
| continue; | ||
| } | ||
| $bom = "\xef\xbb\xbf"; | ||
| if (substr($rte_line[0], 0, 3) === $bom) { | ||
| $rte_line[0] = substr($rte_line[0], 3); | ||
| } | ||
| if ($rte_line[0] == 'RCode' || $rte_line[0] == 'Orig') { // It's the header line, skip it | ||
| continue; | ||
| } | ||
| if ($route->name == 'CDR') { | ||
| $load_arr = [ | ||
| 'route_code' => $rte_line[0], | ||
| 'origin' => $rte_line[1], | ||
| 'destination' => $rte_line[2], | ||
| 'departure_fix' => substr($rte_line[3], 0, 5), // Enforce 5 characters | ||
| 'route_string' => $rte_line[4], | ||
| 'departure_center' => $rte_line[5], | ||
| 'arrival_center' => $rte_line[6], | ||
| 'transit_centers' => $rte_line[7], | ||
| 'coordination_required' => $rte_line[8], | ||
| 'play' => $rte_line[9], | ||
| 'navigation_equipment' => $rte_line[10] | ||
| ]; | ||
| } else { | ||
| $load_arr = [ | ||
| 'orig' => $rte_line[0], | ||
| 'route_string' => $rte_line[1], | ||
| 'dest' => $rte_line[2], | ||
| 'hours1' => $rte_line[3], | ||
| 'hours2' => $rte_line[4], | ||
| 'hours3' => $rte_line[5], | ||
| 'type' => $rte_line[6], | ||
| 'area' => $rte_line[7], | ||
| 'altitude' => (is_numeric($rte_line[8])) ? $rte_line[8] : null, | ||
| 'aircraft' => $rte_line[9], | ||
| 'direction' => $rte_line[10], | ||
| 'seq' => $rte_line[11], | ||
| 'dcntr' => $rte_line[12], | ||
| 'acntr' => $rte_line[13] | ||
| ]; | ||
| } | ||
| $route->model::create($load_arr); | ||
| $this->progressIndicator->advance(); | ||
| } | ||
| fclose($handle); | ||
| } | ||
| $this->progressIndicator->finish("Updating $route->name table... done"); | ||
|
|
||
| // Remove, rename file | ||
| $this->info("Removing unused local $route->name files"); | ||
| if (file_exists($this->path . $route->name . '.csv')) { | ||
| unlink($this->path . $route->name . '.csv'); | ||
| $this->info("- Deleted $route->name.csv"); | ||
| } | ||
| if (file_exists($this->path . $route->name . '_new.csv')) { | ||
| rename($this->path . $route->name . '_new.csv', $this->path . $route->name . '.csv'); | ||
| } | ||
| $this->info("$route->name file cleanup complete"); | ||
| } | ||
| } | ||
|
|
||
| private function call_api($url, $path = null, $write_file = null): string|null { | ||
| $progress = $this->progressIndicator; | ||
| $write_to_filename = (is_null($write_file)) ? basename($url) : $write_file; | ||
| $client = new Client(); | ||
| $response = $client->get($url, [ | ||
| 'config' => [ | ||
| 'curl' => [ | ||
| 'CURLOPT_RETURNTRANSFER' => true, | ||
| 'CURLOPT_CONNECTTIMEOUT' => 3, | ||
| 'CURLOPT_ENCODING' => 'gzip', | ||
| 'CURLOPT_SSL_VERIFYPEER' => false | ||
| ] | ||
| ], | ||
| 'progress' => function () use ($progress) { | ||
| $progress->advance(); | ||
| }, | ||
| 'sink' => $path . $write_to_filename | ||
| ]); | ||
| if ($response->getStatusCode() == 200) { | ||
| return $response->getBody(); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private function setup_progress_indicator(): void { | ||
| $output = new ConsoleOutput; | ||
| $this->progressIndicator = new ProgressIndicator($output); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class PreferredRoute extends Model { | ||
| protected $table = 'prd_route'; | ||
| protected $guarded = []; | ||
|
|
||
| public static function routeLookup(string $departure, string $arrival, string $ac_type = 'jets'): string { | ||
| $routes = PreferredRoute::where('orig', substr($departure, 1))->where('dest', substr($arrival, 1))->where(function ($query) use ($ac_type) { | ||
| $query->where('aircraft', 'LIKE', '%' . strtoupper($ac_type) . '%')->orWhere('aircraft', ''); | ||
| })->first(); | ||
| if (!$routes) { | ||
| return ''; | ||
| } | ||
| $clean_route = self::remove_origin_destination_points($routes->route_string, $departure, $arrival); | ||
| return $clean_route; | ||
| } | ||
|
|
||
| private static function remove_origin_destination_points($route_string, $departure, $arrival): string { | ||
| $route = explode(' ', $route_string); | ||
| if (!is_array($route)) { | ||
| return ''; | ||
| } | ||
| if ($route[0] == substr($departure, 1)) { | ||
| unset($route[0]); | ||
| } | ||
| if (end($route) == substr($arrival, 1)) { | ||
| array_pop($route); | ||
| } | ||
| return implode(' ', $route); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to set
$initializedto true here? Or is that built into Laravel to do automatically?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of a cleaner way to do this. Please let me know if you have a good trick.