def _create_crowfly(pt_journey, crowfly_origin, crowfly_destination, begin, end, mode): section = response_pb2.Section() section.type = response_pb2.CROW_FLY section.origin.CopyFrom(crowfly_origin) section.destination.CopyFrom(crowfly_destination) section.duration = end - begin pt_journey.durations.total += section.duration pt_journey.duration += section.duration section.begin_date_time = begin section.end_date_time = end if section.duration > 0: section.street_network.mode = MODE_TO_PB_MODE.get(mode) # mode is always walking for a teleportation crow_fly else: section.street_network.mode = response_pb2.Walking # Calculate section length from_coord = get_pt_object_coord(section.origin) to_coord = get_pt_object_coord(section.destination) section.length = int(crowfly_distance_between(from_coord, to_coord)) # The section "distances" and "durations" in the response needs to be updated according to the mode. # only if it isn't a 'free' crow_fly if section.duration > 0: setattr(pt_journey.distances, mode, (getattr(pt_journey.distances, mode) + section.length)) setattr(pt_journey.durations, mode, (getattr(pt_journey.durations, mode) + section.duration)) section.id = six.text_type(generate_id()) return section
def create_crowfly(_from, to, begin, end, mode='walking'): section = response_pb2.Section() section.type = response_pb2.CROW_FLY section.origin.CopyFrom(_from) section.destination.CopyFrom(to) section.duration = end-begin; section.begin_date_time = begin section.end_date_time = end section.street_network.mode = response_pb2.Walking section.id = unicode(uuid.uuid4()) return section
def _create_additional_section(self, pt_object, additional_time, begin_date_time, section_id): additional_section = response_pb2.Section() additional_section.id = section_id additional_section.origin.CopyFrom(pt_object) additional_section.destination.CopyFrom(pt_object) additional_section.duration = additional_time additional_section.type = response_pb2.WAITING additional_section.begin_date_time = begin_date_time additional_section.end_date_time = additional_section.begin_date_time + additional_section.duration return additional_section
def create_crowfly(pt_journey, crowfly_origin, crowfly_destination, begin, end, mode='walking'): section = response_pb2.Section() section.type = response_pb2.CROW_FLY section.origin.CopyFrom(crowfly_origin) section.destination.CopyFrom(crowfly_destination) section.duration = end - begin pt_journey.durations.walking += section.duration pt_journey.durations.total += section.duration pt_journey.duration += section.duration section.begin_date_time = begin section.end_date_time = end section.street_network.mode = response_pb2.Walking section.id = unicode(uuid.uuid4()) return section
def _create_crowfly(pt_journey, crowfly_origin, crowfly_destination, begin, end, mode): section = response_pb2.Section() section.type = response_pb2.CROW_FLY section.origin.CopyFrom(crowfly_origin) section.destination.CopyFrom(crowfly_destination) section.duration = end - begin pt_journey.durations.walking += section.duration pt_journey.durations.total += section.duration pt_journey.duration += section.duration section.begin_date_time = begin section.end_date_time = end section.street_network.mode = MODE_TO_PB_MODE.get(mode) section.id = six.text_type(uuid.uuid4()) return section
def add_parking_section_in_direct_path(self, response, pt_object, direct_path_type): logger = logging.getLogger(__name__) logger.info("Creating parking section for direct path") for journey in response.journeys: parking_duration = self.parking_module.get_parking_duration( get_pt_object_coord(pt_object)) parking_section = response_pb2.Section() parking_section.id = 'section_1' parking_section.origin.CopyFrom(pt_object) parking_section.destination.CopyFrom(pt_object) parking_section.duration += parking_duration journey.duration += parking_duration journey.durations.total += parking_duration if direct_path_type == StreetNetworkPathType.ENDING_FALLBACK: # And we have to complete the destination of the first section ourselves # Because Jormun does not do it afterwards journey.sections[0].origin.CopyFrom(pt_object) parking_section.type = response_pb2.LEAVE_PARKING parking_section.begin_date_time = journey.sections[ 0].begin_date_time parking_section.end_date_time = parking_section.begin_date_time + parking_duration # we push off the whole car section for s in journey.sections: s.begin_date_time += parking_duration s.end_date_time += parking_duration else: # And we have to complete the destination of the first section ourselves # Because Jormun does not do it afterwards journey.sections[-1].destination.CopyFrom(pt_object) parking_section.type = response_pb2.PARK parking_section.begin_date_time = journey.sections[ -1].end_date_time parking_section.end_date_time = parking_section.begin_date_time + parking_duration journey.arrival_date_time += parking_duration journey.sections.extend([parking_section]) journey.nb_sections += 1
def _create_crowfly(pt_journey, crowfly_origin, crowfly_destination, begin, end, mode): section = response_pb2.Section() section.type = response_pb2.CROW_FLY section.origin.CopyFrom(crowfly_origin) section.destination.CopyFrom(crowfly_destination) section.duration = end - begin pt_journey.durations.total += section.duration pt_journey.duration += section.duration section.begin_date_time = begin section.end_date_time = end if section.duration > 0: section.street_network.mode = FallbackModes[mode].value # mode is always walking for a teleportation crow_fly else: section.street_network.mode = response_pb2.Walking # Calculate section length from_coord = get_pt_object_coord(section.origin) to_coord = get_pt_object_coord(section.destination) section.length = int(crowfly_distance_between(from_coord, to_coord)) section.id = six.text_type(generate_id()) return section