-
Notifications
You must be signed in to change notification settings - Fork 13
Add Functions and Table Structure to Allow Ground Positions #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
95fc3b6
b3fc07b
f5a50b6
a0c97da
b2cc708
5995fa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,15 @@ | |
| UTC = timezone.utc | ||
|
|
||
|
|
||
| def _get_ground_positions(flight_id: str) -> Iterable: | ||
| return ( | ||
| positions_engine.execute( | ||
| positions.select().where(and_(positions.c.id == flight_id, positions.c.air_ground is not None)).order_by(positions.c.time.desc()) | ||
| ) | ||
| or [] | ||
| ) | ||
|
|
||
|
|
||
| def _get_positions(flight_id: str) -> Iterable: | ||
| return ( | ||
| positions_engine.execute( | ||
|
|
@@ -57,6 +66,16 @@ def _get_positions(flight_id: str) -> Iterable: | |
| ) | ||
|
|
||
|
|
||
| @app.route("/ground_positions/<flight_id>") | ||
| def get_ground_positions(flight_id: str) -> Response: | ||
| """Get positions for a specific flight_id""" | ||
|
jacob-y-pan marked this conversation as resolved.
Outdated
|
||
| result = _get_ground_positions(flight_id) | ||
| if not result: | ||
| abort(404) | ||
| # print("HEY HERE IS THE GROUND_POSITION DATA" + str([dict(e) for e in result])) | ||
|
jacob-y-pan marked this conversation as resolved.
Outdated
|
||
| return jsonify([dict(e) for e in result]) | ||
|
|
||
|
|
||
| @app.route("/positions/<flight_id>") | ||
| def get_positions(flight_id: str) -> Response: | ||
| """Get positions for a specific flight_id""" | ||
|
|
@@ -247,11 +266,28 @@ def get_map(flight_id: str) -> bytes: | |
| bearing = trig.get_cardinal_for_angle(trig.get_bearing_degrees(coord1, coord2)) | ||
| coords = "|".join(f"{pos.latitude},{pos.longitude}" for pos in positions) | ||
|
|
||
| # Do ground positions | ||
| ground_positions = list(_get_ground_positions(flight_id)) | ||
| if not ground_positions: | ||
| abort(404) | ||
| bearing_gp = 0 | ||
| if len(ground_positions) > 1: | ||
| coord1 = (float(ground_positions[1].latitude), float(ground_positions[1].longitude)) | ||
| coord2 = (float(ground_positions[0].latitude), float(ground_positions[0].longitude)) | ||
| bearing_gp = trig.get_cardinal_for_angle(trig.get_bearing_degrees(coord1, coord2)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to do this twice, just determine the bearing of the most recent position/ground_position.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it safe to assume that if the most recent is ground_position the second most recent will also be ground_position?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There might be a case where you happen to have the first ground position after a plane has touched down, meaning the second most recent would be from airborne. It might be useful to have a function that grabs all positions in time order and just works with those at first, later splitting them up by air/ground when needed. |
||
| coords_gp = "|".join(f"{pos.latitude},{pos.longitude}" for pos in ground_positions) | ||
|
|
||
| google_maps_url = "https://maps.googleapis.com/maps/api/staticmap" | ||
| google_maps_params = { | ||
| "size": "640x400", | ||
| "markers": f"anchor:center|icon:https://github.com/flightaware/fids_frontend/raw/master/images/aircraft_{bearing}.png|{positions[0].latitude},{positions[0].longitude}", | ||
| "path": f"color:0x0000ff|weight:5|{coords}", | ||
| "markers": [ | ||
| f"anchor:center|icon:https://github.com/flightaware/fids_frontend/raw/master/images/aircraft_{bearing}.png|{positions[0].latitude},{positions[0].longitude}", | ||
|
jacob-y-pan marked this conversation as resolved.
Outdated
|
||
| f"anchor:center|icon:https://github.com/flightaware/fids_frontend/raw/master/images/aircraft_{bearing_gp}.png|{ground_positions[0].latitude},{ground_positions[0].longitude}" | ||
| ], | ||
| "path": [ | ||
| f"color:0x0000ff|weight:5|{coords}", | ||
| f"color:0xff0000|weight:5|{coords_gp}" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a flight, what you'll tend to see are a group of ground_positions (pre-departure), then a group of positions, and then another group of ground_positions (post-arrival). Ideally this could be represented on the static map with a dual-colored, 3-part line. To represent that, you'd need to figure out where to split up the ground positions so that they can be in 2 separate lists. You might be able to use time gaps in the ground position list to determine this, or perhaps the flight's actual departure and arrival events.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what "perhaps the flight's actual departure and arrival events" means, though I will look at that. Is it possible to even use the coordinates of the locations and determine if it's closer to the destination or origin, or is that too expensive / complicated considering there's no geolocation API being used (thinking of the hackathon haha) ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be more specific, you could cheat (a little) and just say "we're calling every position we have with a time before the flight's departure or after the flight's arrival a ground position". You unfortunately won't have airport coordinates readily available, and even if you did, we're not really trying to distinguish between start and end of flight, but between "in the air" and "on the ground".
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For those flights that have all 3, would we be able to see the ground positions lines? It seems like if the flight is very far the small positions on the ground would barely be visible (I'm kind of seeing that when looking at various flights for pre-departure routes), so maybe expand the map or something like that? |
||
| ], | ||
| "key": google_maps_api_key, | ||
| } | ||
| response = requests.get(google_maps_url, google_maps_params) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.