diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index 4882dc7d..64316c40 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -275,6 +275,24 @@ user_bids: user_id: 1 flight_id: flightid_3 +acars: + - pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: IAH + lat: 29.95691 + lon: -95.345719 + created_at: now + updated_at: now + - pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: MEI + lat: 32.37843 + lon: -88.804267 + created_at: now + updated_at: now + pireps: - id: pirepid_1 user_id: 1 @@ -286,7 +304,7 @@ pireps: arr_airport_id: KJFK flight_time: 180 # 6 hours state: 1 - route: PLMMR2 SPA Q22 BEARI FAK PHLBO3 + route: KAUS SID TNV J87 IAH J2 LCH J22 MEI J239 ATL J52 AJFEB J14 BYJAC Q60 JAXSN J14 COLIN J61 HUBBS J55 SIE STAR KJFK notes: just a pilot report created_at: NOW updated_at: NOW diff --git a/app/Http/Controllers/Admin/PirepController.php b/app/Http/Controllers/Admin/PirepController.php index 2853ce6f..79b67eb6 100644 --- a/app/Http/Controllers/Admin/PirepController.php +++ b/app/Http/Controllers/Admin/PirepController.php @@ -183,8 +183,7 @@ class PirepController extends BaseController $orig_route = $pirep->route; $pirep = $this->pirepRepo->update($attrs, $id); - // A route change in the PIREP, so update the saved points - // in the ACARS table + // A route change in the PIREP, so update the saved points in the ACARS table if($pirep->route !== $orig_route) { $this->pirepSvc->saveRoute($pirep); } diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index fdfc2a3a..10510772 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -37,64 +37,6 @@ class GeoService extends BaseService $this->navRepo = $navRepo; } - /** - * Parse a route string into a collection of Navadata points - * TODO: Add the distance calculation in here - * @param $route - * @param Airport|null $dep - * @param Airport|null $arr - * @return array|Collection - */ - public function routeToNavPoints($route, Airport $dep=null, Airport $arr=null) - { - $route = trim($route); - if(empty($route)) { - return collect(); - } - - $skip_points = ['SID', 'STAR']; - if($dep !== null) { - $skip_points[] = $dep->icao; - } - - if($arr !== null) { - $skip_points[] = $arr->icao; - } - - # Iterate through the route - $route = collect(explode(' ', $route)) - ->transform(function($point) use ($skip_points) { - $point = trim($point); - - if(empty($point)) { - return false; - } - - if(\in_array($point, $skip_points, true)) { - return false; - } - - try { - $navpoints = $this->navRepo->findWhere(['id'=>$point]); - } catch(ModelNotFoundException $e) { - return false; - } - - if($navpoints->count() === 0) { - return false; - } elseif ($navpoints->count() === 1) { - return $navpoints[0]; - } - - # find the closest waypoint... - }) - ->filter(function($value, $key) { - return !empty($value); - }); - - return $route; - } - /** * Determine the closest set of coordinates from the starting position * @param array $coordStart diff --git a/app/Services/PIREPService.php b/app/Services/PIREPService.php index 5ad06666..ca1fe0a4 100644 --- a/app/Services/PIREPService.php +++ b/app/Services/PIREPService.php @@ -66,10 +66,11 @@ class PIREPService extends BaseService return $pirep; } - $route = $this->geoSvc->routeToNavPoints( - $pirep->route, - $pirep->dep_airport, - $pirep->arr_airport + $route = $this->geoSvc->getCoordsFromRoute( + $pirep->dpt_airport_id, + $pirep->arr_airport_id, + [$pirep->dpt_airport->lat, $pirep->dpt_airport->lon], + $pirep->route ); /**