def _make_response(self, raw_json): if not raw_json: return [] ridesharing_journeys = [] for offer in raw_json: res = rsj.RidesharingJourney() res.metadata = self.journey_metadata res.distance = offer.get('distance') res.ridesharing_ad = offer.get('webUrl') res.duration = offer.get('duration') res.origin_pickup_duration = offer.get( 'departureToPickupWalkingTime') res.origin_pickup_distance = offer.get( 'departureToPickupWalkingDistance') res.origin_pickup_shape = self._retreive_shape( offer, 'departureToPickupWalkingPolyline') res.dropoff_dest_duration = offer.get( 'dropoffToArrivalWalkingTime') res.dropoff_dest_distance = offer.get( 'dropoffToArrivalWalkingDistance') res.dropoff_dest_shape = self._retreive_shape( offer, 'dropoffToArrivalWalkingPolyline') shape = self._retreive_shape(offer, 'journeyPolyline') # This is a particular case for Karos. # we don't use the : # driverArrivalLat - driverArrivalLng # driverDepartureLat - driverDepartureLng # Because that doesn't represent the start and the end of our ride. It represents extra # informations about the complete driver ride. # We fill the pickup and dropoff place with the shape if len(shape) >= 2: res.pickup_place = rsj.Place(addr='', lat=shape[0].lat, lon=shape[0].lon) res.dropoff_place = rsj.Place(addr='', lat=shape[-1].lat, lon=shape[-1].lon) else: res.pickup_place = rsj.Place( addr='', lat=offer.get('driverDepartureLat'), lon=offer.get('driverDepartureLng')) res.dropoff_place = rsj.Place( addr='', lat=offer.get('driverArrivalLat'), lon=offer.get('driverArrivalLng')) res.shape = shape res.price = offer.get('price', {}).get('amount') * 100.0 res.currency = "centime" res.available_seats = offer.get('availableSeats') res.total_seats = None res.pickup_date_time = offer.get('driverDepartureDate') res.departure_date_time = res.pickup_date_time - res.origin_pickup_duration res.dropoff_date_time = res.pickup_date_time + offer.get( 'duration') res.arrival_date_time = res.dropoff_date_time + res.dropoff_dest_duration gender_map = {'M': rsj.Gender.MALE, 'F': rsj.Gender.FEMALE} driver_gender = offer.get('driver', {}).get('gender') driver_alias = offer.get('driver', {}).get('firstName') driver_grade = offer.get('driver', {}).get('grade') driver_image = offer.get('driver', {}).get('picture') res.driver = rsj.Individual( alias=driver_alias, gender=gender_map.get(driver_gender, rsj.Gender.UNKNOWN), image=driver_image, rate=driver_grade, rate_count=None, ) ridesharing_journeys.append(res) return ridesharing_journeys
def _make_response(self, raw_json, from_coord, to_coord, instance_params): raw_journeys = raw_json.get('journeys') if not raw_journeys: return [] ridesharing_journeys = [] for j in self._get_ridesharing_journeys(raw_journeys): for p in j.get('paths'): if p.get('mode') != 'RIDESHARINGAD': continue res = rsj.RidesharingJourney() res.metadata = self.journey_metadata res.distance = j.get('distance') res.ridesharing_ad = j.get('url') ridesharing_ad = p['rideSharingAd'] # departure coord lat, lon = from_coord.split(',') departure_coord = Coords(lat=lat, lon=lon) # pick up coord from_data = p['from'] pickup_lat = from_data.get('lat') pickup_lon = from_data.get('lon') pickup_coord = Coords(lat=pickup_lat, lon=pickup_lon) res.pickup_place = rsj.Place(addr=from_data.get('name'), lat=pickup_lat, lon=pickup_lon) res.origin_pickup_distance = int( jormungandr.street_network.utils.crowfly_distance_between( departure_coord, pickup_coord)) # we choose to calculate with speed=1.12 the average speed for a walker res.origin_pickup_duration = jormungandr.street_network.utils.get_manhattan_duration( res.origin_pickup_distance, instance_params.walking_speed) res.origin_pickup_shape = None # Not specified # drop off coord to_data = p['to'] dropoff_lat = to_data.get('lat') dropoff_lon = to_data.get('lon') dropoff_coord = Coords(lat=dropoff_lat, lon=dropoff_lon) res.dropoff_place = rsj.Place(addr=to_data.get('name'), lat=dropoff_lat, lon=dropoff_lon) # arrival coord lat, lon = to_coord.split(',') arrival_coord = Coords(lat=lat, lon=lon) res.dropoff_dest_distance = int( jormungandr.street_network.utils.crowfly_distance_between( dropoff_coord, arrival_coord)) # we choose to calculate with speed=1.12 the average speed for a walker res.dropoff_dest_duration = jormungandr.street_network.utils.get_manhattan_duration( res.dropoff_dest_distance, instance_params.walking_speed) res.dropoff_dest_shape = None # Not specified res.shape = self._retreive_main_shape(p, 'shape', res.pickup_place, res.dropoff_place) res.pickup_date_time = make_timestamp_from_str( p['departureDate']) res.departure_date_time = res.pickup_date_time - res.origin_pickup_duration res.dropoff_date_time = make_timestamp_from_str( p['arrivalDate']) res.arrival_date_time = res.dropoff_date_time + res.dropoff_dest_duration res.duration = res.dropoff_date_time - res.pickup_date_time user = ridesharing_ad['user'] gender = user.get('gender') gender_map = { 'MALE': rsj.Gender.MALE, 'FEMALE': rsj.Gender.FEMALE } res.driver = rsj.Individual( alias=user.get('alias'), gender=gender_map.get(gender, rsj.Gender.UNKNOWN), image=user.get('imageUrl'), rate=user.get('rating', {}).get('rate'), rate_count=user.get('rating', {}).get('count'), ) # the usual form of the price for InstantSystem is: "170 EUR" # which means "170 EURO cents" also equals "1.70 EURO" # In Navitia so far prices are in "centime" so we transform it to: "170 centime" price = ridesharing_ad['price'] res.price = price.get('amount') if price.get('currency') == "EUR": res.currency = "centime" else: res.currency = price.get('currency') res.available_seats = ridesharing_ad['vehicle'][ 'availableSeats'] res.total_seats = None ridesharing_journeys.append(res) return ridesharing_journeys
def _make_response(self, raw_json): raw_journeys = raw_json.get('journeys') if not raw_journeys: return [] ridesharing_journeys = [] for j in self._get_ridesharing_journeys(raw_journeys): for p in j.get('paths'): if p.get('mode') != 'RIDESHARINGAD': continue res = rsj.RidesharingJourney() res.metadata = self.journey_metadata res.distance = j.get('distance') res.ridesharing_ad = j.get('url') ridesharing_ad = p['rideSharingAd'] from_data = p['from'] res.pickup_place = rsj.Place(addr=from_data.get('name'), lat=from_data.get('lat'), lon=from_data.get('lon')) to_data = p['to'] res.dropoff_place = rsj.Place(addr=to_data.get('name'), lat=to_data.get('lat'), lon=to_data.get('lon')) # shape is a list of type_pb2.GeographicalCoord() res.shape = [] shape = decode_polyline(p.get('shape'), precision=5) if not shape or res.pickup_place.lon != shape[0][ 0] or res.pickup_place.lat != shape[0][1]: coord = type_pb2.GeographicalCoord() coord.lon = res.pickup_place.lon coord.lat = res.pickup_place.lat res.shape.append(coord) for c in shape: coord = type_pb2.GeographicalCoord() coord.lon = c[0] coord.lat = c[1] res.shape.append(coord) if not shape or res.dropoff_place.lon != shape[0][ 0] or res.dropoff_place.lat != shape[0][1]: coord = type_pb2.GeographicalCoord() coord.lon = res.dropoff_place.lon coord.lat = res.dropoff_place.lat res.shape.append(coord) res.pickup_date_time = utils.make_timestamp_from_str( p['departureDate']) res.dropoff_date_time = utils.make_timestamp_from_str( p['arrivalDate']) user = ridesharing_ad['user'] gender = user.get('gender') gender_map = { 'MALE': rsj.Gender.MALE, 'FEMALE': rsj.Gender.FEMALE } res.driver = rsj.Individual( alias=user.get('alias'), gender=gender_map.get(gender, rsj.Gender.UNKNOWN), image=user.get('imageUrl'), rate=user.get('rating', {}).get('rate'), rate_count=user.get('rating', {}).get('count')) # the usual form of the price for InstantSystem is: "170 EUR" # which means "170 EURO cents" also equals "1.70 EURO" # In Navitia so far prices are in "centime" so we transform it to: "170 centime" price = ridesharing_ad['price'] res.price = price.get('amount') if price.get('currency') == "EUR": res.currency = "centime" else: res.currency = price.get('currency') res.available_seats = ridesharing_ad['vehicle'][ 'availableSeats'] res.total_seats = None ridesharing_journeys.append(res) return ridesharing_journeys
def _make_response(self, raw_json): if not raw_json: return [] ridesharing_journeys = [] for offer in raw_json: res = rsj.RidesharingJourney() res.metadata = self.journey_metadata res.distance = offer.get('distance') res.ridesharing_ad = offer.get('webUrl') res.duration = offer.get('duration') res.origin_pickup_duration = offer.get( 'departureToPickupWalkingTime') res.origin_pickup_distance = offer.get( 'departureToPickupWalkingDistance') res.origin_pickup_shape = self._retreive_shape( offer, 'departureToPickupWalkingPolyline') res.dropoff_dest_duration = offer.get( 'dropoffToArrivalWalkingTime') res.dropoff_dest_distance = offer.get( 'dropoffToArrivalWalkingDistance') res.dropoff_dest_shape = self._retreive_shape( offer, 'dropoffToArrivalWalkingPolyline') res.pickup_place = rsj.Place(addr='', lat=offer.get('driverDepartureLat'), lon=offer.get('driverDepartureLng')) res.dropoff_place = rsj.Place(addr='', lat=offer.get('driverArrivalLat'), lon=offer.get('driverArrivalLng')) res.shape = self._retreive_main_shape(offer, 'journeyPolyline', res.pickup_place, res.dropoff_place) # For Klaxit the price is in euro res.price = offer.get('price', {}).get('amount') * 100.0 res.currency = "centime" res.available_seats = offer.get('available_seats') res.total_seats = None res.pickup_date_time = offer.get('driverDepartureDate') res.departure_date_time = res.pickup_date_time - res.origin_pickup_duration res.dropoff_date_time = res.pickup_date_time + offer.get( 'duration') res.arrival_date_time = res.dropoff_date_time + res.dropoff_dest_duration driver_alias = offer.get('driver', {}).get('alias') driver_grade = offer.get('driver', {}).get('grade') driver_image = offer.get('driver', {}).get('picture') res.driver = rsj.Individual(alias=driver_alias, gender=None, image=driver_image, rate=driver_grade, rate_count=None) ridesharing_journeys.append(res) return ridesharing_journeys
def _make_response(self, raw_json, request_datetime, from_coord, to_coord): if not raw_json: return [] ridesharing_journeys = [] for offer in raw_json: res = rsj.RidesharingJourney() res.metadata = self.journey_metadata res.distance = offer.get('distance') res.duration = offer.get('duration') res.ridesharing_ad = offer.get('web_url') # departure coord lat, lon = from_coord.split(',') departure_coord = Coords(lat=lat, lon=lon) # pick up coord pickup_lat = offer.get('pickup_latitude') pickup_lon = offer.get('pickup_longitude') pickup_coord = Coords(lat=pickup_lat, lon=pickup_lon) res.pickup_place = rsj.Place(addr='', lat=pickup_lat, lon=pickup_lon) res.origin_pickup_duration = offer.get( 'departure_to_pickup_walking_time') res.origin_pickup_shape = None # Not specified res.origin_pickup_distance = int( jormungandr.street_network.utils.crowfly_distance_between( departure_coord, pickup_coord)) # drop off coord dropoff_lat = offer.get('dropoff_latitude') dropoff_lon = offer.get('dropoff_longitude') dropoff_coord = Coords(lat=dropoff_lat, lon=dropoff_lon) res.dropoff_place = rsj.Place(addr='', lat=dropoff_lat, lon=dropoff_lon) # arrival coord lat, lon = to_coord.split(',') arrival_coord = Coords(lat=lat, lon=lon) res.dropoff_dest_duration = offer.get( 'dropoff_to_arrival_walking_time') res.dropoff_dest_shape = None # Not specified res.dropoff_dest_distance = int( jormungandr.street_network.utils.crowfly_distance_between( dropoff_coord, arrival_coord)) res.shape = self._retreive_main_shape(offer, 'journey_polyline', res.pickup_place, res.dropoff_place) currency = offer.get('price', {}).get('currency') if currency == "EUR": res.currency = "centime" res.price = offer.get('price', {}).get('amount') * 100.0 else: res.currency = currency res.price = offer.get('price', {}).get('amount') res.available_seats = offer.get('available_seats') res.total_seats = None # departure coord is absent in the offer and hence to be generated from the request res.departure_date_time = request_datetime res.pickup_date_time = res.departure_date_time + res.origin_pickup_duration res.dropoff_date_time = res.pickup_date_time + res.duration res.arrival_date_time = res.dropoff_date_time + res.dropoff_dest_duration res.driver = rsj.Individual(alias=None, gender=None, image=None, rate=None, rate_count=None) ridesharing_journeys.append(res) return ridesharing_journeys