def test_filter_end_date_not_included(self): # the end date should not be included: FilterExtract(self.G, self.fname_copy, start_date="2007-01-02", end_date="2010-12-31").create_filtered_copy() hash_copy = hashlib.md5(open(self.fname_copy, 'rb').read()).hexdigest() self.assertNotEqual(self.hash_orig, hash_copy) G_copy = GTFS(self.fname_copy) dsut_end = G_copy.get_day_start_ut("2010-12-31") dsut_to_trip_I = G_copy.get_tripIs_within_range_by_dsut( dsut_end, dsut_end + 24 * 3600) self.assertEqual(len(dsut_to_trip_I), 0) calendar_copy = G_copy.get_table("calendar") max_date_calendar = max([ datetime.datetime.strptime(el, "%Y-%m-%d") for el in calendar_copy["end_date"].values ]) min_date_calendar = max([ datetime.datetime.strptime(el, "%Y-%m-%d") for el in calendar_copy["start_date"].values ]) end_date_not_included = datetime.datetime.strptime( "2010-12-31", "%Y-%m-%d") start_date_not_included = datetime.datetime.strptime( "2007-01-01", "%Y-%m-%d") self.assertLess(max_date_calendar, end_date_not_included, msg="the last date should not be included in calendar") self.assertLess(start_date_not_included, min_date_calendar) os.remove(self.fname_copy)
def validate_day_start_ut(conn): """This validates the day_start_ut of the days table.""" G = GTFS(conn) cur = conn.execute('SELECT date, day_start_ut FROM days') for date, day_start_ut in cur: #print date, day_start_ut assert day_start_ut == G.get_day_start_ut(date)
def test_filter_by_start_and_end_full_range(self): # untested tables with filtering: stops, shapes # test filtering by start and end time, copy full range FilterExtract(self.G, self.fname_copy, start_date=u"2007-01-01", end_date=u"2011-01-01", update_metadata=False).create_filtered_copy() G_copy = GTFS(self.fname_copy) dsut_end = G_copy.get_day_start_ut("2010-12-31") dsut_to_trip_I = G_copy.get_tripIs_within_range_by_dsut( dsut_end, dsut_end + 24 * 3600) self.assertGreater(len(dsut_to_trip_I), 0) os.remove(self.fname_copy)
def __create_temporal_extract_from_main_db(self, days, output_db_path): if os.path.isfile(output_db_path): os.remove(output_db_path) main_G = GTFS(self.main_db_path) assert isinstance(main_G, GTFS) day_extract_date_start = self.get_weekly_extract_start_date() start_date_ut = main_G.get_day_start_ut(day_extract_date_start) three_am_seconds = 3 * 3600 fe = filter.FilterExtract(main_G, output_db_path, update_metadata=True, trip_earliest_start_time_ut=start_date_ut + three_am_seconds, # inclusive trip_latest_start_time_ut=start_date_ut + three_am_seconds + days * 24 * 3600) # exclusive fe.create_filtered_copy()