def get_cleaned_timeline_for_trip(user_id, trip_id):
    """
    Get an ordered sequence of sections and stops corresponding to this trip.
    """
    return esdt.Timeline(esda.CLEANED_STOP_KEY, esda.CLEANED_SECTION_KEY,
                         get_cleaned_stops_for_trip(user_id, trip_id),
                         get_cleaned_sections_for_trip(user_id, trip_id))
Esempio n. 2
0
def link_trip_timeline(tl, section_map, stop_map):
    filled_in_sections = [
        _fill_section(s, section_map[s.get_id()], stop_map) for s in tl.trips
    ]
    filled_in_stops = [
        _fill_stop(s, stop_map[s.get_id()], section_map) for s in tl.places
    ]
    return esdtl.Timeline(esda.CLEANED_STOP_KEY, esda.CLEANED_SECTION_KEY,
                          filled_in_stops, filled_in_sections)
Esempio n. 3
0
def create_and_link_timeline(tl, user_id, trip_map):
    last_cleaned_place = esdp.get_last_place_entry(esda.CLEANED_PLACE_KEY,
                                                   user_id)
    cleaned_places = []
    curr_cleaned_start_place = last_cleaned_place
    if curr_cleaned_start_place is None:
        # If it is not present - maybe this user is getting started for the first
        # time, we create an entry based on the first trip from the timeline
        curr_cleaned_start_place = get_filtered_place(tl.first_place())
        # We just created this place here, so lets add it to the created places
        # and insert rather than update it
        cleaned_places.append(curr_cleaned_start_place)

    if curr_cleaned_start_place is None:
        # If the timeline has no entries, we give up and return
        return (None, None)

    for raw_trip in tl.trips:
        if raw_trip.get_id() in trip_map:
            # there is a clean representation for this trip, so we can link its
            # start to the curr_cleaned_start_place
            curr_cleaned_trip = trip_map[raw_trip.get_id()]
            raw_start_place = tl.get_object(raw_trip.data.start_place)
            link_trip_start(curr_cleaned_trip, curr_cleaned_start_place,
                            raw_start_place)

            raw_end_place = tl.get_object(raw_trip.data.end_place)
            curr_cleaned_end_place = get_filtered_place(raw_end_place)
            cleaned_places.append(curr_cleaned_end_place)
            link_trip_end(curr_cleaned_trip, curr_cleaned_end_place,
                          raw_end_place)

            curr_cleaned_start_place = curr_cleaned_end_place
        else:
            # this is a squished trip, so we combine the start place with the
            # current start place we do not need to combine both start and end
            # places, since the end place of one trip is the start place of another. We combine start places instead of end places
            # because when the squishy part ends, we combine the start place of the un-squished trip
            # with the existing cleaned start and create a new entry for the un-squished end
            link_squished_place(curr_cleaned_start_place,
                                tl.get_object(raw_trip.data.start_place))

    return (last_cleaned_place,
            esdtl.Timeline(esda.CLEANED_PLACE_KEY, esda.CLEANED_TRIP_KEY,
                           cleaned_places, trip_map.values()))
def get_timeline_for_trip(user_id, trip_id):
    """
    Get an ordered sequence of sections and stops corresponding to this trip.
    """
    return esdt.Timeline(get_stops_for_trip(user_id, trip_id),
                         get_sections_for_trip(user_id, trip_id))