def route_calc_all(less_coordinates, route_name, num_processes, algorithm): route_logger = get_origin_logger(logger, origin=route_name) # check to see if we can use OR-Tools to perform our routecalc import platform if platform.architecture()[0] == "64bit" and algorithm == 'route': # OR-Tools is only available for 64bit python route_logger.debug("64-bit python detected, checking if we can use OR-Tools") try: pywrapcp routing_enums_pb2 except Exception: route_logger.debug("OR-Tools not available, using MAD routecalc") else: route_logger.debug("Using OR-Tools for routecalc") return route_calc_ortools(less_coordinates, route_name) route_logger.debug("Using MAD quick routecalc") from mapadroid.route.routecalc.calculate_route_quick import route_calc_impl return route_calc_impl(less_coordinates, route_name, num_processes)
def getJsonRoute(self, coords: List[Tuple[str, str]], max_radius: int, max_coords_within_radius: int, in_memory: bool, num_processes: int = 1, algorithm: str = 'optimized', useS2: bool = False, S2level: int = 15, route_name: str = 'Unknown') -> List[Dict[str, float]]: export_data = [] if useS2: logger.debug("Using S2 method for calculation with S2 level: {}", S2level) if not in_memory and \ (self._data['fields']['routefile'] is not None and len( self._data['fields']['routefile']) > 0): logger.debug('Using routefile from DB') for line in self._data['fields']['routefile']: # skip empty lines if not line.strip(): continue lineSplit = line.split(',') export_data.append({ 'lat': float(lineSplit[0].strip()), 'lng': float(lineSplit[1].strip()) }) return export_data lessCoordinates = coords if len(coords) > 0 and max_radius and max_coords_within_radius: logger.info("Calculating route for {}", route_name) newCoords = self.getLessCoords(coords, max_radius, max_coords_within_radius, useS2, S2level) lessCoordinates = np.zeros(shape=(len(newCoords), 2)) for i in range(len(lessCoordinates)): lessCoordinates[i][0] = newCoords[i][0] lessCoordinates[i][1] = newCoords[i][1] logger.debug("Coords summed up: {}, that's just {} coords", str(lessCoordinates), str(len(lessCoordinates))) logger.debug("Got {} coordinates", len(lessCoordinates)) if len(lessCoordinates) < 3: logger.debug( "less than 3 coordinates... not gonna take a shortest route on that" ) export_data = [] for i in range(len(lessCoordinates)): export_data.append({ 'lat': lessCoordinates[i][0].item(), 'lng': lessCoordinates[i][1].item() }) else: logger.info( "Calculating a short route through all those coords. Might take a while" ) from timeit import default_timer as timer start = timer() if algorithm == 'quick': from mapadroid.route.routecalc.calculate_route_quick import route_calc_impl else: from mapadroid.route.routecalc.calculate_route_optimized import route_calc_impl sol_best = route_calc_impl(lessCoordinates, route_name, num_processes) end = timer() logger.info("Calculated route in {} minutes", str((end - start) / 60)) for i in range(len(sol_best)): export_data.append({ 'lat': lessCoordinates[int(sol_best[i])][0].item(), 'lng': lessCoordinates[int(sol_best[i])][1].item() }) if not in_memory: calc_coords = [] for coord in export_data: calc_coord = '%s,%s' % (coord['lat'], coord['lng']) calc_coords.append(calc_coord) # Only save if we aren't calculating in memory self._data['fields']['routefile'] = calc_coords self.save(update_time=True) return export_data