Ejemplo n.º 1
0
def oneHotBookingClass(bc, bin_size=1):
    """ Returns a binned 1-to-K or one-hot encoding of BC.
    
    bc: a booking class letter
    bin_size: number of bc that fit into one bin
    
    if bin_size=1 (default), we have a true 1-K encoding
    """
    assert len(Utils.bc_hierarchy) % bin_size == 0, "Invalid Bin Size"

    cabin, rank = Utils.mapBookingClassToCabinHierarchy(bc)
    
    enc_vector = np.zeros(len(Utils.bc_hierarchy)/bin_size)
    enc_vector[rank/bin_size] = 1

    return enc_vector
Ejemplo n.º 2
0
	def countCabinCapacityPerFlight(self):
		"""
		Counts the total capcity of a flight in every cabin on the plane

		returns:
			dictionary of {flight, dictionary of {cabin, cabin capacity}}
		"""
		flights = self.f.getUniqueFlightsAndBookings()
		capacities = {}
		for booking_group, data in flights:
			flight = booking_group[0:4]
			bc = booking_group[4]
			cabin, rank = Utils.mapBookingClassToCabinHierarchy(bc)

			if flight not in capacities:
				capacities[flight] = {}

			capacities[flight][cabin] = data['CAP'].mean()

		return capacities
Ejemplo n.º 3
0
	def countTotalBookedPerFlight(self):
		"""
		Counts the total number of passengers on a flight in every cabin on the
		plane

		returns:
			dictionary of {flight, dictionary of {cabin, total booked}}
		"""
		flights = self.f.getUniqueFlightsAndBookings()
		total_bookings = {}
		for booking_group, data in flights:
			flight = booking_group[0:4]
			bc = booking_group[4]
			cabin, rank = Utils.mapBookingClassToCabinHierarchy(bc)

			if flight not in total_bookings:
				total_bookings[flight] = {}

			total_bookings[flight][cabin] = data['TOTALBKD'].mean()

		return total_bookings	
Ejemplo n.º 4
0
    including OneHot or 1-K Methods and binning the rank
    """
    return oneHotBookingClass(bc, bin_size)

def oneHotBookingClass(bc, bin_size=1):
    """ Returns a binned 1-to-K or one-hot encoding of BC.
    
    bc: a booking class letter
    bin_size: number of bc that fit into one bin
    
    if bin_size=1 (default), we have a true 1-K encoding
    """
    assert len(Utils.bc_hierarchy) % bin_size == 0, 
        "Error: Bin Size must evenly divide into the number of booking classes"

    cabin, rank = Utils.mapBookingClassToCabinHierarchy(bc)
    
    enc_vector = np.zeros(len(Utils.bc_hierarchy)/bin_size)
    enc_vector[rank/bin_size] = 1

    return enc_vector

def sortBCGroupby(groupby):
    tups = [(bc, bc_df) for bc, bc_df in groupby]
    return sorted(tups, key=lambda tup: Utils.compareBCs(tup[0]))

def interpolate(keyday_vals, keydays, *args):
    interps = [np.interp(keyday_vals, keydays, arg, left=0) for arg in args]

    return interps