def call_kraken(self, req, instance, tag=None): resp = None """ for all combinaison of departure and arrival mode we call kraken """ logger = logging.getLogger(__name__) # filter walking if bss in mode ? for o_mode, d_mode in itertools.product(self.origin_modes, self.destination_modes): req.journeys.streetnetwork_params.origin_mode = o_mode req.journeys.streetnetwork_params.destination_mode = d_mode local_resp = instance.send_and_receive(req) if local_resp.response_type == response_pb2.ITINERARY_FOUND: # if a specific tag was provided, we tag the journeys # and we don't call the qualifier, it will be done after # with the journeys from the previous query if tag: for j in local_resp.journeys: j.type = tag else: #we qualify the journeys request_type = "arrival" if req.journeys.clockwise else "departure" qualifier_one(local_resp.journeys, request_type) if not resp: resp = local_resp else: self.merge_response(resp, local_resp) if not resp: resp = local_resp logger.debug("for mode %s|%s we have found %s journeys: %s", o_mode, d_mode, len(local_resp.journeys), [j.type for j in local_resp.journeys]) self.__fill_uris(resp) return resp
def get_journey(self, pb_req, instance, original_request): resp = self.call_kraken(pb_req, instance) if not resp or (pb_req.requested_api != type_pb2.PLANNER and pb_req.requested_api != type_pb2.ISOCHRONE): return new_request, tag = self.check_missing_journey(resp.journeys, pb_req) if new_request: #we have to call kraken again with a modified version of the request new_resp = self.call_kraken(new_request, instance, tag) self.merge_response(resp, new_resp) # we qualify the journeys with the previous one # because we need all journeys to qualify them correctly request_type = "arrival" if new_request.journeys.clockwise else "departure" qualifier_one(resp.journeys, request_type) return resp