def _convert_to_ac_props( self, data: dict, ) -> Union[Dict[types.Callsign, props.AircraftProperties], str]: ac_props = {} try: for i in range(len(data["id"])): callsign = types.Callsign(data["id"][i]) ac_props[callsign] = props.AircraftProperties( aircraft_type=data["actype"][i], altitude=types.Altitude(data["alt"][i] / METERS_PER_FOOT), callsign=callsign, cleared_flight_level=None, ground_speed=types.GroundSpeed(int(data["gs"][i])), heading=types.Heading(int(data["trk"][i])), initial_flight_level=None, position=types.LatLon(data["lat"][i], data["lon"][i]), requested_flight_level=None, route_name=None, vertical_speed=types.VerticalSpeed( int(data["vs"][i] * 60 / METERS_PER_FOOT)), ) return ac_props except Exception: return f"Error parsing ac data from stream: {traceback.format_exc()}"
def test_convert_aircraft_props(): """Tests for convert_aircraft_props""" ac_props = props.AircraftProperties( aircraft_type="A380", altitude=types.Altitude(18_500), callsign=types.Callsign("TEST"), cleared_flight_level=types.Altitude("FL225"), ground_speed=types.GroundSpeed(23), heading=types.Heading(47), initial_flight_level=types.Altitude(18_500), position=types.LatLon(43.8, 123.4), requested_flight_level=types.Altitude(25_000), route_name=None, vertical_speed=types.VerticalSpeed(32), ) converted = utils.convert_aircraft_props(ac_props) assert isinstance(converted, dict) assert len(converted) == 1 converted_props = converted["TEST"] assert len(converted_props) == 9 assert converted_props["actype"] == "A380" assert converted_props["cleared_fl"] == 22_500 assert converted_props["current_fl"] == 18_500 assert converted_props["gs"] == 23.0 assert converted_props["hdg"] == 47 assert converted_props["lat"] == 43.8 assert converted_props["lon"] == 123.4 assert converted_props["requested_fl"] == 25_000 assert converted_props["vs"] == 32.0
def _parse_aircraft_properties( ac_props: dict, ) -> Union[props.AircraftProperties, str]: try: # TODO Not currently available: gs, hdg, pos, vs return props.AircraftProperties( aircraft_type=ac_props["flight-data"]["type"], altitude=types.Altitude(f'FL{ac_props["pos"]["afl"]}'), callsign=types.Callsign(ac_props["flight-data"]["callsign"]), cleared_flight_level=None, ground_speed=types.GroundSpeed(ac_props["pos"]["speed"]), heading=types.Heading(0), initial_flight_level=None, position=types.LatLon(ac_props["pos"]["lat"], ac_props["pos"]["long"]), requested_flight_level=None, route_name=None, vertical_speed=types.VerticalSpeed(0), ) except Exception: return f"Error parsing AircraftProperties: {traceback.format_exc()}"
dt=0.01, scenario_name="test-scenario", scenario_time=0, sector_name="test-sector", seed=0, speed=1.0, state=props.SimState.INIT, utc_datetime=datetime.datetime.now(), ) TEST_AIRCRAFT_PROPS = props.AircraftProperties( aircraft_type="TEST1", altitude=types.Altitude(18_500), callsign="A380", cleared_flight_level=types.Altitude(22_000), ground_speed=types.GroundSpeed(53), heading=types.Heading(74), initial_flight_level=types.Altitude(18_500), position=types.LatLon(51.529761, -0.127531), requested_flight_level=types.Altitude(25_300), route_name=None, vertical_speed=types.VerticalSpeed(73), ) def endpoint_path(endpoint: str) -> str: """Returns the endpoint path""" return f"{API_PREFIX}/{endpoint}" # TODO(rkm 2020-01-12) Aiming to remove this since the tests can be simplified by using
import pytest import bluebird.metrics.bluebird.metrics as metrics import bluebird.utils.properties as props import bluebird.utils.types as types from bluebird.utils.abstract_aircraft_controls import AbstractAircraftControls _TEST_CALLSIGN_1 = "TEST1" _TEST_CALLSIGN_2 = "TEST2" _TEST_PROPS = props.AircraftProperties( aircraft_type="A380", altitude=types.Altitude("FL185"), callsign=_TEST_CALLSIGN_1, cleared_flight_level=types.Altitude("FL234"), ground_speed=types.GroundSpeed(160), heading=types.Heading(128), initial_flight_level=types.Altitude("FL185"), position=types.LatLon(23, 45), requested_flight_level=types.Altitude("FL250"), route_name=None, vertical_speed=types.VerticalSpeed(120), ) def test_pairwise_separation_metric(): """ Tests the pairwise_separation_metric function """ mock_aircraft_controls = mock.create_autospec(