-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
369 lines (360 loc) · 15.6 KB
/
main.py
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import mysql.connector as con
import pandas as pd
import matplotlib.pyplot as pl
import numpy as np
mycon=con.connect(host='localhost', user='root', passwd='rampage', charset='utf8', database='project')
if mycon.is_connected()==False:
print("Not Connected")
cur=mycon.cursor()
res='y'
while res=='y' or res=='Y':
print("\n\nMENU \n1.Retrieve \n2.Updation \n3.Insertion \n4.Deletion \n5.Visualization \n6.Exit")
response=int(input("Enter your choice: "))
#RETRIEVAL OF INFORMATION IN DIFFERENT WAYS
if response==1:
print()
print("\U0001f600 WELCOME TO AIRPORT RETRIEVAL SERVICE \U0001f600")
print()
print("SUB-MENU \n 1.Display All \n 2.Filtered Column Display \n 3.Search Name-Wise")
subch=int(input("ENTER THE SUB-CHOICE: "))
if subch==1:
query='select passengerid,passengername,age,gender,p.flightno,airlines,destination from passenger p,flight f where p.flightno=f.flightno'
cur.execute(query)
data=cur.fetchall()
#for row in data:
#print(row)
df=pd.DataFrame(data, columns=['PassengerID','Passengername','Age','Gender','Flightno','Airlines','Destination'])
print(df)
if subch==2:
lst=[]
col=[]
n=int(input("ENTER THE NUMBER OF COLUMNS YOU WANT IN DISPLAY- "))
for i in range(0,n):
ele=input('INPUT: ')
lst.append(ele)
col.append(ele)
lst.append(',')
lst=lst[:-1]
print(lst)
inp=''.join(lst)
print()
#print(inp)
query="select {} from passenger p,flight f where p.flightno=f.flightno".format(inp)
cur.execute(query)
data=cur.fetchall()
#for row in data:
#print(row)
df=pd.DataFrame(data,columns=col)
print(df)
if subch==3:
name=input("Enter the name you want in display- ")
query="select passengerid,passengername,age,gender,p.flightno,airlines,destination from passenger p,flight f where p.flightno=f.flightno and passengername='{}'".format(name)
cur.execute(query)
data=cur.fetchall()
#for row in data:
#print(row)
df=pd.DataFrame(data,columns=['PassengerID','Passengername','Age','Gender','Flightno','Airlines','Destination'])
print(df)
#UPDATION OF DIFFERENT TABLES
if response==2:
print("")
login=input("ENTER YOUR LOGIN_ID: ")
if login=='RJ10' or login=='RJ12':
pswrd=input("ENTER PASSWORD: ")
print()
if pswrd=="tiger":
print("\U0001f600 WELCOME TO AIRPORT UPDATION SERVICE \U0001f600")
print()
print("SUB-MENU \n 1.Passenger Table \n 2.Flight Table")
subch=int(input("ENTER THE SUB-CHOICE: "))
if subch==1:
name=input("ENTER THE NAME OF THE PASSENGER-")
fno=input("ENTER THE CHANGED FLIGHT NUMBER-")
st="update passenger set flightno='{}' where passengername='{}'".format(fno,name)
cur.execute(st)
mycon.commit()
cur.execute("select * from passenger")
data=cur.fetchall()
#for row in data:
#print(row)
print()
print('NEW DATAFRAME FORMED IS:')
df=pd.DataFrame(data, columns=['PassengerID','Passengername','Age','Gender','Flightno'])
print(df)
if subch==2:
fno=input("ENTER THE FLIGHT NUMBER-")
dest=input("ENTER THE NEW DESTINATION-")
st="update flight set destination='{}' where flightno='{}'".format(dest,fno)
cur.execute(st)
mycon.commit()
cur.execute("select * from flight")
data=cur.fetchall()
#for row in data:
#print(row)
print('NEW DATAFRAME FORMED IS:')
df=pd.DataFrame(data, columns=['Flightno','Airlines','Destination'])
print(df)
else:
print("!!! LOGIN FAILED !!!")
break
else:
print("!!! LOGIN FAILED !!!")
break
#INSERTION INTO DIFFERENT TABLES
if response==3:
print()
login=input("ENTER YOUR LOGIN_ID: ")
if login=='RJ10' or login=='RJ12':
pswrd=input("ENTER PASSWORD: ")
print()
if pswrd=="tiger":
print("\U0001f600 WELCOME TO AIRPORT INSERTION SERVICE \U0001f600")
print()
print("SUB-MENU \n 1.Passenger Table \n 2.Flight Table")
subch=int(input("ENTER THE SUB-CHOICE: "))
if subch==1:
pid=int(input("ENTER PASSENGER_ID-"))
name=str(input("ENTER PASSENGERNAME-"))
age=input("ENTER THE AGE-")
gender=input("ENTER THE GENDER-")
fno=input("ENTER THE FLIGHT NUMBER-")
query="insert into passenger values({},'{}',{},'{}','{}')".format(pid,name,age,gender,fno)
cur.execute(query)
mycon.commit()
cur.execute("select * from passenger")
data=cur.fetchall()
#for row in data:
#print(row)
print('NEW DATAFRAME FORMED IS:')
df=pd.DataFrame(data, columns=['PassengerID','Passengername','Age','Gender','Flightno'])
print(df)
if subch==2:
fno=input("ENTER THE FLIGHT NUMBER-")
air=str(input("ENTER AIRLINES-"))
dest=input("ENTER THE DESTINATION-")
query="insert into flight values('{}','{}','{}')".format(fno,air,dest)
cur.execute(query)
mycon.commit()
cur.execute("select * from flight")
data=cur.fetchall()
#for row in data:
#print(row)
print('NEW DATAFRAME FORMED IS:')
df=pd.DataFrame(data, columns=['Flightno','Airlines','Destination'])
print(df)
else:
print("!!! LOGIN FAILED !!!")
break
else:
print("!!! LOGIN FAILED !!!")
break
#DELETION FROM DIFFERENT TABLES
if response==4:
print()
login=input("ENTER YOUR LOGIN_ID: ")
if login=='RJ10' or login=='RJ12':
pswrd=input("ENTER PASSWORD: ")
print()
if pswrd=="tiger":
print("\U0001f600 WELCOME TO AIRPORT DELETION SERVICE \U0001f600")
print()
print("SUB-MENU \n 1.Passenger Table \n 2.Flight Table")
subch=int(input("ENTER THE SUB-CHOICE: "))
if subch==1:
name=input("ENTER THE NAME OF PASSENGER WHOSE RECORD IS TO BE REMOVED-")
st="delete from passenger where passengername='{}'".format(name)
cur.execute(st)
mycon.commit()
cur.execute("select * from passenger")
data=cur.fetchall()
#for row in data:
#print(row)
print('NEW DATAFRAME FORMED IS:')
df=pd.DataFrame(data, columns=['PassengerID','Passengername','Age','Gender','Flightno'])
print(df)
if subch==2:
fno=input("ENTER THE FLIGHT NUMBER-")
st="delete from flight where flightno='{}'".format(fno)
cur.execute(st)
mycon.commit()
cur.execute("select * from flight")
data=cur.fetchall()
#for row in data:
#print(row)
print('NEW DATAFRAME FORMED IS:')
df=pd.DataFrame(data, columns=['Flightno','Airlines','Destination'])
print(df)
else:
print("!!! LOGIN FAILED !!!")
break
else:
print("!!! LOGIN FAILED !!!")
break
#VISUALIZATION IN DIFFERENT WAYS
if response==5:
print()
print("\U0001f600 WELCOME TO AIRPORT VISUALIZATION SERVICE \U0001f600")
print()
print("SUB-MENU \n 1.Total Distribution of Flights \n 2.Preferred Place \n 3.Place-Wise Distribution \n 4.Gender Distribution (Place-Wise)")
subch=int(input("\nENTER SUB-CHOICE: "))
if subch==1:
query='select airlines,count(*) from flight group by airlines'
cur.execute(query)
data=cur.fetchall()
#for row in data:
#print(row)
print('Table formed is:')
print()
df=pd.DataFrame(data, columns=['Airlines','Number'])
print(df)
print()
print('GRAPH CHOICE \n1.Bar Chart \n2.Line Chart \n3.Scatter Chart \n4.Pie Chart')
pl.title("Total Number of Flights")
graphch=int(input("Enter Graph Choice: "))
if graphch==1:
pl.bar(df['Airlines'],df['Number'])
pl.xlabel('Airlines Available')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==2:
pl.plot(df['Airlines'],df['Number'])
pl.xlabel('Airlines')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==3:
pl.scatter(df['Airlines'],df['Number'])
pl.xlabel('Airlines')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==4:
pl.pie(df['Number'],labels=df['Airlines'],shadow=True)
pl.show()
if subch==2:
query='select destination,count(*) from flight group by destination'
cur.execute(query)
data=cur.fetchall()
#for row in data:
#print(row)
print('\n\nTemporary Table:')
print()
df=pd.DataFrame(data, columns=['Destination','Number'])
print(df)
print()
print('GRAPH CHOICE \n1.Bar Chart \n2.Line Chart \n3.Scatter Chart \n4.Pie Chart')
pl.title("Preferred Destination")
graphch=int(input("ENTER GRAPH CHOICE: "))
if graphch==1:
pl.bar(df['Destination'],df['Number'])
pl.xlabel('Places')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==2:
pl.plot(df['Destination'],df['Number'])
pl.xlabel('Places')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==3:
pl.scatter(df['Destination'],df['Number'])
pl.xlabel('Places')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==4:
pl.pie(df['Number'],labels=df['Destination'], shadow=True)
pl.show()
if subch==3:
dest=input("Enter Destination: ")
query="select airlines,destination,count(airlines) from flight group by destination,airlines having destination='{}'".format(dest)
cur.execute(query)
data=cur.fetchall()
#for row in data:
#print(row)
print('Table formed is:')
print()
df=pd.DataFrame(data,columns=['Airlines','Destination','Number'])
del df['Destination']
print(df)
print()
print('GRAPH CHOICE \n1.Bar Chart \n2.Line Chart \n3.Scatter Chart \n4.Pie Chart')
pl.title("Airline Distribution To Destination")
graphch=int(input("ENTER GRAPH CHOICE: "))
if graphch==1:
pl.bar(df['Airlines'],df['Number'])
pl.xlabel('Airlines Available')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==2:
pl.plot(df['Airlines'],df['Number'])
pl.xlabel('Airlines')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==3:
pl.scatter(df['Airlines'],df['Number'])
pl.xlabel('Airlines')
pl.ylabel('Number of Airlines')
pl.show()
if graphch==4:
pl.pie(df['Number'],labels=df['Airlines'], shadow=True)
pl.show()
if subch==4:
gend='f'
dest=input("Enter the Destination: ")
query="select p.gender,f.destination,f.airlines,count(p.gender) from passenger p,flight f where p.flightno=f.flightno group by gender,airlines,destination having gender='f' and destination='{}'".format(dest)
cur.execute(query)
data=cur.fetchall()
#for row in data:
#print(row)
print('Table formed (for females is):')
df=pd.DataFrame(data, columns=['Gender','Destination','Airlines','Number'])
del df['Destination']
del df['Gender']
print(df)
print()
gend1='m'
query1="select p.gender,f.destination,f.airlines,count(p.gender) from passenger p,flight f where p.flightno=f.flightno group by gender,airlines,destination having gender='m' and destination='{}'".format(dest)
cur.execute(query1)
data1=cur.fetchall()
#for row in data:
#print(row)
print('Table formed (for males is):')
df1=pd.DataFrame(data1, columns=['Gender','Destination','Airlines','Number'])
del df1['Destination']
del df1['Gender']
print(df1)
print()
print('GRAPH CHOICE \n1.Comparitive Bar Chart \n2.Line Chart \n3.Scatter Chart')
pl.title("Gender Distribution Of Airlines")
graphch=int(input("ENTER GRAPH CHOICE: "))
if graphch==1:
x=np.arange(3)
y=['Air India','IndiGo','Vistara']
pl.bar(x,df['Number'],width=0.3,label='Females')
pl.bar(x+0.3,df1['Number'],width=0.3,label='Males')
pl.legend(loc='upper right')
pl.xticks(x,y)
pl.xlabel('Airlines Available')
pl.ylabel('Number of People')
pl.show()
if graphch==2:
pl.plot(df['Airlines'],df['Number'],color='b',marker='x',label='Females')
pl.plot(df1['Airlines'],df1['Number'],color='r',marker='d',label='Males')
pl.xlabel('Airlines')
pl.ylabel('Number of People')
pl.legend(loc='upper right')
pl.show()
if graphch==3:
pl.scatter(df['Airlines'],df['Number'],color='b',label='Females')
pl.scatter(df1['Airlines'],df1['Number'],color='r',label='Males')
pl.xlabel('Airlines')
pl.ylabel('Number of People')
pl.legend(loc='upper left')
pl.show()
#EXITING FROM THE SOFTWARE
if response==6:
print("Thank You For Using This Software")
break
res=input("Do you want to continue (Y/N)?")
if res=='y' or res=='Y':
continue
else:
break
mycon.close()