Skip to content

Commit

Permalink
Fix GeoService errors when viewing PIREP #498
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Jan 15, 2020
1 parent d4da0a6 commit bef879a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/Models/Pirep.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
19 changes: 16 additions & 3 deletions app/Services/GeoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\Service;
use App\Models\Acars;
use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepState;
use App\Models\Flight;
use App\Models\GeoJson;
use App\Models\Pirep;
Expand Down Expand Up @@ -231,11 +232,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' => [
Expand Down

0 comments on commit bef879a

Please sign in to comment.