Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/Models/Vatsim/NetworkAircraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Location\Coordinate;
use Location\Distance\Haversine;

class NetworkAircraft extends Model
{
Expand Down Expand Up @@ -168,4 +169,23 @@ public function aircraft(): BelongsTo
{
return $this->belongsTo(Aircraft::class);
}

public function isNearDestination(float $thresholdNauticalMiles = 5.0): bool
{
if (!$this->destinationAirfield?->latitude || !$this->destinationAirfield?->longitude) {
return false;
}

$distanceToAirfieldInNm = LocationService::metersToNauticalMiles(
$this->latLong->getDistance($this->coordinate, new Haversine())
);

return $distanceToAirfieldInNm <= $thresholdNauticalMiles;
}

public function hasLanded(): bool
{
$isOnGround = $this->groundSpeed < 50;
return $isOnGround && $this->isNearDestination();
}
}
18 changes: 12 additions & 6 deletions app/Services/Stand/StandOccupationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,22 @@ private function occupyStands(Collection $standsToOccupy): void
}

/**
* Given some stands that have been recently occupied, remove any conflicting stand assignments.
* Given some stands that have been recently occupied, remove any conflicting stand assignments, unless the
* aircraft has already landed.
*/
private function deleteConflictingAssignmentsFollowingOccupation(Collection $newOccupations): void
{
StandAssignment::whereNotIn('callsign', $newOccupations->pluck('callsign'))
$conflictingAssignments = StandAssignment::with('aircraft')
->whereNotIn('callsign', $newOccupations->pluck('callsign'))
->whereIn('stand_id', $newOccupations->pluck('stand_id'))
->get()
->each(function (StandAssignment $assignment) {
$this->assignmentsService->deleteStandAssignment($assignment);
});
->get();

foreach ($conflictingAssignments as $assignment) {
if ($assignment->aircraft && $assignment->aircraft->hasLanded()) {
continue;
}
$this->assignmentsService->deleteStandAssignment($assignment);
}
}

/**
Expand Down