Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion db-updater/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@
sa.Column("wind_direction", sa.Integer, key="wind_dir"),
sa.Column("wind_quality", sa.Integer),
sa.Column("wind_speed", sa.Integer),
# New columns from ground_positions
sa.Column("air_ground", sa.String),
sa.Column("airport", sa.String),
)
VALID_EVENTS = {"position"}
VALID_EVENTS = {"position", "ground_position"}

engine_args: dict = {}
db_url: str = os.environ["DB_URL"]
Expand Down Expand Up @@ -480,6 +483,11 @@ def process_keepalive_message(data: dict) -> None:
print(f'Based on keepalive["pitr"], we are {behind} behind realtime')


def process_ground_position_message(data: dict) -> None:
"""Groundposition message type"""
return add_to_cache(data)


def disambiguate_altitude(data: dict):
"""Replaces the alt field in the passed dict with an unambiguous field name"""

Expand Down Expand Up @@ -534,6 +542,8 @@ def main():
"flightplan": process_flightplan_message,
"keepalive": process_keepalive_message,
"position": process_position_message,
# maybe change here
Comment thread
jacob-y-pan marked this conversation as resolved.
Outdated
"ground_position": process_ground_position_message,
}

consumer = None
Expand Down
40 changes: 38 additions & 2 deletions fids/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"""
Comment thread
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]))
Comment thread
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"""
Expand Down Expand Up @@ -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))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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}",
Comment thread
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}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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) ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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)
Expand Down