def testServicePeriodDateOutsideValidRange(self): # regular service, no exceptions, start_date invalid period = transitfeed.ServicePeriod() period.service_id = "WEEKDAY" period.start_date = "20070101" period.end_date = "21071231" period.day_of_week[0] = True self.ValidateAndExpectDateOutsideValidRange(period, "end_date", "21071231") # regular service, no exceptions, start_date invalid period2 = transitfeed.ServicePeriod() period2.service_id = "SUNDAY" period2.start_date = "18990101" period2.end_date = "19991231" period2.day_of_week[6] = True self.ValidateAndExpectDateOutsideValidRange(period2, "start_date", "18990101") # regular service, no exceptions, both start_date and end_date invalid period3 = transitfeed.ServicePeriod() period3.service_id = "SATURDAY" period3.start_date = "18990101" period3.end_date = "29991231" period3.day_of_week[5] = True period3.Validate(self.problems) e = self.accumulator.PopDateOutsideValidRange("start_date") self.assertEquals("18990101", e.value) e.FormatProblem() # should not throw any exceptions e.FormatContext() # should not throw any exceptions e = self.accumulator.PopDateOutsideValidRange("end_date") self.assertEqual("29991231", e.value) e.FormatProblem() # should not throw any exceptions e.FormatContext() # should not throw any exceptions self.accumulator.AssertNoMoreExceptions()
def testTwoService(self): schedule = transitfeed.Schedule() sp1 = transitfeed.ServicePeriod() sp1.service_id = "sp1" sp1.SetDateHasService("20081231") sp1.SetDateHasService("20090101") schedule.AddServicePeriodObject(sp1) sp2 = transitfeed.ServicePeriod() sp2.service_id = "sp2" sp2.SetStartDate("20081201") sp2.SetEndDate("20081231") sp2.SetWeekendService() sp2.SetWeekdayService() schedule.AddServicePeriodObject(sp2) self.assertEquals( [], schedule.GetServicePeriodsActiveEachDate(date(2009, 1, 1), date(2009, 1, 1))) date_services = schedule.GetServicePeriodsActiveEachDate(date(2008, 12, 31), date(2009, 1, 2)) self.assertEquals( [date(2008, 12, 31), date(2009, 1, 1)], [d for d, _ in date_services]) self.assertEquals(set([sp1, sp2]), set(date_services[0][1])) self.assertEquals([sp1], date_services[1][1])
def _create_service_period(self, schedule, operation): try: service = schedule.GetServicePeriod(operation) if service is not None: return service except KeyError: print("INFO. No existe el service_period para la operación:", operation, " por lo que será creado") if operation == "weekday": service = transitfeed.ServicePeriod("weekday") service.SetWeekdayService(True) service.SetWeekendService(False) elif operation == "saturday": service = transitfeed.ServicePeriod("saturday") service.SetWeekdayService(False) service.SetWeekendService(False) service.SetDayOfWeekHasService(5, True) elif operation == "sunday": service = transitfeed.ServicePeriod("sunday") service.SetWeekdayService(False) service.SetWeekendService(False) service.SetDayOfWeekHasService(6, True) else: raise KeyError("uknown operation keyword") service.SetStartDate(self.config['feed_info']['start_date']) service.SetEndDate(self.config['feed_info']['end_date']) schedule.AddServicePeriodObject(service) return schedule.GetServicePeriod(operation)
def __init__(self, config): super(TripsCreatorBrFlorianopolis, self).__init__(config) self.start_date = datetime.strptime(self.config['feed_info']['start_date'], "%Y%m%d") self.service_weekday = transitfeed.ServicePeriod("weekday") self.service_weekday.SetStartDate(self.config['feed_info']['start_date']) self.service_weekday.SetEndDate(self.config['feed_info']['end_date']) self.service_weekday.SetWeekdayService(True) self.service_weekday.SetWeekendService(False) self.service_saturday = transitfeed.ServicePeriod("saturday") self.service_saturday.SetStartDate(self.config['feed_info']['start_date']) self.service_saturday.SetEndDate(self.config['feed_info']['end_date']) self.service_saturday.SetWeekdayService(False) self.service_saturday.SetWeekendService(False) self.service_saturday.SetDayOfWeekHasService(5, True) self.service_sunday = transitfeed.ServicePeriod("sunday") self.service_sunday.SetStartDate(self.config['feed_info']['start_date']) self.service_sunday.SetEndDate(self.config['feed_info']['end_date']) self.service_sunday.SetWeekdayService(False) self.service_sunday.SetWeekendService(False) self.service_sunday.SetDayOfWeekHasService(6, True) self.exceptions = None
def testTwoService(self): schedule = transitfeed.Schedule() sp1 = transitfeed.ServicePeriod() sp1.service_id = "sp1" sp1.set_date_has_service("20081231") sp1.set_date_has_service("20090101") schedule.add_service_period_object(sp1) sp2 = transitfeed.ServicePeriod() sp2.service_id = "sp2" sp2.set_start_date("20081201") sp2.set_end_date("20081231") sp2.set_weekend_service() sp2.set_weekday_service() schedule.add_service_period_object(sp2) self.assertEquals([], schedule.get_service_periods_active_each_date( date(2009, 1, 1), date(2009, 1, 1))) date_services = schedule.get_service_periods_active_each_date( date(2008, 12, 31), date(2009, 1, 2)) self.assertEquals( [date(2008, 12, 31), date(2009, 1, 1)], [d for d, _ in date_services]) self.assertEquals(set([sp1, sp2]), set(date_services[0][1])) self.assertEquals([sp1], date_services[1][1])
def _create_service_period(self, feed, operation): try: service = feed.GetServicePeriod(operation) if service is not None: return service except KeyError: print("INFO. There is no service_period for this service:", operation, " therefore it will be created.") if operation == "weekday": service = transitfeed.ServicePeriod("weekday") service.SetWeekdayService(True) service.SetWeekendService(False) elif operation == "saturday": service = transitfeed.ServicePeriod("saturday") service.SetWeekdayService(False) service.SetWeekendService(False) service.SetDayOfWeekHasService(5, True) elif operation == "sunday": service = transitfeed.ServicePeriod("sunday") service.SetWeekdayService(False) service.SetWeekendService(False) service.SetDayOfWeekHasService(6, True) else: raise KeyError("uknown operation keyword") service.SetStartDate(self.config['feed_info']['start_date']) service.SetEndDate(self.config['feed_info']['end_date']) feed.AddServicePeriodObject(service) return feed.GetServicePeriod(operation)
def testServicePeriodDateOutsideValidRange(self): # regular service, no exceptions, start_date invalid period = transitfeed.ServicePeriod() period.service_id = 'WEEKDAY' period.start_date = '20070101' period.end_date = '21071231' period.day_of_week[0] = True self.ValidateAndExpectDateOutsideValidRange(period, 'end_date', '21071231') # regular service, no exceptions, start_date invalid period2 = transitfeed.ServicePeriod() period2.service_id = 'SUNDAY' period2.start_date = '18990101' period2.end_date = '19991231' period2.day_of_week[6] = True self.ValidateAndExpectDateOutsideValidRange(period2, 'start_date', '18990101') # regular service, no exceptions, both start_date and end_date invalid period3 = transitfeed.ServicePeriod() period3.service_id = 'SATURDAY' period3.start_date = '18990101' period3.end_date = '29991231' period3.day_of_week[5] = True period3.validate(self.problems) e = self.accumulator.pop_date_outside_valid_range('start_date') self.assertEquals('18990101', e.value) e.format_problem() # should not throw any exceptions e.format_context() # should not throw any exceptions e = self.accumulator.pop_date_outside_valid_range('end_date') self.assertEqual('29991231', e.value) e.format_problem() # should not throw any exceptions e.format_context() # should not throw any exceptions self.accumulator.assert_no_more_exceptions()
def testHasExceptions(self): # A new ServicePeriod object has no exceptions period = transitfeed.ServicePeriod() self.assertFalse(period.HasExceptions()) # Only regular service, no exceptions period.service_id = "WEEKDAY" period.start_date = "20070101" period.end_date = "20071231" period.day_of_week[0] = True self.assertFalse(period.HasExceptions()) # Regular service + removed service exception period.SetDateHasService("20070101", False) self.assertTrue(period.HasExceptions()) # Regular service + added service exception period.SetDateHasService("20070101", True) self.assertTrue(period.HasExceptions()) # Only added service exception period = transitfeed.ServicePeriod() period.SetDateHasService("20070101", True) self.assertTrue(period.HasExceptions()) # Only removed service exception period = transitfeed.ServicePeriod() period.SetDateHasService("20070101", False) self.assertTrue(period.HasExceptions())
def testHasExceptions(self): # A new ServicePeriod object has no exceptions period = transitfeed.ServicePeriod() self.assertFalse(period.has_exceptions()) # Only regular service, no exceptions period.service_id = 'WEEKDAY' period.start_date = '20070101' period.end_date = '20071231' period.day_of_week[0] = True self.assertFalse(period.has_exceptions()) # Regular service + removed service exception period.set_date_has_service('20070101', False) self.assertTrue(period.has_exceptions()) # Regular service + added service exception period.set_date_has_service('20070101', True) self.assertTrue(period.has_exceptions()) # Only added service exception period = transitfeed.ServicePeriod() period.set_date_has_service('20070101', True) self.assertTrue(period.has_exceptions()) # Only removed service exception period = transitfeed.ServicePeriod() period.set_date_has_service('20070101', False) self.assertTrue(period.has_exceptions())
def runTest(self): # success case period = transitfeed.ServicePeriod() repr(period) # shouldn't crash period.service_id = 'WEEKDAY' period.start_date = '20070101' period.end_date = '20071231' period.day_of_week[0] = True repr(period) # shouldn't crash period.validate(self.problems) # missing start_date. If one of start_date or end_date is None then # ServicePeriod.Validate assumes the required column is missing and already # generated an error. Instead set it to an empty string, such as when the # csv cell is empty. See also comment in ServicePeriod.Validate. period.start_date = '' self.ValidateAndExpectMissingValue(period, 'start_date') period.start_date = '20070101' # missing end_date period.end_date = '' self.ValidateAndExpectMissingValue(period, 'end_date') period.end_date = '20071231' # invalid start_date period.start_date = '2007-01-01' self.ValidateAndExpectInvalidValue(period, 'start_date') period.start_date = '20070101' # impossible start_date period.start_date = '20070229' self.ValidateAndExpectInvalidValue(period, 'start_date') period.start_date = '20070101' # invalid end_date period.end_date = '2007/12/31' self.ValidateAndExpectInvalidValue(period, 'end_date') period.end_date = '20071231' # start & end dates out of order period.end_date = '20060101' self.ValidateAndExpectInvalidValue(period, 'end_date') period.end_date = '20071231' # no service in period period.day_of_week[0] = False self.ValidateAndExpectOtherProblem(period) period.day_of_week[0] = True # invalid exception date period.set_date_has_service('2007', False) self.ValidateAndExpectInvalidValue(period, 'date', '2007') period.reset_date_to_normal_service('2007') period2 = transitfeed.ServicePeriod(field_list=[ 'serviceid1', '20060101', '20071231', '1', '0', 'h', '1', '1', '1', '1' ]) self.ValidateAndExpectInvalidValue(period2, 'wednesday', 'h') repr(period) # shouldn't crash
def test_MultipleServicesCausesNoDefault(self): schedule = transitfeed.Schedule() service1 = transitfeed.ServicePeriod() service1.service_id = "SERVICE1" service1.SetDateHasService("20070101", True) schedule.AddServicePeriodObject(service1) service2 = transitfeed.ServicePeriod() service2.service_id = "SERVICE2" service2.SetDateHasService("20070201", True) schedule.AddServicePeriodObject(service2) service_d = schedule.GetDefaultServicePeriod() self.assertEqual(service_d, None)
def test_MultipleServicesCausesNoDefault(self): schedule = transitfeed.Schedule() service1 = transitfeed.ServicePeriod() service1.service_id = 'SERVICE1' service1.set_date_has_service('20070101', True) schedule.add_service_period_object(service1) service2 = transitfeed.ServicePeriod() service2.service_id = 'SERVICE2' service2.set_date_has_service('20070201', True) schedule.add_service_period_object(service2) service_d = schedule.get_default_service_period() self.assertEqual(service_d, None)
def SimpleSchedule(self): """Return a minimum schedule that will load without warnings.""" schedule = transitfeed.Schedule(problem_reporter=self.problems) schedule.AddAgency("Fly Agency", "http://iflyagency.com", "America/Los_Angeles") service_period = transitfeed.ServicePeriod("WEEK") service_period.SetWeekdayService(True) service_period.SetStartDate("20091203") service_period.SetEndDate("20111203") service_period.SetDateHasService("20091203") schedule.AddServicePeriodObject(service_period) stop1 = schedule.AddStop(lng=1.00, lat=48.2, name="Stop 1", stop_id="stop1") stop2 = schedule.AddStop(lng=1.01, lat=48.2, name="Stop 2", stop_id="stop2") stop3 = schedule.AddStop(lng=1.03, lat=48.2, name="Stop 3", stop_id="stop3") route = schedule.AddRoute("54C", "", "Bus", route_id="054C") trip = route.AddTrip(schedule, "bus trip", trip_id="CITY1") trip.AddStopTime(stop1, stop_time="12:00:00") trip.AddStopTime(stop2, stop_time="12:00:45") trip.AddStopTime(stop3, stop_time="12:02:30") return schedule
def testServicePeriodExceptionDateOutsideValidRange(self): """ date exceptions of ServicePeriod must be in [1900,2100] """ # regular service, 3 exceptions, date of 1st and 3rd invalid period = transitfeed.ServicePeriod() period.service_id = 'WEEKDAY' period.start_date = '20070101' period.end_date = '20071231' period.day_of_week[0] = True period.set_date_has_service('21070101', False) # removed service exception period.set_date_has_service('20070205', False) # removed service exception period.set_date_has_service('10070102', True) # added service exception period.validate(self.problems) # check for error from first date exception e = self.accumulator.pop_date_outside_valid_range('date') self.assertEqual('10070102', e.value) e.format_problem() # should not throw any exceptions e.format_context() # should not throw any exceptions # check for error from third date exception e = self.accumulator.pop_date_outside_valid_range('date') self.assertEqual('21070101', e.value) e.format_problem() # should not throw any exceptions e.format_context() # should not throw any exceptions self.accumulator.assert_no_more_exceptions()
def runTest(self): schedule = transitfeed.Schedule( problem_reporter=util.ExceptionProblemReporterNoExpiration()) schedule.AddAgency("Sample Agency", "http://example.com", "America/Los_Angeles") route = transitfeed.Route() route.route_id = "SAMPLE_ID" route.route_type = 3 route.route_long_name = "Sample Route" schedule.AddRouteObject(route) service_period = transitfeed.ServicePeriod("WEEK") service_period.SetStartDate("20070101") service_period.SetEndDate("20071231") service_period.SetWeekdayService(True) schedule.AddServicePeriodObject(service_period) trip1 = transitfeed.Trip() trip1.route_id = "SAMPLE_ID" trip1.service_id = "WEEK" trip1.trip_id = "SAMPLE_TRIP" schedule.AddTripObject(trip1) trip2 = transitfeed.Trip() trip2.route_id = "SAMPLE_ID" trip2.service_id = "WEEK" trip2.trip_id = "SAMPLE_TRIP" try: schedule.AddTripObject(trip2) self.fail("Expected Duplicate ID validation failure") except transitfeed.DuplicateID as e: self.assertEqual("trip_id", e.column_name) self.assertEqual("SAMPLE_TRIP", e.value)
def testServicePeriodExceptionDateOutsideValidRange(self): """ date exceptions of ServicePeriod must be in [1900,2100] """ # regular service, 3 exceptions, date of 1st and 3rd invalid period = transitfeed.ServicePeriod() period.service_id = "WEEKDAY" period.start_date = "20070101" period.end_date = "20071231" period.day_of_week[0] = True period.SetDateHasService("21070101", False) # removed service exception period.SetDateHasService("20070205", False) # removed service exception period.SetDateHasService("10070102", True) # added service exception period.Validate(self.problems) # check for error from first date exception e = self.accumulator.PopDateOutsideValidRange("date") self.assertEqual("10070102", e.value) e.FormatProblem() # should not throw any exceptions e.FormatContext() # should not throw any exceptions # check for error from third date exception e = self.accumulator.PopDateOutsideValidRange("date") self.assertEqual("21070101", e.value) e.FormatProblem() # should not throw any exceptions e.FormatContext() # should not throw any exceptions self.accumulator.AssertNoMoreExceptions()
def setUp(self): self.accumulator = util.RecordingProblemAccumulator( self, ("ExpirationDate", "NoServiceExceptions")) self.problems = transitfeed.ProblemReporter(self.accumulator) schedule = OverlappingBlockSchedule(problem_reporter=self.problems) schedule.AddAgency("Demo Transit Authority", "http://dta.org", "America/Los_Angeles") sp1 = transitfeed.ServicePeriod("SID1") sp1.SetWeekdayService(True) sp1.SetStartDate("20070605") sp1.SetEndDate("20080605") schedule.AddServicePeriodObject(sp1) sp2 = transitfeed.ServicePeriod("SID2") sp2.SetDayOfWeekHasService(0) sp2.SetDayOfWeekHasService(2) sp2.SetDayOfWeekHasService(4) sp2.SetStartDate("20070605") sp2.SetEndDate("20080605") schedule.AddServicePeriodObject(sp2) sp3 = transitfeed.ServicePeriod("SID3") sp3.SetWeekendService(True) sp3.SetStartDate("20070605") sp3.SetEndDate("20080605") schedule.AddServicePeriodObject(sp3) self.stop1 = schedule.AddStop( lng=-116.75167, lat=36.915682, name="Stagecoach Hotel & Casino", stop_id="S1", ) self.stop2 = schedule.AddStop(lng=-116.76218, lat=36.905697, name="E Main St / S Irving St", stop_id="S2") self.route = schedule.AddRoute("", "City", "Bus", route_id="CITY") self.schedule = schedule self.sp1 = sp1 self.sp2 = sp2 self.sp3 = sp3
def runTest(self): schedule = transitfeed.Schedule(problem_reporter=self.problems) schedule.AddAgency("Sample Agency", "http://example.com", "America/Los_Angeles") route = transitfeed.Route() route.route_id = "SAMPLE_ID" route.route_type = 3 route.route_long_name = "Sample Route" schedule.AddRouteObject(route) service_period = transitfeed.ServicePeriod("WEEK") service_period.SetStartDate("20070101") service_period.SetEndDate("20071231") service_period.SetWeekdayService(True) schedule.AddServicePeriodObject(service_period) trip = transitfeed.Trip() trip.route_id = "SAMPLE_ID" trip.service_id = "WEEK" trip.trip_id = "SAMPLE_TRIP" schedule.AddTripObject(trip) stop1 = transitfeed.Stop() stop1.stop_id = "STOP1" stop1.stop_name = "Stop 1" stop1.stop_lat = 78.243587 stop1.stop_lon = 32.258937 schedule.AddStopObject(stop1) trip.AddStopTime(stop1, arrival_time="12:00:00", departure_time="12:00:00") stop2 = transitfeed.Stop() stop2.stop_id = "STOP2" stop2.stop_name = "Stop 2" stop2.stop_lat = 78.253587 stop2.stop_lon = 32.258937 schedule.AddStopObject(stop2) trip.AddStopTime(stop2, arrival_time="12:05:00", departure_time="12:05:00") schedule.Validate() stop3 = transitfeed.Stop() stop3.stop_id = "STOP3" stop3.stop_name = "Stop 3" stop3.stop_lat = 78.243587 stop3.stop_lon = 32.268937 schedule.AddStopObject(stop3) trip.AddStopTime(stop3, arrival_time="12:10:00", departure_time="12:10:00") schedule.Validate() self.accumulator.AssertNoMoreExceptions() stop4 = transitfeed.Stop() stop4.stop_id = "STOP4" stop4.stop_name = "Stop 4" stop4.stop_lat = 78.243588 stop4.stop_lon = 32.268936 schedule.AddStopObject(stop4) trip.AddStopTime(stop4, arrival_time="12:15:00", departure_time="12:15:00") schedule.Validate() e = self.accumulator.PopException('StopsTooClose') self.accumulator.AssertNoMoreExceptions()
def test_SetDefault(self): schedule = transitfeed.Schedule() service1 = transitfeed.ServicePeriod() service1.SetDateHasService("20070101", True) service1.service_id = "SERVICE1" schedule.SetDefaultServicePeriod(service1) self.assertEqual(service1, schedule.GetDefaultServicePeriod()) self.assertEqual(service1, schedule.GetServicePeriod(service1.service_id))
def test_AssumeSingleServiceIsDefault(self): schedule = transitfeed.Schedule() service1 = transitfeed.ServicePeriod() service1.SetDateHasService("20070101", True) service1.service_id = "SERVICE1" schedule.AddServicePeriodObject(service1) self.assertEqual(service1, schedule.GetDefaultServicePeriod()) self.assertEqual(service1.service_id, schedule.GetDefaultServicePeriod().service_id)
def test_AssumeSingleServiceIsDefault(self): schedule = transitfeed.Schedule() service1 = transitfeed.ServicePeriod() service1.set_date_has_service('20070101', True) service1.service_id = 'SERVICE1' schedule.add_service_period_object(service1) self.assertEqual(service1, schedule.get_default_service_period()) self.assertEqual(service1.service_id, schedule.get_default_service_period().service_id)
def test_SetDefault(self): schedule = transitfeed.Schedule() service1 = transitfeed.ServicePeriod() service1.set_date_has_service('20070101', True) service1.service_id = 'SERVICE1' schedule.set_default_service_period(service1) self.assertEqual(service1, schedule.get_default_service_period()) self.assertEqual(service1, schedule.get_service_period(service1.service_id))
def runTest(self): period = transitfeed.ServicePeriod() period.service_id = 'WEEKDAY' period.start_date = '20070101' period.end_date = '20071231' period.set_weekday_service(True) period.set_date_has_service('20071231', False) period.validate(self.problems) self.assertEqual(('20070101', '20071231'), period.get_date_range()) period2 = transitfeed.ServicePeriod() period2.service_id = 'HOLIDAY' period2.set_date_has_service('20071225', True) period2.set_date_has_service('20080101', True) period2.set_date_has_service('20080102', False) period2.validate(self.problems) self.assertEqual(('20071225', '20080101'), period2.get_date_range()) period2.start_date = '20071201' period2.end_date = '20071225' period2.validate(self.problems) self.assertEqual(('20071201', '20080101'), period2.get_date_range()) period3 = transitfeed.ServicePeriod() self.assertEqual((None, None), period3.get_date_range()) period4 = transitfeed.ServicePeriod() period4.service_id = 'halloween' period4.set_date_has_service('20051031', True) self.assertEqual(('20051031', '20051031'), period4.get_date_range()) period4.validate(self.problems) schedule = transitfeed.Schedule(problem_reporter=self.problems) self.assertEqual((None, None), schedule.get_date_range()) schedule.add_service_period_object(period) self.assertEqual(('20070101', '20071231'), schedule.get_date_range()) schedule.add_service_period_object(period2) self.assertEqual(('20070101', '20080101'), schedule.get_date_range()) schedule.add_service_period_object(period4) self.assertEqual(('20051031', '20080101'), schedule.get_date_range()) self.accumulator.assert_no_more_exceptions()
def runTest(self): period = transitfeed.ServicePeriod() period.service_id = "WEEKDAY" period.start_date = "20070101" period.end_date = "20071231" period.SetWeekdayService(True) period.SetDateHasService("20071231", False) period.Validate(self.problems) self.assertEqual(("20070101", "20071231"), period.GetDateRange()) period2 = transitfeed.ServicePeriod() period2.service_id = "HOLIDAY" period2.SetDateHasService("20071225", True) period2.SetDateHasService("20080101", True) period2.SetDateHasService("20080102", False) period2.Validate(self.problems) self.assertEqual(("20071225", "20080101"), period2.GetDateRange()) period2.start_date = "20071201" period2.end_date = "20071225" period2.Validate(self.problems) self.assertEqual(("20071201", "20080101"), period2.GetDateRange()) period3 = transitfeed.ServicePeriod() self.assertEqual((None, None), period3.GetDateRange()) period4 = transitfeed.ServicePeriod() period4.service_id = "halloween" period4.SetDateHasService("20051031", True) self.assertEqual(("20051031", "20051031"), period4.GetDateRange()) period4.Validate(self.problems) schedule = transitfeed.Schedule(problem_reporter=self.problems) self.assertEqual((None, None), schedule.GetDateRange()) schedule.AddServicePeriodObject(period) self.assertEqual(("20070101", "20071231"), schedule.GetDateRange()) schedule.AddServicePeriodObject(period2) self.assertEqual(("20070101", "20080101"), schedule.GetDateRange()) schedule.AddServicePeriodObject(period4) self.assertEqual(("20051031", "20080101"), schedule.GetDateRange()) self.accumulator.AssertNoMoreExceptions()
def loadCalendar(self): logger.info("Loading Calendar") days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] for s in self.db.query(Calendar).all(): service = transitfeed.ServicePeriod() service.SetServiceId(s.service_id) service.SetStartDate(str(s.start_date)) service.SetEndDate(str(s.end_date)) for i, day in enumerate(days): hasService = bool(int(getattr(s, day))) service.SetDayOfWeekHasService(i, hasService) self.schedule.AddServicePeriodObject(service)
def testOneService(self): schedule = transitfeed.Schedule() sp1 = transitfeed.ServicePeriod() sp1.service_id = "sp1" sp1.set_date_has_service("20090101") sp1.set_date_has_service("20090102") schedule.add_service_period_object(sp1) self.assertEquals([], schedule.get_service_periods_active_each_date( date(2009, 1, 1), date(2009, 1, 1))) self.assertEquals([(date(2008, 12, 31), []), (date(2009, 1, 1), [sp1])], schedule.get_service_periods_active_each_date( date(2008, 12, 31), date(2009, 1, 2)))
def runTest(self): import transitfeed schedule = transitfeed.Schedule() schedule.AddAgency("Sample Agency", "http://example.com", "America/Los_Angeles") route = transitfeed.Route() route.route_id = "SAMPLE_ID" route.route_type = 3 route.route_short_name = "66" route.route_long_name = "Sample Route" schedule.AddRouteObject(route) service_period = transitfeed.ServicePeriod("WEEK") service_period.SetStartDate("20070101") service_period.SetEndDate("20071231") service_period.SetWeekdayService(True) schedule.AddServicePeriodObject(service_period) trip = transitfeed.Trip() trip.route_id = "SAMPLE_ID" trip.service_period = service_period trip.trip_id = "SAMPLE_TRIP" trip.direction_id = "0" trip.block_id = None schedule.AddTripObject(trip) stop1 = transitfeed.Stop() stop1.stop_id = "STOP1" stop1.stop_name = "Stop 1" stop1.stop_lat = 78.243587 stop1.stop_lon = 32.258937 schedule.AddStopObject(stop1) trip.AddStopTime(stop1, arrival_time="12:00:00", departure_time="12:00:00") stop2 = transitfeed.Stop() stop2.stop_id = "STOP2" stop2.stop_name = "Stop 2" stop2.stop_lat = 78.253587 stop2.stop_lon = 32.258937 schedule.AddStopObject(stop2) trip.AddStopTime(stop2, arrival_time="12:05:00", departure_time="12:05:00") schedule.Validate() # not necessary, but helpful for finding problems schedule.WriteGoogleTransitFeed("new_feed.zip")
def loadDefaultTripStartTimes(self): if self.trip_start_times_default: return self.trip_start_times_default = [item for item in defaults.startTimes()] logger.info("Loading Default Calendar") days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] service = transitfeed.ServicePeriod() service.SetServiceId('default') service.SetStartDate('20150101') service.SetEndDate('20151201') for i, day in enumerate(days): service.SetDayOfWeekHasService(i, True) self.schedule.AddServicePeriodObject(service)
def testOneService(self): schedule = transitfeed.Schedule() sp1 = transitfeed.ServicePeriod() sp1.service_id = "sp1" sp1.SetDateHasService("20090101") sp1.SetDateHasService("20090102") schedule.AddServicePeriodObject(sp1) self.assertEquals( [], schedule.GetServicePeriodsActiveEachDate(date(2009, 1, 1), date(2009, 1, 1))) self.assertEquals( [(date(2008, 12, 31), []), (date(2009, 1, 1), [sp1])], schedule.GetServicePeriodsActiveEachDate(date(2008, 12, 31), date(2009, 1, 2)))
def runTest(self): schedule = transitfeed.Schedule() schedule.AddAgency("Sample Agency", "http://example.com", "America/Los_Angeles") route = transitfeed.Route() route.route_id = "SAMPLE_ID" route.route_type = 3 route.route_short_name = "66" route.route_long_name = "Sample Route acute letter e\202" schedule.AddRouteObject(route) service_period = transitfeed.ServicePeriod("WEEK") service_period.SetStartDate("20070101") service_period.SetEndDate("20071231") service_period.SetWeekdayService(True) schedule.AddServicePeriodObject(service_period) trip = transitfeed.Trip() trip.route_id = "SAMPLE_ID" trip.service_period = service_period trip.trip_id = "SAMPLE_TRIP" schedule.AddTripObject(trip) stop1 = transitfeed.Stop() stop1.stop_id = "STOP1" stop1.stop_name = u'Stop 1 acute letter e\202' stop1.stop_lat = 78.243587 stop1.stop_lon = 32.258937 schedule.AddStopObject(stop1) trip.AddStopTime(stop1, arrival_time="12:00:00", departure_time="12:00:00") stop2 = transitfeed.Stop() stop2.stop_id = "STOP2" stop2.stop_name = "Stop 2" stop2.stop_lat = 78.253587 stop2.stop_lon = 32.258937 schedule.AddStopObject(stop2) trip.AddStopTime(stop2, arrival_time="12:05:00", departure_time="12:05:00") schedule.Validate() schedule.WriteGoogleTransitFeed(self.tempfilepath)