Beispiel #1
0
    def __init__(self, axes):
        """
        Mirror data across specified axes, randomly during pre-processing, and using all permutations during full
        pre-processing.
        :param axes: Dimensions across which data is mirrored. (list)
        """

        # Check first dimension (batch size) is not flipped
        if 0 in axes:
            raise ValueError('Cannot flip across dimension 0 (batch size)!')

        # Prepare amount of crops and size at each dimension
        self.axes = axes

        # Call parent initializer
        Operator.__init__(self, num_modes=2**len(self.axes))
Beispiel #2
0
    def __init__(self, sizes, amounts=None):
        """
        Crop data across all dimensions, randomly during random pre-processing, and at N evenly spread locations per
        dimension during full pre-processing.
        :param sizes: Size of the crop at each dimension. Use -1 to specify full size. (list)
        :param amounts: Number of evenly-spread crops per dimension during full pre-processing. (list)
        """

        # Prepare amount of crops and size at each dimension
        amounts = [1] * len(sizes) if amounts is None else amounts
        self.amounts = amounts if isinstance(
            amounts, (list, tuple)) else [amounts] * len(self.sizes)
        self.sizes = sizes

        # Call parent initializer
        Operator.__init__(self, num_modes=np.prod(amounts))
Beispiel #3
0
    def __init__(self, axes, ranges):
        """
        Shift data across specified axes, randomly during pre-processing, doing nothing during full-augmentation.
        :param axes: Dimensions across which to shift. (list)
        :param ranges: Range of the shifts across each dimension. (list of lists)
        """

        # Check first dimension (batch size) is not shifted
        if 0 in axes:
            raise ValueError('Cannot shift across dimension 0 (batch size)!')

        # Prepare operator attributes
        self.axes = axes
        self.ranges = ranges

        # Call parent initializer
        Operator.__init__(self, num_modes=1)
  def bootstrap_gtfs(self, gtfs_feed, feedname='unknown', populate=True):
    # Make sure the GTFS feed is completely loaded.
    gtfs_feed.preload()

    # Set onestopId
    if 'onestopId' not in self.data:
      self.data['onestopId'] = self.make_onestop(
        geohash=geom.geohash_features(gtfs_feed.stops()),
        name=feedname
      )
    feedid = self.onestop()

    # Override operator Onestop IDs
    agency_onestop = {}
    for i in self.operatorsInFeed():
      agency_onestop[i['gtfsAgencyId']] = i['onestopId']

    # Check for agencies.
    gtfs_agencies = []
    for gtfs_agency in gtfs_feed.agencies():
      if populate or gtfs_agency.id() in agency_onestop:
        gtfs_agencies.append(gtfs_agency)
      else:
        # Unknown agency
        pass
    if not gtfs_agencies:
      return

    # Create TL Stops
    stops = {}
    # sort; process all parent stations first.
    order = []
    order += sorted(filter(lambda x:x.location_type()==1, gtfs_feed.stops()), key=lambda x:x.id())
    order += sorted(filter(lambda x:x.location_type()!=1, gtfs_feed.stops()), key=lambda x:x.id())
    for gtfs_stop in order:
      # Create stop from GTFS
      stop = Stop.from_gtfs(gtfs_stop, feedid)
      # Merge into parent station
      parent = gtfs_stop.get('parent_station')
      if parent:
        stop = gtfs_feed.stop(parent)._tl_ref
      # Merge with existing stop
      key = stop.onestop()
      stop = stops.get(key) or stop
      stops[key] = stop
      # Add identifiers and tags
      gtfs_stop._tl_ref = stop
      stop.add_identifier(gtfs_stop.feedid(feedid))

    # Create TL Routes
    for gtfs_route in gtfs_feed.routes():
      if not gtfs_route.stops():
        continue
      # Create route from GTFS
      route = Route.from_gtfs(gtfs_route, feedid)
      # Link to TL Stops
      for gtfs_stop in gtfs_route.stops():
        t = getattr(gtfs_stop, '_tl_ref', None)
        if t:
          route.add_child(t)
      # Maintain reference to GTFS Route
      gtfs_route._tl_ref = route

    # Create TL Agencies
    for gtfs_agency in gtfs_agencies:
      operator = Operator.from_gtfs(
        gtfs_agency,
        feedid,
        onestop_id=agency_onestop.get(gtfs_agency.id())
      )
      for gtfs_route in gtfs_agency.routes():
        t = getattr(gtfs_route, '_tl_ref', None)
        if t:
          operator.add_child(t)
      # Inelegant.
      operator._cache_onestop()
      # Add agency to feed
      self.add_child(operator)
Beispiel #5
0
 def __init__(self, order):
     self.order = tuple(order)
     Operator.__init__(self, num_modes=1)
Beispiel #6
0
 def __init__(self, args, sess):
     Operator.__init__(self, args, sess)
Beispiel #7
0
 def __init__(self, weight=1, bias=0):
     self.weight = weight
     self.bias = bias
     Operator.__init__(self, num_modes=1)
 def test_from_json(self):
     feed = util.example_feed()
     entity = util.example_feed().operator(self.expect['onestopId'])
     roundtrip = Operator.from_json(entity.json())
     self._sanity(roundtrip)
 def test_init(self):
     entity = Operator()
 def test_from_json(self):
   feed = util.example_feed()
   entity = util.example_feed().operator(self.expect['onestopId'])
   roundtrip = Operator.from_json(entity.json())
   self._sanity(roundtrip)
Beispiel #11
0
        elif user_input == 4:
            new_op.printByMonth()
            
        elif user_input == 5:
            new_op.printByDay()
            
        else:
            print("Please enter an option from the menu")
        
        print("")
        user_input = getUserInputFromMenu(menu)
    

flag = True
user_input = 0
new_op = Operator()
new_op.loadOperators()

if len(new_op.list_of_operators) != 0:
    flag = False
    user_input = mainMenu()

while flag == False:
    if user_input == 3:
        flag = True
        break
        
    elif user_input == 1:
        managerMenu(new_op)
    
    elif user_input == 2:
    def bootstrap_gtfs(self, gtfs_feed, feedname='unknown', populate=True):
        # Make sure the GTFS feed is completely loaded.
        gtfs_feed.preload()

        # Set onestopId
        if 'onestopId' not in self.data:
            self.data['onestopId'] = self.make_onestop(
                geohash=geom.geohash_features(gtfs_feed.stops()),
                name=feedname)
        feedid = self.onestop()

        # Override operator Onestop IDs
        agency_onestop = {}
        for i in self.operatorsInFeed():
            agency_onestop[i['gtfsAgencyId']] = i['onestopId']

        # Check for agencies.
        gtfs_agencies = []
        for gtfs_agency in gtfs_feed.agencies():
            if populate or gtfs_agency.id() in agency_onestop:
                gtfs_agencies.append(gtfs_agency)
            else:
                # Unknown agency
                pass
        if not gtfs_agencies:
            return

        # Create TL Stops
        stops = {}
        # sort; process all parent stations first.
        order = []
        order += sorted(filter(lambda x: x.location_type() == 1,
                               gtfs_feed.stops()),
                        key=lambda x: x.id())
        order += sorted(filter(lambda x: x.location_type() != 1,
                               gtfs_feed.stops()),
                        key=lambda x: x.id())
        for gtfs_stop in order:
            # Create stop from GTFS
            stop = Stop.from_gtfs(gtfs_stop, feedid)
            # Merge into parent station
            parent = gtfs_stop.get('parent_station')
            if parent:
                stop = gtfs_feed.stop(parent)._tl_ref
            # Merge with existing stop
            key = stop.onestop()
            stop = stops.get(key) or stop
            stops[key] = stop
            # Add identifiers and tags
            gtfs_stop._tl_ref = stop
            stop.add_identifier(gtfs_stop.feedid(feedid))

        # Create TL Routes
        for gtfs_route in gtfs_feed.routes():
            if not gtfs_route.stops():
                continue
            # Create route from GTFS
            route = Route.from_gtfs(gtfs_route, feedid)
            # Link to TL Stops
            for gtfs_stop in gtfs_route.stops():
                t = getattr(gtfs_stop, '_tl_ref', None)
                if t:
                    route.add_child(t)
            # Maintain reference to GTFS Route
            gtfs_route._tl_ref = route

        # Create TL Agencies
        for gtfs_agency in gtfs_agencies:
            operator = Operator.from_gtfs(gtfs_agency,
                                          feedid,
                                          onestop_id=agency_onestop.get(
                                              gtfs_agency.id()))
            for gtfs_route in gtfs_agency.routes():
                t = getattr(gtfs_route, '_tl_ref', None)
                if t:
                    operator.add_child(t)
            # Inelegant.
            operator._cache_onestop()
            # Add agency to feed
            self.add_child(operator)