def shortest_route(self, source_id, target_id): path = nx.shortest_path(self.graph, source_id, target_id) route_id = str(uuid.uuid4()) route = Route(route_id, self.graph.node[path[0]]['lat'], self.graph.node[path[0]]['lon'], PlacesDAO.get_place_name_by_id(source_id) + " to " + PlacesDAO.get_place_name_by_id(target_id)) for i in range(0, len(path)): n = self.graph.node[path[i]] if i+1 == len(path): # this is the final step in the path, so there is no next edge route.steps.append(Step( route_id, i, n['lat'], n['lon'], None, None, n['city_name'] if 'city_name' in n else None, )) else: next_road = self.graph.get_edge_data(path[i], path[i+1]) route.steps.append(Step( route_id, i, n['lat'], n['lon'], next_road['name'], next_road['geom'], n['city_name'] if 'city_name' in n else None )) return route
def get_places_from_partial_name(name): print(name) rl = PlacesDAO.get_city_and_state_from_partial(name) return Response(json.dumps(rl, indent=4), mimetype='application/json')