Skip to content

Commit

Permalink
Merge pull request #1396 from AndyTWF/stand-assignment-predictor
Browse files Browse the repository at this point in the history
Stand assignment predictor
  • Loading branch information
AndyTWF authored Oct 9, 2023
2 parents 2e06316 + 141d5ab commit 8461696
Show file tree
Hide file tree
Showing 92 changed files with 5,688 additions and 758 deletions.
88 changes: 0 additions & 88 deletions app/Allocator/Stand/AbstractArrivalStandAllocator.php

This file was deleted.

48 changes: 30 additions & 18 deletions app/Allocator/Stand/AirlineAircraftArrivalStandAllocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,47 @@

namespace App\Allocator\Stand;

use App\Models\Aircraft\Aircraft;
use App\Models\Vatsim\NetworkAircraft;
use App\Services\AirlineService;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;

class AirlineAircraftArrivalStandAllocator extends AbstractArrivalStandAllocator
class AirlineAircraftArrivalStandAllocator implements ArrivalStandAllocator, RankableArrivalStandAllocator
{
private AirlineService $airlineService;
use SelectsFromAirlineSpecificStands;

public function __construct(AirlineService $airlineService)
/**
* This allocator uses the standard SelectsFromAirlineSpecificStands trait to generate a stand query,
* with additional filters that only stands for a specific aircraft type are selected.
*/
public function allocate(NetworkAircraft $aircraft): ?int
{
$this->airlineService = $airlineService;
// We cant allocate a stand if we don't know the airline or aircraft type
if ($aircraft->airline_id === null || $aircraft->aircraft_id === null) {
return null;
}

return $this->selectAirlineSpecificStands(
$aircraft,
$this->queryFilter($aircraft)
);
}

protected function getOrderedStandsQuery(Builder $stands, NetworkAircraft $aircraft): ?Builder
public function getRankedStandAllocation(NetworkAircraft $aircraft): Collection
{
$airline = $this->airlineService->getAirlineForAircraft($aircraft);
if ($airline === null) {
return null;
// We cant allocate a stand if we don't know the airline or aircraft type
if ($aircraft->airline_id === null || $aircraft->aircraft_id === null) {
return collect();
}

$aircraftType = Aircraft::where('code', $aircraft->planned_aircraft)->first();
if (!$aircraftType) {
return null;
}
return $this->selectRankedAirlineSpecificStands(
$aircraft,
$this->queryFilter($aircraft)
);
}

return $stands->with('airlines')
->airline($airline)
->where('airline_stand.aircraft_id', $aircraftType->id)
->orderBy('airline_stand.priority');
private function queryFilter(NetworkAircraft $aircraft): Closure
{
return fn (Builder $query) => $query->where('airline_stand.aircraft_id', $aircraft->aircraft_id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,53 @@

namespace App\Allocator\Stand;

use App\Models\Aircraft\Aircraft;
use App\Models\Vatsim\NetworkAircraft;
use App\Services\AirlineService;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;

class AirlineAircraftTerminalArrivalStandAllocator extends AbstractArrivalStandAllocator
class AirlineAircraftTerminalArrivalStandAllocator implements ArrivalStandAllocator, RankableArrivalStandAllocator
{
private AirlineService $airlineService;
use SelectsStandsFromAirlineSpecificTerminals;

public function __construct(AirlineService $airlineService)
/*
* This allocator:
*
* - Selects stands that are size appropriate and available
* - Filters these to stands at terminals that are specifically selected for the airline AND a given aircraft type
* - Orders these stands by the airline's priority for the stand
* - Orders these stands by the common conditions, minus the general allocation priority
* (see OrdersStandsByCommonConditions)
* - Selects the first stand that pops up
*/
public function allocate(NetworkAircraft $aircraft): ?int
{
$this->airlineService = $airlineService;
// We can only allocate a stand if we know the airline and aircraft type
if ($aircraft->airline_id === null || $aircraft->aircraft_id === null) {
return null;
}

return $this->selectStandsAtAirlineSpecificTerminals(
$aircraft,
$this->queryFilter($aircraft)
);
}

protected function getOrderedStandsQuery(Builder $stands, NetworkAircraft $aircraft): ?Builder
public function getRankedStandAllocation(NetworkAircraft $aircraft): Collection
{
$airline = $this->airlineService->getAirlineForAircraft($aircraft);
if ($airline === null) {
return null;
// We cant allocate a stand if we don't know the airline or aircraft type
if ($aircraft->airline_id === null || $aircraft->aircraft_id === null) {
return collect();
}

$aircraftType = Aircraft::where('code', $aircraft->planned_aircraft)->first();
if (!$aircraftType) {
return null;
}
return $this->selectRankedStandsAtAirlineSpecificTerminals(
$aircraft,
$this->queryFilter($aircraft)
);
}

return $stands->join('terminals', 'terminals.id', '=', 'stands.terminal_id')
->join('airline_terminal', 'terminals.id', '=', 'airline_terminal.terminal_id')
->where('airline_terminal.airline_id', $airline->id)
->where('airline_terminal.aircraft_id', $aircraftType->id)
->orderBy('airline_terminal.priority');
private function queryFilter(NetworkAircraft $aircraft): Closure
{
return fn (Builder $query) => $query->where('airline_terminal.aircraft_id', $aircraft->aircraft_id);
}
}
30 changes: 0 additions & 30 deletions app/Allocator/Stand/AirlineArrivalStandAllocator.php

This file was deleted.

50 changes: 41 additions & 9 deletions app/Allocator/Stand/AirlineCallsignArrivalStandAllocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,61 @@

use App\Models\Vatsim\NetworkAircraft;
use App\Services\AirlineService;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;

class AirlineCallsignArrivalStandAllocator extends AbstractArrivalStandAllocator
class AirlineCallsignArrivalStandAllocator implements ArrivalStandAllocator, RankableArrivalStandAllocator
{
use SelectsFromAirlineSpecificStands;
use UsesCallsignSlugs;

private AirlineService $airlineService;
private readonly AirlineService $airlineService;

public function __construct(AirlineService $airlineService)
{
$this->airlineService = $airlineService;
}

protected function getOrderedStandsQuery(Builder $stands, NetworkAircraft $aircraft): ?Builder
/**
* This allocator:
*
* - Selects stands that are size appropriate and available
* - Filters these to stands that are specifically selected for the airline and a specific callsign
* - Orders these stands by the airline's priority for the stand
* - Orders these stands by the common conditions, minus the general allocation priority
* (see OrdersStandsByCommonConditions)
* - Selects the first stand that pops up
*/
public function allocate(NetworkAircraft $aircraft): ?int
{
$airline = $this->airlineService->getAirlineForAircraft($aircraft);
if ($airline === null) {
// We can only allocate a stand if we know the airline
if ($aircraft->airline_id === null) {
return null;
}

return $stands->with('airlines')
->airline($airline)
->where('airline_stand.full_callsign', $this->getFullCallsignSlug($aircraft))
->orderBy('airline_stand.priority');
return $this->selectAirlineSpecificStands(
$aircraft,
$this->queryFilter($aircraft)
);
}

public function getRankedStandAllocation(NetworkAircraft $aircraft): Collection
{
// We can only allocate a stand if we know the airline
if ($aircraft->airline_id === null) {
return collect();
}

return $this->selectRankedAirlineSpecificStands(
$aircraft,
$this->queryFilter($aircraft)
);
}

private function queryFilter(NetworkAircraft $aircraft): Closure
{
return fn (Builder $query) =>
$query->where('airline_stand.full_callsign', $this->getFullCallsignSlug($aircraft));
}
}
Loading

0 comments on commit 8461696

Please sign in to comment.