def test_bboxQuery_largedata(self): points = [Point(x, y, 1) for x, y in combinations(range(-200, 200), 2)] correct = list(filter(lambda f: f[0] >= -10 and f[0] <= 10 and f[1] >= -10 and f[1] <= 10, points)) tree = RangeTree() tree.create(points) bbox = BBox(-10, -10, 10, 10) result = tree.bboxQuery(bbox) self.assertEqual(len(result), len(correct)) self.assertEqual(set(correct), set(result))
def test_bboxQuery_miss(self): points = [ Point(-2, 1, 1), Point(-1, 0, 1), Point(-2, 0, 1), Point(-2, 0, 1), Point(0, 0, 1), Point(1, 0, 1), Point(3, 3, 1), ] tree = RangeTree() tree.create(points) bbox = BBox(5, 5, 7, 7) result = tree.bboxQuery(bbox) self.assertEqual(result, [])
def test_bboxQuery_simple(self): points = [ Point(-2, 1, 1), Point(-1, 0, 1), Point(-2, 0, 1), Point(0, 0, 1), Point(1, 0, 1), Point(3, 3, 1), ] correct = [ Point(-2, 1, 1), Point(-1, 0, 1), Point(-2, 0, 1), ] tree = RangeTree() tree.create(points) bbox = BBox(-2.5, -2, -0.5, 2) result = tree.bboxQuery(bbox) self.assertEqual(len(result), len(correct)) self.assertEqual(set(result), set(correct))
from rangetree import RangeTree, BBox, Point, readPointFile, GeometryException from flask import Flask, jsonify, make_response, request, render_template import os app = Flask(__name__) app.config.update(dict(SECRET_KEY='development key')) points = readPointFile( os.path.join(os.path.dirname(__file__), 'data/ipv6data.csv')) tree = RangeTree() tree.create(points) @app.route('/ipv6/api/v1.0/locations', methods=['GET']) def get_points(): try: args = request.args.to_dict() bbox = BBox(float(args['lowerx']), float(args['lowery']), float(args['upperx']), float(args['uppery'])) except GeometryException: return make_response('Geometry Exception: invalid bounding box', 400) except TypeError: return make_response( 'Invalid inputs. Please use float args for lowerx, lowery, upperx, uppery', 400) return jsonify([p.heatPoint() for p in tree.bboxQuery(bbox)]) @app.route('/ipv6/') def index():
def test_create(self): points = [Point(x, y, 1) for x, y in combinations(range(-10, 10), 2)] tree = RangeTree() tree.create(points) self.assertEqual(len(points), len(tree.traverse())) self.assertEqual(set(points), set(tree.traverse()))
def test_create_null(self): points = [] tree = RangeTree() tree.create(points) self.assertEqual(len(points), len(tree.traverse())) self.assertEqual(set(points), set(tree.traverse()))