Skip to content

Commit 5a53a80

Browse files
feat: user & restaurant mock data (#48)
Co-authored-by: Ben Petrillo <benpetrillo.bp@gmail.com>
1 parent e9db6ed commit 5a53a80

File tree

6 files changed

+148
-6
lines changed

6 files changed

+148
-6
lines changed
Binary file not shown.
3.38 KB
Binary file not shown.

backend/cmd/db/script/insert_db.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
from pymongo import MongoClient
2-
from restaurant_setup import convert_to_mongo_db_format, load_env_variable
2+
from restaurant_setup import convert_to_mongo_db_format, load_env_variable, generate_mock_restaurant_data
3+
from users_setup import generate_user_data
34

45
mongo_db_uri = load_env_variable("backend/.env", "MONGO_DB_URI")
56
client = MongoClient(mongo_db_uri)
6-
db = client['dev-restaurants-api']
7+
db = client['Production']
78
collection = db['restaurants']
89

910
def insert_db(restaurants):
1011
for place in restaurants:
1112
collection.insert_one(place)
13+
14+
def delete_documents():
15+
collection.delete_many({})
1216

13-
restaurants_for_mongo = convert_to_mongo_db_format()
14-
insert_db(restaurants_for_mongo)
17+
#restaurants_for_mongo = convert_to_mongo_db_format()
18+
# users_for_mongo = generate_user_data()
19+
mock_restaurant_data = generate_mock_restaurant_data()
20+
insert_db(mock_restaurant_data)
21+
# delete_documents()

backend/cmd/db/script/restaurant_setup.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import requests
22
#from googlemaps import GooglePlaces, types, lang
33
import json
4+
import pandas as pd
5+
import random
6+
7+
min_num = 0 # Minimum value of review id
8+
max_num = 50 # Maximum value of review id
9+
min_size = 0 # Minimum size of the amount of reviews
10+
max_size = 50 # Maximum size of the amount of reviews
11+
style_list = ['Pub', 'Restaurant', 'Bar', 'Cafe']
412

513
def load_env_variable(file_path, key):
614
with open(file_path, "r") as f:
@@ -118,7 +126,52 @@ def convert_to_mongo_db_format():
118126
restaurants_for_mongo.append(restaurant_for_mongo)
119127
return restaurants_for_mongo
120128

129+
def generate_mock_restaurant_data():
130+
mock_restaurants = []
131+
df = pd.read_csv("backend/cmd/db/script/mock_restaurant_data.csv")
132+
tags = {}
133+
tags['servesBreakfast'] = 'Serves Breakfast'
134+
tags['servesLunch'] = 'Serves Lunch'
135+
tags['servesDinner'] = 'Serves Dinner'
136+
tags['servesBeer'] = 'Serves Beer'
137+
tags['servesWine'] = 'Serves Wine'
138+
tags['servesBrunch'] = 'Serves Brunch'
139+
tags['servesVegetarianFood'] = 'Serves Vegetarian Food'
140+
tags['servesCocktails'] = 'Serves Cocktails'
141+
tags['servesDessert'] = 'Serves Dessert'
142+
tags['servesCoffee'] = 'Serves Coffee'
143+
available_tags = ['servesBreakfast', 'servesLunch', 'servesDinner', 'servesBeer', 'servesWine', 'servesBrunch', 'servesVegetarianFood', 'servesCocktails', 'servesDessert', 'servesCoffee']
144+
145+
for index, row in df.iterrows():
146+
mock_restaurants_for_mongo = {}
147+
mock_restaurants_for_mongo['name'] = row['name']
148+
mock_restaurants_for_mongo['address'] = {}
149+
mock_restaurants_for_mongo['address']['street'] = row['address.street']
150+
mock_restaurants_for_mongo['address']['zipcode'] = row['address.zipcode']
151+
mock_restaurants_for_mongo['address']['state'] = row['address.state']
152+
mock_restaurants_for_mongo['address']['location'] = {}
153+
mock_restaurants_for_mongo['address']['location']['latitude'] = row['address.location.latitude']
154+
mock_restaurants_for_mongo['address']['location']['longitude'] = row['address.location.longitude']
155+
list_size = random.randint(min_size, max_size)
156+
menu_list = list(set([random.randint(min_num, max_num) for _ in range(list_size)]))
157+
mock_restaurants_for_mongo['menuItems'] = menu_list
158+
mock_restaurants_for_mongo['ratingAvg'] = {}
159+
mock_restaurants_for_mongo['ratingAvg']['overall'] = row['ratingAvg.overall']
160+
mock_restaurants_for_mongo['ratingAvg']['return'] = row['ratingAvg.return']
161+
mock_restaurants_for_mongo['style'] = style_list[random.randint(0, 3)]
162+
mock_restaurants_for_mongo['picture'] = row['picture']
163+
mock_restaurants_for_mongo['restaurant'] = row['description']
164+
list_size = random.randint(0, 9)
165+
tags_idx_list = list(set([random.randint(0, 9) for _ in range(list_size)]))
166+
tag_list = []
167+
for idx in tags_idx_list:
168+
tag_list.append(available_tags[idx])
169+
mock_restaurants_for_mongo['tags'] = []
170+
for tag in tag_list:
171+
mock_restaurants_for_mongo['tags'].append(tag)
172+
mock_restaurants.append(mock_restaurants_for_mongo)
173+
return mock_restaurants
174+
121175

122176
#google_places_search()
123-
#convert_to_mongo_db_format()
124-
177+
#convert_to_mongo_db_format()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# create restrcution options, choose from random
2+
# have user ids choose from random following/followers, etc.
3+
# use some of mock data
4+
import pandas as pd
5+
import random
6+
7+
restrictions = ['vegetarian', 'gluten free', 'vegan', 'keto', 'low calorie']
8+
user_dict = []
9+
min_num = 0 # Minimum value of review id
10+
max_num = 10000 # Maximum value of review id
11+
min_size = 0 # Minimum size of the amount of reviews
12+
max_size = 50 # Maximum size of the amount of reviews
13+
14+
def generate_user_data():
15+
df = pd.read_csv("backend/cmd/db/script/mock_user_data.csv")
16+
print(len(df))
17+
for index, row in df.iterrows():
18+
user_entry = {}
19+
user_entry['username'] = row['username']
20+
user_entry['password'] = row['password']
21+
list_size = random.randint(min_size, max_size)
22+
random_list = list(set([random.randint(min_num, max_num) for _ in range(list_size)]))
23+
user_entry['reviews'] = random_list
24+
list_size = random.randint(min_size, max_size)
25+
list_size = random.randint(0, 4)
26+
preferences_idx_list = list(set([random.randint(0, 4) for _ in range(list_size)]))
27+
user_entry['preferences'] = {}
28+
preferences_list = []
29+
for idx in preferences_idx_list:
30+
preferences_list.append(restrictions[idx])
31+
user_entry['preferences']['restrictions'] = preferences_list
32+
user_entry['following'] = list(set([random.randint(min_num, max_num) for _ in range(list_size)]))
33+
user_entry['followingCount'] = len(user_entry['following'])
34+
list_size = random.randint(min_size, max_size)
35+
user_entry['followers'] = list(set([random.randint(min_num, max_num) for _ in range(list_size)]))
36+
user_entry['followersCount'] = len(user_entry['followers'])
37+
user_entry['profile_picture'] = ""
38+
user_dict.append(user_entry)
39+
return user_dict
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* global use, db */
2+
// MongoDB Playground
3+
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
4+
5+
const database = 'Production';
6+
const collection = 'restaurants';
7+
8+
// The current database to use.
9+
use(database);
10+
11+
// Create a new collection.
12+
db.createCollection(collection);
13+
14+
// The prototype form to create a collection:
15+
/* db.createCollection( <name>,
16+
{
17+
capped: <boolean>,
18+
autoIndexId: <boolean>,
19+
size: <number>,
20+
max: <number>,
21+
storageEngine: <document>,
22+
validator: <document>,
23+
validationLevel: <string>,
24+
validationAction: <string>,
25+
indexOptionDefaults: <document>,
26+
viewOn: <string>,
27+
pipeline: <pipeline>,
28+
collation: <document>,
29+
writeConcern: <document>,
30+
timeseries: { // Added in MongoDB 5.0
31+
timeField: <string>, // required for time series collections
32+
metaField: <string>,
33+
granularity: <string>,
34+
bucketMaxSpanSeconds: <number>, // Added in MongoDB 6.3
35+
bucketRoundingSeconds: <number>, // Added in MongoDB 6.3
36+
},
37+
expireAfterSeconds: <number>,
38+
clusteredIndex: <document>, // Added in MongoDB 5.3
39+
}
40+
)*/
41+
42+
// More information on the `createCollection` command can be found at:
43+
// https://www.mongodb.com/docs/manual/reference/method/db.createCollection/

0 commit comments

Comments
 (0)