Exemplo n.º 1
0
def flights():
    if 'view' not in flask.request.args:
        return flask.jsonify(
            rid.ErrorResponse(
                message='Missing required "view" parameter')), 400
    try:
        view = geo.make_latlng_rect(flask.request.args['view'])
    except ValueError as e:
        return flask.jsonify(
            rid.ErrorResponse(message='Error parsing view: {}'.format(e))), 400

    include_recent_positions = flask.request.args.get(
        'include_recent_positions', 'False').lower() == 'true'

    diagonal = view.lo().get_distance(
        view.hi()).degrees * geo.EARTH_CIRCUMFERENCE_KM / 360
    if diagonal > rid.NetMaxDisplayAreaDiagonal:
        msg = 'Requested diagonal of {} km exceeds limit of {} km'.format(
            diagonal, rid.NetMaxDisplayAreaDiagonal)
        return flask.jsonify(rid.ErrorResponse(message=msg)), 413

    now = arrow.utcnow().datetime
    flights = []
    for test_id, record in db.tests.items():
        for flight in record.flights:
            reported_flight = _get_report(flight, now, view,
                                          include_recent_positions)
            if reported_flight is not None:
                flights.append(reported_flight)
    return flask.jsonify(
        rid.GetFlightsResponse(timestamp=StringBasedDateTime(now),
                               flights=flights)), 200
Exemplo n.º 2
0
 def from_arguments(cls, args: argparse.Namespace):
     adapter: auth.AuthAdapter = auth.make_auth_adapter(args.auth)
     dss_client = infrastructure.DSSTestSession(args.dss, adapter)
     area: s2sphere.LatLngRect = geo.make_latlng_rect(args.area)
     start_time = datetime.datetime.fromisoformat(args.start_time)
     end_time = start_time + datetime.timedelta(hours=args.trace_hours)
     logger = tracerlog.Logger(
         args.output_folder) if args.output_folder else None
     return ResourceSet(dss_client, area, logger, start_time, end_time)
Exemplo n.º 3
0
 def from_arguments(cls, args: argparse.Namespace):
     adapter: auth.AuthAdapter = auth.make_auth_adapter(args.auth)
     dss_client = infrastructure.DSSTestSession(args.dss, adapter)
     area: s2sphere.LatLngRect = geo.make_latlng_rect(args.area)
     start_time = datetime.datetime.fromisoformat(args.start_time)
     end_time = start_time + datetime.timedelta(hours=args.trace_hours)
     if args.kml_server and args.kml_folder is None:
         raise ValueError(
             'If --kml-server is specified, --kml-folder must also be specified'
         )
     kml_session = infrastructure.KMLGenerationSession(
         args.kml_server, args.kml_folder) if args.kml_server else None
     logger = tracerlog.Logger(args.output_folder,
                               kml_session) if args.output_folder else None
     return ResourceSet(dss_client, area, logger, start_time, end_time)
Exemplo n.º 4
0
def request_rid_poll():
    if 'area' not in flask.request.form:
        flask.abort(400, 'Missing area')

    try:
        area = geo.make_latlng_rect(flask.request.form['area'])
    except ValueError as e:
        flask.abort(400, str(e))

    flights_result = fetch.rid.all_flights(
        context.resources.dss_client, area,
        flask.request.form.get('include_recent_positions'),
        flask.request.form.get('get_details'),
        flask.request.form.get('enhanced_details'))
    log_name = context.resources.logger.log_new('clientrequest_getflights',
                                                flights_result)
    return flask.redirect(flask.url_for('logs', log=log_name))
Exemplo n.º 5
0
def display_data() -> Tuple[str, int]:
    """Implements retrieval of current display data per automated testing API."""

    if 'view' not in flask.request.args:
        return flask.jsonify(
            rid.ErrorResponse(
                message='Missing required "view" parameter')), 400
    try:
        view = geo.make_latlng_rect(flask.request.args['view'])
    except ValueError as e:
        return flask.jsonify(
            rid.ErrorResponse(message='Error parsing view: {}'.format(e))), 400

    # Determine what kind of response to produce
    diagonal = geo.get_latlngrect_diagonal_km(view)
    if diagonal > rid.NetMaxDisplayAreaDiagonal:
        return flask.jsonify(
            rid.ErrorResponse(message='Requested diagonal was too large')), 413

    # Get ISAs in the DSS
    t = arrow.utcnow().datetime
    isas_response: fetch.FetchedISAs = fetch.isas(resources.utm_client, view,
                                                  t, t)
    if not isas_response.success:
        response = rid.ErrorResponse(message='Unable to fetch ISAs from DSS')
        response['errors'] = [isas_response]
        return flask.jsonify(response), 412

    # Fetch flights from each unique flights URL
    validated_flights: List[rid.RIDFlight] = []
    tx = db.value
    flight_info: Dict[str, database.FlightInfo] = {
        k: v
        for k, v in tx.flights.items()
    }

    for flights_url in isas_response.flight_urls:
        flights_response = fetch.flights(resources.utm_client, flights_url,
                                         view, True)
        if not flights_response.success:
            response = rid.ErrorResponse(
                message='Error querying {}'.format(flights_url))
            response['errors'] = [flights_response]
            return flask.jsonify(response), 412
        for flight in flights_response.flights:
            try:
                validated_flight: rid.RIDFlight = ImplicitDict.parse(
                    flight, rid.RIDFlight)
            except ValueError as e:
                response = rid.ErrorResponse(
                    message='Error parsing flight from {}'.format(flights_url))
                response['parse_error'] = str(e)
                response['flights'] = flights_response.flights
                return flask.jsonify(response), 412
            validated_flights.append(validated_flight)
            flight_info[flight.id] = database.FlightInfo(
                flights_url=flights_url)

    if diagonal <= rid.NetDetailsMaxDisplayAreaDiagonal:
        # Construct detailed flights response
        response = observation_api.GetDisplayDataResponse(flights=[
            _make_flight_observation(f, view) for f in validated_flights
        ])
        with db as tx:
            for k, v in flight_info.items():
                tx.flights[k] = v
        return flask.jsonify(response)
    else:
        # Construct clusters response
        return 'Cluster response not yet implemented', 500