From b8ef541d8d4fabcc9f27ccd11824cf10b0476aac Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Wed, 15 Jan 2020 08:56:18 -0500 Subject: [PATCH] Fix GeoService errors when viewing PIREP #498 --- app/Models/Pirep.php | 3 +++ app/Services/GeoService.php | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index d8c338a54..c0af97700 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -267,6 +267,9 @@ public function getProgressPercentAttribute() $upper_bound = $this->planned_distance; } + $upper_bound = empty($upper_bound) ? 1 : $upper_bound; + $distance = empty($distance) ? $upper_bound : $distance; + return round(($distance / $upper_bound) * 100, 0); } diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index 41a43f953..8c524b5ac 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -231,11 +231,23 @@ public function getFeatureFromAcars(Pirep $pirep) ]); }*/ - return [ - 'position' => [ + // If there is a position update from ACARS, show where it is + // Otherwise, just assume it's at the arrival airport currently + if ($pirep->position) { + $position = [ 'lat' => $pirep->position->lat, 'lon' => $pirep->position->lon, - ], + ]; + } else { + // if arrived, show it being at the arrival airport + $position = [ + 'lat' => $pirep->arr_airport->lat, + 'lon' => $pirep->arr_airport->lon, + ]; + } + + return [ + 'position' => $position, 'line' => $route->getLine(), 'points' => $route->getPoints(), 'airports' => [