Example #1
0
 def __getattr__(self, name):
     if name == 'stop_id':
         return self.stop.stop_id
     elif name == 'arrival_time':
         return (self.arrival_secs != None
                 and util.FormatSecondsSinceMidnight(self.arrival_secs)
                 or '')
     elif name == 'departure_time':
         return (self.departure_secs != None
                 and util.FormatSecondsSinceMidnight(self.departure_secs)
                 or '')
     elif name == 'shape_dist_traveled':
         return ''
     raise AttributeError(name)
    def AddStopTimeObject(self, stoptime, schedule=None, problems=None):
        """Add a StopTime object to the end of this trip.

    Args:
      stoptime: A StopTime object. Should not be reused in multiple trips.
      schedule: Schedule object containing this trip which must be
      passed to Trip.__init__ or here
      problems: ProblemReporter object for validating the StopTime in its new
      home

    Returns:
      None
    """
        if schedule is None:
            schedule = self._schedule
        if schedule is None:
            warnings.warn(
                "No longer supported. _schedule attribute is used to get "
                "stop_times table", DeprecationWarning)
        if problems is None:
            problems = schedule.problem_reporter

        if stoptime._cursor_factory is None:
            stoptime._cursor_factory = schedule

        new_secs = stoptime.GetTimeSecs()
        cursor = schedule._connection.cursor()
        cursor.execute(
            "SELECT max(stop_sequence), max(arrival_secs), "
            "max(departure_secs) FROM stop_times WHERE trip_id=?",
            (self.trip_id, ))
        row = cursor.fetchone()
        if row[0] is None:
            # This is the first stop_time of the trip
            stoptime.stop_sequence = 1
            if new_secs == None:
                problems.OtherProblem(
                    'No time for first StopTime of trip_id "%s"' %
                    (self.trip_id, ))
        else:
            stoptime.stop_sequence = row[0] + 1
            prev_secs = max(row[1], row[2])
            if new_secs != None and new_secs < prev_secs:
                problems.OtherProblem(
                    'out of order stop time for stop_id=%s trip_id=%s %s < %s'
                    % (util.EncodeUnicode(
                        stoptime.stop_id), util.EncodeUnicode(self.trip_id),
                       util.FormatSecondsSinceMidnight(new_secs),
                       util.FormatSecondsSinceMidnight(prev_secs)))
        self._AddStopTimeObjectUnordered(stoptime)
Example #3
0
 def TooManyConsecutiveStopTimesWithSameTime(self,
     trip_id,
     number_of_stop_times,
     time_in_secs,
     type=TYPE_WARNING):
   e = TooManyConsecutiveStopTimesWithSameTime(trip_id=trip_id,
       number_of_stop_times=number_of_stop_times,
       stop_time=util.FormatSecondsSinceMidnight(time_in_secs),
       context=None,
       context2=self._context,
       type=type)
   self.AddToAccumulator(e)
Example #4
0
 def _HeadwayOutputTuple(self, headway):
     return (self.trip_id,
             util.FormatSecondsSinceMidnight(headway[0]),
             util.FormatSecondsSinceMidnight(headway[1]),
             unicode(headway[2]),
             unicode(headway[3]))