function FSBuild()
 {
     # Setup the inserts into chunks of 1000
     $chunksOrig = 250;
     Airway::truncate();
     $total = 0;
     $list = array();
     $chunks = $chunksOrig;
     $this->line('Loading airways segments...');
     $handle = fopen($this->option('fsbuild') . '/fsb_awy2.txt', 'r');
     while ($line = fscanf($handle, "%s %s %s %s %s %s %s\n")) {
         if ($line[0][0] == ';') {
             continue;
         }
         list($airway, $seq, $ident, , , $airway_type) = $line;
         $list[] = compact('ident', 'airway', 'airway_type', 'seq');
         $total++;
         if ($total == $chunks) {
             Airway::insert($list);
             $this->line('Inserted batch (' . $chunks . ')');
             $list = array();
             $chunks += $chunksOrig;
         }
     }
     Airway::insert($list);
     $this->line('Inserted batch (' . $chunks . ')');
     fclose($handle);
     $this->line($total . ' airway segments loaded...');
     $this->line('Loading VORs...');
     $total = 0;
     $updated = 0;
     $updated_list = array();
     $list = array();
     $chunks = $chunksOrig;
     $handle = fopen($this->option('fsbuild') . '/fsb_vor.txt', 'r');
     while ($lineinfo = fscanf($handle, "%s %s %s %s %s %s\n")) {
         if ($lineinfo[0][0] == ';') {
             continue;
         }
         list($ident, $name, $lat, $lon, $type, $freq) = $lineinfo;
         $lat = $this->coordinatesFSBuild($lat);
         $lon = $this->coordinatesFSBuild($lon);
         if (isset($this->navs[$ident])) {
             $latRange = $this->coordinateRange($lat);
             $lonRange = $this->coordinateRange($lon);
             foreach ($this->navs[$ident] as $existing) {
                 if ($latRange[0] >= $existing['lat'] && $latRange[1] <= $existing['lat'] && $lonRange[0] >= $existing['lon'] && $existing['lon'] <= $lonRange[1]) {
                     continue 2;
                 }
             }
         }
         $name = ucwords(strtolower(str_replace('_', ' ', $name)));
         $type = 'V';
         $freq *= 100;
         $list[] = compact('ident', 'name', 'lat', 'lon', 'freq', 'type');
         if ($total == $chunks) {
             Waypoint::insert($list);
             $this->line('Inserted batch (' . $chunks . ')');
             $list = array();
             $chunks += $chunksOrig;
         }
         $total++;
     }
     Waypoint::insert($list);
     $this->line('Inserted batch (' . $chunks . ')');
     fclose($handle);
     $this->line($total . ' VORs added, ' . $updated . ' updated');
     $this->line('Loading NDBs...');
     // Add NDBs
     $total = 0;
     $chunks = $chunksOrig;
     $list = array();
     $handle = fopen($this->option('fsbuild') . '/fsb_ndb.txt', 'r');
     while ($lineinfo = fscanf($handle, "%s %s %s %s %s %s\n")) {
         if ($lineinfo[0][0] == ';') {
             continue;
         }
         list($ident, $name, $lat, $lon, $type, $freq) = $lineinfo;
         $lat = $this->coordinatesFSBuild($lat);
         $lon = $this->coordinatesFSBuild($lon);
         if (isset($this->navs[$ident])) {
             $latRange = $this->coordinateRange($lat);
             $lonRange = $this->coordinateRange($lon);
             foreach ($this->navs[$ident] as $existing) {
                 if ($latRange[0] >= $existing['lat'] && $latRange[1] <= $existing['lat'] && $lonRange[0] >= $existing['lon'] && $existing['lon'] <= $lonRange[1]) {
                     continue 2;
                 }
             }
         }
         $name = ucwords(strtolower(str_replace('_', ' ', $name)));
         $type = 'N';
         $list[] = compact('ident', 'name', 'lat', 'lon', 'type', 'freq');
         if ($total == $chunks) {
             Waypoint::insert($list);
             $this->line('Inserted batch (' . $chunks . ')');
             $list = array();
             $chunks += $chunksOrig;
         }
         $total++;
     }
     Waypoint::insert($list);
     $this->line('Inserted batch (' . $chunks . ')');
     fclose($handle);
     $this->line($total . ' NDBs added, ' . $updated . ' updated');
     $this->line('Loading SIDs...');
     $handle = fopen($this->option('fsbuild') . '/fsb_sids.txt', 'r');
     $currentAirport = null;
     $data = array();
     $total = 0;
     fscanfe($handle, '%s %s %s %s\\n', function ($lineinfo) use(&$data, &$currentAirport, &$total) {
         if ($lineinfo[0][0] == ';' || $lineinfo[0][0] == '*' || is_null($lineinfo)) {
             return;
         } elseif ($lineinfo[0][0] == '[') {
             $currentAirport = substr($lineinfo[0], 1, -1);
         } elseif ($lineinfo[0] == 'T') {
             $total++;
             $data[$currentAirport . ':' . $lineinfo[1]] = array('airport' => $currentAirport, 'ident' => $lineinfo[1], 'runway' => $lineinfo[3], 'waypoints' => array());
         } else {
             $data[$currentAirport . ':' . $lineinfo[0]]['waypoints'][] = $lineinfo[1];
         }
     });
     foreach ($data as $sid) {
         if (!array_key_exists('ident', $sid)) {
             continue;
         }
         $wpt = new DepApp();
         $wpt->ident = $sid['ident'];
         $wpt->airport_id = $sid['airport'];
         $wpt->runway = $sid['runway'];
         $wpt->route = implode(' ', $sid['waypoints']);
         $wpt->type = 'D';
         $sids[] = $wpt->toArray();
     }
     $this->line($total . ' SIDs added');
     fclose($handle);
     progressiveInsert(new DepApp(), $sids);
     $this->line('Loading STARs...');
     $handle = fopen($this->option('fsbuild') . '/fsb_stars.txt', 'r');
     $currentAirport = null;
     $data = array();
     $total = 0;
     fscanfe($handle, '%s %s %s %s\\n', function ($lineinfo) use(&$data, &$currentAirport, &$total) {
         if ($lineinfo[0][0] == ';' || $lineinfo[0][0] == '*' || is_null($lineinfo)) {
             return;
         } elseif ($lineinfo[0][0] == '[') {
             $currentAirport = substr($lineinfo[0], 1, -1);
         } elseif ($lineinfo[0] == 'T') {
             $total++;
             $data[$currentAirport . ':' . $lineinfo[1]] = array('airport' => $currentAirport, 'ident' => $lineinfo[1], 'runway' => $lineinfo[3], 'waypoints' => array());
         } else {
             $data[$currentAirport . ':' . $lineinfo[0]]['waypoints'][] = $lineinfo[1];
         }
     });
     foreach ($data as $star) {
         if (!array_key_exists('ident', $star)) {
             continue;
         }
         $wpt = new DepApp();
         $wpt->ident = $star['ident'];
         $wpt->airport_id = $star['airport'];
         $wpt->runway = $star['runway'];
         $wpt->route = implode(' ', $star['waypoints']);
         $wpt->type = 'A';
         $stars[] = $wpt->toArray();
     }
     $this->line($total . ' STARs added');
     fclose($handle);
     progressiveInsert(new DepApp(), $stars);
 }
Beispiel #2
0
 protected function airways($waypoints)
 {
     return Airway::whereIn('airway', $waypoints)->orderBy('seq')->get()->groupBy('airway');
 }