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 _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 try_parse_lat_lon(args: dict) -> Union[types.LatLon, Response]: """Attempts to parse a LatLon from an argument dict""" try: assert "lat" in args, "Expected args to contain 'lat'" assert "lon" in args, "Expected args to contain 'lon'" return types.LatLon(args["lat"], args["lon"]) except AssertionError as exc: return bad_request_resp(f"Invalid LatLon: {exc}")
def test_aircraft_properties_from_data(): aircraft_data = TEST_SCENARIO["aircraft"][0] assert AircraftProperties.from_data(aircraft_data) == AircraftProperties( aircraft_type=aircraft_data["type"], altitude=types.Altitude(f'FL{aircraft_data["currentFlightLevel"]}'), callsign=types.Callsign(aircraft_data["callsign"]), cleared_flight_level=types.Altitude( f'FL{aircraft_data["clearedFlightLevel"]}'), ground_speed=None, heading=None, initial_flight_level=types.Altitude( f'FL{aircraft_data["currentFlightLevel"]}'), position=types.LatLon(aircraft_data["startPosition"][1], aircraft_data["startPosition"][0]), requested_flight_level=types.Altitude( f'FL{aircraft_data["requestedFlightLevel"]}'), route_name=None, vertical_speed=None, )
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()}"
def from_data(cls, data: Dict[str, Any]) -> "AircraftProperties": """ Create an AircraftProperties from the current sector element and an "aircraft" object from the scenario json """ return cls( aircraft_type=data["type"], altitude=types.Altitude(data["currentFlightLevel"]), callsign=types.Callsign(data["callsign"]), cleared_flight_level=types.Altitude(data["clearedFlightLevel"]), ground_speed=None, # TODO(rkm 2020-01-22) Check if we should know the initial heading here heading=None, position=types.LatLon(data["startPosition"][1], data["startPosition"][0]), requested_flight_level=types.Altitude( data["requestedFlightLevel"]), route_name=None, vertical_speed=None, initial_flight_level=types.Altitude(data["currentFlightLevel"]), )
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 # get_app_mock def patch_utils_path(endpoint: str) -> str: """Returns the utils module to be patched for the given endpoint"""
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( spec=AbstractAircraftControls) # Test invalid args