def get_pt_object(type, lon, lat): pt_object = type_pb2.PtObject() pt_object.embedded_type = type if type == type_pb2.ADDRESS: pt_object.address.coord.lat = lat pt_object.address.coord.lon = lon return pt_object
def make_pt_object(embedded_type, lon, lat, uri=None): pt_object = type_pb2.PtObject() pt_object.embedded_type = embedded_type if uri: pt_object.uri = uri if embedded_type == type_pb2.STOP_POINT: pt_object.stop_point.coord.lat = lat pt_object.stop_point.coord.lon = lon elif embedded_type == type_pb2.STOP_AREA: pt_object.stop_area.coord.lat = lat pt_object.stop_area.coord.lon = lon elif embedded_type == type_pb2.ADDRESS: pt_object.address.coord.lat = lat pt_object.address.coord.lon = lon elif embedded_type == type_pb2.ADMINISTRATIVE_REGION: pt_object.administrative_region.coord.lat = lat pt_object.administrative_region.coord.lon = lon elif embedded_type == type_pb2.POI: pt_object.poi.coord.lat = lat pt_object.poi.coord.lon = lon elif embedded_type == type_pb2.ACCESS_POINT: pt_object.access_point.coord.lat = lat pt_object.access_point.coord.lon = lon pt_object.access_point.uri = uri return pt_object
def get_direction_name_with_destination_id_tag_test(): timeo = Timeo( id=u"tata-é$~#@\"*!'`§èû", timezone='UTC', service_url='http://bob.com/', service_args={ 'a': 'bobette', 'b': '12' }, destination_id_tag="source", instance=MockInstance(), ) stop_point = type_pb2.PtObject() stop_point.embedded_type = type_pb2.STOP_POINT stop_point.stop_area.label = 'destination de Bob' stop_point.stop_area.uri = 'destination_de_Bob' with mock.patch( 'jormungandr.ptref.PtRef.get_stop_point', lambda PtRef, line_uri, destination_id_tag, object_code: stop_point, ): result = timeo._get_direction("line_uri", "object_code", "default_value") assert result == Direction("destination_de_Bob", "destination de Bob")
def make_pt_object_with_sp_mode(lon, lat, uri, mode_uri=None): pt_object = type_pb2.PtObject() pt_object.embedded_type = type_pb2.STOP_POINT if uri: pt_object.uri = uri pt_object.stop_point.coord.lat = lat pt_object.stop_point.coord.lon = lon if mode_uri: physical_mode = pt_object.stop_point.physical_modes.add() physical_mode.uri = mode_uri return pt_object
def get_pt_object(embedded_type, lon, lat): pt_object = type_pb2.PtObject() pt_object.embedded_type = embedded_type if embedded_type == type_pb2.STOP_POINT: pt_object.stop_point.coord.lat = lat pt_object.stop_point.coord.lon = lon elif embedded_type == type_pb2.STOP_AREA: pt_object.stop_area.coord.lat = lat pt_object.stop_area.coord.lon = lon elif embedded_type == type_pb2.ADDRESS: pt_object.address.coord.lat = lat pt_object.address.coord.lon = lon elif embedded_type == type_pb2.ADMINISTRATIVE_REGION: pt_object.administrative_region.coord.lat = lat pt_object.administrative_region.coord.lon = lon elif embedded_type == type_pb2.POI: pt_object.poi.coord.lat = lat pt_object.poi.coord.lon = lon return pt_object
def place(self, place): req = request_pb2.Request() req.requested_api = type_pb2.place_uri req.place_uri.uri = place req.place_uri.depth = 2 response = self.instance.send_and_receive(req) if response.places: return response.places[0] if utils.is_coord(place): # In some cases, the given "from" is not always a findable address by kraken # we just forward the given coord and return a pt object lon, lat = utils.get_lon_lat(place) p = type_pb2.PtObject() p.uri = place p.embedded_type = type_pb2.ADDRESS p.address.coord.lon = lon p.address.coord.lat = lat p.address.uri = place return p return None
def place(self, place): req = request_pb2.Request() req.requested_api = type_pb2.place_uri req.place_uri.uri = place req.place_uri.depth = 2 response = self.instance.send_and_receive(req) if response.places: return response.places[0] if place.startswith("coord:"): # In some cases, the given "from" is not always a findable address by kraken # we just forward the given coord and return a pt object _, lon, lat = place.split(':') uri = '{};{}'.format(lon, lat) p = type_pb2.PtObject() p.uri = uri p.embedded_type = type_pb2.ADDRESS p.address.coord.lon = float(lon) p.address.coord.lat = float(lat) p.address.uri = uri return p return None
def _retrieve_access_points(self, stop_point, access_points_map, places_isochrone): if self._direct_path_type == StreetNetworkPathType.BEGINNING_FALLBACK: access_points = (ap for ap in stop_point.access_points if ap.is_entrance) else: access_points = (ap for ap in stop_point.access_points if ap.is_exit) for ap in access_points: # we convert the access point to pt object in order to make it easier to handle in later computation pt_object_ap = type_pb2.PtObject( name=ap.name, uri=ap.uri, embedded_type=type_pb2.ACCESS_POINT, access_point=ap) if ap.uri not in access_points_map: # every object in place_isochrone has a type of PtObject. We convert the AccessPoint into PtObject places_isochrone.append(pt_object_ap) access_points_map[ap.uri].append( AccessMapElement(stop_point.uri, pt_object_ap))