Skip to content

Commit f62e49c

Browse files
committed
pray
1 parent e4532aa commit f62e49c

File tree

15 files changed

+2044
-109
lines changed

15 files changed

+2044
-109
lines changed

‎answers.txt‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
SELECT DISTINCT *
3+
FROM public."Dhall" as dh
4+
LEFT JOIN public."{name}_Calories" as c ON c."Name" = dh."Name"
5+
WHERE "Location" ILIKE '%{name}%'
6+
7+
SELECT *
8+
FROM public."Dhall"
9+
WHERE "Ingredients" ILIKE '%{name}%'
10+
11+
SELECT DISTINCT *
12+
FROM public."Dhall"
13+
WHERE "Meal Type" ILIKE '%{name}%'

‎app.py‎

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
importos
22
fromdatetimeimportdatetime
3-
4-
fromflaskimportFlask, redirect, render_template, request, send_from_directory, url_for
3+
fromflaskimportFlask, jsonify, redirect, render_template, request, send_from_directory, url_for
54
fromflask_migrateimportMigrate
65
fromflask_sqlalchemyimportSQLAlchemy
76
fromflask_wtf.csrfimportCSRFProtect
8-
7+
fromsqlalchemyimportMetaData
98

109
app=Flask(__name__, static_folder='static')
1110
csrf=CSRFProtect(app)
@@ -36,83 +35,88 @@
3635

3736
@app.route('/', methods=['GET'])
3837
defindex():
39-
print('Request for index page received')
40-
restaurants=Restaurant.query.all()
41-
returnrender_template('index.html', restaurants=restaurants)
42-
43-
@app.route('/<int:id>', methods=['GET'])
44-
defdetails(id):
45-
restaurant=Restaurant.query.where(Restaurant.id==id).first()
46-
reviews=Review.query.where(Review.restaurant==id)
47-
returnrender_template('details.html', restaurant=restaurant, reviews=reviews)
48-
49-
@app.route('/create', methods=['GET'])
50-
defcreate_restaurant():
51-
print('Request for add restaurant page received')
52-
returnrender_template('create_restaurant.html')
53-
54-
@app.route('/add', methods=['POST'])
55-
@csrf.exempt
56-
defadd_restaurant():
57-
try:
58-
name=request.values.get('restaurant_name')
59-
street_address=request.values.get('street_address')
60-
description=request.values.get('description')
61-
except (KeyError):
62-
# Redisplay the question voting form.
63-
returnrender_template('add_restaurant.html',{
64-
'error_message': "You must include a restaurant name, address, and description",
65-
})
66-
else:
67-
restaurant=Restaurant()
68-
restaurant.name=name
69-
restaurant.street_address=street_address
70-
restaurant.description=description
71-
db.session.add(restaurant)
72-
db.session.commit()
38+
returnrender_template('index.html')
39+
40+
@app.route('/dining_hall/<name>', methods= ['GET'])
41+
defdiningHall(name):
42+
43+
# TODO Write SQL Query to get all food items at dining hall ->{name}
44+
45+
sql=f'''
46+
SELECT NULL
47+
'''
48+
49+
withdb.engine.connect() asconn:
50+
result=conn.execute(db.text(sql)).fetchall()
51+
52+
rows= [dict(row._mapping) forrowinresult]
53+
returnrender_template('index.html', results=rows)
54+
55+
@app.route('/meat/<name>', methods= ['GET'])
56+
defmeat(name):
7357

74-
returnredirect(url_for('details', id=restaurant.id))
58+
# TODO Write SQL Query to get all food items containing meat ->{name}
7559

76-
@app.route('/review/<int:id>', methods=['POST'])
60+
sql=f'''
61+
SELECT NULL
62+
'''
63+
64+
withdb.engine.connect() asconn:
65+
result=conn.execute(db.text(sql)).fetchall()
66+
67+
rows= [dict(row._mapping) forrowinresult]
68+
returnrender_template('index.html', results=rows)
69+
70+
@app.route('/meal_type/<name>', methods= ['GET'])
71+
defmealType(name):
72+
name=name.lower()
73+
74+
# TODO Write SQL Query to get all food item served during meal_type ->{name}
75+
76+
sql=f'''
77+
SELECT NULL
78+
'''
79+
80+
withdb.engine.connect() asconn:
81+
result=conn.execute(db.text(sql)).fetchall()
82+
83+
rows= [dict(row._mapping) forrowinresult]
84+
returnrender_template('index.html', results=rows)
85+
86+
87+
@app.route('/add_dhall', methods=['POST'])
7788
@csrf.exempt
78-
defadd_review(id):
89+
defadd_dhall():
7990
try:
80-
user_name=request.values.get('user_name')
81-
rating=request.values.get('rating')
82-
review_text=request.values.get('review_text')
83-
except (KeyError):
84-
#Redisplay the question voting form.
85-
returnrender_template('add_review.html',{
86-
'error_message': "Error adding review",
91+
name=request.form.get('name')
92+
ingredients=request.form.get('ingredients')
93+
station=request.form.get('station')
94+
location=request.form.get('location')
95+
meal_type=request.form.get('meal_type')
96+
item_id=request.form.get('item_id') # BIGINT
97+
exceptKeyErrorase:
98+
returnjsonify({'error': f'Missing parameter: {str(e)}'}), 400
99+
100+
sql='''
101+
INSERT INTO public."Dhall" ("Name", "Ingredients", "Station", "Location", "Meal Type", "Item ID")
102+
VALUES (:name, :ingredients, :station, :location, :meal_type, :item_id)
103+
'''
104+
105+
withdb.engine.begin() asconn:
106+
conn.execute(db.text(sql),{
107+
'name': name,
108+
'ingredients': ingredients,
109+
'station': station,
110+
'location': location,
111+
'meal_type': meal_type,
112+
'item_id': int(item_id)
87113
})
88-
else:
89-
review=Review()
90-
review.restaurant=id
91-
review.review_date=datetime.now()
92-
review.user_name=user_name
93-
review.rating=int(rating)
94-
review.review_text=review_text
95-
db.session.add(review)
96-
db.session.commit()
97-
98-
returnredirect(url_for('details', id=id))
99-
100-
@app.context_processor
101-
defutility_processor():
102-
defstar_rating(id):
103-
reviews=Review.query.where(Review.restaurant==id)
104-
105-
ratings= []
106-
review_count=0
107-
forreviewinreviews:
108-
ratings+= [review.rating]
109-
review_count+=1
110-
111-
avg_rating=sum(ratings) /len(ratings) ifratingselse0
112-
stars_percent=round((avg_rating/5.0) *100) ifreview_count>0else0
113-
return{'avg_rating': avg_rating, 'review_count': review_count, 'stars_percent': stars_percent}
114-
115-
returndict(star_rating=star_rating)
114+
115+
returnredirect(url_for('index'))
116+
117+
@app.route('/add_dhall_form', methods=['GET'])
118+
defadd_dhall_form():
119+
returnrender_template('add.html')
116120

117121
@app.route('/favicon.ico')
118122
deffavicon():

‎data/Granby.csv‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Name,Ingredients,Station,Location,Meal Type,Item ID,DiningHall
2+
General Tso's Chicken ,"Ingredients: ""CHICKEN BREAST BNLS SKNLS RANDOM CVP FRESH - DRAINED, TRIMMED, SLICED"" (ingredient details unavailable at this time), ""SAUCE GENERAL TSO RTU"" (ingredient details unavailable at this time), ""VEGETABLE FRESH CARROT - TRIMMED, SLICED"" (ingredient details unavailable at this time), ""VEGETABLE FRESH ONION YELLOW - TRIMMED, CUT"" (ingredient details unavailable at this time), ""VEGETABLE FRESH BROCCOLI AP CROWNS - TRIMMED, CUT"" (ingredient details unavailable at this time), ""VEGETABLE FRESH PEPPER GREEN - SEEDED, CUT"" (ingredient details unavailable at this time), ""VEGETABLE FRESH ONION GREEN SCALLION - TRIMMED"" (ingredient details unavailable at this time), ""OIL OLIVE EXTRA VIRGIN"" (ingredient details unavailable at this time)",Kosher Kitchen,Kosher Kitchen ,lunch,1,Granby
3+
Rosemary Roast Potatoes,"Ingredients: ""VEGETABLE FRESH POTATO RED SIZE SMALL ""B"" - CUT"" (ingredient details unavailable at this time), ""OIL BLEND VEGETABLE 90 / EVO 10"" (ingredient details unavailable at this time), ""SALT KOSHER"" (ingredient details unavailable at this time), ""HERB FRESH ROSEMARY - LEAVES, MINCED"" (ingredient details unavailable at this time), ""SPICE PEPPER BLACK TABLE GRIND"" (ingredient details unavailable at this time)",Kosher Kitchen,Kosher Kitchen ,lunch,2,Granby
4+
Garlic Roasted Vegetables,"Ingredients: ""VEGETABLE FRESH SQUASH YELLOW - TRIMMED, CUT"" (ingredient details unavailable at this time), ""VEGETABLE FRESH SQUASH ZUCCHINI - TRIMMED, CUT"" (ingredient details unavailable at this time), ""VEGETABLE FRESH ONION YELLOW - TRIMMED, CUT"" (ingredient details unavailable at this time), ""VEGETABLE FRESH MUSHROOM - TRIMMED, SLICED"" (ingredient details unavailable at this time), ""VEGETABLE FRESH PEPPER GREEN - SEEDED, DICED"" (ingredient details unavailable at this time), ""VEGETABLE FRESH PEPPER RED - SEEDED, CUT"" (ingredient details unavailable at this time), ""VEGETABLE FRESH GARLIC WHOLE CLOVES AP PEELED - MINCED"" (ingredient details unavailable at this time), ""OIL BLEND VEGETABLE 90 / EVO 10"" (ingredient details unavailable at this time), ""SEASONING ITALIAN"" (ingredient details unavailable at this time)",Kosher Kitchen,Kosher Kitchen ,lunch,3,Granby
5+
Hot Dog,"Ingredients: ""VEGETABLE FRESH ONION YELLOW - TRIMMED, DICED"" (ingredient details unavailable at this time), ""MUSTARD YELLOW"" (ingredient details unavailable at this time), ""ROLL HOT DOG GF 2 OZ - THAWED"" (ingredient details unavailable at this time), ""FRANK MEAT 8/1 6"" FZ - THAWED"" (ingredient details unavailable at this time)",Kosher Kitchen,Kosher Kitchen ,lunch,4,Granby
6+
Bbq Chicken,"Ingredients: ""SAUCE BBQ SWEET BABY RAY'S"" (ingredient details unavailable at this time), ""SEASONING ROTISSERIE CHICKEN"" (ingredient details unavailable at this time), ""CHICKEN 8 CUT 4.5 OZ IQF - THAWED"" (ingredient details unavailable at this time)",Kosher Kitchen,Kosher Kitchen ,dinner,5,Granby
7+
Scallion Mashed Potatoes Non Dairy,"Ingredients: ""VEGETABLE FRESH POTATO RED SIZE SMALL ""B"" - CUT"" (ingredient details unavailable at this time), ""MILK SOY REFRIGERATED"" (ingredient details unavailable at this time), ""MARGARINE SOLID UNSALTED ZTF"" (ingredient details unavailable at this time), ""VEGETABLE FRESH ONION GREEN SCALLION - TRIMMED, SLICED"" (ingredient details unavailable at this time), ""SALT KOSHER"" (ingredient details unavailable at this time), ""SPICE PEPPER BLACK TABLE GRIND"" (ingredient details unavailable at this time)",Kosher Kitchen,Kosher Kitchen ,dinner,6,Granby
8+
Lemon Sesame Green Beans,"Ingredients: ""VEGETABLE FRESH BEAN GREEN WHOLE - TRIMMED"" (ingredient details unavailable at this time), ""OIL SESAME"" (ingredient details unavailable at this time), ""VEGETABLE FRESH GARLIC WHOLE CLOVES AP PEELED - MINCED"" (ingredient details unavailable at this time), ""SPICE SESAME SEED WHOLE WHITE"" (ingredient details unavailable at this time), ""FRUIT FRESH LEMON ZEST - GRATED"" (ingredient details unavailable at this time), ""HERB FRESH CILANTRO - LEAVES, CHOPPED"" (ingredient details unavailable at this time), ""SALT KOSHER"" (ingredient details unavailable at this time), ""SPICE PEPPER BLACK TABLE GRIND"" (ingredient details unavailable at this time)",Kosher Kitchen,Kosher Kitchen ,dinner,7,Granby

‎data/Granby_calories.csv‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Name,Calories
2+
General Tso's Chicken ,170
3+
Rosemary Roast Potatoes,85
4+
Garlic Roasted Vegetables,55
5+
Hot Dog,335
6+
Bbq Chicken,345
7+
Scallion Mashed Potatoes Non Dairy,95
8+
Lemon Sesame Green Beans,50

0 commit comments

Comments
(0)