Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def runTest(self):
     schedule = self.SimpleSchedule()
     # Make a new trip without any stop times
     trip = schedule.GetRoute("054C").AddTrip(trip_id="054C-00")
     stop1 = schedule.GetStop('stop1')
     stop2 = schedule.GetStop('stop2')
     stop3 = schedule.GetStop('stop3')
     stoptime1 = transitfeed.StopTime(self.problems,
                                      stop1,
                                      stop_time='12:00:00',
                                      stop_sequence=1)
     stoptime2 = transitfeed.StopTime(self.problems,
                                      stop2,
                                      stop_time='11:30:00',
                                      stop_sequence=2)
     stoptime3 = transitfeed.StopTime(self.problems,
                                      stop3,
                                      stop_time='12:15:00',
                                      stop_sequence=3)
     trip._AddStopTimeObjectUnordered(stoptime1, schedule)
     trip._AddStopTimeObjectUnordered(stoptime2, schedule)
     trip._AddStopTimeObjectUnordered(stoptime3, schedule)
     trip.Validate(self.problems)
     e = self.accumulator.PopException('OtherProblem')
     self.assertTrue(e.FormatProblem().find('Timetravel detected') != -1)
     self.assertTrue(
         e.FormatProblem().find('number 2 in trip 054C-00') != -1)
     self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 3
0
 def runTest(self):
     schedule = self.SimpleSchedule()
     # Make a new trip without any stop times
     trip = schedule.get_route("054C").add_trip(trip_id="054C-00")
     stop1 = schedule.get_stop('stop1')
     stop2 = schedule.get_stop('stop2')
     stop3 = schedule.get_stop('stop3')
     stoptime1 = transitfeed.StopTime(self.problems,
                                      stop1,
                                      stop_time='12:00:00',
                                      stop_sequence=1)
     stoptime2 = transitfeed.StopTime(self.problems,
                                      stop2,
                                      stop_time='11:30:00',
                                      stop_sequence=2)
     stoptime3 = transitfeed.StopTime(self.problems,
                                      stop3,
                                      stop_time='12:15:00',
                                      stop_sequence=3)
     trip._add_stop_time_object_unordered(stoptime1, schedule)
     trip._add_stop_time_object_unordered(stoptime2, schedule)
     trip._add_stop_time_object_unordered(stoptime3, schedule)
     trip.validate(self.problems)
     e = self.accumulator.pop_exception('OtherProblem')
     self.assertTrue(e.format_problem().find('Timetravel detected') != -1)
     self.assertTrue(
         e.format_problem().find('number 2 in trip 054C-00') != -1)
     self.accumulator.assert_no_more_exceptions()
Ejemplo n.º 4
0
  def runTest(self):
    schedule = self.SimpleSchedule()

    shape = transitfeed.Shape("shape_1")
    shape.AddPoint(36.425288, -117.133162, 0)
    shape.AddPoint(36.424288, -117.133142, 1)
    schedule.AddShapeObject(shape)

    trip = schedule.GetRoute("054C").AddTrip(trip_id="054C-00")
    trip.shape_id = "shape_1"

    stop = transitfeed.Stop(36.425288, -117.133162, "Demo Stop 1", "STOP1")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:11:00", departure_time="5:12:00",
                     stop_sequence=0, shape_dist_traveled=0)
    stop = transitfeed.Stop(36.424288, -117.133142, "Demo Stop 2", "STOP2")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:15:00", departure_time="5:16:00",
                     stop_sequence=1, shape_dist_traveled=1)

    stop = transitfeed.Stop(36.423288, -117.133122, "Demo Stop 3", "STOP3")
    schedule.AddStopObject(stop)
    trip.AddStopTime(stop, arrival_time="5:18:00", departure_time="5:19:00",
                     stop_sequence=2, shape_dist_traveled=2)
    self.accumulator.AssertNoMoreExceptions()
    schedule.Validate(self.problems)
    e = self.accumulator.PopException('OtherProblem')
    self.assertMatchesRegex('shape_dist_traveled=2', e.FormatProblem())
    self.accumulator.AssertNoMoreExceptions()

    # Error if the distance decreases.
    shape.AddPoint(36.421288, -117.133132, 2)
    stop = transitfeed.Stop(36.421288, -117.133122, "Demo Stop 4", "STOP4")
    schedule.AddStopObject(stop)
    stoptime = transitfeed.StopTime(self.problems, stop,
                                    arrival_time="5:29:00",
                                    departure_time="5:29:00", stop_sequence=3,
                                    shape_dist_traveled=1.7)
    trip.AddStopTimeObject(stoptime, schedule=schedule)
    self.accumulator.AssertNoMoreExceptions()
    schedule.Validate(self.problems)
    e = self.accumulator.PopException('InvalidValue')
    self.assertMatchesRegex('stop STOP4 has', e.FormatProblem())
    self.assertMatchesRegex('shape_dist_traveled=1.7', e.FormatProblem())
    self.assertMatchesRegex('distance was 2.0.', e.FormatProblem())
    self.assertEqual(e.type, transitfeed.TYPE_ERROR)
    self.accumulator.AssertNoMoreExceptions()

    # Warning if distance remains the same between two stop_times
    stoptime.shape_dist_traveled = 2.0
    trip.ReplaceStopTimeObject(stoptime, schedule=schedule)
    schedule.Validate(self.problems)
    e = self.accumulator.PopException('InvalidValue')
    self.assertMatchesRegex('stop STOP4 has', e.FormatProblem())
    self.assertMatchesRegex('shape_dist_traveled=2.0', e.FormatProblem())
    self.assertMatchesRegex('distance was 2.0.', e.FormatProblem())
    self.assertEqual(e.type, transitfeed.TYPE_WARNING)
    self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
 def runTest(self):
     schedule = transitfeed.Schedule(problem_reporter=self.problems)
     schedule.add_agency("\xc8\x8b Fly Agency", "http://iflyagency.com",
                         "America/Los_Angeles")
     schedule.get_default_service_period().set_date_has_service('20070101')
     stop1 = schedule.add_stop(lng=140, lat=48.2, name="Stop 1")
     stop2 = schedule.add_stop(lng=140.001, lat=48.201, name="Stop 2")
     route = schedule.add_route("B", "Beta", "Bus")
     trip = route.add_trip(schedule, "bus trip")
     trip.add_stop_time_object(transitfeed.StopTime(self.problems,
                                                    stop1,
                                                    arrival_secs=10,
                                                    departure_secs=10),
                               schedule=schedule,
                               loader_problems=self.problems)
     trip.add_stop_time_object(transitfeed.StopTime(self.problems,
                                                    stop2,
                                                    arrival_secs=20,
                                                    departure_secs=20),
                               schedule=schedule,
                               loader_problems=self.problems)
     # TODO: Factor out checks or use mock problems object
     self.ExpectOtherProblemInClosure(
         lambda: trip.add_stop_time_object(transitfeed.StopTime(
             self.problems, stop1, arrival_secs=15, departure_secs=15),
                                           schedule=schedule,
                                           loader_problems=self.problems))
     trip.add_stop_time_object(transitfeed.StopTime(self.problems, stop1),
                               schedule=schedule,
                               loader_problems=self.problems)
     self.ExpectOtherProblemInClosure(
         lambda: trip.add_stop_time_object(transitfeed.StopTime(
             self.problems, stop1, arrival_secs=15, departure_secs=15),
                                           schedule=schedule,
                                           loader_problems=self.problems))
     trip.add_stop_time_object(transitfeed.StopTime(self.problems,
                                                    stop1,
                                                    arrival_secs=30,
                                                    departure_secs=30),
                               schedule=schedule,
                               loader_problems=self.problems)
     self.accumulator.assert_no_more_exceptions()
    def runTest(self):
        stop = transitfeed.Stop()
        self.ExpectInvalidValueInClosure(
            'arrival_time', '1a:00:00', lambda: transitfeed.StopTime(
                self.problems, stop, arrival_time="1a:00:00"))
        self.ExpectInvalidValueInClosure(
            'departure_time', '1a:00:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='1a:00:00'))
        self.ExpectInvalidValueInClosure(
            'pickup_type', '7.8',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='7.8',
                                         drop_off_type='0'))
        self.ExpectInvalidValueInClosure(
            'drop_off_type', 'a',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='3',
                                         drop_off_type='a'))
        self.ExpectInvalidValueInClosure(
            'shape_dist_traveled', '$',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='3',
                                         drop_off_type='0',
                                         shape_dist_traveled='$'))
        self.ExpectInvalidValueInClosure(
            'shape_dist_traveled', '0,53',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time='10:05:00',
                                         pickup_type='3',
                                         drop_off_type='0',
                                         shape_dist_traveled='0,53'))
        self.ExpectOtherProblemInClosure(lambda: transitfeed.StopTime(
            self.problems, stop, pickup_type='1', drop_off_type='1'))
        self.ExpectInvalidValueInClosure(
            'departure_time', '10:00:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="11:00:00",
                                         departure_time="10:00:00"))
        self.ExpectMissingValueInClosure(
            'arrival_time', lambda: transitfeed.StopTime(
                self.problems, stop, departure_time="10:00:00"))
        self.ExpectMissingValueInClosure(
            'arrival_time',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         departure_time="10:00:00",
                                         arrival_time=""))
        self.ExpectMissingValueInClosure(
            'departure_time', lambda: transitfeed.StopTime(
                self.problems, stop, arrival_time="10:00:00"))
        self.ExpectMissingValueInClosure(
            'departure_time',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time=""))
        self.ExpectInvalidValueInClosure(
            'departure_time', '10:70:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time="10:70:00"))
        self.ExpectInvalidValueInClosure(
            'departure_time', '10:00:62',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:00",
                                         departure_time="10:00:62"))
        self.ExpectInvalidValueInClosure(
            'arrival_time', '10:00:63',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:00:63",
                                         departure_time="10:10:00"))
        self.ExpectInvalidValueInClosure(
            'arrival_time', '10:60:00',
            lambda: transitfeed.StopTime(self.problems,
                                         stop,
                                         arrival_time="10:60:00",
                                         departure_time="11:02:00"))
        self.ExpectInvalidValueInClosure(
            'stop', "id",
            lambda: transitfeed.StopTime(self.problems,
                                         "id",
                                         arrival_time="10:00:00",
                                         departure_time="11:02:00"))
        self.ExpectInvalidValueInClosure(
            'stop', "3",
            lambda: transitfeed.StopTime(self.problems,
                                         "3",
                                         arrival_time="10:00:00",
                                         departure_time="11:02:00"))
        self.ExpectInvalidValueInClosure(
            'stop', None,
            lambda: transitfeed.StopTime(self.problems,
                                         None,
                                         arrival_time="10:00:00",
                                         departure_time="11:02:00"))

        # The following should work
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="10:00:00",
                             departure_time="10:05:00",
                             pickup_type='1',
                             drop_off_type='1')
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="10:00:00",
                             departure_time="10:05:00",
                             pickup_type='1',
                             drop_off_type='1')
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="1:00:00",
                             departure_time="1:05:00")
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="24:59:00",
                             departure_time="25:05:00")
        transitfeed.StopTime(self.problems,
                             stop,
                             arrival_time="101:01:00",
                             departure_time="101:21:00")
        transitfeed.StopTime(self.problems, stop)
        self.accumulator.AssertNoMoreExceptions()
Ejemplo n.º 8
0
def create_gtfs_trip_stoptimes(trip, trip_start_time, trip_start_period_i,
                               serv_headways, route_def,
                               prebuilt_stop_info_list, mode_config, schedule,
                               seg_speed_model):
    """Creates the actual stop times on a route.
    Since Apr 2014, now needs to access curr_period and serv_headways,
    since we are allowing for time-dependent vehicle speeds by serv period.
    Still uses pre-calculated list of stops, segments along a route."""

    if VERBOSE:
        print("\n%s() called on route '%s', trip_id = %d, trip start time %s"\
            % (inspect.stack()[0][3], route_def.name, trip.trip_id,\
                str(trip_start_time)))

    if len(route_def.ordered_seg_ids) == 0:
        print("Warning: for route name '%s', no route segments defined " \
            "skipping." % route_def.name)
        return

    # We will also create the stopping time object as a timedelta, as this way
    # it will handle trips that cross midnight the way GTFS requires
    # (as a number that can increases past 24:00 hours,
    # rather than ticking back to 00:00)
    start_time_delta = datetime.combine(TODAY, trip_start_time) - \
        datetime.combine(TODAY, time(0))
    cumulative_time_on_trip = timedelta(0)
    # These variable needed to track change in periods for possible
    # time-dependent vehicle speed in peak or off-peak
    period_at_stop_i = trip_start_period_i
    peak_status = serv_headways[period_at_stop_i][m_t_info.PEAK_STATUS_COL]
    time_at_stop = trip_start_time
    end_elapsed_curr_p = m_t_info.calc_service_time_elapsed_end_period(
        serv_headways, period_at_stop_i)
    n_stops_on_route = len(prebuilt_stop_info_list)

    for stop_seq, s_info in enumerate(prebuilt_stop_info_list):
        # Enter a stop at first stop in the segment in chosen direction.
        problems = None
        # Enter the stop info now at the start. Then will add on time in this
        # segment.
        # Need to add cumulative time on trip start time to get it as a 'daily'
        # time_delta, suited for GTFS.
        stop_time_delta = start_time_delta + cumulative_time_on_trip
        time_at_stop = (datetime.min + stop_time_delta).time()
        time_sec_for_gtfs = stop_time_delta.days * 24*60*60 \
            + stop_time_delta.seconds
        gtfs_stop_time = transitfeed.StopTime(
            problems,
            s_info.gtfs_stop,
            pickup_type=0,  # Regularly scheduled pickup 
            drop_off_type=0,  # Regularly scheduled drop off
            shape_dist_traveled=None,
            arrival_secs=time_sec_for_gtfs,
            departure_secs=time_sec_for_gtfs,
            stop_time=time_sec_for_gtfs,
            stop_sequence=stop_seq)
        trip.AddStopTimeObject(gtfs_stop_time)
        if VERBOSE:
            print("Added stop # %d for this route (stop ID %s) - at t %s" \
                % (stop_seq, gtfs_stop.stop_id, stop_time_delta))

        # Given elapsed time at stop we just added:- have we just crossed over
        # int peak period of schedule for this mode? Will affect calc. time to
        # next stop.
        # N.B.: first part of check is- for last trips of the 'day'
        # (even if after # midnite), they will may still be on the
        # road/rails after the
        # nominal end time of the period. In this case, just keep going
        # in same conditions of current period.
        serv_elapsed = m_t_info.calc_total_service_time_elapsed(
            serv_headways, time_at_stop)
        if (period_at_stop_i+1 < len(serv_headways)) \
                and serv_elapsed >= end_elapsed_curr_p:
            period_at_stop_i += 1
            peak_status =  \
                serv_headways[period_at_stop_i][m_t_info.PEAK_STATUS_COL]
            end_elapsed_curr_p = m_t_info.calc_service_time_elapsed_end_period(
                serv_headways, period_at_stop_i)

        # Only have to do time inc. calculations if more stops remaining.
        if (stop_seq + 1) < n_stops_on_route:
            time_inc = s_info.calc_time_on_next_segment(
                seg_speed_model, mode_config, stop_time_delta, peak_status)
            cumulative_time_on_trip += time_inc
    return