-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfinal.py
More file actions
126 lines (107 loc) · 4.54 KB
/
final.py
File metadata and controls
126 lines (107 loc) · 4.54 KB
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
import pandas as pd
import sqlite3
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity
class Restaurant:
def __init__(self, max_price, people, min_price, cuisine, locality, favourite_restaurant=""):
self.max_price = max_price
self.people = people
self.min_price = min_price
self.cuisine = cuisine
self.locality = locality
self.favourite_restaurant = favourite_restaurant
@classmethod
def rest(cls, self):
cnx = sqlite3.connect("roop.db")
lko_rest = pd.read_sql_query("SELECT * FROM rest", cnx)
cnx.close()
lko_rest = lko_rest.drop_duplicates(subset="address", keep="first")
def fav(lko_rest1):
lko_rest1 = lko_rest1.reset_index()
count1 = CountVectorizer(stop_words="english")
count_matrix = count1.fit_transform(lko_rest1["highlights"])
cosine_sim2 = cosine_similarity(count_matrix, count_matrix)
sim = list(enumerate(cosine_sim2[0]))
sim = sorted(sim, key=lambda x: x[1], reverse=True)
sim = sim[1:11]
indi = [i[0] for i in sim]
final = lko_rest1.copy().iloc[indi[0]]
final = pd.DataFrame(final)
final = final.T
for i in range(1, len(indi)):
final1 = lko_rest1.copy().iloc[indi[i]]
final1 = pd.DataFrame(final1)
final1 = final1.T
final = pd.concat([final, final1])
return final
def rest_rec(
cost,
people=2,
min_cost=0,
cuisine=[],
Locality=[],
fav_rest="",
lko_rest=lko_rest,
):
cost = cost + 200
x = cost / people
y = min_cost / people
lko_rest1 = lko_rest.copy().loc[lko_rest["locality"] == Locality[0]]
for i in range(1, len(Locality)):
lko_rest2 = lko_rest.copy().loc[lko_rest["locality"] == Locality[i]]
lko_rest1 = pd.concat([lko_rest1, lko_rest2])
lko_rest1.drop_duplicates(subset="name", keep="last", inplace=True)
lko_rest_locale = lko_rest1.copy()
lko_rest_locale = lko_rest_locale.loc[
lko_rest_locale["average_cost_for_one"] <= x
]
lko_rest_locale = lko_rest_locale.loc[
lko_rest_locale["average_cost_for_one"] >= y
]
lko_rest_locale["Start"] = lko_rest_locale["cuisines"].str.find(cuisine[0])
lko_rest_cui = lko_rest_locale.copy().loc[lko_rest_locale["Start"] >= 0]
for i in range(1, len(cuisine)):
lko_rest_locale["Start"] = lko_rest_locale["cuisines"].str.find(
cuisine[i]
)
lko_rest_cu = lko_rest_locale.copy().loc[lko_rest_locale["Start"] >= 0]
lko_rest_cui = pd.concat([lko_rest_cui, lko_rest_cu])
lko_rest_cui.drop_duplicates(subset="name", keep="last", inplace=True)
if fav_rest != "":
favourite_restaurant = lko_rest.loc[lko_rest["name"] == fav_rest].drop_duplicates()
favourite_restaurant = pd.DataFrame(favourite_restaurant)
lko_rest3 = pd.concat([favourite_restaurant, lko_rest_cui])
lko_rest3.drop("Start", axis=1, inplace=True)
rest_selected = fav(lko_rest3)
else:
lko_rest_cui = lko_rest_cui.sort_values("score", ascending=False)
rest_selected = lko_rest_cui.head(10)
return rest_selected
rest_sugg = rest_rec(
self.max_price,
self.people,
self.min_price,
self.cuisine,
self.locality,
self.favourite_restaurant,
)
rest_list1 = rest_sugg.copy().loc[
:,
[
"name",
"address",
"locality",
"timings",
"aggregate_rating",
"url",
"cuisines",
"votes"
],
]
rest_list = pd.DataFrame(rest_list1)
rest_list = rest_list.reset_index()
rest_list = rest_list.rename(columns={"index": "res_id"})
rest_list.drop("res_id", axis=1, inplace=True)
rest_list = rest_list.T
self.rest_list = rest_list
return