Esempio n. 1
0
def return_a_to_b(**kwargs):
    """
    Return JSON data giving a distance between two points
    """
    request = dict([(i,calc.parse_latlon(j)) for (i,j) in kwargs.items()])
    distance = calc.haversine(request['a'][1], request['a'][0], request['b'][1], request['b'][0])
    return flask.json.jsonify(request = request, distance = distance)
Esempio n. 2
0
def return_data(**kwargs):
    """
    Return JSON data based on bounding box
    """
    request = dict([(i,calc.parse_latlon(j)) for (i,j) in kwargs.items()])
    api_url = "https://benjaminbenben.cloudant.com/floodnet/_design/oxflood/_view/full"

    params = {
        'descending': 'true',
        'limit': '1',
    }
    s = requests.Session()
    #s.mount('http://', CachingHTTPAdapter())
    #s.mount('https://', CachingHTTPAdapter())

    # Test data?
    if flask.request.args.get('test'):
        import json, os
        raw_data = json.load(open(os.path.dirname(__file__) + "/test_data/example.json"))
    else:
        raw_data = s.get(api_url, params = params).json()

    # Map data into format suitable for heat maps
    data = [_parse_result(r)
      # Test data needs filtering by tags
      for r in raw_data["rows"] ]

    return flask.json.jsonify(request = request, data = data)
Esempio n. 3
0
def return_test_data(**kwargs):
    """
    Return example JSON data based on bounding box
    """
    request = dict([(i,calc.parse_latlon(j)) for (i,j) in kwargs.items()])

    test_data = (
      {'lat': 51.7761, 'lon': -1.264, 'value': 1.0},
      {'lat': 51.7763, 'lon': -1.263, 'value': 0.7},
      {'lat': 51.7765, 'lon': -1.265, 'value': 1.2},
    )
    return flask.json.jsonify(request = request, data = test_data)
Esempio n. 4
0
def return_parsed_request(**kwargs):
    """
    Parse a bounding box URL similar to the /data call
    """
    request = dict([(i,calc.parse_latlon(j)) for (i,j) in kwargs.items()])
    return flask.json.jsonify(request = request)