Exemplo n.º 1
0
Arquivo: views.py Projeto: hmpf/nav
def get_formatted_data(
    variant,
    db,
    format_,
    bounds,
    viewport_size,
    limit,
    time_interval,
    do_create_edges,
    do_fetch_data,
):
    """Get formatted output for given conditions.

    variant -- name of the map variant to create data for (variants
    are defined in the configuration file)

    db -- a database connection object.

    format -- the name of a format (see output_formats.py)

    bounds -- a dictionary with keys (minLon, maxLon, minLat, maxLat)
    describing the bounds of the interesting region.

    viewport_size -- a dictionary with keys (width, height), the width
    and height of the user's viewport for the map in pixels.

    limit -- the minimum distance (in pixels) there may be between two
    points without them being collapsed to one.

    time_interval -- dictionary with keys ('start', 'end'). Values
    should be strings describing times in the syntax expected by
    rrdfetch. (see http://oss.oetiker.ch/rrdtool/doc/rrdfetch.en.html)

    Return value: formatted data as a string.

    """
    data = get_data(db, bounds, time_interval)
    _logger.debug('build_graph')
    graph = build_graph(data)
    _logger.debug('simplify')
    simplify(graph, bounds, viewport_size, limit)
    if do_fetch_data:
        _logger.debug('_attach_cpu_load')
        _attach_cpu_load(graph, time_interval)
        if do_create_edges:
            _logger.debug('_attach_traffic_load')
            _attach_traffic_load(graph, time_interval)
    _logger.debug('create_features')
    features = create_features(variant, graph, do_create_edges)
    _logger.debug('format')
    output = format_data(format_, features)
    return output
Exemplo n.º 2
0
def get_formatted_data(variant, db, format_, bounds, viewport_size, limit,
                       time_interval):
    """Get formatted output for given conditions.

    variant -- name of the map variant to create data for (variants
    are defined in the configuration file)

    db -- a database connection object.

    format -- the name of a format (see output_formats.py)

    bounds -- a dictionary with keys (minLon, maxLon, minLat, maxLat)
    describing the bounds of the interesting region.

    viewport_size -- a dictionary with keys (width, height), the width
    and height of the user's viewport for the map in pixels.

    limit -- the minimum distance (in pixels) there may be between two
    points without them being collapsed to one.

    time_interval -- dictionary with keys ('start', 'end'). Values
    should be strings describing times in the syntax expected by
    rrdfetch. (see http://oss.oetiker.ch/rrdtool/doc/rrdfetch.en.html)

    Return value: formatted data as a string.

    """
    logger.debug('get_data')
    data = get_data(db, bounds, time_interval)
    logger.debug('build_graph')
    graph = build_graph(data)
    logger.debug('simplify')
    simplify(graph, bounds, viewport_size, limit)
    logger.debug('create_features')
    features = create_features(variant, graph)
    logger.debug('format')
    output = format_data(format_, features)
    return output