예제 #1
0
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
예제 #2
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()}"
예제 #3
0
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,
    )
예제 #4
0
파일: properties.py 프로젝트: rkm/bluebird
 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"]),
     )
예제 #5
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()}"
Tests for BlueBird's built-in metrics (provided by Aviary)
"""
from unittest import mock

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