-
Notifications
You must be signed in to change notification settings - Fork 6
/
backup
194 lines (128 loc) · 6.13 KB
/
backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import sys
import sqlite3
import pandas as pd
import numpy as np
######################################################################################################################
# #
# Functions Reading Values from Files and DB #
# #
#######################################################################################################################
def read_seat_config():
conn = sqlite3.connect('airline_seating.db')
cur = conn.cursor()
row_data = cur.execute('''select * from rows_cols''')
for row in row_data:
nrows = row[0]
seat_config = row[1]
seat_col = len(seat_config)
return nrows,seat_config,seat_col
def read_booking(n):
column_names = ['passenger_name, no_of_passenger']
df = pd.read_csv('bookings.csv', header=None)
passenger_name = df.loc[n,0] #Setting Index to 1 as index starts from 0
no_of_passenger = df.loc[n,1]
return passenger_name,no_of_passenger
def generate_seat_map():
nrows, seat_config, seat_col = read_seat_config()
seats = np.zeros(shape=(nrows-1, seat_col-1))
return seats, nrows, seat_config, seat_col
######################################################################################################################
# #
# Validity Functions #
# #
#######################################################################################################################
'''
Function Name: check_overbooking()
Description: This function first find the total number of passengers from the booking list, if booking is more than
the number of available seats in a aircraft then program will exit(0). However, program should accept all passenger till
it is has no space to accommodate any new passenger.
'''
def check_overbooking():
nrows, seat_config, seat_col = read_seat_config()
passenger_total =0
for i in range(nrows+1):
passenger_name, no_of_passenger = read_booking(i)
passenger_total +=no_of_passenger
if passenger_total > (seat_col*nrows):
print("Cannot Proceed: No. of Passenger can't be more than no. of available seats")
exit(0)
def empty_booking_list():
nrows, seat_config, seat_col = read_seat_config()
for i in range(nrows + 1):
passenger_name, no_of_passenger = read_booking(1)
if passenger_name == "" or no_of_passenger ==0 or no_of_passenger == " ":
print("Cannot Proceed: Passenger Information is Missing")
exit(0)
#######################################################################################################################
# #
# Seat Allocation Functions #
# #
#######################################################################################################################
def allot_seats():
for n in range(1,10):
passenger_name, no_of_passenger = read_booking(n)
if no_of_passenger == 1:
i,j = single_seat_allocation(passenger_name,no_of_passenger)
print("Seat Allocated to ",passenger_name, " is >>",i,j)
break
else:
family_seat_allocation(passenger_name,no_of_passenger)
def single_seat_allocation(passenger_name,no_of_passenger):
seats, nrows, seat_config, seat_col = generate_seat_map()
for i in range(nrows-1):
for j in range(seat_col-1):
if seats[i][j] == 0.0:
seats[i][j] = 1.0
break;
break
print(seats)
return i,j
def any_seat_allocation(passenger_name,no_of_passenger):
print("Naeee")
def family_seat_allocation(passenger_name,no_of_passenger):
print("Yayaya")
allot_seats()
import sys
import sqlite3
import pandas as pd
def read_seat_config():
conn = sqlite3.connect('airline_seating.db')
cur = conn.cursor()
row_data = cur.execute('''select * from rows_cols''')
for row in row_data:
nrows = row[0]
seat_config = row[1]
return nrows,seat_config
def create_seat_map():
nrows,seat_config = read_seat_config()
seat_number = []
seats = [{str(nrows)+ltr:'Empty' for ltr in seat_config} for seats in range(1,nrows+1)]
for seat_col in range(1,nrows+1):
for ltr in seat_config:
seat_number.append(str(seat_col) + ltr)
return seats, nrows, seat_config, seat_number
create_seat_map()
def read_booking(n):
column_names = ['passenger_name, no_of_passenger']
df = pd.read_csv('bookings.csv', header=None)
passenger_name = df.loc[n,0] #Setting Index to 1 as index starts from 0
no_of_passenger = df.loc[n,1]
return passenger_name,no_of_passenger
def allot_seats():
for n in range(1,10):
passenger_name, no_of_passenger = read_booking(n)
if no_of_passenger == 1:
single_seat_allocation(passenger_name,no_of_passenger)
else:
family_seat_allocation(passenger_name,no_of_passenger)
def single_seat_allocation(passenger_name,no_of_passenger):
seats, nrows, seat_config, seat_number = create_seat_map()
for i in range(1,nrows+1):
for j in seat_number:
seatsx = str(j)
print(seats[i]['1A'])
def any_seat_allocation(passenger_name,no_of_passenger):
print("Naeee")
def family_seat_allocation(passenger_name,no_of_passenger):
print("Yayaya")
allot_seats()