def testStopSectionTimeline(self): eaist.segment_current_trips(self.testUUID) eaiss.segment_current_sections(self.testUUID) tl = esdt.get_raw_timeline(self.testUUID, self.day_start_ts, self.day_end_ts) for i, element in enumerate(tl): logging.debug("%s: %s" % (i, type(element))) curr_type = self.get_type(element) if curr_type == ecwrt.Rawtrip: curr_tl = esdtq.get_raw_timeline_for_trip( self.testUUID, element.get_id()) logging.debug("Got timeline %s for trip %s" % (curr_tl, element.start_fmt_time)) prev_sub_type = None prev_element = None checked_count = 0 j = 0 for j, curr_element in enumerate(curr_tl): logging.debug("curr_element = %s" % curr_element) curr_sub_type = self.get_type(curr_element) if prev_sub_type is not None: checked_count = checked_count + 1 self.assertNotEqual(prev_sub_type, curr_sub_type) if prev_sub_type == ecws.Stop: self.assertEqual(prev_element.starting_section, curr_element.get_id()) else: self.assertEqual(prev_sub_type, ecwsc.Section) self.assertEqual(prev_element.end_stop, curr_element.get_id()) prev_sub_type = curr_sub_type prev_element = curr_element self.assertEqual(checked_count, j)
def testStopSectionTimeline(self): eaist.segment_current_trips(self.testUUID) eaiss.segment_current_sections(self.testUUID) tl = esdt.get_raw_timeline(self.testUUID, self.day_start_ts, self.day_end_ts) for i, element in enumerate(tl): logging.debug("%s: %s" % (i, type(element))) curr_type = self.get_type(element) if curr_type == ecwrt.Rawtrip: curr_tl = esdtq.get_raw_timeline_for_trip(self.testUUID, element.get_id()) logging.debug("Got timeline %s for trip %s" % (curr_tl, element.start_fmt_time)) prev_sub_type = None prev_element = None checked_count = 0 j = 0 for j, curr_element in enumerate(curr_tl): logging.debug("curr_element = %s" % curr_element) curr_sub_type = self.get_type(curr_element) if prev_sub_type is not None: checked_count = checked_count + 1 self.assertNotEqual(prev_sub_type, curr_sub_type) if prev_sub_type == ecws.Stop: self.assertEqual(prev_element.starting_section, curr_element.get_id()) else: self.assertEqual(prev_sub_type, ecwsc.Section) self.assertEqual(prev_element.end_stop, curr_element.get_id()) prev_sub_type = curr_sub_type prev_element = curr_element self.assertEqual(checked_count, j)
def get_maps_for_range_old(user_id, start_ts, end_ts): # First, get the timeline for that range. ts = esta.TimeSeries.get_time_series(user_id) trip_list = esdt.get_trips(user_id, estt.TimeQuery("data.start_ts", start_ts, end_ts)) # TODO: Should the timeline support random access as well? # If it did, we wouldn't need this additional map # I think that it would be good to support a doubly linked list, i.e. prev and next in addition # to the iteration interface place_list = esdp.get_places(user_id, estt.TimeQuery("data.exit_ts", start_ts, end_ts)) place_list = place_list + (esdp.get_places(user_id, estt.TimeQuery("data.enter_ts", start_ts, end_ts))) place_map = dict([(p.get_id(), p) for p in place_list]) map_list = [] flipped_midpoint = lambda p1_p22: [old_div((p1_p22[0].coordinates[1] + p1_p22[1].coordinates[1]),2), old_div((p1_p22[0].coordinates[0] + p1_p22[1].coordinates[0]),2)] for i, trip in enumerate(trip_list): logging.debug("-" * 20 + trip.start_fmt_time + "=>" + trip.end_fmt_time + "(" + str(trip.end_ts - trip.start_ts) + ")") if (len(esdt.get_raw_sections_for_trip(user_id, trip.get_id())) == 0 and len(esdt.get_raw_stops_for_trip(user_id, trip.get_id())) == 0): logging.debug("Skipping trip because it has no stops and no sections") continue start_point = gj.GeoJSON.to_instance(trip.start_loc) end_point = gj.GeoJSON.to_instance(trip.end_loc) curr_map = folium.Map(flipped_midpoint((start_point, end_point))) map_list.append(curr_map) logging.debug("About to display places %s and %s" % (trip.start_place, trip.end_place)) update_place(curr_map, trip.start_place, place_map, marker_color='green') update_place(curr_map, trip.end_place, place_map, marker_color='red') # TODO: Should get_timeline_for_trip work on a trip_id or on a trip object # it seems stupid to convert trip object -> id -> trip object curr_trip_timeline = esdt.get_raw_timeline_for_trip(user_id, trip.get_id()) for i, trip_element in enumerate(curr_trip_timeline): # logging.debug("Examining element %s of type %s" % (trip_element, type(trip_element))) if type(trip_element) == ecws.Stop: time_query = esds.get_time_query_for_stop(trip_element.get_id()) logging.debug("time_query for stop %s = %s" % (trip_element, time_query)) stop_points_df = ts.get_data_df("background/filtered_location", time_query) # logging.debug("stop_points_df.head() = %s" % stop_points_df.head()) if len(stop_points_df) > 0: update_line(curr_map, stop_points_df, line_color = sel_color_list[-1], popup="%s -> %s" % (trip_element.enter_fmt_time, trip_element.exit_fmt_time)) else: assert(type(trip_element) == ecwsc.Section) time_query = esdsc.get_time_query_for_section(trip_element.get_id()) logging.debug("time_query for section %s = %s" % (trip_element, "[%s,%s,%s]" % (time_query.timeType, time_query.startTs, time_query.endTs))) section_points_df = ts.get_data_df("background/filtered_location", time_query) logging.debug("section_points_df.tail() = %s" % section_points_df.tail()) if len(section_points_df) > 0: update_line(curr_map, section_points_df, line_color = sel_color_list[trip_element.sensed_mode.value], popup="%s (%s -> %s)" % (trip_element.sensed_mode, trip_element.start_fmt_time, trip_element.end_fmt_time)) else: logging.warning("found no points for section %s" % trip_element) return map_list
def get_filtered_trip(ts, trip): logging.debug("Filtering trip %s" % trip) trip_tl = esdtq.get_raw_timeline_for_trip(trip.user_id, trip.get_id()) # trip_tl is the timeline for this particular trip, which contains the # section_entries and trip_entries if len(trip_tl.trips) == 0: logging.info("Found zero section trip %s " % trip) return None # Else, this is a non-zero section trip filtered_trip_data = ecwct.Cleanedtrip() _copy_non_excluded(old_data=trip.data, new_data=filtered_trip_data, excluded_list=filtered_trip_excluded) filtered_trip_data.raw_trip = trip.get_id() filtered_trip_entry = ecwe.Entry.create_entry(trip.user_id, esda.CLEANED_TRIP_KEY, filtered_trip_data, create_id=True) # Map from old section id -> new section object section_map = {} for section in trip_tl.trips: section_map[section.get_id()] = get_filtered_section( filtered_trip_entry, section) stop_map = {} for stop in trip_tl.places: stop_map[stop.get_id()] = get_filtered_stop(filtered_trip_entry, stop) # TODO: DO we need to add the stop distances too? They should be small... trip_distance = sum( [section.data.distance for section in section_map.values()]) filtered_trip_data.distance = trip_distance filtered_trip_entry["data"] = filtered_trip_data # After we have linked everything back together. NOW we can save the entries linked_tl = link_trip_timeline(trip_tl, section_map, stop_map) for entry in linked_tl: ts.insert(entry) return filtered_trip_entry
def get_filtered_trip(ts, trip): logging.debug("Filtering trip %s" % trip) trip_tl = esdtq.get_raw_timeline_for_trip(trip.user_id, trip.get_id()) # trip_tl is the timeline for this particular trip, which contains the # section_entries and trip_entries if len(trip_tl.trips) == 0: logging.info("Found zero section trip %s " % trip) return None # Else, this is a non-zero section trip filtered_trip_data = ecwct.Cleanedtrip() _copy_non_excluded(old_data=trip.data, new_data=filtered_trip_data, excluded_list=filtered_trip_excluded) filtered_trip_data.raw_trip = trip.get_id() filtered_trip_entry = ecwe.Entry.create_entry(trip.user_id, esda.CLEANED_TRIP_KEY, filtered_trip_data, create_id = True) # Map from old section id -> new section object section_map = {} for section in trip_tl.trips: section_map[section.get_id()] = get_filtered_section(filtered_trip_entry, section) stop_map = {} for stop in trip_tl.places: stop_map[stop.get_id()] = get_filtered_stop(filtered_trip_entry, stop) # TODO: DO we need to add the stop distances too? They should be small... trip_distance = sum([section.data.distance for section in section_map.values()]) filtered_trip_data.distance = trip_distance filtered_trip_entry["data"] = filtered_trip_data # After we have linked everything back together. NOW we can save the entries linked_tl = link_trip_timeline(trip_tl, section_map, stop_map) for entry in linked_tl: ts.insert(entry) return filtered_trip_entry