-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
423 lines (328 loc) · 13.1 KB
/
main.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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
from random import *
import datetime
fNames = ["Taylor", "Jake", "Sam", "Logan", "Terry", "Jack", "Guy", "Ignore", "Placeholder", "Name", "Dani", "Becka",
"Lucy", "Brandon", "Nicolas", "Chris", "Alex", "Amelia", "Timothy", "Chamod"]
lNames = ["Smith", "Bolas", "Grant", "Dougan", "Poirier", "Name", "Taylor", "Randall", "Estey", "Jackson", "Chin",
"Kwan", "Butts", "Placeholder"]
city = ["Spruce", "Stony", "Edmonton", "Calgary",
"Quebec City", "Vancouver", "Victoria", "Toronton"]
provinces = ["AB", "BC", "SK", "QB", "NT", "MT"]
country = ["CA", "US", "UK", "RU"]
building = ["Homer", "Flanders", "Marge", "Lisa", "Bart"]
room = ["11", "12", "13", "14", "21", "22", "23", "31", "32"]
depts = ["Biol", "Chem", "Phys", "Math", "Cmpt",
"Hist", "Engl", "Anth", "Stat", "Soci"]
terms = ["Fall", "Winter"]
days = ["mwf", "tth"]
mwf_timeslots = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
tth_timeslots = [1, 2, 3, 4, 5, 6]
def choose_random_characters(num, rand=True):
return ''.join([choice("abcdefghijklmnopqrstuvwxyz") for i in range(randint(1, num) if rand else num)])
def choose_random_num(num, rand=True):
return ''.join([choice("1234567890") for i in range(randint(1, 10) if rand else num)])
def choose_random_city():
return city[randint(0, len(city) - 1)]
def choose_random_province():
return provinces[randint(0, len(provinces) - 1)]
def choose_random_country():
return country[randint(0, len(country) - 1)]
class Address:
def __init__(self):
self.nameS = ""
self.numS = ""
self.apt = ""
self.city = ""
self.province = ""
self.country = ""
self.zip = ""
self.phone = ""
self.make_address()
def make_address(self):
self.nameS = choose_random_characters(10)
self.numS = choose_random_num(10)
self.apt = choose_random_num(10) if randint(0, 1) == 1 else ""
self.city = choose_random_city()
self.province = provinces[randint(0, len(provinces) - 1)]
self.country = choose_random_country()
self.zip = ''.join([choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ") if i % 2 == 0 else choice("1234567890")
for i in range(6)])
self.phone = choose_random_num(10, False)
def address_attributes(self):
return_string = "street_name, street_number, " + \
"city, province, country, zip, phone_number"
return return_string
def address_string(self):
return_string = "'" + self.nameS + "', '" + self.numS + "', '" + \
self.city + "', '" + self.province + "', '" + self.country \
+ "', '" + self.zip + "', '" + self.phone + "'"
return return_string
class Person(Address):
def __init__(self):
self.fName = ""
self.lName = ""
Address.__init__(self)
self.make_person()
def make_person(self):
self.fName = fNames[randint(0, len(fNames) - 1)]
self.lName = lNames[randint(0, len(lNames) - 1)]
def person_attributes(self):
return_string = "first_name, last_name"
return return_string + ", " + self.address_attributes()
def person_string(self):
return_string = "'" + self.fName + "', '" + self.lName + "'"
return return_string + ", " + self.address_string()
class Student(Person):
count = 1111111111
def __init__(self):
Student.count += 1
self.studID = str(Student.count)
self.gender = list({"M", "F", "?"})[randint(0, 2)]
self.classes = []
Person.__init__(self)
def get_id(self):
return self.studID
def student_attributes(self):
return_string = "s_id, gender, sin, email, street_address, date_of_birth"
return return_string + ", " + self.person_attributes()
def student_string(self):
return_string = "" + self.studID + ", '" + self.gender + "', '123456789', '" + \
str(self.studID) + "@" + "wacewan.org', 'placeholder', '01/01/0001'"
return return_string + ", " + self.person_string()
def add_class(self, class_added):
if len(self.classes) < 1:
self.classes.append(class_added)
else:
for c in self.classes:
if c.day != class_added.day or c.timeslot != class_added.timeslot:
self.classes.append(class_added)
break
def get_takes(self):
return [Takes(self, c.sect_id) for c in self.classes]
def get_courses(self):
return self.classes
class Prof(Person):
count = 111111111
def __init__(self, department):
Prof.count += 1
self.profID = str(Prof.count)
self.dept = department
self.salary = randint(1, 12) * 10000
Person.__init__(self)
def get_PID(self):
return self.profID
def prof_attributes(self):
return_string = "i_id, dept, salary, first_name, last_name"
return return_string
def prof_string(self):
return_string = "" + self.profID + ", '" + self.dept + "', " + str(self.salary) + ", '" +\
self.fName + "', '" + self.lName + "'"
return return_string
class Department:
def __init__(self, dept_name):
self.name = dept_name
self.head = ""
self.building = building[randint(0, len(building) - 1)]
self.room = room[randint(0, len(room) - 1)]
self.profs = []
self.courses = []
def set_head(self):
self.head = self.profs[randint(0, len(self.profs) - 1)].get_PID()
def dept_attributes(self):
return_string = "name, building, room"
return return_string
def dept_string(self):
return_string = "'" + self.name + "', '" + \
self.building + "', '" + self.room + "'"
return return_string
def add_prof(self, prof):
self.profs.append(prof)
def add_course(self):
self.courses.append(Course(self.name))
def get_courses(self):
return self.courses
def get_rand_inst(self):
return self.profs[randint(0, len(self.profs)-1)]
class Course:
count = 1111
def __init__(self, department):
Course.count += 1
self.CID = str(Course.count)
self.title = choose_random_characters(10)
self.dept = department
self.sections = []
def course_attributes(self):
return_string = "c_id, title, credit, term, department"
return return_string
def course_string(self):
return_string = "" + self.CID + ", '" + \
self.title + "', 3, 'Fall', '" + self.dept + "'"
return return_string
def get_CID(self):
return self.CID
class Section:
count = 1
def __init__(self, instructor, course):
Section.count += 1
self.sect_id = str(Section.count)
self.inst = instructor
self.year = 2021
self.term = "Fall"
self.room = "111"
self.c_id = course
self.limit = randint(30, 100)
self.enrolled = 0
day_poss = randint(0, 1)
self.timeslot = mwf_timeslots[randint(0, len(
mwf_timeslots)-1)] if day_poss == 0 else tth_timeslots[randint(0, len(tth_timeslots)-1)]
self.day = days[day_poss]
time = 7 + self.timeslot
self.start_time = datetime.datetime.strptime(
str(time) + ":00", "%H:%M")
self.end_time = datetime.datetime.strptime(
str(time + 1) + ":00", "%H:%M")
def get_cid(self):
return self.c_id
def course_attributes(self):
return_string = "section_id, year, term, start_time, end_time, days, room_number, instructor, course, student_limit"
return return_string
def course_string(self):
return_string = "" + self.sect_id + ", '" + str(self.year) + "', '" + self.term + "', '" +\
str(self.start_time) + "', '" + str(self.end_time) + "', '" + self.day + "', '" + self.room + "', '" +\
self.inst + "', " + str(self.c_id) + ", " + str(self.limit)
return return_string
def not_full(self):
return self.enrolled < self.limit
def increment_enroll(self):
self.enrolled += 1
def set_term(self, new_term):
self.term = new_term
class Prereqs:
def __init__(self, c1, c2):
self.course = c1.get_CID()
self.prereq = c2.get_CID()
def pre_attributes(self):
return_string = "c_id, p_id"
return return_string
def pre_string(self):
return_string = "'" + self.course + "', '" + self.prereq + "'"
return return_string
def get_related(self, cid):
if cid == self.prereq:
return self.course
if cid == self.course:
return self.prereq
return cid
class Takes:
def __init__(self, student, section):
self.student = student.get_id()
self.course = section
def take_attributes(self):
return_string = "s_id, c_id"
return return_string
def take_string(self):
return_string = "" + self.student + ", " + self.course + ""
return return_string
def framing(table, attributes, values):
command = "INSERT INTO " + table + " (" + attributes + ")\n" \
+ "VALUES (" + values + ")"
return command
open('query_file.sql', 'w').close()
my_file = open("query_file.sql", "w+")
# make departments
departments = []
for dept_name in depts:
departments.append(Department(dept_name))
my_file.write(framing(
"department", departments[-1].dept_attributes(), departments[-1].dept_string()) + "\n")
# make profs
for indi_dept in departments:
profs_in = randint(10, 20)
for i in range(profs_in):
new_prof = Prof(indi_dept.name)
indi_dept.add_prof(new_prof)
my_file.write(framing(
"instructor", new_prof.prof_attributes(), new_prof.prof_string()) + "\n")
# assign head
indi_dept.set_head()
# make students
students = []
student_count = randint(10000, 15000)
for i in range(student_count):
students.append(Student())
my_file.write(framing(
"student", students[-1].student_attributes(), students[-1].student_string()) + "\n")
# make courses
prereqs = []
for indi_dept in departments:
cor_num = randint(5, 15)
for i in range(cor_num):
indi_dept.add_course()
my_file.write(framing(
"course", indi_dept.courses[-1].course_attributes(), indi_dept.courses[-1].course_string()) + "\n")
# add course pre req
if i > 5:
num_prereqs = randint(0, 2)
for i in range(num_prereqs):
prereqs.append(Prereqs(
indi_dept.courses[-1], indi_dept.courses[randint(0, len(indi_dept.courses)-2)]))
my_file.write(framing(
"prereq", prereqs[-1].pre_attributes(), prereqs[-1].pre_string()) + "\n")
# make sections for year
fall_sections = []
for indi_dept in departments:
for course in indi_dept.get_courses():
z = randint(1, 2)
cor_sec = []
for i in range(z):
# assign profs to sections
inst = indi_dept.get_rand_inst().profID
cor_sec.append(Section(inst, course.CID))
fall_sections.append(cor_sec)
for sect in cor_sec:
my_file.write(
framing("section", sect.course_attributes(), sect.course_string()) + "\n")
# create and print the winter courses available
winter_sections = []
for indi_dept in departments:
for course in indi_dept.get_courses():
z = randint(1, 2)
cor_sec = []
for i in range(z):
# assign profs to sections
inst = indi_dept.get_rand_inst().profID
new_sect = Section(inst, course.CID)
new_sect.set_term("Winter")
cor_sec.append(new_sect)
winter_sections += cor_sec
for sect in cor_sec:
my_file.write(
framing("section", sect.course_attributes(), sect.course_string()) + "\n")
# give students classes, up to 5 but at least 1, , make sure students aren't taking a course and its prereq
for stud in students:
i = 0
num_courses = randint(1, 7)
poss_classes = [i for i in range(len(fall_sections) - 1)]
shuffle(poss_classes)
while i < num_courses and len(poss_classes) > 1:
class_num = poss_classes.pop()
taking_req = False
for req in prereqs:
requisite = req.get_related(fall_sections[class_num][0].get_cid())
for c in stud.get_courses():
if c == requisite:
taking_req = True
a = randint(0, len(fall_sections[class_num])-1)
while a < len(fall_sections[class_num]) and not fall_sections[class_num][a].not_full():
a = a+1
if not taking_req and a < len(fall_sections[class_num]) and fall_sections[class_num][a].not_full():
fall_sections[class_num][a].increment_enroll()
stud.add_class(fall_sections[class_num][a])
i += 1
takes = []
for stud in students:
#takes.append(stud.get_takes())
for take in stud.get_takes():
my_file.write(framing("takes", take.take_attributes(),
take.take_string()) + "\n")
my_file.close()
# start with just the one year