Beispiel #1
0
 def validate(self, validator=None):
     validator = super(Frequency, self).validate(validator)
     # Required
     with validator(self):
         assert self.get('trip_id'), "Required: trip_id"
     with validator(self):
         assert self.get('start_time'), "Required: start_time"
     with validator(self):
         assert self.get('end_time'), "Required: end_time"
     with validator(self):
         assert validation.valid_widetime(self.get('start_time')), \
           "Invalid start_time"
     with validator(self):
         assert validation.valid_widetime(self.get('end_time')), \
           "Invalid end_time"
     with validator(self):
         assert self.end() >= self.start(), \
           "Invalid end_time, must at least start_date"
     with validator(self):
         assert validation.valid_int(self.get('headway_secs'), vmin=1), \
           "Invalid headway_secs"
     # Optional
     with validator(self):
         if self.get('exact_times'):
             assert validation.valid_bool(self.get('exact_times'), empty=True), \
               "Invalid exact_times"
     return validator
Beispiel #2
0
 def validate(self, validator=None):
   validator = super(FareAttribute, self).validate(validator)
   # Required
   with validator(self):
     assert self.get('fare_id'), "Required: fare_id"
   with validator(self):
     assert self.get('price'), "Required: price"
   with validator(self):
     assert validation.valid_float(self.get('price')), "Invalid price"
   with validator(self):
     assert self.get('currency_type'), "Required: currency_type"
   with validator(self):
     assert self.get('payment_method'), "Required: payment_method"
   with validator(self):
     assert validation.valid_bool(self.get('payment_method')), \
       "Invalid payment_method"
   with validator(self):
     assert validation.valid_int(self.get('transfers'), vmin=0, vmax=2, empty=True), \
       "Invalid transfers"
   # Optional
   with validator(self):
     if self.get('transfer_duration'):
       assert validation.valid_int(self.get('transfer_duration'), vmin=0), \
         "Invalid transfer_duration"
   return validator
Beispiel #3
0
 def validate(self, validator=None):
   validator = super(Frequency, self).validate(validator)
   # Required
   with validator(self):
     assert self.get('trip_id'), "Required: trip_id"
   with validator(self):
     assert self.get('start_time'), "Required: start_time"
   with validator(self):
     assert self.get('end_time'), "Required: end_time"
   with validator(self):
     assert validation.valid_widetime(self.get('start_time')), \
       "Invalid start_time"
   with validator(self):
     assert validation.valid_widetime(self.get('end_time')), \
       "Invalid end_time"
   with validator(self):
     assert self.end() >= self.start(), \
       "Invalid end_time, must at least start_date"
   with validator(self):
     assert validation.valid_int(self.get('headway_secs'), vmin=1), \
       "Invalid headway_secs"
   # Optional
   with validator(self):
     if self.get('exact_times'):
       assert validation.valid_bool(self.get('exact_times'), empty=True), \
         "Invalid exact_times"
   return validator
Beispiel #4
0
 def validate(self, validator=None):
   validator = super(ServicePeriod, self).validate(validator)
   with validator(self):
     assert self.get('service_id'), "Required: service_id"
   with validator(self):
     assert validation.valid_bool(self.get('monday')), "Required: monday"
   with validator(self):
     assert validation.valid_bool(self.get('tuesday')), "Required: tuesday"
   with validator(self):
     assert validation.valid_bool(self.get('wednesday')), "Required: wednesday"
   with validator(self):
     assert validation.valid_bool(self.get('thursday')), "Required: thursday"
   with validator(self):
     assert validation.valid_bool(self.get('friday')), "Required: friday"
   with validator(self):
     assert validation.valid_bool(self.get('saturday')), "Required: saturday"
   with validator(self):
     assert validation.valid_bool(self.get('sunday')), "Required: sunday"
   with validator(self):
     assert validation.valid_date(self.get('start_date'), empty=True), "Invalid start_date"
   with validator(self):
     assert validation.valid_date(self.get('start_end'), empty=True), "Invalid start_end"
   with validator(self):
     assert self.end() >= self.start(), \
       "Invalid end_date, must be at least start_date"
   # TODO: Warnings
   #   - no days of the week
   return validator
Beispiel #5
0
 def validate(self, validator=None):
     validator = super(Stop, self).validate(validator)
     # Required
     with validator(self):
         assert self.get('stop_id'), "Required: stop_id"
     with validator(self):
         assert self.get('stop_name'), "Required: stop_name"
     with validator(self):
         assert self.get('stop_lat'), "Required: stop_lat"
     with validator(self):
         assert self.get('stop_lon'), "Required: stop_lon"
     with validator(self):
         assert validation.valid_point(
             self.point()), "Invalid stop_lon/stop_lat"
     # TODO: Warnings:
     #  - stop too close to 0,0
     # Optional
     with validator(self):
         if self.get('stop_desc') == self.get('stop_name'):
             raise validation.ValidationWarning(
                 "stop_desc and stop_name are the same")
     with validator(self):
         if self.get('zone_id') and int(self.get('location_type') or 0):
             raise validation.ValidationWarning(
                 "A station cannot have a zone_id")
     with validator(self):
         if self.get('stop_url'):
             assert validation.valid_url(
                 self.get('stop_url')), "Invalid stop_url"
     with validator(self):
         if self.get('location_type'):
             assert validation.valid_bool(self.get('location_type'), empty=True), \
               "Invalid location_type"
     with validator(self):
         if int(self.get('location_type')
                or 0) and self.get('parent_station'):
             assert not self.get('parent_station'), \
               "A station cannot contain another station"
     with validator(self):
         if self.get('stop_timezone'):
             assert validation.valid_tz(
                 self.get('stop_timezone')), "Invalid timezone"
     with validator(self):
         if self.get('wheelchair_boarding'):
             assert validation.valid_int(self.get('wheelchair_boarding'), vmin=0, vmax=2, empty=True), \
               "Invalid wheelchair_boarding"
     with validator(self):
         if self.get('stop_code'):
             pass
     return validator
Beispiel #6
0
 def validate(self, validator=None):
   validator = super(StopTime, self).validate(validator)
   # Required
   with validator(self):
     assert self.get('trip_id'), "Required: trip_id"
   with validator(self):
     assert \
       (self.get('arrival_time') and self.get('departure_time')) or \
       (not self.get('arrival_time') and not self.get('departure_time')), \
       "Both arrival_time and departure_time must be set, or both must be empty."
   with validator(self):
     if self.get('arrival_time'):
       assert validation.valid_widetime(self.get('arrival_time')), \
         "Invalid arrival_time: %s"%self.get('arrival_time')
   with validator(self):
     if self.get('departure_time'):
       assert validation.valid_widetime(self.get('departure_time')), \
         "Invalid departure_time: %s"%self.get('departure_time')
   with validator(self): 
     assert self.arrive() <= self.depart(), \
       "Cannot depart before arriving!: %s -> %s"%(self.arrive(), self.depart())
   with validator(self):
     assert self.sequence() >= 0, \
       "Invalid stop_sequence: %s"%self.get('stop_sequence')
   # TODO: Warnings - useless stops (cant pickup or dropoff)
   # Optional
   with validator(self):
     if self.get('pickup_type'):
       assert validation.valid_int(self.get('pickup_type'), vmin=0, vmax=3), \
         "Invalid pickup_type, must be 0,1,2,3: %s"%self.get('pickup_type')
   with validator(self): 
     if self.get('drop_off_type'):
       assert validation.valid_int(self.get('drop_off_type'), vmin=0, vmax=3), \
         "Invalid drop_off_type, must be 0,1,2,3: %s"%self.get('drop_off_type')
   with validator(self):
     if self.get('timepoint'):
       assert validation.valid_bool(self.get('timepoint'), empty=True), \
         "Invalid timepoint"
   with validator(self):
     if int(self.get('timepoint',0)) == 1:
       assert self.arrive() and self.depart(), \
         "Exact timepoints require arrival_time and departure_time"
   with validator(self):
     if self.get('stop_headsign'):
       pass
   with validator(self):
     if self.get('shape_dist_traveled'):
       pass
   return validator
Beispiel #7
0
 def validate(self, validator=None):
   validator = super(Stop, self).validate(validator)
   # Required
   with validator(self): 
     assert self.get('stop_id'), "Required: stop_id"
   with validator(self): 
     assert self.get('stop_name'), "Required: stop_name"
   with validator(self): 
     assert self.get('stop_lat'), "Required: stop_lat"
   with validator(self): 
     assert self.get('stop_lon'), "Required: stop_lon"
   with validator(self): 
     assert validation.valid_point(self.point()), "Invalid stop_lon/stop_lat"
   # TODO: Warnings: 
   #  - stop too close to 0,0
   # Optional
   with validator(self):
     if self.get('stop_desc') == self.get('stop_name'):
       raise validation.ValidationWarning("stop_desc and stop_name are the same")        
   with validator(self):
     if self.get('zone_id') and int(self.get('location_type') or 0):
       raise validation.ValidationWarning("A station cannot have a zone_id")
   with validator(self): 
     if self.get('stop_url'):
       assert validation.valid_url(self.get('stop_url')), "Invalid stop_url"
   with validator(self): 
     if self.get('location_type'):
       assert validation.valid_bool(self.get('location_type'), empty=True), \
         "Invalid location_type"
   with validator(self):
     if int(self.get('location_type') or 0) and self.get('parent_station'):
       assert not self.get('parent_station'), \
         "A station cannot contain another station"          
   with validator(self):
     if self.get('stop_timezone'):
       assert validation.valid_tz(self.get('stop_timezone')), "Invalid timezone"
   with validator(self): 
     if self.get('wheelchair_boarding'):
       assert validation.valid_int(self.get('wheelchair_boarding'), vmin=0, vmax=2, empty=True), \
         "Invalid wheelchair_boarding"
   with validator(self):
     if self.get('stop_code'):
       pass
   return validator
Beispiel #8
0
 def validate(self, validator=None):
     validator = super(Trip, self).validate(validator)
     # Required
     with validator(self):
         assert self.get('route_id'), "Required: route_id"
     with validator(self):
         assert self.get('service_id'), "Required: service_id"
     with validator(self):
         assert self.get('trip_id'), "Required: trip_id"
     # TODO: Warnings:
     #   speed/vehicle_type
     #   duplicate trips
     # Optional
     with validator(self):
         if self.get('direction_id'):
             assert validation.valid_bool(
                 self.get('direction_id')), "Invalid direction_id"
     with validator(self):
         if self.get('wheelchair_accessible'):
             assert validation.valid_int(self.get('wheelchair_accessible'), vmin=0, vmax=2, empty=True), \
               "Invalid wheelchair_accessible"
     with validator(self):
         if self.get('bikes_allowed'):
             assert validation.valid_int(self.get('bikes_allowed'), vmin=0, vmax=2, empty=True), \
               "Invalid bikes_allowed"
     with validator(self):
         if self.get('trip_headsign'):
             pass
     with validator(self):
         if self.get('trip_short_name'):
             pass
     with validator(self):
         if self.get('block_id'):
             pass
     with validator(self):
         if self.get('shape_id'):
             pass
Beispiel #9
0
 def validate(self, validator=None):
   validator = super(Trip, self).validate(validator)
   # Required
   with validator(self):
     assert self.get('route_id'), "Required: route_id"
   with validator(self):
     assert self.get('service_id'), "Required: service_id"
   with validator(self):
     assert self.get('trip_id'), "Required: trip_id"
   # TODO: Warnings:
   #   speed/vehicle_type
   #   duplicate trips
   # Optional
   with validator(self):
     if self.get('direction_id'):
       assert validation.valid_bool(self.get('direction_id')), "Invalid direction_id"
   with validator(self):
     if self.get('wheelchair_accessible'):
       assert validation.valid_int(self.get('wheelchair_accessible'), vmin=0, vmax=2, empty=True), \
         "Invalid wheelchair_accessible"
   with validator(self):
     if self.get('bikes_allowed'):
       assert validation.valid_int(self.get('bikes_allowed'), vmin=0, vmax=2, empty=True), \
         "Invalid bikes_allowed"
   with validator(self):
     if self.get('trip_headsign'):
       pass
   with validator(self):
     if self.get('trip_short_name'):
       pass
   with validator(self):
     if self.get('block_id'):
       pass
   with validator(self):
     if self.get('shape_id'):
       pass
Beispiel #10
0
 def validate(self, validator=None):
     validator = super(ServicePeriod, self).validate(validator)
     with validator(self):
         assert self.get('service_id'), "Required: service_id"
     with validator(self):
         assert validation.valid_bool(
             self.get('monday')), "Required: monday"
     with validator(self):
         assert validation.valid_bool(
             self.get('tuesday')), "Required: tuesday"
     with validator(self):
         assert validation.valid_bool(
             self.get('wednesday')), "Required: wednesday"
     with validator(self):
         assert validation.valid_bool(
             self.get('thursday')), "Required: thursday"
     with validator(self):
         assert validation.valid_bool(
             self.get('friday')), "Required: friday"
     with validator(self):
         assert validation.valid_bool(
             self.get('saturday')), "Required: saturday"
     with validator(self):
         assert validation.valid_bool(
             self.get('sunday')), "Required: sunday"
     with validator(self):
         assert validation.valid_date(self.get('start_date'),
                                      empty=True), "Invalid start_date"
     with validator(self):
         assert validation.valid_date(self.get('start_end'),
                                      empty=True), "Invalid start_end"
     with validator(self):
         assert self.end() >= self.start(), \
           "Invalid end_date, must be at least start_date"
     # TODO: Warnings
     #   - no days of the week
     return validator