def __init__(self,
                 schedule=None,
                 from_stop_id=None,
                 to_stop_id=None,
                 transfer_type=None,
                 min_transfer_time=None,
                 field_dict=None):
        Persistable.__init__(self, None)

        self._schedule = None
        if field_dict:
            self.__dict__.update(field_dict)
        else:
            self.from_stop_id = from_stop_id
            self.to_stop_id = to_stop_id
            self.transfer_type = transfer_type
            self.min_transfer_time = min_transfer_time

        if getattr(self, 'transfer_type', None) in ("", None):
            # Use the default, recommended transfer, if attribute is not set or blank
            self.transfer_type = 0
        else:
            try:
                self.transfer_type = util.NonNegIntStringToInt(
                    self.transfer_type)
            except (TypeError, ValueError):
                pass

        if hasattr(self, 'min_transfer_time'):
            try:
                self.min_transfer_time = util.NonNegIntStringToInt(
                    self.min_transfer_time)
            except (TypeError, ValueError):
                pass
        else:
            self.min_transfer_time = None
        if schedule is not None:
            # Note from Tom, Nov 25, 2009: Maybe calling __init__ with a schedule
            # should output a DeprecationWarning. A schedule factory probably won't
            # use it and other GenericGTFSObject subclasses don't support it.
            schedule.AddTransferObject(self)
Exemple #2
0
 def ValidateRouteTypeHasValidValue(self, problems):
     if self.route_type is not None:
         try:
             if not isinstance(self.route_type, int):
                 self.route_type = util.NonNegIntStringToInt(
                     self.route_type, problems)
         except (TypeError, ValueError):
             problems.InvalidValue('route_type', self.route_type)
         else:
             if self.route_type not in self._ROUTE_TYPE_IDS:
                 problems.InvalidValue('route_type',
                                       self.route_type,
                                       type=problems_module.TYPE_WARNING)
Exemple #3
0
  def ParseAttributes(self, problems):
    """Parse all attributes, calling problems as needed.

    Return True if all of the values are valid.
    """
    if util.IsEmpty(self.shape_id):
      problems.MissingValue('shape_id')
      return

    try:
      if not isinstance(self.shape_pt_sequence, int):
        self.shape_pt_sequence = \
                util.NonNegIntStringToInt(self.shape_pt_sequence, problems)
      elif self.shape_pt_sequence < 0:
        problems.InvalidValue('shape_pt_sequence', self.shape_pt_sequence,
                              'Value should be a number (0 or higher)')
    except (TypeError, ValueError):
      problems.InvalidValue('shape_pt_sequence', self.shape_pt_sequence,
                            'Value should be a number (0 or higher)')
      return

    try:
      if not isinstance(self.shape_pt_lat, (int, float)):
        self.shape_pt_lat = util.FloatStringToFloat(self.shape_pt_lat, problems)
      if abs(self.shape_pt_lat) > 90.0:
        problems.InvalidValue('shape_pt_lat', self.shape_pt_lat)
        return
    except (TypeError, ValueError):
      problems.InvalidValue('shape_pt_lat', self.shape_pt_lat)
      return

    try:
      if not isinstance(self.shape_pt_lon, (int, float)):
        self.shape_pt_lon = util.FloatStringToFloat(self.shape_pt_lon, problems)
      if abs(self.shape_pt_lon) > 180.0:
        problems.InvalidValue('shape_pt_lon', self.shape_pt_lon)
        return
    except (TypeError, ValueError):
      problems.InvalidValue('shape_pt_lon', self.shape_pt_lon)
      return

    if abs(self.shape_pt_lat) < 1.0 and abs(self.shape_pt_lon) < 1.0:
      problems.InvalidValue('shape_pt_lat', self.shape_pt_lat,
                            'Point location too close to 0, 0, which means '
                            'that it\'s probably an incorrect location.',
                            type=problems_module.TYPE_WARNING)
      return

    if self.shape_dist_traveled == '':
      self.shape_dist_traveled = None

    if (self.shape_dist_traveled is not None and
        not isinstance(self.shape_dist_traveled, (int, float))):
      try:
        self.shape_dist_traveled = \
                util.FloatStringToFloat(self.shape_dist_traveled, problems)
      except (TypeError, ValueError):
        problems.InvalidValue('shape_dist_traveled', self.shape_dist_traveled,
                              'This value should be a positive number.')
        return

    if self.shape_dist_traveled is not None and self.shape_dist_traveled < 0:
      problems.InvalidValue('shape_dist_traveled', self.shape_dist_traveled,
                            'This value should be a positive number.')
      return

    return True