-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCourseCatalogGUI.py
More file actions
618 lines (520 loc) · 28.8 KB
/
Copy pathCourseCatalogGUI.py
File metadata and controls
618 lines (520 loc) · 28.8 KB
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
# Name: Ben Hung & Daniel Wong
# Final Project
# Module: CourseCatalogGUI.py
import tkinter as tk
import sqlite3
from Course import Course
import re
from collections import defaultdict
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
class Plotter():
def __init__(self):
'''Constructor for Plotter'''
self.figure = None
def createPiePlot(self, *params):
'''Create a pie plot of the data by passing parameters'''
key_list, value_list = params
fig, ax = plt.subplots(figsize =(4, 4))
colors = ['#DD7596', '#8EB897']
ax.pie(value_list, labels= key_list, autopct='%1.1f%%', wedgeprops = {'linewidth':3,'edgecolor':'white'}, colors=colors)
ax.set_facecolor('#F0F0F0')
plt.tight_layout()
return fig
def createBarPlot(self, *params):
'''Create a bar plot of the data by passing parameters'''
key_list, value_list = params
fig, ax = plt.subplots(figsize=(4, 4))
plt.xlabel("Years")
plt.ylabel("Number of classes")
if len(key_list) == 1:
ax.bar(range(len(key_list)), value_list, align="center", color="pink")
ax.set_xticks(range(len(key_list)))
key_list.reverse() #Reverses the order of x-ticks so it is correct
ax.set_xticklabels(key_list)
else:
plt.bar(key_list, value_list, align="center", color="pink")
plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))
plt.gca().yaxis.set_major_locator(MaxNLocator(integer=True))
return fig
def createLinePlot(self, *params):
'''Create a line plot of the data by passing parameters'''
online, inperson = params
fig = plt.figure(figsize =(6,6))
plt.plot(online.keys(), online.values(), "-g", label="Online")
plt.plot(inperson.keys(), inperson.values(), "-b", label="In-Person")
plt.legend(loc="best")
plt.xlabel("Years")
plt.ylabel("Number of classes")
plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))
return fig
class Stats(tk.Toplevel):
def __init__(self, master, type, item):
'''Constructor for Stats Class inheriting from MainWindow'''
super().__init__(master)
self.item = item
self.type = type
self.userSearch = tk.StringVar()
self.selItem = ""
if len(self.item[0]) != 1:
self.courseStrings = [f"{course[0]} {course[1]} {course[2]}" for course in item]
else:
self.courseStrings = None
self.createStatInterface()
# Configuring the rows and columns to expand in the center when window size is changed.
for i in range(self.grid_size()[1]):
self.grid_rowconfigure(i, weight=1)
for i in range(self.grid_size()[0]):
self.grid_columnconfigure(i, weight=1)
def createStatInterface(self):
'''Creates the interface of the GUI'''
self.title(f"{self.type} Stats")
tk.Label(self, text=f"Search up a {self.type}", font=("Arial", 11), fg="blue").grid(padx=10, pady=10)
entry = tk.Entry(self, textvariable=self.userSearch)
entry.bind("<KeyRelease>", self.checkValidRangeListBox)
entry.grid(padx=10, pady=10)
#Create the listbox of teacher names or coures names
self.listFrame = tk.Frame(self)
self.S = tk.Scrollbar(self.listFrame)
self.listBox = tk.Listbox(self.listFrame, height=10, width=40, selectmode="single", yscrollcommand=self.S.set)
for item in self.item:
self.listBox.insert(tk.END, ' '.join(item))
self.S.config(command=self.listBox.yview)
self.S.grid(row=2, column=1, sticky="ns")
self.listBox.grid(row=2, column=0, padx=5, pady=5)
self.listBox.bind("<<ListboxSelect>>", self.fillEntry)
self.listFrame.grid()
def fillEntry(self, event):
'''Gets the item from the ListBox Selection'''
selItemIdx = self.listBox.curselection()
self.selItem = self.listBox.get(selItemIdx)
self.destroy()
def checkValidRangeListBox(self, event):
'''Updates the listbox as the user types in the search box'''
typed = self.userSearch.get()
if typed == "":
updatedItems = self.item
else:
updatedItems = []
if self.courseStrings:
for i, item in enumerate(self.courseStrings):
if typed.lower() in item.lower():
updatedItems.append(self.item[i])
else:
for item in self.item:
if typed.lower() in item[0].lower():
updatedItems.append(item)
self.listBox.delete(0, tk.END)
for item in updatedItems:
self.listBox.insert(tk.END, ' '.join(item))
#Getters
@property
def get_item(self):
return self.selItem
class DisplayTimes(tk.Toplevel):
def __init__(self, master, classesTaught, courseSel):
'''Constructor for the DisplayTimes window, inheriting from MainWin'''
super().__init__(master)
self.classesTaught = classesTaught
self.courseSel = courseSel
self.title(f"Meeting times for {courseSel}")
self.computeData()
self.displayTimes()
def computeData(self):
'''Computes the class meeting time data.'''
match = re.match(r'CIS (\d+[A-Za-z]*)', self.courseSel)
courseNum = (match.group(1))
self.courses = [course for course in self.classesTaught if course.courseNum == courseNum]
def displayTimes(self):
'''Displays the times that each course meets on.'''
height = len(self.courses)
# Displaying labels.
labels = ["Term", "Start Time", "End Time", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
for i, label in enumerate(labels):
tkLabel = tk.StringVar()
tkLabel.set(label)
tk.Entry(self, textvariable=tkLabel, state="disabled").grid(row=0, column=i)
# Using entry widgets to create a "grid" type structure to display data.
for i in range(1, height+1):
tkTerm = tk.StringVar(value=f"{self.courses[i-1].term}")
tkStartTime = tk.StringVar(value=f"{self.courses[i-1].startTime}")
tkEndTime = tk.StringVar(value=f"{self.courses[i-1].endTime}")
if tkStartTime.get() == "" or tkEndTime.get() == "":
tkStartTime.set("ONLINE")
tkEndTime.set("ONLINE")
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
for j, day in enumerate(days, 3):
if self.courses[i-1].meetsOn(day):
tk.Entry(self, textvariable=tk.StringVar(value="⬛"), state="disabled", justify="center").grid(row=i, column=j)
else:
tk.Entry(self, textvariable=tk.StringVar(value="⬜"), state="disabled", justify="center").grid(row=i, column=j)
tk.Entry(self, textvariable=tkTerm, state="disabled").grid(row=i, column=0)
tk.Entry(self, textvariable=tkStartTime, state="disabled").grid(row=i, column=1)
tk.Entry(self, textvariable=tkEndTime, state="disabled").grid(row=i, column=2)
class ProfResultWin(tk.Toplevel):
def __init__(self, master, classesTaught, profSel):
'''Constructor for the ProfResultWin, inheriting from MainWin'''
super().__init__(master)
self.classesTaught = classesTaught
self.profSel = profSel
self.master = master
self.ratio = {}
self.courses = set()
self.numClasses = 0
self.computeData()
self.createInterface()
# Configuring the rows and columns to expand in the center when window size is changed.
for i in range(self.grid_size()[1]):
self.grid_rowconfigure(i, weight=1)
for i in range(self.grid_size()[0]):
self.grid_columnconfigure(i, weight=1)
def createInterface(self):
'''Creates the interface of the GUI'''
self.title("Professor Information")
tk.Label(self, text=f"Lookup for {self.profSel}", font=("Arial", 11), fg="blue").grid(padx=10, pady=10)
# General professor information.
tk.Label(self, text=f"Number of classes taught from 2010-2024: {self.numClasses}").grid(pady=10)
tk.Label(self, text="Courses taught (click one to see course meeting times!):").grid()
#Creates a listbox and scrollbar of the courses taught at De Anza.
self.listFrame = tk.Frame(self)
self.S = tk.Scrollbar(self.listFrame)
self.listFrame.grid()
self.listBox = tk.Listbox(self.listFrame, height=10, width=50, selectmode="single", yscrollcommand=self.S.set)
self.S.config(command=self.listBox.yview)
self.listBox.insert(tk.END, *sorted(self.courses))
self.listBox.bind("<<ListboxSelect>>", self.launchMeetingTimes)
self.listBox.grid(row=3, padx=5, pady=5)
self.S.grid(row=3, column=1, sticky="ns")
#Creates a pie plot of the online and in-person ratios
plotObj = Plotter()
fig = plotObj.createPiePlot(list(self.ratio.keys()), list(self.ratio.values()))
canvas = FigureCanvasTkAgg(fig, master=self)
canvas.draw()
canvas.get_tk_widget().grid(pady=10)
# Configuring the rows and columns to expand in the center when window size is changed.
for i in range(self.grid_size()[1]):
self.grid_rowconfigure(i, weight=1)
for i in range(self.grid_size()[0]):
self.grid_columnconfigure(i, weight=1)
def launchMeetingTimes(self, event):
'''Launch meeting time window'''
selItemIdx = self.listBox.curselection()
DisplayTimes(self.master, self.classesTaught, self.listBox.get(selItemIdx)) # Not sure if this is the correct implementation, to pass master in to create the window.
def computeData(self):
'''Computes the calculation data for the GUI'''
self.numClasses = len(self.classesTaught)
# Computing the number of classes taught online vs in person.
self.ratio = {"Online": 0, "In-Person": 0}
for classTaught in self.classesTaught:
self.courses.add(f"{classTaught.subject} {classTaught.courseNum}: {classTaught.title}")
if classTaught.room == "ONLINE":
self.ratio["Online"] += 1
elif classTaught.room != "N/A":
self.ratio["In-Person"] += 1
#Calculate the percentages
self.ratio["Online"] = self.ratio["Online"] / self.numClasses * 100
self.ratio["In-Person"] = self.ratio["In-Person"] / self.numClasses * 100
class CourseResultWin(tk.Toplevel):
def __init__(self, master, classesTaught, profSel):
'''Constructor for the CourseResultWin, inheriting from MainWin'''
super().__init__(master)
self.classesTaught = classesTaught
self.profSel = profSel
self.timesTaught = defaultdict(int)
self.courses = set()
self.userSearch = tk.StringVar()
self.totalTimes = 0
self.startYear = 0
self.endYear = 0
self.computeData()
self.createInterface()
# Configuring the rows and columns to expand in the center when window size is changed.
for i in range(self.grid_size()[1]):
self.grid_rowconfigure(i, weight=1)
for i in range(self.grid_size()[0]):
self.grid_columnconfigure(i, weight=1)
def createInterface(self):
'''Creates the interface of the GUI'''
self.title("Course Information")
#General course information
titleFrame = tk.Frame(self)
titleFrame.grid(padx=10, pady=10)
tk.Label(titleFrame, text=f"Lookup for {self.profSel}", font=("Arial", 11), fg="blue").grid(padx=10, pady=10)
if not self.startYear == self.endYear:
tk.Label(self, text= f"Taught {self.totalTimes} times from {self.startYear}-{self.endYear}").grid()
else:
tk.Label(self, text= f"Taught {self.totalTimes} times in {self.startYear}").grid()
#Creates a listbox and scrollbar of course names
self.listFrame = tk.Frame(self)
self.S = tk.Scrollbar(self.listFrame)
self.listFrame.grid()
self.bodyFrame = tk.Frame(self)
self.listBox = tk.Listbox(self.listFrame, height=10, width=50, selectmode="single", yscrollcommand=self.S.set)
self.S.config(command=self.listBox.yview)
self.listBox.insert(tk.END, *sorted(self.courses))
self.listBox.grid(row=0, column=0, padx=5, pady=5)
self.S.grid(row=0, column=1, sticky="ns")
# Creates a scale for the user to search by a range of years.
tk.Label(self, text="Filter plot by a range of years:").grid()
self.startYearScale = tk.Scale(self.bodyFrame, from_=self.startYear, to=self.endYear, troughcolor="slateblue4", orient=tk.HORIZONTAL, length=300, command=self.updateStartYear)
self.endYearScale = tk.Scale(self.bodyFrame, from_=self.startYear, to=self.endYear, troughcolor="slateblue4", orient=tk.HORIZONTAL, length=300, command=self.updateEndYear)
self.startYearScale.set(self.startYear)
self.endYearScale.set(self.endYear)
tk.Label(self.bodyFrame, text="Start year:").grid(row=0, column=0, padx=5)
tk.Label(self.bodyFrame, text="End year:").grid(row=1, column=0, padx=5)
self.startYearScale.grid(row=0, column=1)
self.endYearScale.grid(row=1, column=1)
self.bodyFrame.grid()
tk.Button(self, text="Refresh Plot", command=self.refreshPlot).grid()
#Creates a pie plot of the online and in-person ratios and bar plot.
self.plotFrame = tk.Frame(self)
self.plotFrame.grid()
self.plotObj = Plotter()
fig1 = self.plotObj.createPiePlot(list(self.ratio.keys()), list(self.ratio.values()))
fig2 = self.plotObj.createBarPlot(list(self.timesTaught.keys()), list(self.timesTaught.values()))
fig_list = [fig1, fig2]
for col, fig in enumerate(fig_list):
canvas = FigureCanvasTkAgg(fig, master=self.plotFrame)
canvas.get_tk_widget().grid(row=0,column=col, padx=20, pady=20)
canvas.draw()
def updateStartYear(self, event):
'''Updates the startYear of the scale and prevents the bars from overlapping'''
if self.startYearScale.get() > self.endYearScale.get():
self.startYearScale.set(self.endYearScale.get() - 1)
def updateEndYear(self, event):
'''Updates the endYear of the scale and prevents the bars from overlapping'''
if self.endYearScale.get() < self.startYearScale.get():
self.endYearScale.set(self.startYearScale.get() + 1)
def computeData(self):
'''Computes the calculation data for the GUI'''
#Find the total number of times taught
for classTaught in self.classesTaught:
self.timesTaught[int(classTaught.term[:4])] += 1
# Computing data.
self.totalTimes = sum(self.timesTaught.values())
self.startYear, self.endYear = (list(self.timesTaught.keys())[-1], (list(self.timesTaught.keys()))[0])
self.numClasses = len(self.classesTaught)
# Computing classes taught online vs in person.
self.ratio = {"Online": 0, "In-Person": 0}
for classTaught in self.classesTaught:
self.courses.add(f"{classTaught.professor}")
if classTaught.room == "ONLINE":
self.ratio["Online"] += 1
elif classTaught.room != "N/A":
self.ratio["In-Person"] += 1
#Calculate the ratio
self.ratio["Online"] = self.ratio["Online"] / self.numClasses * 100
self.ratio["In-Person"] = self.ratio["In-Person"] / self.numClasses * 100
def refreshPlot(self):
'''Refreshes the Plots once the user enters a valid range'''
startYear, endYear = int(self.startYearScale.get()), int(self.endYearScale.get())
numYears = endYear - startYear
year_list = []
value_list = []
for i in range(numYears + 1):
year = startYear + i
year_list.append(year)
value_list.append(self.timesTaught[year])
# Computing classes taught online vs in person.
self.ratio = {"Online": 0, "In-Person": 0}
for classTaught in self.classesTaught:
if classTaught.room == "ONLINE" and int(classTaught.term[:4]) in year_list:
self.ratio["Online"] += 1
elif classTaught.room != "N/A" and int(classTaught.term[:4]) in year_list:
self.ratio["In-Person"] += 1
#Calculate the ratio
self.ratio["Online"] = self.ratio["Online"] / self.numClasses * 100
self.ratio["In-Person"] = self.ratio["In-Person"] / self.numClasses * 100
fig1 = self.plotObj.createBarPlot(year_list, value_list)
fig2 = self.plotObj.createPiePlot(list(self.ratio.keys()), list(self.ratio.values()))
for col, fig in enumerate([fig2, fig1]):
canvas = FigureCanvasTkAgg(fig, master=self.plotFrame)
canvas.get_tk_widget().grid(row=0, column=col, padx=20, pady=20)
canvas.draw()
class MiscResultWin(tk.Toplevel):
def __init__(self, master, classesTaught):
'''Constructor for the MiscResultWin, inheriting from MainWin'''
super().__init__(master)
self.classesTaught = classesTaught
self.numClasses = 0
self.yearsOnline = defaultdict(int)
self.yearsInPerson = defaultdict(int)
self.favRooms = {}
self.favProfs = {}
self.computeData()
self.createInterface()
# Configuring the rows and columns to expand in the center when window size is changed.
for i in range(self.grid_size()[1]):
self.grid_rowconfigure(i, weight=1)
for i in range(self.grid_size()[0]):
self.grid_columnconfigure(i, weight=1)
def createInterface(self):
'''Creates the interface of the GUI'''
self.title("Miscellaneous Information")
tk.Label(self, text=f"Miscellaneous Information", font=("Arial", 11), fg="blue").grid(padx=10, pady=10)
# General information.
tk.Label(self, text=f"Number of classes taught from 2010-2024: {self.numClasses}").grid(pady=10)
tk.Label(self, text=f"Favorite Room: {self.favRooms[1][0]} with {self.favRooms[1][1]} classes taught there (excluding online classes)").grid(pady=10)
tk.Label(self, text=f"Professor with most classes: {self.favProfs[0][0]} with {self.favProfs[0][1]} courses taught").grid(pady=10)
#Creates a line plot of the online to in-person trend across the years
self.plotObj = Plotter()
fig = self.plotObj.createLinePlot(self.yearsOnline, self.yearsInPerson)
canvas = FigureCanvasTkAgg(fig, master=self)
canvas.get_tk_widget().grid(pady=10)
canvas.draw()
def computeData(self):
'''Computes the calculation data for the GUI'''
self.numClasses = len(self.classesTaught)
# Computing classes taught online vs in person.
for classTaught in self.classesTaught:
self.favRooms[classTaught.room] = self.favRooms.get(classTaught.room, 0) + 1
self.favProfs[classTaught.professor] = self.favProfs.get(classTaught.professor, 0) + 1
if classTaught.room == "ONLINE":
self.yearsOnline[int(classTaught.term[:4])] += 1
elif classTaught.room != "N/A":
self.yearsInPerson[int(classTaught.term[:4])] += 1
self.favRooms = sorted(self.favRooms.items(), key = lambda t: t[1], reverse=True)
self.favProfs = sorted(self.favProfs.items(), key = lambda t: t[1], reverse=True)
class MainWin(tk.Tk):
def __init__(self):
'''Constructor for MainWin, inheriting from tk Class'''
super().__init__()
self.title("Course Catalog GUI")
# We will keep all database processing within main.
self.conn = sqlite3.connect('CourseData.db')
self.cur = self.conn.cursor()
# Selecting the most recent term. Because of the way we inserted things, it will select the latest first.
self.cur.execute("SELECT quarter from QuartersDB ORDER BY id DESC")
mostRecentTerm = self.cur.fetchone()[0][:4]
tk.Label(self, text=f"Look up class data and stats from 2010-{mostRecentTerm}", font=("Arial", 11), fg="blue").grid(padx=10, pady=10) # Change to latest data later.
frame = tk.Frame(self)
tk.Button(frame, text="Professor Stats", command=self.profStats).grid(row=0, column=0, padx=5)
tk.Button(frame, text="Course Stats", command=self.courseStats).grid(row=0, column=1, padx=5)
tk.Button(frame, text="Misc Stats", command=self.miscStats).grid(row=0, column=2, padx=5)
frame.grid(padx=10, pady=10)
# Configuring the rows and columns to expand in the center when window size is changed.
for i in range(self.grid_size()[1]):
self.grid_rowconfigure(i, weight=1)
for i in range(self.grid_size()[0]):
self.grid_columnconfigure(i, weight=1)
self.protocol("WM_DELETE_WINDOW", self.destroyWin)
def profStats(self):
'''Joins the table and fetches the class data upon user professor selection, calling ProfResultWin to display'''
self.cur.execute("SELECT name FROM ProfessorsDB")
profs = self.cur.fetchall()
profWin = Stats(self, "Professors", profs)
profWin.wait_window()
selProf = profWin.get_item
if selProf != "":
# Getting required data for the professor.
self.cur.execute('''SELECT CoursesNumDB.number, SubjectsDB.subject, CoursetitlesDB.title, RoomsDB.room, QuartersDB.quarter,
CoursesDB.startTime, CoursesDB.endTime, CoursesDB.sunday, CoursesDB.monday, CoursesDB.tuesday,
CoursesDB.wednesday, CoursesDB.thursday, CoursesDB.friday, CoursesDB.saturday
FROM CoursesDB
JOIN CoursesNumDB ON CoursesDB.courseNumId = CoursesNumDB.id
JOIN SubjectsDB ON CoursesDB.subjectId = SubjectsDB.id
JOIN CoursetitlesDB ON CoursesDB.titleId = CoursetitlesDB.id
JOIN RoomsDB ON CoursesDB.roomId = RoomsDB.id
JOIN QuartersDB ON CoursesDB.termId = QuartersDB.id
JOIN ProfessorsDB ON CoursesDB.profId = ProfessorsDB.id
WHERE ProfessorsDB.name = (?)''', (selProf,))
classesTaughtData = self.cur.fetchall()
classesTaught = []
for classTaught in classesTaughtData:
courseNum, subject, title, room, term, startTime, endTime, *days = classTaught
daysDict = {
"Sunday": days[0],
"Monday": days[1],
"Tuesday": days[2],
"Wednesday": days[3],
"Thursday": days[4],
"Friday": days[5],
"Saturday": days[6]
}
course = Course(courseNum, selProf, subject, title, room, term, startTime, endTime, daysDict)
classesTaught.append(course)
# Launching result window.
self.resultWin = ProfResultWin(self, classesTaught, selProf)
def courseStats(self):
'''Joins the table and fetches the class data upon user course selection, calling CourseResultWin to display'''
self.cur.execute('''SELECT SubjectsDB.subject, CoursesNumDB.number, CoursetitlesDB.title
FROM CoursesDB
JOIN CoursesNumDB ON CoursesDB.courseNumId = CoursesNumDB.id
JOIN SubjectsDB ON CoursesDB.subjectId = SubjectsDB.id
JOIN CoursetitlesDB ON CoursesDB.titleId = CoursetitlesDB.id''')
courses = self.cur.fetchall()
courses = sorted(set(courses))
courseWin = Stats(self, "Courses", courses)
courseWin.wait_window()
selCourse = courseWin.get_item
if selCourse != "":
match = re.match(r'CIS (\d+[A-Za-z]*)', selCourse)
courseNum = (match.group(1))
# Getting required data for the professor.
self.cur.execute('''SELECT CoursesNumDB.number, ProfessorsDB.name, SubjectsDB.subject, CoursetitlesDB.title, RoomsDB.room, QuartersDB.quarter,
CoursesDB.startTime, CoursesDB.endTime, CoursesDB.sunday, CoursesDB.monday, CoursesDB.tuesday,
CoursesDB.wednesday, CoursesDB.thursday, CoursesDB.friday, CoursesDB.saturday
FROM CoursesDB
JOIN CoursesNumDB ON CoursesDB.courseNumId = CoursesNumDB.id
JOIN SubjectsDB ON CoursesDB.subjectId = SubjectsDB.id
JOIN CoursetitlesDB ON CoursesDB.titleId = CoursetitlesDB.id
JOIN RoomsDB ON CoursesDB.roomId = RoomsDB.id
JOIN QuartersDB ON CoursesDB.termId = QuartersDB.id
JOIN ProfessorsDB ON CoursesDB.profId = ProfessorsDB.id
WHERE CoursesNumDB.number = (?)''', (courseNum,))
classesTaughtData = self.cur.fetchall()
classesTaught = []
for classTaught in classesTaughtData:
courseNum, professor, subject, title, room, term, startTime, endTime, *days = classTaught
daysDict = {
"Sunday": days[0],
"Monday": days[1],
"Tuesday": days[2],
"Wednesday": days[3],
"Thursday": days[4],
"Friday": days[5],
"Saturday": days[6]
}
course = Course(courseNum, professor, subject, title, room, term, startTime, endTime, daysDict)
classesTaught.append(course)
# Launching result window.
self.resultWin = CourseResultWin(self, classesTaught, selCourse)
def miscStats(self):
'''Joins the table and fetches the data, calling MiscResultWin to display'''
self.cur.execute('''SELECT CoursesNumDB.number, ProfessorsDB.name, SubjectsDB.subject, CoursetitlesDB.title, RoomsDB.room, QuartersDB.quarter,
CoursesDB.startTime, CoursesDB.endTime, CoursesDB.sunday, CoursesDB.monday, CoursesDB.tuesday,
CoursesDB.wednesday, CoursesDB.thursday, CoursesDB.friday, CoursesDB.saturday
FROM CoursesDB
JOIN CoursesNumDB ON CoursesDB.courseNumId = CoursesNumDB.id
JOIN SubjectsDB ON CoursesDB.subjectId = SubjectsDB.id
JOIN CoursetitlesDB ON CoursesDB.titleId = CoursetitlesDB.id
JOIN RoomsDB ON CoursesDB.roomId = RoomsDB.id
JOIN QuartersDB ON CoursesDB.termId = QuartersDB.id
JOIN ProfessorsDB ON CoursesDB.profId = ProfessorsDB.id''')
classesTaughtData = self.cur.fetchall()
classesTaught = []
for classTaught in classesTaughtData:
courseNum, professor, subject, title, room, term, startTime, endTime, *days = classTaught
daysDict = {
"Sunday": days[0],
"Monday": days[1],
"Tuesday": days[2],
"Wednesday": days[3],
"Thursday": days[4],
"Friday": days[5],
"Saturday": days[6]
}
course = Course(courseNum, professor, subject, title, room, term, startTime, endTime, daysDict)
classesTaught.append(course)
# Launching MiscStat window.
self.miscStats = MiscResultWin(self, classesTaught)
def destroyWin(self):
'''Destroys the main window and closes the connection to the database.'''
self.conn.close()
self.destroy()
self.quit()
app = MainWin()
app.mainloop()