-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudocode-main.txt
338 lines (313 loc) · 15.1 KB
/
pseudocode-main.txt
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
GLOBAL app = Flask(__name__)
app.secret_key = "SIR"
GLLOBLA CONST login_manager = LoginManager()
login_manager.init_app(app)
GLOBAL CONST products = {
"Classics Range": [
Product("Pepperoni Pizza", 21, "Our signature base topped with fresh Italian tomato sauce, spicy cured pork salami and mozzarella cheese.", "https://www.dominos.com.au/ManagedAssets/AU/product/P480/AU_P480_en_hero_12569.jpg?v370349117"),
Product("Chicken Supreme Pizza", 23.50, "Our signature base topped with fresh Italian tomato sauce, 100% Aussie chicken breast, sliced red onion, capsicum, mushrooms, pineapple, mozzarella and oregano.", "https://www.dominos.com.au/ManagedAssets/AU/product/P422/AU_P422_en_hero_8129.jpg?v807560171"),
Product("BBQ Meatlovers Pizza", 25.50, "Our signature base topped with Hickory BBQ sauce, 100% Aussie beef, pepperoni, rasher bacon, Italian sausage, sliced red onion, mozzarella and oregano.", "https://www.dominos.com.au/ManagedAssets/AU/product/P019/AU_P019_en_hero_4055.jpg?v1694200044"),
Product("Veg Supreme Pizza", 22.5, "Our signature base topped with fresh Italian tomato sauce, sliced red onion, capsicum, mushrooms, pineapple, baby spinach, kalamata olives, mozzarella and oregano.", "https://www.dominos.com.au/ManagedAssets/AU/product/P456/AU_P456_en_hero_10451.png?v1150158411"),
Product("Hawaiian Pizza", 19, "Our signature base topped with fresh Italian tomato sauce, 100% Aussie ham, sweet juicy pineapple and mozzarella cheese.", "https://www.dominos.com.au/ManagedAssets/AU/product/P005/AU_P005_en_hero_4055.jpg?v692091788"),
Product("Margherita Pizza", 18.5, "Our signature base topped with fresh Italian tomato sauce, mozzarella cheese and oregano.", "https://www.dominos.com.au/ManagedAssets/AU/product/P301/AU_P301_en_hero_4055.jpg?v-1013096145"),
Product("Spicy Special", 20, "Our signature base topped with fresh Italian tomato sauce, 100% Aussie beef, pepperoni, sliced red onion, jalapeños, chilli flakes, mozzarella and oregano.", "https://www.dominos.com.au/ManagedAssets/AU/product/P502/AU_P502_en_hero_12276.jpg?v1552340311"),
CustomisableProduct("Build Your Own Pizza", 15, "Papa's signature base, topped with sauces and toppings of your choice!", "static/BYOP.png", [
ProductOption("Sauce", {
"Tomato": [0.5, False],
"BBQ": [0.5, False],
"Pesto": [1.5, False],
}),
ProductOption("Cheese", {
"Mozzarella": [0.5, False],
"Cheddar": [0.5, False],
"Parmesan": [1.5, False],
}),
ProductOption("Meat", {
"Pepperoni": [1, False],
"Ham": [1, False],
"Beef": [1.5, False],
"Chicken": [1.5, False],
"Bacon": [1.5, False],
"Sausage": [1.5, False],
"Salami": [1.5, False],
"Pork": [1.5, False],
}),
ProductOption("Vegetables", {
"Pineapple": [0.5, False],
"Mushroom": [0.5, False],
"Onion": [0.5, False],
"Capsicum": [0.5, False],
"Olives": [0.5, False],
"Jalapenos": [0.5, False],
"Spinach": [0.5, False],
"Tomato": [0.5, False],
"Chilli": [0.5, False],
"Garlic": [0.5, False],
"Mystery": [1.5, False],
})
])
],
"Sides": [
Product("Garlic Bread", 8, "Oven baked bread, topped with garlic and herb butter.", "https://order.dominos.com.au/ManagedAssets/AU/product/S00001/AU_S00001_en_hero_3970.jpg?v914720366"),
Product("Cheesy Garlic Bread", 10, "Oven baked bread, topped with garlic and herb butter, infused with aromatic mozzarella cheese.", "https://www.dominos.com.au/ManagedAssets/AU/product/S00335/AU_S00335_en_hero_3970.jpg?v1445520942"),
Product("Straight-Cut Chips", 10, "Oven baked chips, seasoned with salt and pepper.", "https://www.dominos.com.au/ManagedAssets/AU/product/S00016/AU_S00016_en_hero_12301.jpg?v1581437728"),
Product("Spicy Loaded Chips", 14, "Oven baked chips, topped with spicy beef, pepperoni, sliced red onion, jalapeños, chilli flakes, and Papa's signature cheese sauce.", "https://www.dominos.com.au/ManagedAssets/AU/product/S00568/AU_S00568_en_hero_12569.jpg?v2043401138"),
],
"Drinks": [
CustomisableProduct("Pepsi", 2, "1.25L/600mL. Coca-Cola is the most popular soft drink in history, as well as the best-known brand in the world.", "https://www.dominos.com.au/ManagedAssets/AU/variety/Variety.Pepsi/AU_Variety.Pepsi_en_menu_12324.jpg?v-1367151555", [
ProductOption("Size", {
"1.25L": [1, False],
"600mL": [0, False]
}, False)
]),
CustomisableProduct("Solo", 2, "1.25L/600mL. Solo is the world's leading lemon-lime flavoured soft drink.", "https://www.dominos.com.au/ManagedAssets/AU/variety/Variety.Solo/AU_Variety.Solo_en_menu_12324.jpg?v229998257", [
ProductOption("Size", {
"1.25L": [1, False],
"600mL": [0, False]
}, False)
]),
CustomisableProduct("Sunkist", 2.5, "1.25L/600mL. Sunkist is a bubbly, fruit-flavoured soft drink that has a great, fruity taste.", "https://www.dominos.com.au/ManagedAssets/AU/variety/Variety.Sunkist/AU_Variety.Sunkist_en_menu_12324.jpg?v545627267", [
ProductOption("Size", {
"1.25L": [1, False],
"600mL": [0, False]
}, False)
]),
CustomisableProduct("Mountain Dew", 2.5, "1.25L/600mL. For the gamers.", "https://www.dominos.com.au/ManagedAssets/AU/variety/Variety.MountainDew/AU_Variety.MountainDew_en_menu_12324.jpg?v2083099670", [
ProductOption("Size", {
"1.25L": [1, False],
"600mL": [0, False]
}, False)
]),
CustomisableProduct("Build Your Own Milkshake", 8, "Choose from a variety of flavours and toppings to create your own milkshake!", "https://www.dominos.com.au/ManagedAssets/AU/variety/Variety.Milkshake/AU_Variety.Milkshake_en_menu_12324.jpg?v-1367151555", [
ProductOption("Flavour", {
"Chocolate": [1.5, False],
"Strawberry": [1.5, False],
"Vanilla": [1.5, False],
"Mint": [2, False],
}),
ProductOption("Topping", {
"Chocolate Syrup": [0.5, False],
"Strawberry Syrup": [0.5, False],
"Caramel Syrup": [0.5, False],
"Mystery": [1.5, False],
})
])
],
}
GLOBAL cart = []
FUNCTION load_user(user_id)
users = OPEN_READ("users.txt")
lines = []
WHILE NOT users.EOF
line = users.READLINE()
user = User.parse_from_text(line.strip())
IF user.cust_id == user_id THEN
RETURN user
END IF
END WHILE
RETURN None
END load_user
FUNCTION create_product(product_name, options)
new_product = NULL
FOR EACH category IN products DO
FOR EACH product IN products[category] DO
IF product.name == product_name THEN
new_product = DEEP_COPY(product)
BREAK
END IF
END FOR
END FOR
IF new_product == NULL THEN
RAISE ValueError("Invalid product name")
END IF
IF new_product.is_customisable() THEN
FOR EACH option_name IN options DO
FOR EACH option_value IN options[option_name] DO
new_product.set_option(option_name, option_value)
END FOR
END FOR
END IF
RETURN new_product
END create_product
FUNCTION action_login(id, password)
user = load_user(id)
IF user == None THEN
flash('Invalid ID. Please try again.')
RETURN render_template('login.html')
END IF
login_user(user)
IF user != None AND user.check_password(password) THEN
RETURN render_template('login.html')
END IF
END action_login
FUNCTION action_signup(first_name, last_name, cust_id, address, email, password, loyalty)
IF User.check_if_user_exists(cust_id) THEN
flash('User with ID already exists. Please try again.')
RETURN render_template('login.html')
END IF
user = new User(first_name, last_name, cust_id, address, email, password, loyalty)
users = OPEN_WRITE('users.txt')
users.WRITELINE(user.parse_to_text())
flash('Account created successfully! You can now log in.')
CLOSE('users.txt')
RETURN render_template('login.html')
END action_signup
@app.route('/')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/menu', methods=['GET', 'POST'])
def menu():
if request.method == 'POST':
new_product = create_product(request.form['name'], dict((key, request.form.getlist(key)) for key in request.form.keys()))
cart.append(new_product)
return render_template('menu.html', products=products)
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST' and 'adminpassword' in request.form: #a POST request from the form
if request.form['adminpassword'] != 'admin':
flash('Invalid password. Please try again.')
else:
#set route to admin page
return redirect(url_for('admin'))
return render_template('login.html')
elif request.method == 'POST' and 'login' in request.form:
return action_login(request.form['custid'], request.form['password'])
elif request.method == 'POST' and 'signup' in request.form:
first_name = request.form['firstname']
last_name = request.form['lastname']
cust_id = request.form['custid']
address = request.form['address']
email = request.form['email']
password = request.form['password']
loyalty = False
if 'loyaltymember' in request.form:
loyalty = True if request.form["loyaltymember"] == "on" else False
return action_signup(first_name, last_name, cust_id, address, email, password, loyalty)
return render_template('login.html')
@app.route('/cart', methods=['GET', 'POST'])
def cart_page():
delivery = False
added = False
if request.method == 'POST':
print(request.form)
print('POST')
if 'delivery' in request.form:
print('interesting')
delivery = True
if 'place_order' in request.form:
print('huh')
added = True
subtotal = sum([product.price for product in cart]) #product.price IMPLEMENTS POLYMORPHISM!!!
total = subtotal
over_one_hundred = False
loyalty = False
discount_amount = 0
if delivery:
total += 8
if subtotal > 100:
over_one_hundred = True
discount_amount = 0.05 * total
total -= discount_amount
elif current_user.is_authenticated:
if current_user.loyalty_member:
loyalty = True
discount_amount = 0.05 * total
total -= discount_amount
gst = total / 11
if added:
print('added')
if len(cart) > 0:
print('len is valid')
today = date.today()
order = Order(current_user, cart, delivery, today, total)
with open('orders.txt', 'a') as f:
f.write(order.parse_to_text())
cart.clear()
flash('Order placed successfully!')
redirect(url_for('home'))
else:
flash('Cart is empty. Please add items to cart before placing an order.')
return render_template('cart.html', items=cart, subtotal=subtotal, gst=gst, total=total, delivery=delivery, loyalty=loyalty, discount=discount_amount, over_one_hundred=over_one_hundred)
def delivery_frequency(orders: list):
delivery_frequency = []
for order in orders:
date = order.date.strftime('%Y-%m-%d')
found = False
for i in range(len(delivery_frequency)):
if delivery_frequency[i][0] == date:
delivery_frequency[i][1] += 1
found = True
break
if not found:
delivery_frequency.append([date, 1])
return json.dumps(delivery_frequency)
def total_sales(orders: list):
total_sales = []
for order in orders:
date = order.date.strftime('%Y-%m-%d')
found = False
for i in range(len(total_sales)):
if total_sales[i][0] == date:
total_sales[i][1] += order.total
found = True
break
if not found:
total_sales.append([date, order.total])
return json.dumps(total_sales)
def product_sales(orders: list):
product_sales = {}
for order in orders:
for product in order.products:
if product.name not in product_sales:
product_sales[product.name] = [[order.date.strftime('%Y-%m-%d'), 1]]
else:
found = False
for i in range(len(product_sales[product.name])):
if product_sales[product.name][i][0] == order.date.strftime('%Y-%m-%d'):
product_sales[product.name][i][1] += 1
found = True
break
if not found:
product_sales[product.name].append([order.date.strftime('%Y-%m-%d'), 1])
for product in product_sales:
product_sales[product] = json.dumps(product_sales[product])
return json.dumps(product_sales)
@app.route('/admin')
def admin():
all_orders = []
#orders are seperated by ==========, set string as everything inside
with open('orders.txt', 'r') as f:
string = ""
parse_number = 0
for line in f:
if line.strip() == "==========" and parse_number != 0:
parse_number += 1
all_orders.append(Order.parse_from_text(string))
string = ""
elif parse_number == 0 and line.strip() == "==========":
parse_number += 1
else:
string += line
if string:
all_orders.append(Order.parse_from_text(string))
#2d list for delivery frequenncy per day in format [date, frequency]
delivery_json = delivery_frequency(all_orders)
#2d list for total sales per day in format [date, sales] where sales is the sum of total prices of orders on that day
total_sales_json = total_sales(all_orders)
#dictionary with format {'product_name': [[date, quantity sold], [date, quantity sold], ...]}
product_sales_json = product_sales(all_orders)
list_of_products_sold = []
for order in all_orders:
for product in order.products:
list_of_products_sold.append(product.name)
list_of_products_sold = list(set(list_of_products_sold))
return render_template('admin.html', list_of_products_sold=list_of_products_sold, delivery_json=delivery_json, total_sales_json=total_sales_json, product_sales_json=product_sales_json)
@app.route('/logout')
@login_required
def logout():
logout_user()
flash('You have been logged out.')
return render_template('home.html')