Skip to content

Commit

Permalink
Add load_factor and load_factor_variance to flights #352
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Mar 6, 2020
1 parent 9ed2e3f commit 49326f6
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 120 deletions.
30 changes: 16 additions & 14 deletions app/Database/factories/FlightFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
'alt_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id;
},
'distance' => $faker->numberBetween(1, 1000),
'route' => null,
'level' => 0,
'dpt_time' => $faker->time(),
'arr_time' => $faker->time(),
'flight_time' => $faker->numberBetween(60, 360),
'has_bid' => false,
'active' => true,
'visible' => true,
'days' => 0,
'start_date' => null,
'end_date' => null,
'created_at' => $faker->dateTimeBetween('-1 week', 'now'),
'updated_at' => static function (array $flight) {
'distance' => $faker->numberBetween(1, 1000),
'route' => null,
'level' => 0,
'dpt_time' => $faker->time(),
'arr_time' => $faker->time(),
'flight_time' => $faker->numberBetween(60, 360),
'load_factor' => $faker->randomElement([15, 20, 50, 90, 100]),
'load_factor_variance' => $faker->randomElement([15, 20, 50, 90, 100]),
'has_bid' => false,
'active' => true,
'visible' => true,
'days' => 0,
'start_date' => null,
'end_date' => null,
'created_at' => $faker->dateTimeBetween('-1 week', 'now'),
'updated_at' => static function (array $flight) {
return $flight['created_at'];
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class FlightsAddLoadFactor extends Migration
{
/**
* Add a `load_factor` and `load_factor_variance` columns to the expenses table
*/
public function up()
{
Schema::table('flights', function (Blueprint $table) {
$table->decimal('load_factor', 5, 2)
->nullable()
->after('flight_type');

$table->decimal('load_factor_variance', 5, 2)
->nullable()
->after('load_factor');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('flights', function (Blueprint $table) {
$table->dropColumn('load_factor');
$table->dropColumn('load_factor_variance');
});
}
}
52 changes: 45 additions & 7 deletions app/Database/seeds/dev/sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,16 @@ airports:
lat: 25.2528
lon: 55.3644
ground_handling_cost: 50

- id: OMAA
iata: AUH
icao: OMAA
name: Abu Dhabi International Airport
location: Abu Dhabi
country:
timezone: Asia/Dubai
lat: 24.433
lon: 54.6511
ground_handling_cost: 50
#
aircraft:
- id: 1
Expand Down Expand Up @@ -283,6 +292,7 @@ flights:
arr_time: 11PM EST
flight_time: 240
flight_type: J
load_factor: 100
created_at: NOW
updated_at: NOW
- id: flightid_3
Expand All @@ -294,6 +304,7 @@ flights:
arr_airport_id: KJFK
flight_time: 480
flight_type: J
load_factor: 63
dpt_time: 9AM CST
arr_time: 1030AM CST
route: PITZZ4 MNURE WLEEE4
Expand All @@ -308,6 +319,37 @@ flights:
arr_airport_id: MWCR
flight_time: 70
flight_type: 'J'
load_factor: 80
dpt_time: '0800'
arr_time: '0900'
route: 'MLY5 KEMBO UG442 SIA UG633 OTEKO UR640 NALRO GUBEL3'
created_at: NOW
updated_at: NOW
- id: flightid_5
airline_id: 1
flight_number: 112
route_code:
route_leg:
dpt_airport_id: OMAA
arr_airport_id: OMDB
flight_time: 30
flight_type: 'J'
load_factor:
dpt_time: '0800'
arr_time: '0900'
route: 'MLY5 KEMBO UG442 SIA UG633 OTEKO UR640 NALRO GUBEL3'
created_at: NOW
updated_at: NOW
- id: flightid_6
airline_id: 1
flight_number: 113
route_code:
route_leg:
dpt_airport_id: OMDB
arr_airport_id: OMAA
flight_time: 30
flight_type: 'J'
load_factor: 100
dpt_time: '0800'
arr_time: '0900'
route: 'MLY5 KEMBO UG442 SIA UG633 OTEKO UR640 NALRO GUBEL3'
Expand Down Expand Up @@ -467,12 +509,8 @@ pirep_fares:

pirep_fields:
- id: 1
name: departure terminal
slug: departure-terminal
required: 1
- id: 2
name: arrival terminal
slug: arrival-terminal
name: Cost Index
slug: cost-index
required: 0

pirep_field_values:
Expand Down
14 changes: 14 additions & 0 deletions app/Database/seeds/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@
options: ''
type: int
description: 'Number of hours to expire bids after'
- key: flights.default_load_factor
name: 'Load Factor'
group: flights
value: 82
options: ''
type: number
description: 'The default load factor for a flight, as a percent'
- key: flights.load_factor_variance
name: 'Load Factor Variance'
group: flights
value: 5
options: ''
type: number
description: 'How much the load factor can vary per-flight'
- key: pireps.duplicate_check_time
name: 'PIREP duplicate time check'
group: pireps
Expand Down
13 changes: 11 additions & 2 deletions app/Http/Resources/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
use App\Support\Units\Distance;
use stdClass;

/**
* @mixin \App\Models\Flight
*/
class Flight extends Response
{
/**
* Set the fields on the flight object
*
* @mixin \App\Models\Flight
*/
private function setFields()
{
Expand Down Expand Up @@ -42,6 +43,14 @@ public function toArray($request)

$res['ident'] = $this->ident;

if (empty($res['load_factor'])) {
$res['load_factor'] = setting('flights.default_load_factor');
}

if (empty($res['load_factor_variance'])) {
$res['load_factor_variance'] = setting('flights.load_factor_variance');
}

$distance = new Distance($res['distance'], config('phpvms.internal_units.distance'));
$res['distance'] = $distance->getResponseUnits();

Expand Down
44 changes: 26 additions & 18 deletions app/Models/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* @property int flight_time
* @property string route
* @property int level
* @property float load_factor
* @property float load_factor_variance
* @property Airport dpt_airport
* @property Airport arr_airport
* @property Airport alt_airport
Expand Down Expand Up @@ -65,6 +67,8 @@ class Flight extends Model
'distance',
'flight_time',
'flight_type',
'load_factor',
'load_factor_variance',
'route',
'notes',
'start_date',
Expand All @@ -75,27 +79,31 @@ class Flight extends Model
];

protected $casts = [
'flight_number' => 'integer',
'days' => 'integer',
'level' => 'integer',
'distance' => 'float',
'flight_time' => 'integer',
'start_date' => 'date',
'end_date' => 'date',
'has_bid' => 'boolean',
'route_leg' => 'integer',
'active' => 'boolean',
'visible' => 'boolean',
'flight_number' => 'integer',
'days' => 'integer',
'level' => 'integer',
'distance' => 'float',
'flight_time' => 'integer',
'start_date' => 'date',
'end_date' => 'date',
'load_factor' => 'double',
'load_factor_variance' => 'double',
'has_bid' => 'boolean',
'route_leg' => 'integer',
'active' => 'boolean',
'visible' => 'boolean',
];

public static $rules = [
'airline_id' => 'required|exists:airlines,id',
'flight_number' => 'required',
'route_code' => 'nullable',
'route_leg' => 'nullable',
'dpt_airport_id' => 'required|exists:airports,id',
'arr_airport_id' => 'required|exists:airports,id',
'level' => 'nullable',
'airline_id' => 'required|exists:airlines,id',
'flight_number' => 'required',
'route_code' => 'nullable',
'route_leg' => 'nullable',
'dpt_airport_id' => 'required|exists:airports,id',
'arr_airport_id' => 'required|exists:airports,id',
'load_factor' => 'nullable|numeric',
'load_factor_variance' => 'nullable|numeric',
'level' => 'nullable',
];

/**
Expand Down
1 change: 1 addition & 0 deletions app/Services/ImportExport/ExpenseImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ExpenseImporter extends ImportExport
'name' => 'required',
'amount' => 'required|numeric',
'type' => 'required',
'flight_type' => 'nullable',
'charge_to_user' => 'nullable|boolean',
'multiplier' => 'nullable|numeric',
'active' => 'nullable|boolean',
Expand Down
42 changes: 22 additions & 20 deletions app/Services/ImportExport/FlightImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,28 @@ class FlightImporter extends ImportExport
* Should match the database fields, for the most part
*/
public static $columns = [
'airline' => 'required',
'flight_number' => 'required',
'route_code' => 'nullable',
'route_leg' => 'nullable',
'dpt_airport' => 'required',
'arr_airport' => 'required',
'alt_airport' => 'nullable',
'days' => 'nullable',
'dpt_time' => 'nullable',
'arr_time' => 'nullable',
'level' => 'nullable|integer',
'distance' => 'nullable|numeric',
'flight_time' => 'required|integer',
'flight_type' => 'required|alpha',
'route' => 'nullable',
'notes' => 'nullable',
'active' => 'nullable|boolean',
'subfleets' => 'nullable',
'fares' => 'nullable',
'fields' => 'nullable',
'airline' => 'required',
'flight_number' => 'required',
'route_code' => 'nullable',
'route_leg' => 'nullable',
'dpt_airport' => 'required',
'arr_airport' => 'required',
'alt_airport' => 'nullable',
'days' => 'nullable',
'dpt_time' => 'nullable',
'arr_time' => 'nullable',
'level' => 'nullable|integer',
'distance' => 'nullable|numeric',
'flight_time' => 'required|integer',
'flight_type' => 'required|alpha',
'load_factor' => 'nullable',
'load_factor_variance' => 'nullable',
'route' => 'nullable',
'notes' => 'nullable',
'active' => 'nullable|boolean',
'subfleets' => 'nullable',
'fares' => 'nullable',
'fields' => 'nullable',
];

private $airportSvc;
Expand Down
14 changes: 14 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,17 @@ function _fmt($line, array $replace)
return $line;
}
}

if (!function_exists('docs_link')) {
/**
* Return a link to the docs
*
* @param string $key Key from phpvms.config.docs
*
* @return string
*/
function docs_link($key)
{
return config('phpvms.docs.root').config('phpvms.docs.'.$key);
}
}
7 changes: 6 additions & 1 deletion config/phpvms.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
* The links to various docs on the documentation site
*/
'docs' => [
'cron' => 'http://docs.phpvms.net/configuration/cron',
'root' => 'http://docs.phpvms.net',
'cron' => '/configuration/cron',
'finances' => '/concepts/finances',
'importing_legacy' => '/setup/importing-from-v2-v5',
'load_factor' => '/operations/flights#load-factor',
'subfleets' => '/concepts/basics#subfleets-and-aircraft',
],
];
2 changes: 1 addition & 1 deletion modules/Importer/Resources/views/step1-configure.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<li>The first user's password (admin) will be "admin". Please change it after logging in</li>
<li>User passwords will be reset and they will need to use "Forgot Password" to reset it</li>
<li>If you have more than 1000 PIREPs or flights, it's best to use the command-line importer!
<a href="http://docs.phpvms.net/setup/importing-from-v2-v5" target="_blank">Click here</a> to
<a href="{{ docs_link('importing_legacy') }}" target="_blank">Click here</a> to
see the documentation of how to use it.
</li>
<li><strong>THIS WILL WIPE OUT YOUR EXISTING DATA</strong> - this is required to make sure that things like
Expand Down
3 changes: 2 additions & 1 deletion modules/Vacentral/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ protected function registerConfig()
], 'config');

$this->mergeConfigFrom(
__DIR__.'/../Config/config.php', 'vacentral'
__DIR__.'/../Config/config.php',
'vacentral'
);
}
}
2 changes: 1 addition & 1 deletion resources/views/admin/dashboard/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="alert alert-danger" role="alert">
There was a problem running the cron; make sure it's setup and check logs at
<span class="text-monospace bg-gradient-dark">storage/logs/cron.log</span>.
<a href="{{ config('phpvms.docs.cron') }}" target="_blank">See the docs</a>
<a href="{{ docs_link('cron') }}" target="_blank">See the docs</a>
</div>
@endif

Expand Down
Loading

0 comments on commit 49326f6

Please sign in to comment.