Example #1
0
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 testQuerySectionsForTrip(self):
     new_trip = self.create_fake_trip()
     new_section = ecwc.Section()
     new_section.trip_id = new_trip.get_id()
     new_section.start_ts = 5
     new_section.end_ts = 6
     ts = esta.TimeSeries.get_time_series(self.testUserId)
     ts.insert_data(self.testUserId, esda.RAW_SECTION_KEY, new_section) 
     ret_entries = esdt.get_raw_sections_for_trip(self.testUserId, new_trip.get_id())
     self.assertEqual([entry.data for entry in ret_entries], [new_section])
Example #3
0
 def testQuerySectionsForTrip(self):
     new_trip = self.create_fake_trip()
     new_section = ecwc.Section()
     new_section.trip_id = new_trip.get_id()
     new_section.start_ts = 5
     new_section.end_ts = 6
     ts = esta.TimeSeries.get_time_series(self.testUserId)
     ts.insert_data(self.testUserId, esda.RAW_SECTION_KEY, new_section) 
     ret_entries = esdt.get_raw_sections_for_trip(self.testUserId, new_trip.get_id())
     self.assertEqual([entry.data for entry in ret_entries], [new_section])
    def testIOSSegmentationWrapperWithAutoTrip(self):
        eaist.segment_current_trips(self.iosUUID)
        eaiss.segment_current_sections(self.iosUUID)

        tq_trip = estt.TimeQuery("data.start_ts", 1446700000, 1446900000)
        created_trips = esda.get_entries(esda.RAW_TRIP_KEY, self.iosUUID,
                                         tq_trip)

        self.assertEqual(len(created_trips), 2)
        logging.debug("created trips = %s" % created_trips)

        sections_stops = [(len(esdt.get_raw_sections_for_trip(self.iosUUID, trip.get_id())),
                           len(esdt.get_raw_stops_for_trip(self.iosUUID, trip.get_id())))
                          for trip in created_trips]
        logging.debug(sections_stops)
        self.assertEqual(len(sections_stops), len(created_trips))
        # The expected value was copy-pasted from the debug statement above
        self.assertEqual(sections_stops,
                         [(0, 0), (11, 10)])
    def testSegmentationWrapperWithAutoTrip(self):
        eaist.segment_current_trips(self.androidUUID)
        eaiss.segment_current_sections(self.androidUUID)

        tq_trip = estt.TimeQuery("data.start_ts", 1440658800, 1440745200)
        created_trips = esda.get_entries(esda.RAW_TRIP_KEY, self.androidUUID,
                                         tq_trip)

        self.assertEqual(len(created_trips), 8)

        sections_stops = [(len(esdt.get_raw_sections_for_trip(self.androidUUID, trip.get_id())),
                           len(esdt.get_raw_stops_for_trip(self.androidUUID, trip.get_id())))
                          for trip in created_trips]
        logging.debug(sections_stops)
        self.assertEqual(len(sections_stops), len(created_trips))
        # The expected value was copy-pasted from the debug statement above
        self.assertEqual(sections_stops,
                         [(2, 1), (1, 0), (2, 1), (2, 1), (1, 0), (2, 1),
                          (4, 3), (2, 1)])
Example #6
0
    def testIOSSegmentationWrapperWithAutoTrip(self):
        eaist.segment_current_trips(self.iosUUID)
        eaiss.segment_current_sections(self.iosUUID)

        tq_trip = estt.TimeQuery("data.start_ts", 1446700000, 1446900000)
        created_trips = esda.get_entries(esda.RAW_TRIP_KEY, self.iosUUID,
                                         tq_trip)

        self.assertEqual(len(created_trips), 2)
        logging.debug("created trips = %s" % created_trips)

        sections_stops = [(len(esdt.get_raw_sections_for_trip(self.iosUUID, trip.get_id())),
                           len(esdt.get_raw_stops_for_trip(self.iosUUID, trip.get_id())))
                          for trip in created_trips]
        logging.debug(sections_stops)
        self.assertEqual(len(sections_stops), len(created_trips))
        # The expected value was copy-pasted from the debug statement above
        self.assertEqual(sections_stops,
                         [(0, 0), (11, 10)])
Example #7
0
    def testSegmentationWrapperWithAutoTrip(self):
        eaist.segment_current_trips(self.androidUUID)
        eaiss.segment_current_sections(self.androidUUID)

        tq_trip = estt.TimeQuery("data.start_ts", 1440658800, 1440745200)
        created_trips = esda.get_entries(esda.RAW_TRIP_KEY, self.androidUUID,
                                         tq_trip)

        self.assertEqual(len(created_trips), 8)

        sections_stops = [(len(esdt.get_raw_sections_for_trip(self.androidUUID, trip.get_id())),
                           len(esdt.get_raw_stops_for_trip(self.androidUUID, trip.get_id())))
                          for trip in created_trips]
        logging.debug(sections_stops)
        self.assertEqual(len(sections_stops), len(created_trips))
        # The expected value was copy-pasted from the debug statement above
        self.assertEqual(sections_stops,
                         [(2, 1), (1, 0), (2, 1), (2, 1), (1, 0), (2, 1),
                          (4, 3), (2, 1)])
    def testSegmentationWrapperWithAutoTrip(self):
        eaist.segment_current_trips(self.testUUID)
        eaiss.segment_current_sections(self.testUUID)

        tq_trip = estt.TimeQuery("data.start_ts", 1440658800, 1440745200)
        created_trips = esda.get_entries(esda.RAW_TRIP_KEY, self.testUUID,
                                         tq_trip)

        for i, trip in enumerate(created_trips):
            logging.debug("current trip is %s" % trip)
            created_stops = esdt.get_raw_stops_for_trip(self.testUUID, trip.get_id())
            created_sections = esdt.get_raw_sections_for_trip(self.testUUID, trip.get_id())

            for j, stop in enumerate(created_stops):
                logging.info("Retrieved stops %s: %s -> %s" %
                             (j, stop.data.enter_fmt_time,
                              stop.data.exit_fmt_time))
            for j, section in enumerate(created_sections):
                logging.info("Retrieved sections %s: %s -> %s" %
                             (j, section.data.start_fmt_time,
                              section.data.end_fmt_time))
Example #9
0
    def testSegmentationWrapperWithAutoTrip(self):
        eaist.segment_current_trips(self.testUUID)
        eaiss.segment_current_sections(self.testUUID)

        tq_trip = estt.TimeQuery("data.start_ts", 1440658800, 1440745200)
        created_trips = esda.get_entries(esda.RAW_TRIP_KEY, self.testUUID,
                                         tq_trip)

        for i, trip in enumerate(created_trips):
            logging.debug("current trip is %s" % trip)
            created_stops = esdt.get_raw_stops_for_trip(
                self.testUUID, trip.get_id())
            created_sections = esdt.get_raw_sections_for_trip(
                self.testUUID, trip.get_id())

            for j, stop in enumerate(created_stops):
                logging.info(
                    "Retrieved stops %s: %s -> %s" %
                    (j, stop.data.enter_fmt_time, stop.data.exit_fmt_time))
            for j, section in enumerate(created_sections):
                logging.info("Retrieved sections %s: %s -> %s" %
                             (j, section.data.start_fmt_time,
                              section.data.end_fmt_time))
    def testSegmentationWrapperWithManualTrip(self):
        ts = esta.TimeSeries.get_time_series(self.androidUUID)
        test_trip = ecwrt.Rawtrip()
        test_trip.start_ts = 1440695152.989
        test_trip.start_fmt_time = "2015-08-27 10:05:52.989000-07:00"
        test_trip.start_local_dt = {
            'year': 2015,
            'month': 8,
            'day': 27,
            'hour': 10,
            'minute': 5,
            'second': 52,
            'timezone': "America/Los_Angeles"
        }
        test_trip.start_loc = {
            "type": "Point",
            "coordinates": [-122.4029569, 37.6162024]
        }

        test_trip.end_ts = 1440699266.669
        test_trip.end_fmt_time = "2015-08-27 11:14:26.669000-07:00"
        test_trip.end_local_dt = {
            'year': 2015,
            'month': 8,
            'day': 27,
            'hour': 11,
            'minute': 14,
            'second': 26,
            'timezone': "America/Los_Angeles"
        }
        test_trip.end_loc = {
            "type": "Point",
            "coordinates": [-122.2603947, 37.875023]
        }
        test_trip_id = ts.insert(
            ecwe.Entry.create_entry(self.androidUUID, "segmentation/raw_trip",
                                    test_trip))
        eaiss.segment_trip_into_sections(self.androidUUID, test_trip_id,
                                         "DwellSegmentationTimeFilter")

        created_stops_entries = esdt.get_raw_stops_for_trip(
            self.androidUUID, test_trip_id)
        created_sections_entries = esdt.get_raw_sections_for_trip(
            self.androidUUID, test_trip_id)
        created_stops = [entry.data for entry in created_stops_entries]
        created_sections = [entry.data for entry in created_sections_entries]

        tq_stop = estt.TimeQuery("data.enter_ts", 1440658800, 1440745200)
        queried_stops = esda.get_objects(esda.RAW_STOP_KEY, self.androidUUID,
                                         tq_stop)

        tq_section = estt.TimeQuery("data.start_ts", 1440658800, 1440745200)
        queried_sections = esda.get_objects(esda.RAW_SECTION_KEY,
                                            self.androidUUID, tq_section)

        for i, stop in enumerate(created_stops):
            logging.info("Retrieved stop %s: %s -> %s" %
                         (i, stop.enter_fmt_time, stop.exit_fmt_time))
        for i, section in enumerate(created_sections):
            logging.info("Retrieved section %s: %s -> %s" %
                         (i, section.start_fmt_time, section.end_fmt_time))

        self.assertEqual(len(created_stops), 1)
        self.assertEqual(created_stops[0].enter_ts, 1440698066.704)
        self.assertEqual(created_stops[0].exit_ts, 1440698306.892)
        self.assertEqual(created_stops[0].exit_loc,
                         created_sections[1].start_loc)
        self.assertEqual(created_stops[0].ending_section,
                         created_sections_entries[0].get_id())
        self.assertEqual(created_stops[0].starting_section,
                         created_sections_entries[1].get_id())

        self.assertEqual(len(created_sections), 2)
        logging.info("Checking fields for section %s" % created_sections[0])
        self.assertEqual(created_sections[0].start_ts, 1440695152.989)
        self.assertEqual(created_sections[0].end_ts, 1440698066.704)
        self.assertIsNone(created_sections[0].start_stop)
        self.assertEqual(created_sections[0].end_stop,
                         created_stops_entries[0].get_id())

        logging.info("Checking fields for section %s" % created_sections[1])
        self.assertEqual(created_sections[1].start_ts, 1440698306.892)
        self.assertEqual(created_sections[1].end_ts, 1440699266.669)
        self.assertEqual(created_sections[1].start_stop,
                         created_stops_entries[0].get_id())
        self.assertIsNone(created_sections[1].end_stop)

        self.assertEqual(created_sections, queried_sections)
        self.assertEqual(created_stops, queried_stops)
    def testSegmentationWrapperWithManualTrip(self):
        ts = esta.TimeSeries.get_time_series(self.androidUUID)
        test_trip = ecwrt.Rawtrip()
        test_trip.start_ts = 1440695152.989
        test_trip.start_fmt_time = "2015-08-27 10:05:52.989000-07:00"
        test_trip.start_local_dt = {
            'year': 2015,
            'month': 8,
            'day': 27,
            'hour': 10,
            'minute': 5,
            'second': 52,
            'timezone': "America/Los_Angeles"
        }
        test_trip.start_loc = {
                "type": "Point",
                "coordinates": [
                    -122.4029569,
                    37.6162024
                ]
            }

        test_trip.end_ts = 1440699266.669
        test_trip.end_fmt_time = "2015-08-27 11:14:26.669000-07:00"
        test_trip.end_local_dt = {
            'year': 2015,
            'month': 8,
            'day': 27,
            'hour': 11,
            'minute': 14,
            'second': 26,
            'timezone': "America/Los_Angeles"
        }
        test_trip.end_loc = {
                "type": "Point",
                "coordinates": [
                    -122.2603947,
                    37.875023
                ]
            }

        test_place = ecwrp.Rawplace()
        test_place.location = test_trip.start_loc
        test_place.exit_ts = test_trip.start_ts
        test_place.exit_local_dt = test_trip.start_local_dt
        test_place.exit_fmt_time = test_trip.start_fmt_time
        test_place_entry = ecwe.Entry.create_entry(self.androidUUID,
            "segmentation/raw_place", test_place)
        test_trip.start_place = test_place_entry.get_id()

        test_trip_id = ts.insert(ecwe.Entry.create_entry(self.androidUUID,
            "segmentation/raw_trip", test_trip))
        test_trip_entry = ts.get_entry_from_id(esda.RAW_TRIP_KEY, test_trip_id)
        test_place.starting_trip = test_trip_id
        ts.insert(test_place_entry)

        eaiss.segment_trip_into_sections(self.androidUUID, test_trip_entry, "DwellSegmentationTimeFilter")

        created_stops_entries = esdt.get_raw_stops_for_trip(self.androidUUID, test_trip_id)
        created_sections_entries = esdt.get_raw_sections_for_trip(self.androidUUID, test_trip_id)
        created_stops = [entry.data for entry in created_stops_entries]
        created_sections = [entry.data for entry in created_sections_entries]

        tq_stop = estt.TimeQuery("data.enter_ts", 1440658800, 1440745200)
        queried_stops = esda.get_objects(esda.RAW_STOP_KEY, self.androidUUID, tq_stop)

        tq_section = estt.TimeQuery("data.start_ts", 1440658800, 1440745200)
        queried_sections = esda.get_objects(esda.RAW_SECTION_KEY, self.androidUUID, tq_section)

        for i, stop in enumerate(created_stops):
            logging.info("Retrieved stop %s: %s -> %s" % (i, stop.enter_fmt_time, stop.exit_fmt_time))
        for i, section in enumerate(created_sections):
            logging.info("Retrieved section %s: %s -> %s" % (i, section.start_fmt_time, section.end_fmt_time))

        self.assertEqual(len(created_stops), 1)
        self.assertEqual(created_stops[0].enter_ts, 1440698066.704)
        self.assertEqual(created_stops[0].exit_ts, 1440698306.892)
        self.assertEqual(created_stops[0].exit_loc, created_sections[1].start_loc)
        self.assertEqual(created_stops[0].ending_section, created_sections_entries[0].get_id())
        self.assertEqual(created_stops[0].starting_section, created_sections_entries[1].get_id())

        self.assertEqual(len(created_sections), 2)
        logging.info("Checking fields for section %s" % created_sections[0])
        self.assertEqual(created_sections[0].start_ts, 1440695152.989)
        self.assertEqual(created_sections[0].end_ts, 1440698066.704)
        self.assertIsNone(created_sections[0].start_stop)
        self.assertEqual(created_sections[0].end_stop, created_stops_entries[0].get_id())

        logging.info("Checking fields for section %s" % created_sections[1])
        self.assertEqual(created_sections[1].start_ts, 1440698306.892)
        self.assertEqual(created_sections[1].end_ts, 1440699266.669)
        self.assertEqual(created_sections[1].start_stop, created_stops_entries[0].get_id())
        self.assertIsNone(created_sections[1].end_stop)

        self.assertEqual(created_sections, queried_sections)
        self.assertEqual(created_stops, queried_stops)
    def testSegmentationWrapperWithManualTrip(self):
        ts = esta.TimeSeries.get_time_series(self.testUUID)
        test_trip = ecwrt.Rawtrip()
        test_trip.start_ts = 1440695152.989
        test_trip.start_fmt_time = "2015-08-27 10:05:52.989000-07:00"
        test_trip.start_loc = {
                "type": "Point",
                "coordinates": [
                    -122.4029569,
                    37.6162024
                ]
            }

        test_trip.end_ts = 1440699266.669
        test_trip.end_fmt_time = "2015-08-27 11:14:26.669000-07:00"
        test_trip.end_loc = {
                "type": "Point",
                "coordinates": [
                    -122.2603947,
                    37.875023
                ]
            }
        test_trip_id = ts.insert(ecwe.Entry.create_entry(self.testUUID,
            "segmentation/raw_trip", test_trip))
        eaiss.segment_trip_into_sections(self.testUUID, test_trip_id, "DwellSegmentationTimeFilter")

        created_stops_entries = esdt.get_raw_stops_for_trip(self.testUUID, test_trip_id)
        created_sections_entries = esdt.get_raw_sections_for_trip(self.testUUID, test_trip_id)
        created_stops = [entry.data for entry in created_stops_entries]
        created_sections = [entry.data for entry in created_sections_entries]

        tq_stop = estt.TimeQuery("data.enter_ts", 1440658800, 1440745200)
        queried_stops = esda.get_objects(esda.RAW_STOP_KEY, self.testUUID, tq_stop)

        tq_section = estt.TimeQuery("data.start_ts", 1440658800, 1440745200)
        queried_sections = esda.get_objects(esda.RAW_SECTION_KEY, self.testUUID, tq_section)

        for i, stop in enumerate(created_stops):
            logging.info("Retrieved stop %s: %s -> %s" % (i, stop.enter_fmt_time, stop.exit_fmt_time))
        for i, section in enumerate(created_sections):
            logging.info("Retrieved section %s: %s -> %s" % (i, section.start_fmt_time, section.end_fmt_time))

        self.assertEqual(len(created_stops), 1)
        self.assertEqual(created_stops[0].enter_ts, 1440698066.704)
        self.assertEqual(created_stops[0].exit_ts, 1440698306.892)
        self.assertEqual(created_stops[0].exit_loc, created_sections[1].start_loc)
        self.assertEqual(created_stops[0].ending_section, created_sections_entries[0].get_id())
        self.assertEqual(created_stops[0].starting_section, created_sections_entries[1].get_id())

        self.assertEqual(len(created_sections), 2)
        logging.info("Checking fields for section %s" % created_sections[0])
        self.assertEqual(created_sections[0].start_ts, 1440695152.989)
        self.assertEqual(created_sections[0].end_ts, 1440698066.704)
        self.assertIsNone(created_sections[0].start_stop)
        self.assertEqual(created_sections[0].end_stop, created_stops_entries[0].get_id())

        logging.info("Checking fields for section %s" % created_sections[1])
        self.assertEqual(created_sections[1].start_ts, 1440698306.892)
        self.assertEqual(created_sections[1].end_ts, 1440699266.669)
        self.assertEqual(created_sections[1].start_stop, created_stops_entries[0].get_id())
        self.assertIsNone(created_sections[1].end_stop)

        self.assertEqual(created_sections, queried_sections)
        self.assertEqual(created_stops, queried_stops)