def test_geonode_constructor(geonode1): # Trivial test for classic constructor act_node = GeoNode(1, 'Node 1', '-0.84571884220576', '51.2945043901003') assert_geonode(geonode1, act_node) return
def test_geonode_from_db_string(geonode3, point1): # Tests GeoNode constructor from_db_string act_node = GeoNode.from_db_string(point1) assert_geonode(geonode3, act_node) return
def test_geonode_from_db_row(geonode1): # Tests GeoNode constructor from_db_row db_row = (1, 'POINT(-0.84571884220576 51.2945043901003)', 'Node 1') act_node = GeoNode.from_db_row(db_row) assert_geonode(geonode1, act_node) return
def get_beds(): """@app.route('/beds') takes plant (plant name number, optional, coercible to int) lat (latitude, coercible to float) long (longitude, coercible to float) n (max number of records required, coercible to int, n=0 returns all Finds n flower beds containing a given plant (optional), sorted in order of proximity to a position defined by lat, long Returns a list of populated Node objects. If the plant is not found, an empty list is returned. If n=0, all matches are returned.""" # Define validation schema schema = Schema({ 'plant': Coerce(int), Required('lat'): Coerce(float), Required('long'): Coerce(float), 'n': Coerce(int) }) # Validate and return a Bad Request error if necessary try: schema(request.args.to_dict()) except MultipleInvalid as err: resp = _handle_exception(err, '400') else: # Call business layer method and return an Internal Server Error if anything goes wrong try: # Default n to 0 if request.args.get('n'): n = request.args['n'] else: n = '0' bl = BLO_GIS(GeoNode(0, '', request.args['long'], request.args['lat'])) beds = bl.get_flower_beds(request.args.get('plant'), n) resp = _get_response(beds) except Exception as err: resp = _handle_exception(err, '500') return resp
def node_details(self, node_id): # Gets full details from node table for id = node_id # Arguments: # node_id - a node id # Returns - a GeoNode object populated with full node details sql = 'SELECT id, ST_AsText(coordinates), name ' \ 'FROM node ' \ 'WHERE id = ' + str(node_id) row = self._execute_query(sql) return GeoNode.from_db_row(row)
def route_place(id): """@app.route('/route/place') takes lat (latitude, coercible to float) long (longitude, coercible to float) id (id of a place, coercible to int) Calculates the shortest route between the given place and a position defined by lat, long Returns a Route object. If route cannot be calculated, an empty object is returned""" # Define validation schema schema = Schema({ Required('lat'): Coerce(float), Required('long'): Coerce(float) }) # Validate and return a Bad Request error if necessary try: schema(request.args.to_dict()) except MultipleInvalid as err: resp = _handle_exception(err, '400') else: # Call business layer method and return an Internal Server Error if anything goes wrong try: bl = BLO_Route(GeoNode(0, '', request.args['long'], request.args['lat'])) route = bl.get_place_route(id) resp = _get_response(route) except PlaceNotFound as err: # id doesn't exist, return 404 resp = _handle_exception(err, '404') except Exception as err: resp = _handle_exception(err, '500') return resp
def geonode12(): return GeoNode(12, 'Node 12', '-0.8519026750896', '51.2916672640752')
def geonode9(): return GeoNode(9, 'Node 9', '-0.85161836093402', '51.2923063246076')
def geonode8(): return GeoNode(8, 'Node 8', '-0.85187317079043', '51.2923985767057')
def node5(): return GeoNode(7, 'Flower Bed 7', '-0.8524337425712866', '51.292041426751496')
def node4(): return GeoNode(4, 'Flower Bed 4', '-0.8517447774739522', '51.29174150409153')
def node3(): return GeoNode(1, 'Flower Bed 1', '-0.8528091015952259', '51.29180649906897')
def geonode6(): # place 2 return GeoNode(0, '', '-0.85324042683577', '51.2912194132039')
def geonode3(): return GeoNode(0, '', '-0.84571884220576', '51.2945043901003')
def geonode4(): return GeoNode(4, 'Node 4', '-0.85234255736804', '51.2920077620013')
def geonode3(): return GeoNode(3, 'Node 3', '-0.8524257058475', '51.2918769305846')
def geonode2(): return GeoNode(2, 'Node 2', '-0.85251421874499', '51.2916135892949')
def geonode1(): return GeoNode(1, 'Node 1', '-0.85302115624881', '51.2914391458255')
def geonode0(): # centre of bed 4 return GeoNode(0, '', '-0.8517447', '51.2917413')
def geonode1(): return GeoNode(1, 'Node 1', '-0.84571884220576', '51.2945043901003')