Beispiel #1
0
def _make_flight_observation(
        flight: rid.RIDFlight,
        view: s2sphere.LatLngRect) -> observation_api.Flight:
    paths: List[List[observation_api.Position]] = []
    current_path: List[observation_api.Position] = []
    previous_position: Optional[observation_api.Position] = None

    lat_min = view.lat_lo().degrees
    lat_max = view.lat_hi().degrees
    lng_min = view.lng_lo().degrees
    lng_max = view.lng_hi().degrees

    # Decompose recent positions into a list of contiguous paths
    for p in flight.recent_positions:
        lat = p.position.lat
        lng = p.position.lng
        position_report = observation_api.Position(lat=lat,
                                                   lng=lng,
                                                   alt=p.position.alt)

        inside_view = lat_min <= lat <= lat_max and lng_min <= lng <= lng_max
        if inside_view:
            # This point is inside the view
            if not current_path and previous_position:
                # Positions were previously outside the view but this one is in
                current_path.append(previous_position)
            current_path.append(position_report)
        else:
            # This point is outside the view
            if current_path:
                # Positions were previously inside the view but this one is out
                current_path.append(position_report)
                paths.append(current_path)
                current_path = []
        previous_position = position_report
    if current_path:
        paths.append(current_path)

    return observation_api.Flight(
        id=flight.id,
        most_recent_position=observation_api.Position(
            lat=flight.current_state.position.lat,
            lng=flight.current_state.position.lng,
            alt=flight.current_state.position.alt),
        recent_paths=[observation_api.Path(positions=path) for path in paths])
Beispiel #2
0
def _make_api_flight(flight: injection_api.TestFlight,
                     sp_behavior: behavior.ServiceProviderBehavior,
                     dp_behavior: behavior.DisplayProviderBehavior,
                     t_earliest: datetime.datetime, t_now: datetime.datetime,
                     lat_min: float, lng_min: float, lat_max: float,
                     lng_max: float) -> observation_api.Flight:
    """Extract the currently-relevant information from a TestFlight.

  :param flight: TestFlight with telemetry for all time
  :param t_earliest: The time before which telemetry should be ignored
  :param t_now: The time after which telemetry should be ignored
  :return: Flight information currently visible in the remote ID system
  """
    paths: List[List[observation_api.Position]] = []
    current_path: List[observation_api.Position] = []
    previous_position: Optional[observation_api.Position] = None
    most_recent_position: Optional[Tuple[datetime.datetime,
                                         observation_api.Position]] = None

    for telemetry in flight.telemetry:
        t = iso8601.parse_date(telemetry.timestamp)
        if t < t_earliest:
            # Not relevant; telemetry more than 60s in the past
            continue
        if t > t_now:
            # Not yet relevant; will occur in the future
            continue
        lat = telemetry.position.lat
        lng = telemetry.position.lng
        alt = telemetry.position.alt

        # Mangle data on the Service Provider side
        if sp_behavior.use_agl_instead_of_wgs84_for_altitude:
            if 'height' in telemetry and telemetry.height.reference == 'TakeoffLocation':
                alt = telemetry.height.distance
            else:
                alt -= flight.telemetry[0].position.alt
        if sp_behavior.use_feet_instead_of_meters_for_altitude:
            alt /= 0.3048

        position_report = _make_position_report(lat, lng, alt, sp_behavior,
                                                dp_behavior)

        inside_view = lat_min <= lat <= lat_max and lng_min <= lng <= lng_max
        if inside_view:
            # This is a relevant point inside the view
            if not current_path and previous_position:
                # Positions were previously outside the view but this one is in
                current_path.append(previous_position)
            current_path.append(position_report)
            if most_recent_position is None or most_recent_position[0] < t:
                most_recent_position = (t, position_report)
        else:
            # This point is in the relevant time range but outside the view
            if current_path:
                # Positions were previously inside the view but this one is out
                current_path.append(position_report)
                paths.append(current_path)
                current_path = []
        previous_position = position_report
    if current_path:
        paths.append(current_path)

    kwargs = {'id': flight.get_id(t_now)}
    if paths and not dp_behavior.always_omit_recent_paths:
        kwargs['recent_paths'] = [
            observation_api.Path(positions=p) for p in paths
        ]
    if most_recent_position:
        kwargs['most_recent_position'] = most_recent_position[1]
    return observation_api.Flight(**kwargs)