Major refactoring for PIREP statuses and states to accomodate ACARS/route data

This commit is contained in:
Nabeel Shahzad
2017-12-19 20:19:36 -06:00
parent ac4958a2be
commit 0375bb420f
38 changed files with 352 additions and 170 deletions

View File

@@ -8,7 +8,7 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Airport::class, function (Faker $faker) {
return [
'id' => strtoupper($faker->unique()->text(5)),
'icao' => function(array $apt) { return $apt['id']; },
'icao' => function(array $apt) { return substr($apt['id'],0, 4); },
'iata' => function (array $apt) { return $apt['id']; },
'name' => $faker->sentence(3),
'country' => $faker->country,

View File

@@ -0,0 +1,15 @@
<?php
use Faker\Generator as Faker;
$factory->define(App\Models\Navpoint::class, function (Faker $faker) {
return [
'id' => $faker->unique()->numberBetween(10, 100000),
'name' => $faker->unique()->text(10),
'title' => $faker->unique()->text(25),
'airway' => $faker->unique()->text(7),
'lat' => $faker->latitude,
'lon' => $faker->longitude,
'freq' => $faker->randomFloat(2, 100, 1000),
];
});

View File

@@ -1,5 +1,7 @@
<?php
use App\Models\Enums\PirepSource;
use App\Models\Enums\PirepState;
use Faker\Generator as Faker;
# Match the list available in tests/data/*.yml
@@ -40,8 +42,8 @@ $factory->define(App\Models\Pirep::class, function (Faker $faker) use ($airlines
'flight_time' => $faker->randomFloat(2),
'route' => $faker->text(200),
'notes' => $faker->text(200),
'source' => $faker->randomElement([0, 1]), # MANUAL/ACARS
'status' => config('enums.pirep_status.PENDING'), //$faker->randomElement([-1, 0, 1]), # REJECTED/PENDING/ACCEPTED
'source' => $faker->randomElement([PirepSource::MANUAL, PirepSource::ACARS]),
'state' => PirepState::PENDING, //$faker->randomElement([-1, 0, 1]), # REJECTED/PENDING/ACCEPTED
'raw_data' => $raw_data ?: $raw_data = json_encode(['key' => 'value']),
'created_at' => $faker->dateTimeBetween('-1 week', 'now'),
'updated_at' => function(array $pirep) {

View File

@@ -29,6 +29,7 @@ class CreateUsersTable extends Migration
$table->decimal('balance', 19)->nullable();
$table->string('timezone', 64)->nullable();
$table->unsignedTinyInteger('status')->default(0);
$table->unsignedTinyInteger('state')->default(0);
$table->boolean('active')->nullable();
$table->rememberToken();
$table->timestamps();

View File

@@ -10,7 +10,7 @@ class CreateAirportsTable extends Migration
Schema::create('airports', function (Blueprint $table) {
$table->string('id', 5)->primary();
$table->string('iata', 5)->nullable();
$table->string('icao', 5);
$table->string('icao', 4);
$table->string('name', 100);
$table->string('location', 100)->nullable();
$table->string('country', 64)->nullable();

View File

@@ -30,7 +30,8 @@ class CreatePirepTables extends Migration
$table->string('route', 250)->nullable();
$table->string('notes', 250)->nullable();
$table->unsignedTinyInteger('source')->default(0);
$table->tinyInteger('status')->default(0); # -1 rejected, 0 pending, 1 accepted
$table->tinyInteger('state')->default(0); # -1 rejected, 0 pending, 1 accepted
#$table->tinyInteger('status')->default(0); # -1 rejected, 0 pending, 1 accepted
$table->longText('raw_data')->nullable();
$table->timestamps();
$table->softDeletes();

View File

@@ -0,0 +1,47 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateNavdataTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
/**
* See for defs, modify/update based on this
* https://github.com/skiselkov/openfmc/blob/master/airac.h
*/
Schema::create('navpoints', function (Blueprint $table) {
$table->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();
$table->float('lat', 7, 4)->default(0.0);
$table->float('lon', 7, 4)->default(0.0);
$table->string('freq', 7);
$table->integer('type');
$table->index('name');
$table->index('airway');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('navpoints');
}
}

View File

@@ -0,0 +1,50 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAcarsTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
/**
* See for defs, modify/update based on this
* https://github.com/skiselkov/openfmc/blob/master/airac.h
*/
Schema::create('acars', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('acars_id', 12);
$table->string('name', 10)->nullable();
$table->float('lat', 7, 4)->default(0.0);
$table->float('lon', 7, 4)->default(0.0);
# TODO: More columns here for what might be required
# polymorphic relation columns.
# parent_type can be flight, pirep or acars
# once
$table->unsignedBigInteger('parent_id');
$table->string('parent_type');
$table->timestamps();
$table->index('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('acars');
}
}

View File

@@ -336,7 +336,7 @@ pireps:
dpt_airport_id: KAUS
arr_airport_id: KJFK
flight_time: 180 # 6 hours
status: 0
state: 0
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
- id: pirepid_2
@@ -347,7 +347,7 @@ pireps:
dpt_airport_id: KJFK
arr_airport_id: KAUS
flight_time: 180 # 6 hours
status: 0
state: 0
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report
- id: pirepid_3
@@ -358,7 +358,7 @@ pireps:
dpt_airport_id: KJFK
arr_airport_id: KAUS
flight_time: 180 # 6 hours
status: 0
state: 0
route: PLMMR2 SPA Q22 BEARI FAK PHLBO3
notes: just a pilot report