-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
523 lines (435 loc) · 18.8 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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
import pandas as pd
import numpy as np
import math
import mplleaflet
import matplotlib.pyplot as plt
from statsmodels.nonparametric.smoothers_lowess import lowess
from scipy import stats
import seaborn
seaborn.set()
def distance(dataframe): # https://www.movable-type.co.uk/scripts/latlong.html
lat1 = dataframe['lat_caller']
lon1 = dataframe['lon_caller']
lat2 = dataframe['lat']
lon2 = dataframe['lon']
R = 6371 * 1000
theta = lat1 * (math.pi/180)
lamda = lat2 * (math.pi/180)
del_theta = (lat2-lat1) * (math.pi/180)
del_lamda = (lon2-lon1) * (math.pi/180)
a = math.sin(del_theta/2) * math.sin(del_theta/2) + math.cos(theta) * math.cos(lamda) * math.sin(del_lamda / 2) * math.sin(del_lamda / 2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = R * c
return d
def user_input(data):
df = pd.read_csv('categories.csv')
print('Please choose what type of amenity you are interested in: ')
print('0. In general')
print('1. Financial')
print('2. Vehicles')
print('3. Health')
print('4. Recreation')
print('5. Food')
print('6. Work')
print('7. Pray')
print('8. Trash')
print('9. Repair')
print('10. Clock')
print('11. Landmark')
print('12. transport')
value = input("")
value = int(value)
category = "N/A"
if(value == 1):
category = "money"
elif(value == 2):
category = "vehicles"
elif(value == 3):
category = "health"
elif(value == 4):
category = "recreation"
elif(value == 5):
category = "food"
elif(value == 6):
category = "work"
elif(value == 7):
category = "pray"
elif(value == 8):
category = "trash"
elif(value == 9):
category = "repair"
elif(value == 10):
category = "clock"
elif(value == 11):
category = "landmarks"
elif(value == 12):
category = "transports"
if(category!="N/A"):
df_category = df[category].dropna()
print("Looking for following of categorical interests")
print(df_category)
data = data[data['amenity'].isin(df_category)]
return data
def city_input():
print('Please choose for which city you are interested in: ')
print('1. Burnaby')
print('2. Surrey')
print('3. Coquitlam')
print('4. Richmond')
print('5. Vancouver')
print('6. North Vancouver')
print('7. West Vancouver')
print('8. Delta')
value = input("")
value = int(value)
category = "N/A"
if(value == 1):
category = "Burnaby"
elif(value == 2):
category = "Surrey"
elif(value == 3):
category = "Coquitlam"
elif(value == 4):
category = "Richmond"
elif(value == 5):
category = "Vancouver"
elif(value == 6):
category = "North Vancouver"
elif(value == 7):
category = "West Vancouver"
elif(value == 8):
category = "Delta"
return category
def executeAI(avg_latlon,amenities):
joined = avg_latlon.join(amenities.set_index('city'),lsuffix='_caller',on='city')
joined['distance'] = joined.apply(distance,axis=1)
if(joined.empty):
print("Sorry nothing to suggest")
else:
all_possible_amenities = pd.DataFrame()
all_possible_amenities['lat'] = joined['lat']
all_possible_amenities['lon'] = joined['lon']
all_possible_amenities['distance'] = joined['distance']
all_possible_amenities['amenity'] = joined['amenity']
all_possible_amenities['city'] = joined['city']
all_possible_amenities['address'] = joined['address']
all_possible_amenities = all_possible_amenities.groupby(['lat','lon']).min()
suggested = all_possible_amenities[all_possible_amenities['distance']>10]
suggested = all_possible_amenities[all_possible_amenities['distance']<2000]
if(suggested.empty):
print("Sorry nothing to suggest")
else:
print()
f = open("Your trip suggessstion.txt", "w")
f.write("I suggest you could go for the uploaded trip to the following amenities\n")
print("I suggest you could go for the uploaded trip to the following amenities ")
suggested = suggested.reset_index()
p = suggested.drop(columns=['lat','lon'])
print(p)
try:
f.write(p.to_string())
except KeyError:
f.write("Null")
f.close()
plt.figure(figsize=(8,6))
fig = plt.figure()
#x = suggested[suggested['amenity'] == 'atm']
#x = x.reset_index()
#plt.scatter(x['lon'],x['lat'])
plt.scatter(suggested['lon'],suggested['lat'])
filtered = lowess(suggested['lat'],suggested['lon'], frac=0.2)
plt.plot(filtered[:, 0], filtered[:, 1],'r-', linewidth=5)
#plt.plot(x,y, 'r-', linewidth=3)
print("Please see the map with blue dot is the suggessted amenities red line is your optimal waliking")
print()
mplleaflet.show(fig=fig)
def execute_nightclub_AI(nightclub,amenities):
joined = nightclub.join(amenities.set_index('city'),lsuffix='_caller',on='city')
if(joined.empty):
print("Sorry no popular nightclub found in your city")
else:
joined['distance'] = joined.apply(distance,axis=1)
joined = joined[joined['distance']<1000]
joined['count'] = joined.groupby(['lat_caller','lon_caller'])['tags'].transform('count')
joined = joined[joined['count']>10]
if(joined.empty):
print("Sorry no popular nightclub found in your city")
else:
suggested = pd.DataFrame()
suggested = joined
suggested = suggested.drop_duplicates(subset=['lat_caller','lon_caller'])
f = open("Nightclub suggessstion.txt", "w")
f.write('Suggested Nightclub info you can find more than 10 Nightclub related amenities within 1Km\n')
print('Suggested Nightclub info you can find more than 10 Nightclub related amenities within 1Km')
print(suggested['address_caller'])
try:
f.write(suggested['address_caller'].to_string())
except KeyError:
f.write("Null")
f.close()
long_info = pd.DataFrame()
long_info['Suggested NightClubs info'] = joined['address_caller']
long_info['Realated_Aminities_Within_1Km'] = joined['amenity']
print()
print("Related amenities info")
print(long_info)
plt.figure(figsize=(8,6))
fig = plt.figure()
plt.scatter(joined['lon_caller'],joined['lat_caller'],30)
plt.scatter(joined['lon'],joined['lat'],10)
filtered = lowess(joined['lat_caller'],joined['lon_caller'], frac=0.7)
plt.plot(filtered[:, 0], filtered[:, 1],'r-', linewidth=5)
print("Please see the map with blue dot is the suggessted nightclub and orange dot is the nearby related amenities red line is your optimal waliking")
print()
mplleaflet.show(fig=fig)
def execute_restaurant_AI(restaurant,amenities):
joined = restaurant.join(amenities.set_index('city'),lsuffix='_caller',on='city')
if(joined.empty):
print("Sorry no popular restaurant found in your city")
else:
joined['distance'] = joined.apply(distance,axis=1)
joined = joined[joined['distance']<500]
joined['count'] = joined.groupby(['lat_caller','lon_caller'])['tags'].transform('count')
joined = joined[joined['count']>20]
if(joined.empty):
print("Sorry no popular restaurant found in your city")
else:
suggested = pd.DataFrame()
suggested = joined
suggested = suggested.drop_duplicates(subset=['lat_caller','lon_caller'])
f = open("restuarant suggessstion.txt", "w")
f.write('Suggested restaurant info you can find more than 20 restaurant related amenities within 500meter\n')
print(suggested['address_caller'])
try:
f.write(suggested['address_caller'].to_string())
except KeyError:
f.write("Null")
f.close()
long_info = pd.DataFrame()
long_info['Suggested restaurant info'] = joined['address_caller']
long_info['Chain_restaurants_Within_500meter'] = joined['amenity']
print()
print("related amenities info")
print(long_info)
plt.figure(figsize=(8,6))
fig = plt.figure()
plt.scatter(joined['lon_caller'],joined['lat_caller'],30)
plt.scatter(joined['lon'],joined['lat'],10)
filtered = lowess(joined['lat_caller'],joined['lon_caller'], frac=0.7)
plt.plot(filtered[:, 0], filtered[:, 1],'r-', linewidth=5)
print("Please see the map with blue dot is the suggessted resturant and orange dot is the nearby related amenities red line is your optimal waliking")
print()
mplleaflet.show(fig=fig)
def execute_medical_AI(medical):
joined = medical.join(medical.set_index('city'),lsuffix='_caller',on='city')
if(joined.empty):
print("Sorry no popular medical facilties found in your city")
else:
joined['distance'] = joined.apply(distance,axis=1)
joined = joined[joined['distance']<1000]
joined['count'] = joined.groupby(['lat_caller','lon_caller'])['tags'].transform('count')
joined = joined[joined['count']>10]
if(joined.empty):
print("Sorry no popular medical facilties found in your city")
else:
suggested = pd.DataFrame()
suggested = joined
suggested = suggested.drop_duplicates(subset=['lat_caller','lon_caller'])
f = open("medical facilties suggessstion.txt", "w")
f.write('Suggested medical facilties info you can find more than 10 medical facilties related amenities within 1Km\n')
print(suggested['address_caller'])
try:
f.write(suggested['address_caller'].to_string())
except KeyError:
f.write("Null")
f.close()
long_info = pd.DataFrame()
long_info['Suggested medical facilties info'] = joined['address_caller']
long_info['Chain_medical_facilties_Within_1KM'] = joined['amenity']
print()
print("Other chain medical facilties info")
print(long_info)
plt.figure(figsize=(8,6))
fig = plt.figure()
plt.scatter(joined['lon_caller'],joined['lat_caller'],30)
plt.scatter(joined['lon'],joined['lat'],10)
filtered = lowess(joined['lat_caller'],joined['lon_caller'], frac=0.7)
plt.plot(filtered[:, 0], filtered[:, 1],'r-', linewidth=5)
print("Please see the map with blue dot is the suggessted medical facilties and orange dot is the nearby related amenities red line is your optimal waliking")
print()
mplleaflet.show(fig=fig)
def execute_work_AI(medical):
joined = medical.join(medical.set_index('city'),lsuffix='_caller',on='city')
if(joined.empty):
print("Sorry no popular work/school facilties found in your city")
else:
joined['distance'] = joined.apply(distance,axis=1)
joined = joined[joined['distance']<2000]
joined['count'] = joined.groupby(['lat_caller','lon_caller'])['tags'].transform('count')
joined = joined[joined['count']>5]
if(joined.empty):
print("Sorry no popular work/school found in your city")
else:
suggested = pd.DataFrame()
suggested = joined
suggested = suggested.drop_duplicates(subset=['lat_caller','lon_caller'])
f = open("work suggessstion.txt", "w")
f.write('Suggested work/school info you can find more than 5 work/school related amenities within 2Km\n')
print(suggested['address_caller'])
try:
f.write(suggested['address_caller'].to_string())
except KeyError:
f.write("Null")
f.close()
long_info = pd.DataFrame()
long_info['Suggested work/school info'] = joined['address_caller']
long_info['Chain_work_or_school_Within_1KM'] = joined['amenity']
print()
print("Other chain work/school facilties info")
print(long_info)
plt.figure(figsize=(8,6))
fig = plt.figure()
plt.scatter(joined['lon_caller'],joined['lat_caller'],30)
plt.scatter(joined['lon'],joined['lat'],10)
filtered = lowess(joined['lat_caller'],joined['lon_caller'], frac=0.7)
plt.plot(filtered[:, 0], filtered[:, 1],'r-', linewidth=5)
print("Please see the map with blue dot is the suggessted medical facilties and orange dot is the nearby related amenities red line is your optimal waliking")
print()
mplleaflet.show(fig=fig)
def execute_vehicles_AI(vehicles):
joined = vehicles.join(vehicles.set_index('city'),lsuffix='_caller',on='city')
if(joined.empty):
print("Sorry no popular vehicles facilties found in your city")
else:
joined['distance'] = joined.apply(distance,axis=1)
joined = joined[joined['distance']<3000]
joined['count'] = joined.groupby(['lat_caller','lon_caller'])['tags'].transform('count')
joined = joined[joined['count']>5]
if(joined.empty):
print("Sorry no popular vehicles found in your city")
else:
suggested = pd.DataFrame()
suggested = joined
suggested = suggested.drop_duplicates(subset=['lat_caller','lon_caller'])
f = open("vehicles suggessstion.txt", "w")
f.write('Suggested vehicles info you can find more than 5 vehiclesrelated amenities within 3Km\n')
print(suggested['address_caller'])
try:
f.write(suggested['address_caller'].to_string())
except KeyError:
f.write("Null")
f.close()
long_info = pd.DataFrame()
long_info['Suggested vehicles info'] = joined['address_caller']
long_info['Chain_vehicles_Within_3KM'] = joined['amenity']
print()
print("Other chain vehicles facilties info")
print(long_info)
plt.figure(figsize=(8,6))
fig = plt.figure()
plt.scatter(joined['lon_caller'],joined['lat_caller'],30)
plt.scatter(joined['lon'],joined['lat'],10)
filtered = lowess(joined['lat_caller'],joined['lon_caller'], frac=0.7)
plt.plot(filtered[:, 0], filtered[:, 1],'r-', linewidth=5)
print("Please see the map with blue dot is the suggessted medical facilties and orange dot is the nearby related amenities red line is your optimal waliking")
print()
mplleaflet.show(fig=fig)
def main():
avg_latlon = pd.read_csv('avg_latlon.csv')
cities_visted = avg_latlon['city'].unique()
amenities = []
print("You have visted follwing cities")
for city in cities_visted:
print(city)
df = pd.read_csv('cities/'+ city + '.csv')
amenities.append(df)
amenities = pd.concat(amenities)
amenities = user_input(amenities)
if(amenities.empty or avg_latlon.empty):
print("Sorry not any popular amenities nearby")
else:
print("Trying to suggest some amenities of your interest you would have visited")
executeAI(avg_latlon,amenities)
print()
print("I might help you with one more adviced if you will be planning to go a nightclub")
print("0 Not interested")
print("1 Interested")
value = input("")
value = int(value)
if(value==1):
city = city_input()
amenities = pd.read_csv('cities/'+ city + '.csv')
nightclub = amenities[amenities['amenity'] == 'nightclub']
category = ['casino','park','bar','stripclub','pub','hospital','atm']
amenities = amenities[amenities['amenity'].isin(category)]
if(amenities.empty or nightclub.empty):
print("Sorry no popular nightclub found in your city")
else:
execute_nightclub_AI(nightclub,amenities)
print()
print("I might help you with one more adviced if you will be planning to go a restaurant")
print("0 Not interested")
print("1 Interested")
value = input("")
value = int(value)
if(value==1):
city = city_input()
amenities = pd.read_csv('cities/'+ city + '.csv')
restaurant = amenities[amenities['amenity'] == 'restaurant']
df = pd.read_csv('categories.csv')
category = df['food'].dropna()
amenities = amenities[amenities['amenity'].isin(category)]
if(amenities.empty or restaurant.empty):
print("Sorry no popular resturant place found in your city")
else:
execute_restaurant_AI(restaurant,amenities)
print()
print("I might help you with one more adviced if you will be planning to go a medical related service")
print("0 Not interested")
print("1 Interested")
value = input("")
value = int(value)
if(value==1):
city = city_input()
amenities = pd.read_csv('cities/'+ city + '.csv')
df = pd.read_csv('categories.csv')
category = df['health'].dropna()
medical = amenities[amenities['amenity'].isin(category)]
if(medical.empty):
print("Sorry no popular resturant place found in your city")
else:
execute_medical_AI(medical)
print()
print("I might help you with one more adviced if you will be planning to go a work related service")
print("0 Not interested")
print("1 Interested")
value = input("")
value = int(value)
if(value==1):
city = city_input()
amenities = pd.read_csv('cities/'+ city + '.csv')
df = pd.read_csv('categories.csv')
category = df['work'].dropna()
work = amenities[amenities['amenity'].isin(category)]
if(work.empty):
print("Sorry no popular resturant place found in your city")
else:
execute_work_AI(work)
print()
print("I might help you with one more adviced if you will be planning to go a vehicle related service")
print("0 Not interested")
print("1 Interested")
value = input("")
value = int(value)
if(value==1):
city = city_input()
amenities = pd.read_csv('cities/'+ city + '.csv')
df = pd.read_csv('categories.csv')
category = df['vehicles'].dropna()
vehicles = amenities[amenities['amenity'].isin(category)]
if(vehicles.empty):
print("Sorry no popular resturant place found in your city")
else:
execute_vehicles_AI(vehicles)
if __name__ == '__main__':
main()