def _direct_path(self, mode, pt_object_origin, pt_object_destination, fallback_extremity, request, direct_path_type): """ :param direct_path_type: we need to "invert" a direct path when it's a ending fallback by car if and only if it's returned by kraken. In other case, it's ignored """ should_invert_journey = (mode == 'car' and direct_path_type == StreetNetworkPathType.ENDING_FALLBACK) if should_invert_journey: pt_object_origin, pt_object_destination = pt_object_destination, pt_object_origin req = request_pb2.Request() req.requested_api = type_pb2.direct_path req.direct_path.origin.place = get_uri_pt_object(pt_object_origin) req.direct_path.origin.access_duration = 0 req.direct_path.destination.place = get_uri_pt_object(pt_object_destination) req.direct_path.destination.access_duration = 0 req.direct_path.datetime = fallback_extremity.datetime req.direct_path.clockwise = fallback_extremity.represents_start req.direct_path.streetnetwork_params.origin_mode = mode req.direct_path.streetnetwork_params.destination_mode = mode req.direct_path.streetnetwork_params.walking_speed = request['walking_speed'] req.direct_path.streetnetwork_params.max_walking_duration_to_pt = request['max_walking_duration_to_pt'] req.direct_path.streetnetwork_params.bike_speed = request['bike_speed'] req.direct_path.streetnetwork_params.max_bike_duration_to_pt = request['max_bike_duration_to_pt'] req.direct_path.streetnetwork_params.bss_speed = request['bss_speed'] req.direct_path.streetnetwork_params.max_bss_duration_to_pt = request['max_bss_duration_to_pt'] req.direct_path.streetnetwork_params.car_speed = request['car_speed'] req.direct_path.streetnetwork_params.max_car_duration_to_pt = request['max_car_duration_to_pt'] response = self.instance.send_and_receive(req) if should_invert_journey: return self._reverse_journeys(response) return response
def direct_path(self, mode, pt_object_origin, pt_object_destination, fallback_extremity, request): req = request_pb2.Request() req.requested_api = type_pb2.direct_path req.direct_path.origin.place = get_uri_pt_object(pt_object_origin) req.direct_path.origin.access_duration = 0 req.direct_path.destination.place = get_uri_pt_object( pt_object_destination) req.direct_path.destination.access_duration = 0 req.direct_path.datetime = fallback_extremity.datetime req.direct_path.clockwise = fallback_extremity.represents_start req.direct_path.streetnetwork_params.origin_mode = mode req.direct_path.streetnetwork_params.destination_mode = mode req.direct_path.streetnetwork_params.walking_speed = request[ 'walking_speed'] req.direct_path.streetnetwork_params.max_walking_duration_to_pt = request[ 'max_walking_duration_to_pt'] req.direct_path.streetnetwork_params.bike_speed = request['bike_speed'] req.direct_path.streetnetwork_params.max_bike_duration_to_pt = request[ 'max_bike_duration_to_pt'] req.direct_path.streetnetwork_params.bss_speed = request['bss_speed'] req.direct_path.streetnetwork_params.max_bss_duration_to_pt = request[ 'max_bss_duration_to_pt'] req.direct_path.streetnetwork_params.car_speed = request['car_speed'] req.direct_path.streetnetwork_params.max_car_duration_to_pt = request[ 'max_car_duration_to_pt'] return self.instance.send_and_receive(req)
def _do_request(self): logger = logging.getLogger(__name__) logger.debug("requesting proximities by crowfly from %s in %s", self._requested_place_obj.uri, self._mode) # When max_duration_to_pt is 0, there is no need to compute the fallback to pt, except if place is a stop_point # or a stop_area if self._max_duration == 0: logger.debug( "max duration equals to 0, no need to compute proximities by crowfly" ) # When max_duration_to_pt is 0, we can get on the public transport ONLY if the place is a stop_point if self._instance.georef.get_stop_points_from_uri( self._requested_place_obj.uri): return [self._requested_place_obj] coord = utils.get_pt_object_coord(self._requested_place_obj) if coord.lat and coord.lon: crow_fly = self._instance.georef.get_crow_fly( utils.get_uri_pt_object(self._requested_place_obj), self._mode, self._max_duration, self._max_nb_crowfly, **self._speed_switcher) logger.debug("finish proximities by crowfly from %s in %s", self._requested_place_obj.uri, self._mode) return crow_fly logger.debug("the coord of requested places is not valid: %s", coord) return []
def get_street_network_routing_matrix(self, origins, destinations, street_network_mode, max_duration, request, **kwargs): # TODO: reverse is not handled as so far speed_switcher = { "walking": request['walking_speed'], "bike": request['bike_speed'], "car": request['car_speed'], "bss": request['bss_speed'], "ridesharing": request['car_no_park_speed'], } req = request_pb2.Request() req.requested_api = type_pb2.street_network_routing_matrix # kraken can only manage 1-n request, so we reverse request if needed if len(origins) > 1: if len(destinations) > 1: logging.getLogger(__name__).error( 'routing matrix error, no unique center point') raise TechnicalError( 'routing matrix error, no unique center point') else: origins, destinations = destinations, origins for o in origins: orig = req.sn_routing_matrix.origins.add() orig.place = get_uri_pt_object(o) orig.access_duration = 0 for d in destinations: dest = req.sn_routing_matrix.destinations.add() dest.place = get_uri_pt_object(d) dest.access_duration = 0 req.sn_routing_matrix.mode = street_network_mode req.sn_routing_matrix.speed = speed_switcher.get( street_network_mode, kwargs.get("walking")) req.sn_routing_matrix.max_duration = max_duration res = self.instance.send_and_receive(req) if res.HasField('error'): logging.getLogger(__name__).error( 'routing matrix query error {}'.format(res.error)) raise TechnicalError('routing matrix fail') return res.sn_routing_matrix
def _get_places_crowfly(instance, mode, place, max_duration_to_pt, max_nb_crowfly=5000, **kwargs): # When max_duration_to_pt is 0, there is no need to compute the fallback to pt, except if place is a stop_point or a # stop_area if max_duration_to_pt == 0: # When max_duration_to_pt is 0, we can get on the public transport ONLY if the place is a stop_point if instance.georef.get_stop_points_from_uri(place.uri): return {mode: place} else: return {mode: []} coord = get_pt_object_coord(place) if not coord.lat and not coord.lon: return {mode: []} res = instance.georef.get_crow_fly(get_uri_pt_object(place), mode, max_duration_to_pt, max_nb_crowfly, **kwargs) return {mode: res}
def _get_crow_fly(self): return self._instance.georef.get_crow_fly( utils.get_uri_pt_object(self._requested_place_obj), self._mode, self._max_duration, self._max_nb_crowfly, **self._speed_switcher)