Exemplo n.º 1
0
  def runTest(self):
    schedule = transitfeed.Schedule(
        problem_reporter=util.ExceptionProblemReporterNoExpiration())
    schedule.NewDefaultAgency(agency_name="Test Agency",
                              agency_timezone="America/Los_Angeles")
    route = schedule.AddRoute(short_name="54C", long_name="Hill", route_type=3)
    schedule.GetDefaultServicePeriod().SetDateHasService("20070101")
    stop1 = schedule.AddStop(36, -117.1, "Demo Stop 1")
    stop2 = schedule.AddStop(36, -117.2, "Demo Stop 2")
    stop3 = schedule.AddStop(36, -117.3, "Demo Stop 3")

    trip = route.AddTrip(schedule, "via Polish Hill")
    trip.ClearStopTimes()
    self.assertFalse(trip.GetStopTimes())
    trip.AddStopTime(stop1, stop_time="5:11:00")
    self.assertTrue(trip.GetStopTimes())
    trip.ClearStopTimes()
    self.assertFalse(trip.GetStopTimes())
    trip.AddStopTime(stop3, stop_time="4:00:00")  # Can insert earlier time
    trip.AddStopTime(stop2, stop_time="4:15:00")
    trip.AddStopTime(stop1, stop_time="4:21:00")
    old_stop_times = trip.GetStopTimes()
    self.assertTrue(old_stop_times)
    trip.ClearStopTimes()
    self.assertFalse(trip.GetStopTimes())
    for st in old_stop_times:
      trip.AddStopTimeObject(st)
    self.assertEqual(trip.GetStartTime(), 4 * 3600)
    self.assertEqual(trip.GetEndTime(), 4 * 3600 + 21 * 60)
Exemplo n.º 2
0
  def setUp(self):
    problems = util.GetTestFailureProblemReporter(self)
    schedule = transitfeed.Schedule(problem_reporter=problems)
    self.schedule = schedule
    schedule.AddAgency("Agency", "http://iflyagency.com",
                       "America/Los_Angeles")
    service_period = schedule.GetDefaultServicePeriod()
    service_period.SetStartDate("20080101")
    service_period.SetEndDate("20090101")
    service_period.SetWeekdayService(True)
    self.stop1 = schedule.AddStop(lng=140.01, lat=0, name="140.01,0")
    self.stop2 = schedule.AddStop(lng=140.02, lat=0, name="140.02,0")
    self.stop3 = schedule.AddStop(lng=140.03, lat=0, name="140.03,0")
    self.stop4 = schedule.AddStop(lng=140.04, lat=0, name="140.04,0")
    self.stop5 = schedule.AddStop(lng=140.05, lat=0, name="140.05,0")
    self.route1 = schedule.AddRoute("1", "One", "Bus")

    self.trip1 = self.route1.AddTrip(schedule, "trip 1", trip_id="trip1")
    # add different types of stop times
    self.trip1.AddStopTime(self.stop1, arrival_time="17:00:00",
        departure_time="17:01:00") # both arrival and departure time
    self.trip1.AddStopTime(self.stop2, schedule=schedule) # non timed
    self.trip1.AddStopTime(self.stop3, stop_time="17:45:00") # only stop_time

    # add headways starting before the trip
    self.trip1.AddFrequency("16:00:00", "18:00:00", 1800) # each 30 min
    self.trip1.AddFrequency("18:00:00", "20:00:00", 2700) # each 45 min
Exemplo n.º 3
0
  def runTest(self):
    schedule = transitfeed.Schedule()
    schedule.AddAgency("\xc8\x8b Fly Agency", "http://iflyagency.com",
                       "America/Los_Angeles")
    service_period = \
      schedule.GetDefaultServicePeriod().SetDateHasService('20070101')
    stop1 = schedule.AddStop(lng=140, lat=48.2, name="Stop 1")
    route = schedule.AddRoute("B", "Beta", "Bus")
    trip = route.AddTrip(schedule, "bus trip")
    stoptime = transitfeed.StopTime(transitfeed.default_problem_reporter, stop1,
                                    arrival_secs=10,
                                    departure_secs=10)
    trip.AddStopTimeObject(stoptime, schedule=schedule)
    stoptimes = trip.GetStopTimes()
    stoptime.departure_secs = 20
    trip.ReplaceStopTimeObject(stoptime, schedule=schedule)
    stoptimes = trip.GetStopTimes()
    self.assertEqual(len(stoptimes), 1)
    self.assertEqual(stoptimes[0].departure_secs, 20)

    unknown_stop = schedule.AddStop(lng=140, lat=48.2, name="unknown")
    unknown_stoptime = transitfeed.StopTime(
        transitfeed.default_problem_reporter, unknown_stop,
        arrival_secs=10,
        departure_secs=10)
    unknown_stoptime.stop_sequence = 5
    # Attempting to replace a non-existent StopTime raises an error
    self.assertRaises(transitfeed.Error, trip.ReplaceStopTimeObject,
        unknown_stoptime, schedule=schedule)
Exemplo n.º 4
0
    def runTest(self):
        accumulator = util.RecordingProblemAccumulator(self)
        problems = transitfeed.ProblemReporter(accumulator)
        schedule = transitfeed.Schedule(problem_reporter=problems)

        today = datetime.date.today()
        yesterday = today - datetime.timedelta(days=1)
        tomorrow = today + datetime.timedelta(days=1)
        two_months_from_today = today + datetime.timedelta(days=60)

        service_period = schedule.get_default_service_period()
        service_period.set_weekday_service(True)
        service_period.set_weekend_service(True)
        service_period.set_end_date(two_months_from_today.strftime("%Y%m%d"))

        service_period.set_start_date(yesterday.strftime("%Y%m%d"))
        schedule.validate()
        accumulator.assert_no_more_exceptions()

        service_period.set_start_date(today.strftime("%Y%m%d"))
        schedule.validate()
        accumulator.assert_no_more_exceptions()

        service_period.set_start_date(tomorrow.strftime("%Y%m%d"))
        schedule.validate()
        accumulator.pop_exception('FutureService')
        accumulator.assert_no_more_exceptions()
Exemplo n.º 5
0
  def testBuildFeedWithUtf8Names(self):
    problems = util.GetTestFailureProblemReporter(self)
    schedule = transitfeed.Schedule(problem_reporter=problems)
    schedule.AddAgency("\xc8\x8b Fly Agency", "http://iflyagency.com",
                       "America/Los_Angeles")
    service_period = schedule.GetDefaultServicePeriod()
    service_period.SetDateHasService('20070101')
    # "u020b i with inverted accent breve" encoded in utf-8
    stop1 = schedule.AddStop(lng=140, lat=48.2, name="\xc8\x8b hub")
    # "u020b i with inverted accent breve" as unicode string
    stop2 = schedule.AddStop(lng=140.001, lat=48.201,
                             name=u"remote \u020b station")
    route = schedule.AddRoute(u"\u03b2", "Beta", "Bus")
    trip = route.AddTrip(schedule, u"to remote \u020b station")
    repr(stop1)
    repr(stop2)
    repr(route)
    repr(trip)
    trip.AddStopTime(stop1, schedule=schedule, stop_time='10:00:00')
    trip.AddStopTime(stop2, stop_time='10:10:00')

    schedule.Validate(problems)
    schedule.WriteGoogleTransitFeed(self.tempfilepath)
    read_schedule = \
        transitfeed.Loader(self.tempfilepath, problems=problems,
                           extra_validation=True).Load()
    self.assertEquals(u'\u020b Fly Agency',
                      read_schedule.GetDefaultAgency().agency_name)
    self.assertEquals(u'\u03b2',
                      read_schedule.GetRoute(route.route_id).route_short_name)
    self.assertEquals(u'to remote \u020b station',
                      read_schedule.GetTrip(trip.trip_id).trip_headsign)
    def runTest(self):
        accumulator = util.RecordingProblemAccumulator(self)
        problems = transitfeed.ProblemReporter(accumulator)
        schedule = transitfeed.Schedule(problem_reporter=problems)

        today = datetime.date.today()
        yesterday = today - datetime.timedelta(days=1)
        tomorrow = today + datetime.timedelta(days=1)
        two_months_from_today = today + datetime.timedelta(days=60)

        service_period = schedule.GetDefaultServicePeriod()
        service_period.SetWeekdayService(True)
        service_period.SetWeekendService(True)
        service_period.SetEndDate(two_months_from_today.strftime("%Y%m%d"))

        service_period.SetStartDate(yesterday.strftime("%Y%m%d"))
        schedule.Validate()
        accumulator.AssertNoMoreExceptions()

        service_period.SetStartDate(today.strftime("%Y%m%d"))
        schedule.Validate()
        accumulator.AssertNoMoreExceptions()

        service_period.SetStartDate(tomorrow.strftime("%Y%m%d"))
        schedule.Validate()
        accumulator.PopException("FutureService")
        accumulator.AssertNoMoreExceptions()
    def runTest(self):
        accumulator = util.RecordingProblemAccumulator(self,
                                                       ("NoServiceExceptions"))
        problems = transitfeed.ProblemReporter(accumulator)
        schedule = transitfeed.Schedule(problem_reporter=problems)

        now = time.mktime(time.localtime())
        seconds_per_day = 60 * 60 * 24
        two_weeks_ago = time.localtime(now - 14 * seconds_per_day)
        two_weeks_from_now = time.localtime(now + 14 * seconds_per_day)
        two_months_from_now = time.localtime(now + 60 * seconds_per_day)
        date_format = "%Y%m%d"

        service_period = schedule.GetDefaultServicePeriod()
        service_period.SetWeekdayService(True)
        service_period.SetStartDate("20070101")

        service_period.SetEndDate(
            time.strftime(date_format, two_months_from_now))
        schedule.Validate()  # should have no problems
        accumulator.AssertNoMoreExceptions()

        service_period.SetEndDate(
            time.strftime(date_format, two_weeks_from_now))
        schedule.Validate()
        e = accumulator.PopException("ExpirationDate")
        self.assertTrue(e.FormatProblem().index("will soon expire"))
        accumulator.AssertNoMoreExceptions()

        service_period.SetEndDate(time.strftime(date_format, two_weeks_ago))
        schedule.Validate()
        e = accumulator.PopException("ExpirationDate")
        self.assertTrue(e.FormatProblem().index("expired"))
        accumulator.AssertNoMoreExceptions()
Exemplo n.º 8
0
 def test_MultipleAgencyCausesNoDefault(self):
     schedule = transitfeed.Schedule()
     agency1 = self.freeAgency()
     schedule.add_agency_object(agency1)
     agency2 = self.freeAgency('2')
     schedule.add_agency_object(agency2)
     self.assertEqual(None, schedule.init_default_agency())
Exemplo n.º 9
0
    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])
Exemplo n.º 10
0
    def runTest(self):
        schedule = transitfeed.Schedule(
            problem_reporter=util.ExceptionProblemReporterNoExpiration())
        schedule.Load(util.DataPath('good_feed.zip'), extra_validation=True)

        # Finally see if write crashes
        schedule.WriteGoogleTransitFeed(tempfile.TemporaryFile())
Exemplo n.º 11
0
 def runTest(self):
   schedule = transitfeed.Schedule(problem_reporter=self.problems)
   schedule.AddAgency("\xc8\x8b Fly Agency", "http://iflyagency.com",
                      "America/Los_Angeles")
   service_period = schedule.GetDefaultServicePeriod().SetDateHasService('20070101')
   stop1 = schedule.AddStop(lng=140, lat=48.2, name="Stop 1")
   stop2 = schedule.AddStop(lng=140.001, lat=48.201, name="Stop 2")
   route = schedule.AddRoute("B", "Beta", "Bus")
   trip = route.AddTrip(schedule, "bus trip")
   trip.AddStopTimeObject(transitfeed.StopTime(self.problems, stop1,
                                               arrival_secs=10,
                                               departure_secs=10),
                          schedule=schedule, problems=self.problems)
   trip.AddStopTimeObject(transitfeed.StopTime(self.problems, stop2,
                                               arrival_secs=20,
                                               departure_secs=20),
                          schedule=schedule, problems=self.problems)
   # TODO: Factor out checks or use mock problems object
   self.ExpectOtherProblemInClosure(lambda:
     trip.AddStopTimeObject(transitfeed.StopTime(self.problems, stop1,
                                                 arrival_secs=15,
                                                 departure_secs=15),
                            schedule=schedule, problems=self.problems))
   trip.AddStopTimeObject(transitfeed.StopTime(self.problems, stop1),
                          schedule=schedule, problems=self.problems)
   self.ExpectOtherProblemInClosure(lambda:
       trip.AddStopTimeObject(transitfeed.StopTime(self.problems, stop1,
                                                   arrival_secs=15,
                                                   departure_secs=15),
                              schedule=schedule, problems=self.problems))
   trip.AddStopTimeObject(transitfeed.StopTime(self.problems, stop1,
                                               arrival_secs=30,
                                               departure_secs=30),
                          schedule=schedule, problems=self.problems)
   self.accumulator.AssertNoMoreExceptions()
Exemplo n.º 12
0
def main():
    usage = """
    %prog <input.kml> <output GTFS.zip>
        
    Reads KML file <input.kml> and creates GTFS file <output GTFS.zip> with
    placemarks in the KML represented as stops.
    """

    parser = util.OptionParserLongError(usage=usage,
                                        version='%prog ' +
                                        transitfeed.__version__)
    options, args = parser.parse_args()
    if len(args) != 2:
        parser.error(
            'You did not provide all required command line arguments.')

    if args[0] == 'IWantMyCrash':
        raise Exception('For testCrashHandler')

    parser = KMLParser()
    feed = transitfeed.Schedule()
    feed.save_all_stops = True
    parser.parse(args[0], feed)
    feed.write_google_transit_feed(args[1])

    print("Done.")
Exemplo n.º 13
0
 def testTripIdConflict(self):
     problems = util.GetTestFailureProblemReporter(self)
     schedule = transitfeed.Schedule(problem_reporter=problems)
     service_period = schedule.GetDefaultServicePeriod()
     service_period.SetDateHasService("20070101")
     route = schedule.AddRoute("0", "Long Name", "Bus")
     route.AddTrip()
     route.AddTrip(
         schedule=schedule,
         headsign="hs1",
         service_period=service_period,
         trip_id="1",
     )
     route.AddTrip(schedule, "hs2", service_period, "2")
     route.AddTrip(trip_id="4")
     route.AddTrip()  # This will be given a random trip_id
     trip_list = sorted(schedule.GetTripList(),
                        key=lambda t: int(t.trip_id))
     self.assertMatchesRegex("0 1 2 4 \d{7,9}",
                             " ".join(t.trip_id for t in trip_list))
     self.assertEqual(",hs1,hs2,,",
                      ",".join(t["trip_headsign"] for t in trip_list))
     for t in trip_list:
         self.assertEqual(service_period.service_id, t.service_id)
         self.assertEqual(route.route_id, t.route_id)
Exemplo n.º 14
0
    def testWithSchedule(self):
        schedule = transitfeed.Schedule(problem_reporter=self.problems)

        stop = transitfeed.Stop(field_dict={})
        # AddStopObject silently fails for Stop objects without stop_id
        schedule.AddStopObject(stop)
        self.assertFalse(schedule.GetStopList())
        self.assertFalse(stop._schedule)

        # Okay to add a stop with only stop_id
        stop = transitfeed.Stop(field_dict={"stop_id": "b"})
        schedule.AddStopObject(stop)
        stop.Validate(self.problems)
        for name in "stop_name stop_lat stop_lon".split():
            e = self.accumulator.PopException("MissingValue")
            self.assertEquals(name, e.column_name)
        self.accumulator.AssertNoMoreExceptions()

        stop.new_column = "val"
        self.assertTrue("new_column" in schedule.GetTableColumns("stops"))

        # Adding a duplicate stop_id fails
        schedule.AddStopObject(transitfeed.Stop(field_dict={"stop_id": "b"}))
        self.accumulator.PopException("DuplicateID")
        self.accumulator.AssertNoMoreExceptions()
Exemplo n.º 15
0
 def test_AssumeSingleAgencyIsDefault(self):
   schedule = transitfeed.Schedule()
   agency1 = self.freeAgency()
   schedule.AddAgencyObject(agency1)
   agency2 = self.freeAgency('2')  # don't add to schedule
   # agency1 is default because it is the only Agency in schedule
   self.assertEqual(agency1, schedule.GetDefaultAgency())
Exemplo n.º 16
0
 def test_MultipleAgencyCausesNoDefault(self):
   schedule = transitfeed.Schedule()
   agency1 = self.freeAgency()
   schedule.AddAgencyObject(agency1)
   agency2 = self.freeAgency('2')
   schedule.AddAgencyObject(agency2)
   self.assertEqual(None, schedule.GetDefaultAgency())
Exemplo n.º 17
0
  def runTest(self):
    schedule = transitfeed.Schedule(self.problems)

    schedule.AddAgency("Demo Agency", "http://example.com",
                        "America/Los_Angeles")
    route1 = schedule.AddRoute(short_name="route1", long_name="route_1",
                               route_type=3)
    route2 = schedule.AddRoute(short_name="route2", long_name="route_2",
                               route_type=1)

    service = schedule.GetDefaultServicePeriod()
    service.SetDateHasService("20070101")

    trip1 = route1.AddTrip(schedule, "trip1", service, "t1")
    trip2 = route2.AddTrip(schedule, "trip2", service, "t2")

    stop1 = schedule.AddStop(36.425288, -117.133162, "stop1")
    stop2 = schedule.AddStop(36.424288, -117.133142, "stop2")
    stop3 = schedule.AddStop(36.423288, -117.134142, "stop3")

    trip1.AddStopTime(stop1, arrival_time="5:11:00", departure_time="5:12:00")
    trip1.AddStopTime(stop2, arrival_time="5:21:00", departure_time="5:22:00")

    trip2.AddStopTime(stop1, arrival_time="6:11:00", departure_time="6:12:00")
    trip2.AddStopTime(stop3, arrival_time="6:21:00", departure_time="6:22:00")

    schedule.Validate(self.problems)
    e = self.accumulator.PopException("StopWithMultipleRouteTypes")
    self.assertTrue(e.FormatProblem().find("Stop stop1") != -1)
    self.assertTrue(e.FormatProblem().find("subway (ID=1)") != -1)
    self.assertTrue(e.FormatProblem().find("bus line (ID=0)") != -1)
    self.accumulator.AssertNoMoreExceptions()
Exemplo n.º 18
0
  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, e:
      self.assertEqual("trip_id", e.column_name)
      self.assertEqual("SAMPLE_TRIP", e.value)
Exemplo n.º 19
0
 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
Exemplo n.º 20
0
  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])
Exemplo n.º 21
0
    def runTest(self):
        accumulator = util.RecordingProblemAccumulator(self,
                                                       "NoServiceExceptions")
        problems = transitfeed.ProblemReporter(accumulator)
        schedule = transitfeed.Schedule(problem_reporter=problems)

        now = time.mktime(time.localtime())
        seconds_per_day = 60 * 60 * 24
        two_weeks_ago = time.localtime(now - 14 * seconds_per_day)
        two_weeks_from_now = time.localtime(now + 14 * seconds_per_day)
        two_months_from_now = time.localtime(now + 60 * seconds_per_day)
        date_format = "%Y%m%d"

        service_period = schedule.get_default_service_period()
        service_period.set_weekday_service(True)
        service_period.set_start_date("20070101")

        service_period.set_end_date(
            time.strftime(date_format, two_months_from_now))
        schedule.validate()  # should have no problems
        accumulator.assert_no_more_exceptions()

        service_period.set_end_date(
            time.strftime(date_format, two_weeks_from_now))
        schedule.validate()
        e = accumulator.pop_exception('ExpirationDate')
        self.assertTrue(e.format_problem().index('will soon expire'))
        accumulator.assert_no_more_exceptions()

        service_period.set_end_date(time.strftime(date_format, two_weeks_ago))
        schedule.validate()
        e = accumulator.pop_exception('ExpirationDate')
        self.assertTrue(e.format_problem().index('expired'))
        accumulator.assert_no_more_exceptions()
Exemplo n.º 22
0
  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()
Exemplo n.º 23
0
 def testEmpty(self):
     schedule = transitfeed.Schedule()
     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), [])],
                       schedule.get_service_periods_active_each_date(
                           date(2008, 12, 31), date(2009, 1, 2)))
Exemplo n.º 24
0
 def runTest(self):
   schedule = transitfeed.Schedule(
       problem_reporter=util.ExceptionProblemReporterNoExpiration())
   try:
     schedule.Load(util.DataPath('duplicate_stop'), extra_validation=True)
     self.fail('OtherProblem exception expected')
   except transitfeed.OtherProblem:
     pass
Exemplo n.º 25
0
 def test_NoAgencyMakeNewDefault(self):
   schedule = transitfeed.Schedule()
   agency = schedule.GetDefaultAgency()
   self.assertTrue(isinstance(agency, transitfeed.Agency))
   self.assertTrue(agency.agency_id)
   self.assertEqual(1, len(schedule.GetAgencyList()))
   self.assertEqual(agency, schedule.GetAgencyList()[0])
   self.assertEqual(agency.agency_id, schedule.GetAgencyList()[0].agency_id)
Exemplo n.º 26
0
def test_gtfs_output():
    schedule = transitfeed.Schedule()
    schedule.AddAgency("Fly Agency", "http://iflyagency.com",
                       "America/Los_Angeles")

    gtfs_stringio = StringIO.StringIO()
    schedule.WriteGoogleTransitFeed(gtfs_stringio)
    return gtfs_stringio.getvalue()
def SaveFeed(input, output):
    tree = ET.parse(urllib.urlopen(input))

    schedule = transitfeed.Schedule()
    service_period = schedule.GetDefaultServicePeriod()
    service_period.SetWeekdayService()
    service_period.SetStartDate("20070314")
    service_period.SetEndDate("20071231")
    # Holidays for 2007
    service_period.SetDateHasService("20070528", has_service=False)
    service_period.SetDateHasService("20070704", has_service=False)
    service_period.SetDateHasService("20070903", has_service=False)
    service_period.SetDateHasService("20071122", has_service=False)
    service_period.SetDateHasService("20071123", has_service=False)
    service_period.SetDateHasService("20071224", has_service=False)
    service_period.SetDateHasService("20071225", has_service=False)
    service_period.SetDateHasService("20071226", has_service=False)
    service_period.SetDateHasService("20071231", has_service=False)

    stops = {}  # Map from xml stop id to python Stop object
    agency = schedule.NewDefaultAgency(name="GBus",
                                       url="http://shuttle/",
                                       timezone="America/Los_Angeles")

    for xml_stop in tree.getiterator("stop"):
        stop = schedule.AddStop(
            lat=float(xml_stop.attrib["lat"]),
            lng=float(xml_stop.attrib["lng"]),
            name=xml_stop.attrib["name"],
        )
        stops[xml_stop.attrib["id"]] = stop

    for xml_shuttleGroup in tree.getiterator("shuttleGroup"):
        if xml_shuttleGroup.attrib["name"] == "Test":
            continue
        r = schedule.AddRoute(short_name="",
                              long_name=xml_shuttleGroup.attrib["name"],
                              route_type="Bus")
        for xml_route in xml_shuttleGroup.getiterator("route"):
            t = r.AddTrip(
                schedule=schedule,
                headsign=xml_route.attrib["name"],
                trip_id=xml_route.attrib["id"],
            )
            trip_stops = []  # Build a list of (time, Stop) tuples
            for xml_schedule in xml_route.getiterator("schedule"):
                trip_stops.append((
                    int(xml_schedule.attrib["time"]) / 1000,
                    stops[xml_schedule.attrib["stopId"]],
                ))
            trip_stops.sort()  # Sort by time
            for (time, stop) in trip_stops:
                t.AddStopTime(stop=stop,
                              arrival_secs=time,
                              departure_secs=time)

    schedule.Validate(problems=NoUnusedStopExceptionProblemReporter())
    schedule.WriteGoogleTransitFeed(output)
Exemplo n.º 28
0
 def runTest(self):
     schedule = transitfeed.Schedule(
         problem_reporter=util.ExceptionProblemReporterNoExpiration())
     try:
         schedule.Load(util.DataPath("duplicate_schedule_id"),
                       extra_validation=True)
         self.fail("DuplicateID exception expected")
     except transitfeed.DuplicateID:
         pass
Exemplo n.º 29
0
 def test_OverwriteExistingAgency(self):
   schedule = transitfeed.Schedule()
   agency1 = self.freeAgency()
   agency1.agency_id = '1'
   schedule.AddAgencyObject(agency1)
   agency2 = schedule.NewDefaultAgency()
   # Make sure agency1 was not overwritten by the new default
   self.assertEqual(agency1, schedule.GetAgency(agency1.agency_id))
   self.assertNotEqual('1', agency2.agency_id)
Exemplo n.º 30
0
 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)