def testQueryStops(self): new_stop = etsa.savePlaceLike(self, esda.RAW_STOP_KEY, ecws.Stop) new_stop["data"]["trip_id"] = self.test_trip_id estb.BuiltinTimeSeries.update(new_stop) ret_arr_one = esds.get_stops_for_trip(self.testUserId, self.test_trip_id) self.assertEqual(len(ret_arr_one), 1) self.assertEqual(ret_arr_one, [new_stop]) ret_arr_list = esds.get_stops_for_trip_list(self.testUserId, [self.test_trip_id]) self.assertEqual(ret_arr_one, ret_arr_list) ret_arr_time = esda.get_objects(esda.RAW_STOP_KEY, self.testUserId, estt.TimeQuery("data.enter_ts", 4, 6)) self.assertEqual([entry.data for entry in ret_arr_list], ret_arr_time)
def testQueryStops(self): new_stop = etsa.savePlaceLike(self, esda.RAW_STOP_KEY, ecws.Stop) new_stop["data"]["trip_id"] = self.test_trip_id estb.BuiltinTimeSeries.update(new_stop) ret_arr_one = esds.get_stops_for_trip(self.testUserId, self.test_trip_id) self.assertEqual(len(ret_arr_one), 1) self.assertEqual(ret_arr_one, [new_stop]) ret_arr_list = esds.get_stops_for_trip_list(self.testUserId, [self.test_trip_id]) self.assertEqual(ret_arr_one, ret_arr_list) ret_arr_time = esda.get_objects(esda.RAW_STOP_KEY, self.testUserId, estt.TimeQuery("data.enter_ts", 4, 6)) self.assertEqual([entry.data for entry in ret_arr_list], ret_arr_time)
def testQuerySections(self): new_section = ecws.Section() new_section.start_ts = 5 new_section.end_ts = 6 new_section.trip_id = self.test_trip_id esta.TimeSeries.get_time_series(self.testUserId).insert_data(self.testUserId, esda.RAW_SECTION_KEY, new_section) ret_arr_one = esds.get_sections_for_trip(self.testUserId, self.test_trip_id) self.assertEqual(len(ret_arr_one), 1) self.assertEqual([entry.data for entry in ret_arr_one], [new_section]) ret_arr_list = esds.get_sections_for_trip_list(self.testUserId, [self.test_trip_id]) self.assertEqual(ret_arr_one, ret_arr_list) ret_arr_time = esda.get_objects(esda.RAW_SECTION_KEY, self.testUserId, estt.TimeQuery("data.start_ts", 4, 6)) self.assertEqual([entry.data for entry in ret_arr_list], ret_arr_time)
def testQuerySections(self): new_section = ecws.Section() new_section.start_ts = 5 new_section.end_ts = 6 new_section.trip_id = self.test_trip_id esta.TimeSeries.get_time_series(self.testUserId).insert_data(self.testUserId, esda.RAW_SECTION_KEY, new_section) ret_arr_one = esds.get_sections_for_trip(self.testUserId, self.test_trip_id) self.assertEqual(len(ret_arr_one), 1) self.assertEqual([entry.data for entry in ret_arr_one], [new_section]) ret_arr_list = esds.get_sections_for_trip_list(self.testUserId, [self.test_trip_id]) self.assertEqual(ret_arr_one, ret_arr_list) ret_arr_time = esda.get_objects(esda.RAW_SECTION_KEY, self.testUserId, estt.TimeQuery("data.start_ts", 4, 6)) self.assertEqual([entry.data for entry in ret_arr_list], ret_arr_time)
def filter_current_sections(user_id): time_query = epq.get_time_range_for_smoothing(user_id) try: sections_to_process = esda.get_objects(esda.RAW_SECTION_KEY, user_id, time_query) for section in sections_to_process: logging.info("^" * 20 + ("Smoothing section %s for user %s" % (section.get_id(), user_id)) + "^" * 20) filter_jumps(user_id, section.get_id()) if len(sections_to_process) == 0: # Didn't process anything new so start at the same point next time last_section_processed = None else: last_section_processed = sections_to_process[-1] epq.mark_smoothing_done(user_id, last_section_processed) except: logging.exception("Marking smoothing as failed") epq.mark_smoothing_failed(user_id)
def filter_current_sections(user_id): time_query = epq.get_time_range_for_smoothing(user_id) try: sections_to_process = esda.get_objects(esda.RAW_SECTION_KEY, user_id, time_query) for section in sections_to_process: logging.info("^" * 20 + ("Smoothing section %s for user %s" % (section.get_id(), user_id)) + "^" * 20) filter_jumps(user_id, section.get_id()) if len(sections_to_process) == 0: # Didn't process anything new so start at the same point next time last_section_processed = None else: last_section_processed = sections_to_process[-1] epq.mark_smoothing_done(user_id, last_section_processed) except: logging.exception("Marking smoothing as failed") epq.mark_smoothing_failed(user_id)
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 queryPlaceLike(utest, key, wrapper): new_trip = createNewPlaceLike(utest, key, wrapper) ret_arr_time = esda.get_objects(key, utest.testUserId, estt.TimeQuery("data.enter_ts", 4, 6)) utest.assertEqual(ret_arr_time, [new_trip.data])
def queryPlaceLike(utest, key, wrapper): new_trip = createNewPlaceLike(utest, key, wrapper) ret_arr_time = esda.get_objects(key, utest.testUserId, estt.TimeQuery("data.enter_ts", 4, 6)) utest.assertEqual(ret_arr_time, [new_trip.data])
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)