Exemplo n.º 1
0
 def ValidateNoDuplicateStopSequences(self, problems):
   cursor = self._schedule._connection.cursor()
   cursor.execute("SELECT COUNT(stop_sequence) AS a, stop_sequence "
                  "FROM stop_times "
                  "WHERE trip_id=? GROUP BY stop_sequence HAVING a > 1",
                  (self.trip_id,))
   for row in cursor:
     problems.InvalidValue('stop_sequence', row[1],
                           'Duplicate stop_sequence in trip_id %s' %
                           self.trip_id)
Exemplo n.º 2
0
  def ValidateStopTimesSequenceHasIncreasingTimeAndDistance(self,
                                                            problems,
                                                            stoptimes):
    if stoptimes:
      route_class = self.GetGtfsFactory().Route
      # Checks that the arrival time for each time point is after the departure
      # time of the previous. Assumes a stoptimes sorted by sequence
      prev_departure = 0
      prev_stop = None
      prev_distance = None
      try:
        route_type = self._schedule.GetRoute(self.route_id).route_type
        max_speed = route_class._ROUTE_TYPES[route_type]['max_speed']
      except KeyError as e:
        # If route_type cannot be found, assume it is 0 (Tram) for checking
        # speeds between stops.
        max_speed = route_class._ROUTE_TYPES[0]['max_speed']
      for timepoint in stoptimes:
        # Distance should be a nonnegative float number, so it should be
        # always larger than None.
        distance = timepoint.shape_dist_traveled
        if distance is not None:
          if distance > prev_distance and distance >= 0:
            prev_distance = distance
          else:
            if distance == prev_distance:
              type = transitfeed.problems.TYPE_WARNING
            else:
              type = transitfeed.problems.TYPE_ERROR
            problems.InvalidValue('stoptimes.shape_dist_traveled', distance,
                  'For the trip %s the stop %s has shape_dist_traveled=%s, '
                  'which should be larger than the previous ones. In this '
                  'case, the previous distance was %s.' %
                  (self.trip_id, timepoint.stop_id, distance, prev_distance),
                  type=type)

        if timepoint.arrival_secs is not None:
          self._CheckSpeed(prev_stop, timepoint.stop, prev_departure,
                           timepoint.arrival_secs, max_speed, problems)

          if timepoint.arrival_secs >= prev_departure:
            prev_departure = timepoint.departure_secs
            prev_stop = timepoint.stop
          else:
            problems.OtherProblem('Timetravel detected! Arrival time '
                                  'is before previous departure '
                                  'at sequence number %s in trip %s' %
                                  (timepoint.stop_sequence, self.trip_id))
Exemplo n.º 3
0
 def GetEndTime(self, problems=default_problem_reporter):
   """Return the last time of the trip. TODO: For trips defined by frequency
   return the last time of the last trip."""
   cursor = self._schedule._connection.cursor()
   cursor.execute(
       'SELECT arrival_secs,departure_secs FROM stop_times WHERE '
       'trip_id=? ORDER BY stop_sequence DESC LIMIT 1', (self.trip_id,))
   (arrival_secs, departure_secs) = cursor.fetchone()
   if departure_secs != None:
     return departure_secs
   elif arrival_secs != None:
     return arrival_secs
   else:
     problems.InvalidValue('arrival_time', '',
                           'The last stop_time in trip %s is missing '
                           'times.' % self.trip_id)
Exemplo n.º 4
0
 def ValidateServiceIdExistsInServiceList(self, problems):
   if self._schedule:
     if (self.service_id and
         self.service_id not in self._schedule.service_periods):
       problems.InvalidValue('service_id', self.service_id)
Exemplo n.º 5
0
 def ValidateRouteIdExistsInRouteList(self, problems):
   if self._schedule:
     if self.route_id and self.route_id not in self._schedule.routes:
       problems.InvalidValue('route_id', self.route_id)
Exemplo n.º 6
0
 def ValidateShapeIdsExistInShapeList(self, problems):
   if self._schedule:
     if self.shape_id and self.shape_id not in self._schedule._shapes:
       problems.InvalidValue('shape_id', self.shape_id)
Exemplo n.º 7
0
 def ValidateDirectionId(self, problems):
   if hasattr(self, 'direction_id') and (not transitfeed.util.IsEmpty(self.direction_id)) \
       and (self.direction_id != '0') and (self.direction_id != '1'):
     problems.InvalidValue('direction_id', self.direction_id,
                           'direction_id must be "0" or "1"')