-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.py
262 lines (215 loc) · 7.12 KB
/
setup.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
"""
Run this file once to setup your database.
"""
from app import db
from app.models import (Servery, MealTime, Meal, MealDish, User,
Dish)
from app.util import current_rice_time
import random
from datetime import time
import datetime
import calendar
def setup_all():
setup_db()
setup_serveries()
db.session.commit()
load_fake_users()
db.session.commit()
def setup_db():
db.drop_all()
db.create_all()
def load_fake_users():
u1 = User(username="a", email="[email protected]")
u2 = User(username="b", email="[email protected]")
db.session.add(u1)
db.session.add(u2)
db.session.commit()
def create_fake_meals_for_current_month():
date = current_rice_time().date()
number_of_days_in_month = calendar.monthrange(date.year, date.month)[1]
for day in range(1, number_of_days_in_month+1):
that_day = datetime.date(date.year, date.month, day)
day_of_the_week = that_day.weekday()
mealtimes = db.session.query(MealTime).filter(
MealTime.day_of_the_week == day_of_the_week).all()
for mealtime in mealtimes:
create_fake_meal(mealtime, that_day)
db.session.commit()
def create_fake_meal(mealtime, date):
meal = Meal(mealtime=mealtime, date=date)
db.session.add(meal)
create_fake_dishes(meal, 5)
def create_fake_dishes(meal, number_of_dishes):
dish_options = db.session.query(Dish).filter(
Dish.servery == meal.mealtime.servery).all()
for dish in random.sample(dish_options, number_of_dishes):
mealdish = MealDish(dish=dish, meal=meal)
db.session.add(mealdish)
def setup_serveries():
serv_info = [
{
'name': 'north',
'fullname': 'North Servery',
'serv_type': 0,
'image': {
'link': './static/img/placeholder.jpeg'
},
"location": {
"latitude": 29.721883,
"longitude": -95.396546
},
'colleges_served': ['Martel', 'Jones', 'Brown'],
'description': 'filler'
},
{
'name': 'seibel',
'fullname': 'Seibel Servery, Abe and Annie',
'serv_type': 0,
'image': {
'link': './static/img/placeholder.jpeg'
},
"location": {
"latitude": "29.716158",
"longitude": "-95.398241"
},
'colleges_served': ['Will Rice', 'Lovett'],
'description': 'filler'
},
{
'name': 'south',
'fullname': 'South Servery',
'serv_type': 1,
'image': {
'link': './static/img/placeholder.jpeg'
},
"location": {
"latitude": "29.715484",
"longitude": "-95.401024"
},
'colleges_served': ['Hanszen', 'Wiess'],
'description': 'filler'
},
{
'name': 'west',
'fullname': 'West Servery',
'serv_type': 1,
'image': {
'link': './static/img/placeholder.jpeg'
},
"location": {
"latitude": "29.721063",
"longitude": "-95.398481"
},
'colleges_served': ['Duncan', 'McMurtry'],
'description': 'filler'
},
{
'name': 'baker',
'fullname': 'Baker College Kitchen',
'serv_type': 2,
'image': {
'link': './static/img/placeholder.jpeg'
},
"location": { # baker college coordinates
"latitude": "29.716976",
"longitude": "-95.399289"
},
'colleges_served': ['Baker'],
'description': 'filler'
},
{
'name': 'sid',
'fullname': 'Sid Richardson Kitchen',
'serv_type': 2,
'image': {
'link': './static/img/placeholder.jpeg'
},
"location": { # sid rich college coordinates
"latitude": "29.715162",
"longitude": "-95.398915"
},
'colleges_served': ['Sid Richardson'],
'description': 'filler'
}
]
# fills servery times
fill_servery(serv_info)
for serv in serv_info:
servery_data = Servery(name=serv['name'], fullname=serv['fullname'])
days = serv['opening_hours']['periods']
for day in days:
for meal_type in days[day].keys():
mealtime = MealTime(
meal_type=meal_type,
day_of_the_week=day,
start_time=days[day][meal_type]['time_open'],
end_time=days[day][meal_type]['time_close'])
servery_data.mealtimes.append(mealtime)
db.session.add(servery_data)
db.session.commit()
def fill_servery(serv):
"""
fills in servery open times
serv type 0 is North/Seibel
serv type 1 is South/West
serv type 2 is Sid/Baker
serv is the servery JSON object and index is its position
"""
for index in xrange(len(serv)):
serv_type = serv[index]["serv_type"]
periods = {}
# M-H
for i in xrange(0, 5):
periods[str(i)] = {
"breakfast": {
"time_open": time(7, 30),
"time_close": time(10, 30)
},
"lunch": {
"time_open": time(11, 30),
"time_close": time(13, 30)
},
"dinner": {
"time_open": time(17, 30),
"time_close": time(19, 30)
}
}
# remove Friday dinners cause they are different for everyone
if i == 4:
del(periods[str(i)]["dinner"])
# add other times for non Sid/Baker
if serv_type in [0, 1]:
# add friday dinner
periods["4"]["dinner"] = {
"time_open": time(17, 0),
"time_close": time(19, 0)
}
# adds sunday dinner and lunch
periods["6"] = {
"lunch": {
"time_open": time(11, 30),
"time_close": time(14, 0)
},
"dinner": {
"time_open": time(17, 0),
"time_close": time(19, 0)
}
}
# adds Saturday lunch/dinner to North/Seibel
if serv_type == 0:
periods["5"] = {
"breakfast": {
"time_open": time(9, 0),
"time_close": time(11, 0)
},
"lunch": {
"time_open": time(11, 30),
"time_close": time(14, 0)
}
}
serv[index]["opening_hours"] = {
"periods": periods
}
del serv[index]["serv_type"]
if __name__ == "__main__":
setup_all()