Add flights to the importer, added a few missing columns with output

This commit is contained in:
Nabeel Shahzad
2018-01-03 21:40:05 -06:00
parent da1b3b16ee
commit 507ce5f24f
5 changed files with 76 additions and 34 deletions

View File

@@ -2,23 +2,22 @@
namespace App\Console\Services;
use Illuminate\Support\Str;
use PDO;
use Hashids\Hashids;
use Doctrine\DBAL\Driver\PDOException;
use Illuminate\Support\Str;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Hash;
use Symfony\Component\Console\Output\ConsoleOutput;
use App\Models\Aircraft;
use App\Models\Airline;
use App\Models\Airport;
use App\Models\Flight;
use App\Models\Rank;
use App\Models\Subfleet;
use App\Models\User;
use App\Models\Enums\UserState;
use App\Facades\Utils;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Hash;
/**
* Class Importer
@@ -53,7 +52,7 @@ class Importer
* CONSTANTS
*/
const BATCH_READ_ROWS = 500;
const BATCH_READ_ROWS = 300;
const SUBFLEET_NAME = 'Imported Aircraft';
/**
@@ -390,8 +389,8 @@ class Importer
foreach ($this->readRows('airports') as $row)
{
$attrs = [
'id' => $row->icao,
'icao' => $row->icao,
'id' => trim($row->icao),
'icao' => trim($row->icao),
'name' => $row->name,
'country' => $row->country,
'lat' => $row->lat,
@@ -412,15 +411,41 @@ class Importer
*/
protected function importFlights()
{
/*$this->comment('--- FLIGHT SCHEDULE IMPORT ---');
$this->comment('--- FLIGHT SCHEDULE IMPORT ---');
$count = 0;
foreach ($this->readRows('schedules') as $row)
{
$airline_id = $this->getMapping('airlines', $row->code);
$attrs = [
'dpt_airport_id' => $row->depicao,
'arr_airport_id' => $row->arricao,
'route' => $row->route ?: '',
'distance' => round($row->distance ?: 0, 2),
'level' => $row->flightlevel ?: 0,
'dpt_time' => $row->deptime ?: '',
'arr_time' => $row->arrtime ?: '',
'flight_time' => $row->flighttime ?: '',
'notes' => $row->notes ?: '',
'active' => $row->enabled ?: true,
];
$flight = Flight::firstOrCreate(
['airline_id' => $airline_id, 'flight_number' => $row->flightnum],
$attrs
);
$this->addMapping('flights', $row->id, $flight->id);
// TODO: deserialize route_details into ACARS table
if($flight->wasRecentlyCreated) {
++$count;
}
}
$this->info('Imported ' . $count . ' flights');*/
$this->info('Imported ' . $count . ' flights');
}
/**
@@ -473,6 +498,8 @@ class Importer
$attrs
);
$this->addMapping('users', $row->pilotid, $user->id);
if ($user->wasRecentlyCreated) {
++$count;
}
@@ -498,6 +525,8 @@ class Importer
{
// TODO: This state might differ between simpilot and classic version
$state = (int) $state;
// Declare array of classic states
$phpvms_classic_states = [
'ACTIVE' => 0,
@@ -516,6 +545,8 @@ class Importer
return UserState::SUSPENDED;
} elseif ($state === $phpvms_classic_states['ON_LEAVE']) {
return UserState::ON_LEAVE;
} else {
$this->error('Unknown status: '. $state);
}
}
}

View File

@@ -24,6 +24,8 @@ class CreateFlightTables extends Migration
$table->string('alt_airport_id', 5)->nullable();
$table->string('dpt_time', 10)->nullable();
$table->string('arr_time', 10)->nullable();
$table->unsignedInteger('level')->default(0);
$table->unsignedDecimal('distance', 19)->default(0.0);
$table->unsignedDecimal('flight_time', 19)->nullable();
$table->text('route')->nullable();
$table->text('notes')->nullable();

View File

@@ -24,6 +24,8 @@ class Flight extends BaseModel
'route',
'dpt_time',
'arr_time',
'level',
'distance',
'notes',
'has_bid',
'active',
@@ -31,12 +33,8 @@ class Flight extends BaseModel
protected $casts = [
'flight_number' => 'integer',
'route_code' => 'string',
'route_leg' => 'string',
'route' => 'string',
'dpt_time' => 'string',
'arr_time' => 'string',
'notes' => 'string',
'level' => 'integer',
'distance' => 'float',
'has_bid' => 'boolean',
'active' => 'boolean',
];

View File

@@ -55,16 +55,26 @@ SAME ROW
<!-- Dpt Time Field -->
<div class="row">
<div class="form-group col-sm-6">
<div class="form-group col-sm-3">
{!! Form::label('dpt_time', 'Departure Time:') !!}
{!! Form::text('dpt_time', null, ['class' => 'form-control']) !!}
</div>
<!-- Arr Time Field -->
<div class="form-group col-sm-6">
<div class="form-group col-sm-3">
{!! Form::label('arr_time', 'Arrival Time:') !!}
{!! Form::text('arr_time', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-sm-3">
{!! Form::label('distance', 'Distance:') !!}
{!! Form::text('distance', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-sm-3">
{!! Form::label('level', 'Flight Level:') !!}
{!! Form::text('level', null, ['class' => 'form-control']) !!}
</div>
</div>
<div class="row">

View File

@@ -25,26 +25,27 @@
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="row">
<div class="col-sm-6">
<span class="title">DEP&nbsp;</span>
{!! $flight->dpt_airport->icao !!}&nbsp;
<span class="title">ARR&nbsp;</span>
{!! $flight->arr_airport->icao !!}&nbsp;
</div>
<div class="col-sm-6 text-right">
<span class="description">{!! $flight->dpt_time !!}</span>
<span class="description">{!! $flight->arr_time !!}</span>
</div>
</div>
<div class="col-sm-5">
<span class="title">DEP&nbsp;</span>
{!! $flight->dpt_airport->icao !!}@if($flight->dpt_time), {!! $flight->dpt_time !!}@endif
<br />
<span class="title">ARR&nbsp;</span>
{!! $flight->arr_airport->icao !!}@if($flight->arr_time), {!! $flight->arr_time !!}@endif
<br />
@if($flight->distance)
<span class="title">DISTANCE&nbsp;</span>
{!! $flight->distance !!} {!! setting('general.distance_unit') !!}
@endif
<br />
@if($flight->level)
<span class="title">LEVEL&nbsp;</span>
{!! $flight->level !!} {!! setting('general.altitude_unit') !!}
@endif
</div>
<div class="col-sm-9">
<div class="col-sm-7">
<div class="row">
<div class="col-sm-12">
<span class="description">ROUTE&nbsp;</span>
<span class="title">ROUTE&nbsp;</span>
{!! $flight->route !!}
</div>
</div>