Skip to content

Commit

Permalink
Add cargo load factor
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 committed Sep 26, 2023
1 parent de0e446 commit 8193763
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
23 changes: 22 additions & 1 deletion app/Database/seeds/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
value: true
options: ''
type: boolean
description: 'When enabled, an aircraft can only be used for one active Bid and Flight/Pirep'
description: 'When enabled, an aircraft can only be used for one active Bid and Flight/Pirep'
- key: bids.expire_time
name: 'Expire Time'
group: bids
Expand All @@ -235,6 +235,27 @@
options: ''
type: number
description: 'How much the load factor can vary per-flight'
- key: flights.different_cargo_load_factor
name: 'Different Cargo Load Factor'
group: flights
value: false
options: ''
type: boolean
description: 'When enabled, v7 will use a different load factor for cargo and passengers fares'
- key: flights.default_cargo_load_factor
name: 'Cargo Load Factor'
group: flights
value: 32
options: ''
type: number
description: 'The default cargo load factor for a flight, as a percent'
- key: flights.cargo_load_factor_variance
name: 'Cargo Load Factor Variance'
group: flights
value: 5
options: ''
type: number
description: 'How much the cargo load factor can vary per-flight'
- key: simbrief.api_key
name: 'Simbrief API Key'
group: simbrief
Expand Down
25 changes: 22 additions & 3 deletions app/Http/Controllers/Frontend/SimBriefController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,34 @@ public function generate(Request $request): RedirectResponse|View
$lfactorv = $flight->load_factor_variance ?? setting('flights.load_factor_variance');

$loadmin = $lfactor - $lfactorv;
$loadmin = $loadmin < 0 ? 0 : $loadmin;
$loadmin = max($loadmin, 0);

$loadmax = $lfactor + $lfactorv;
$loadmax = $loadmax > 100 ? 100 : $loadmax;
$loadmax = min($loadmax, 100);

if ($loadmax === 0) {
$loadmax = 100;
}

if (setting('flights.different_cargo_load_factor', false))
{
$cgolfactor = $flight->load_factor ?? setting('flights.default_cargo_load_factor');
$cgolfactorv = $flight->load_factor_variance ?? setting('flights.cargo_load_factor_variance');

$cgoloadmin = $cgolfactor - $cgolfactorv;
$cgoloadmin = max($cgoloadmin, 0);

$cgoloadmax = $cgolfactor + $cgolfactorv;
$cgoloadmax = min($cgoloadmax, 100);

if ($cgoloadmax === 0) {
$cgoloadmax = 100;
}
} else {
$cgoloadmin = $loadmin;
$cgoloadmax = $loadmax;
}

// Load fares for passengers

$loaddist = []; // The load distribution string
Expand Down Expand Up @@ -195,7 +214,7 @@ public function generate(Request $request): RedirectResponse|View
continue;
}

$count = ceil((($fare->capacity - $tbagload) * rand($loadmin, $loadmax)) / 100);
$count = ceil((($fare->capacity - $tbagload) * rand($cgoloadmin, $cgoloadmax)) / 100);
$tcargoload += $count;
$cargo_load_sheet[] = [
'id' => $fare->id,
Expand Down

0 comments on commit 8193763

Please sign in to comment.