예제 #1
0
	def authCurves(self, network, orgs=None, dests=None, flights=None, 
					cabins=None, bcs=None, date_ranges=None):
		""" Plots AUTH curves for some subset of the data.
		
		AUTH is stated at the level of a cabin-booking class.  AUTH changes
		with time starting from the opening of ticket sales and ending close 
		to departure.   Note that you only have to look at two booking 
		classes (BC) for purpose of overbooking: Y class for Y cabin and J 
		class for J cabin. This is because those classes always have the
		maximum AUTH among all classes in a cabin at a given point of time 
		(they are at the top in hierarchy). 
	
		"""

		df = network.f.getDrillDown(orgs=orgs, dests=dests, flights=flights,
							cabins=cabins, bcs=bcs, date_ranges=date_ranges)

		fltbk = network.f.getUniqueFlightsAndBookings(df)

		plt.figure()
		for g, d in fltbk:
			AUTH = np.array(d.sort(columns='KEYDAY', ascending=False)['AUTH'])
			KEYDAY = np.array(-d.sort(columns='KEYDAY', ascending=False)['KEYDAY'])

			plt.plot(KEYDAY, AUTH)

		title = Utils.createTitleForFeatures(orgs,dests,flights,cabins,bcs,date_ranges)
		plt.title(title)
		plt.xlabel('-KEYDAY')
		plt.ylabel('AUTH')
		plt.show()
예제 #2
0
	def bookingCurves(self, network, orgs=None, dests=None, flights=None, 
						cabins=None, bcs=None, date_ranges=None):
		""" Plots booking curves for some subset of the data.
		
		A booking curve tracks the number of seats booked over time, starting 
		from the opening of ticket sales and ending close to departure
	
		"""

		df = network.f.getDrillDown(orgs=orgs, dests=dests, flights=flights,
							cabins=cabins, bcs=bcs, date_ranges=date_ranges)
		fltbk = network.f.getUniqueFlightsAndBookings(df)

		plt.figure()
		for g, d in fltbk:
			BKD = list(d.sort(columns='KEYDAY', ascending=False)['BKD'])
			KEYDAY = list(-d.sort(columns='KEYDAY', ascending=False)['KEYDAY'])

			ID = d['DATE'].first
			BC = d['BC'].first
				
			plt.plot(KEYDAY, BKD)
			
		title = Utils.createTitleForFeatures(orgs,dests,flights,cabins,bcs,date_ranges)
		plt.title(title)
		plt.xlabel('-KEYDAY')
		plt.ylabel('BKD')
		plt.show()
예제 #3
0
	def overbookingCurves(self, network, orgs=None, dests=None, flights=None, 
						cabins=None, bcs=None, date_ranges=None, normalized=True):
		""" Plots overbooking curves for some subset of the data.
		
		Overbooking is defined where AUTH > CAP.  We plot overbooking as a 
		ratio between AUTH and CAP.  Overbooking varies with time.
	
		"""
		df = network.f.getDrillDown(orgs=orgs, dests=dests, flights=flights,
							cabins=cabins, bcs=bcs, date_ranges=date_ranges)

		fltbk = network.f.getUniqueFlightsAndBookings(df)

		plt.figure()
		
		if normalized:
			for g, d in fltbk:
				# normalized AUTH == OVERBOOKED
				AUTH = np.array(d.sort(columns='KEYDAY', ascending=False)['AUTH'])
				
				# ignore time series that are not overbooked
				if not Utils.isOverbooked(AUTH):
					continue

				KEYDAY = np.array(-d.sort(columns='KEYDAY', ascending=False)['KEYDAY'])
				
				plt.plot(KEYDAY, AUTH)
		else:
			for g, d in fltbk:
				AUTH = np.array(d.sort(columns='KEYDAY', ascending=False)['AUTH'])
				CAP = float(d.iloc[0]['CAP'])
				OVRBKD = AUTH/CAP

				# ignore time series that are not overbooked
				if not Utils.isOverbooked(OVRBKD):
					continue

				KEYDAY = np.array(-d.sort(columns='KEYDAY', ascending=False)['KEYDAY'])
				
				plt.plot(KEYDAY, OVRBKD)

		title = Utils.createTitleForFeatures(orgs,dests,flights,cabins,bcs,date_ranges)
		plt.title(title)
		plt.xlabel('-KEYDAY')
		plt.ylabel('Percentage Overbooked: AUTH / CAP')
		plt.show()
예제 #4
0
	def stackedBookingCurve(self, network, orgs=None, dests=None, 
		                     flights=None, cabins=None, bcs=None, 
		                     date_ranges=None):
		"""
		Generate a summative booking curve for a given flight. In order for this
		function to work properly the arguments must specify one specific flight
		(or a subset of the booking classes on a specific flight). Additionally,
		the network must have been create using a normalized data set.
		"""

		first_flights = network.f.getDrillDown(orgs=orgs, dests=dests, 
											   flights=flights, cabins=cabins, 
											   bcs=bcs, date_ranges=date_ranges)
		groupedByBookings = network.f.getUniqueFlightsAndBookings(first_flights)
		xvals = np.linspace(-1, 0, 101) # Increments of .01 from -1 -> 0
		interps = None
		labels = [g[4] for g, d in groupedByBookings]

		for g, d in groupedByBookings:
			keydays = -d['KEYDAY'] 
			booked = d['BKD']
			yvals = network.interp(xvals, keydays, booked)
			if interps == None:
				interps = yvals
			else:
				interps = np.vstack((interps, yvals))

		# interps is my matrix
		m, n = interps.shape
		interps_sum = np.zeros((m,n))
		for i in range(m-1):
			for j in range(i+1, m):
				interps_sum[j] += interps[i]

		for i in range(m):
			plt.plot(xvals, interps_sum[i])

		plt.legend(labels, loc=6, prop={'size': 14})
		plt.title('Summative Booking Curve\n' + Utils.createTitleForFeatures(orgs, dests, flights, cabins, bcs, date_ranges))
		plt.xlabel('Normalized Keyday')
		plt.ylabel('Normalized Booked')
		plt.show()
예제 #5
0
	def overbookingVsCabinLoadFactor(self, network, orgs=None, dests=None, flights=None, 
									cabins=None, bcs=None, date_ranges=None, 
									normalized=True, subplots=True):
		""" Plots how overbooking varies with Cabin load factor.  Final Cabin Load Factor
		for a particular flight booking class is binned into three separate categories:
		
		Overbooked: CLF > 1
		Underbooked: CLF < .8
		Optimumly booked: .8 < CLF < 1
		
		"""
		df = network.f.getDrillDown(orgs=orgs, dests=dests, flights=flights,
							cabins=cabins, bcs=bcs, date_ranges=date_ranges)

		fltbk = network.f.getUniqueFlightsAndBookings(df)
		# TODO: allow for countFinalCabinLoadFactor to use normalized data		
		CLF_dict = network.countFinalCabinLoadFactor()

		fig = plt.figure()
		# preparing to capture the legend handles
		legend_over = None
		legend_under = None
		legend_optimum = None
		n_over = 0
		n_under = 0
		n_optimum = 0

		if normalized:
			for g, d in fltbk:
				# normalized AUTH == OVERBOOKED
				AUTH = np.array(d.sort(columns='KEYDAY', ascending=False)['AUTH'])
				
				# ignore time series that are not overbooked
				if not Utils.isOverbooked(AUTH):
					continue

				KEYDAY = np.array(-d.sort(columns='KEYDAY', ascending=False)['KEYDAY'])
				DATE = d.iloc[0]['DATE']
				FLT = d.iloc[0]['FLT']
				ORG = d.iloc[0]['ORG']
				DES = d.iloc[0]['DES']
				
				#TODO: See CLF_dict (above)
				CABIN_LOAD_FACTOR = CLF_dict[(DATE, FLT, ORG, DES)]

				if CABIN_LOAD_FACTOR > 1:
					plt.plot(KEYDAY, AUTH, 'r')
				elif CABIN_LOAD_FACTOR < .95: 
					plt.plot(KEYDAY, AUTH, 'y')
				else:
					plt.plot(KEYDAY, AUTH, 'g')
		else:
			for g, d in fltbk:
				
				AUTH = np.array(d.sort(columns='KEYDAY', ascending=False)['AUTH'])
				CAP = float(d.iloc[0]['CAP'])
				OVRBKD = AUTH/CAP

				# ignore time series that are not overbooked
				if not Utils.isOverbooked(OVRBKD):
					continue

				KEYDAY = np.array(-d.sort(columns='KEYDAY', ascending=False)['KEYDAY'])
				DATE = d.iloc[0]['DATE']
				FLT = d.iloc[0]['FLT']
				ORG = d.iloc[0]['ORG']
				DES = d.iloc[0]['DES']

				CABIN_LOAD_FACTOR = CLF_dict[(DATE, FLT, ORG, DES)]

				


				if CABIN_LOAD_FACTOR > 1:
					plt.subplot(311) if subplots else None
					if not legend_over:
						legend_over, = plt.plot(KEYDAY, OVRBKD , 'r')
					else:
						plt.plot(KEYDAY, OVRBKD , 'r')
					n_over += 1

				elif CABIN_LOAD_FACTOR < .95: 
					plt.subplot(313) if subplots else None
					if not legend_under:
						legend_under, = plt.plot(KEYDAY, OVRBKD, 'y')
					else:
						plt.plot(KEYDAY, OVRBKD, 'y')
					n_under += 1

				else:
					plt.subplot(312) if subplots else None
					if not legend_optimum:
						legend_optimum, = plt.plot(KEYDAY, OVRBKD, 'g')
					else:
						plt.plot(KEYDAY, OVRBKD, 'g')
					n_optimum += 1

		title = Utils.createTitleForFeatures(orgs,dests,flights,cabins,bcs,date_ranges)
		plt.subplot(311) if subplots else None
		plt.suptitle(title)
		plt.xlabel('-KEYDAY')
		plt.ylabel('Percentage Overbooked: AUTH / CAP')
		plt.subplot(311)		
		plt.ylim([.25,2])
		plt.subplot(312)		
		plt.ylim([.25,2])
		plt.subplot(313)		
		plt.ylim([.25,2])


		plt.legend([legend_over, legend_optimum, legend_under], 
			["Cabin Load Factor > 1, n={}".format(n_over),
			"Optimum Cabin Load Factor,n={}".format(n_optimum), 
			"Cabin Load Factor < .95, n={}".format(n_under) 
			])
		plt.show()