예제 #1
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()
예제 #2
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()