144
144
47 : "11:30pm"
145
145
}
146
146
147
+ # Handles user registration
147
148
@app .route ("/register" , methods = ["GET" , "POST" ])
148
149
def register ():
149
150
if request .method == "POST" :
@@ -180,6 +181,7 @@ def register():
180
181
return render_template ("register.html" )
181
182
182
183
184
+ # Handles user login
183
185
@app .route ("/login" , methods = ["GET" , "POST" ])
184
186
def index ():
185
187
session .clear ()
@@ -208,6 +210,7 @@ def index():
208
210
# Return the login page
209
211
return render_template ("login.html" )
210
212
213
+ # Handles user logout
211
214
@app .route ("/logout" )
212
215
@login_required
213
216
def logout ():
@@ -270,7 +273,7 @@ def courses():
270
273
# Set the homepage for our website to "main.html"
271
274
@app .route ("/" )
272
275
def home ():
273
- return render_template ("main.html" )#f courses():s():
276
+ return render_template ("main.html" )
274
277
275
278
@app .route ("/prefs" , methods = ["GET" , "POST" ])
276
279
@login_required
@@ -284,7 +287,7 @@ def prefs():
284
287
# Assume that locationlist is the single location they enter into the form
285
288
course = request .form .get ("course" )
286
289
# Check that course as submitted is an integer with six digits
287
- if course % 1 != 0 or len (str (course ))!= 6 :
290
+ if not course . isdigit () or len (str (course ))!= 6 :
288
291
error = "Make sure you are submitting a six number course ID, not the course name!"
289
292
return render_template ("prefs.html" , locations = locations , daysoftheweek = daysoftheweek , time_to_index = time_to_index , error = error )
290
293
# Obtain email from the session id for the currently signed in user
@@ -320,8 +323,9 @@ def prefs():
320
323
# Format the prefs html, sending the list of locations, days of week, and times
321
324
return render_template ("prefs.html" , locations = locations , daysoftheweek = daysoftheweek , time_to_index = time_to_index )
322
325
326
+ # Handles emailing the matched study groups
323
327
def matchemail (people , locations , timeblock , day , uniqueCourse , matched ):
324
- # We looked at this resource to count values: https://www.programiz.com/python-programming/methods/string/count'''
328
+ # We looked at this resource to count values: https://www.programiz.com/python-programming/methods/string/count
325
329
# Create a dictionary whose keys are the locations and whose initial values are zero
326
330
places = {
327
331
"Cabot Library" : 0 ,
@@ -446,6 +450,7 @@ def matchemail(people, locations, timeblock, day, uniqueCourse, matched):
446
450
mail .send (msg )
447
451
return 'Sent'
448
452
453
+ # This is the match algorithm that matches people into study groups
449
454
def match ():
450
455
# Runs timematch on every unique course in the prefs table
451
456
uniqueCourses = db .execute ("SELECT DISTINCT course FROM prefs;" )
@@ -475,6 +480,7 @@ def match():
475
480
matchemail (people , locations , None , None , uniqueCourse ["course" ], 0 )
476
481
477
482
# Prrereq = the sorting has already been filtered by course
483
+ # This handles finding the timeblocks where the most people can be matched into study groups
478
484
def timematch (uniqueCourse , day ):
479
485
# stackedTimelines stores how many people are available at each time represented by each index of
480
486
# stackedTimelines
@@ -555,22 +561,18 @@ def timematch(uniqueCourse, day):
555
561
am_timeblock .sort ()
556
562
pm_timeblock .sort ()
557
563
timeblock = am_timeblock + pm_timeblock
558
- #contained = any(elem in people for elem in duplicates)
559
564
for person in people :
560
565
if person in duplicates :
561
566
break
562
567
if not person in duplicates :
563
-
564
- #if not contained:
565
568
grouper (uniqueCourse , timeblock , people , day )
566
569
for r in people :
567
570
duplicates .append (r )
568
571
key += 1
569
572
key += count
570
- # Handle left over people
571
573
572
574
573
- # prereq = the sorting has already been filtered by course and time
575
+ # Prereq = the sorting has already been filtered by course and time
574
576
# Grouping algorithm for people for a particular time interval by group size
575
577
def grouper (uniqueCourse , timeblock , emails , day ):
576
578
timestring = ""
@@ -595,11 +597,6 @@ def grouper(uniqueCourse, timeblock, emails, day):
595
597
medium = sizeCount (course_entries , "m" )
596
598
small = number_of_people - large - medium
597
599
if small > (medium + large ):
598
- #remainder = number_of_people % 3
599
- #if remainder == 0:
600
- # matchemail(emails[], locationstring, timeblock, day, uniqueCourse, True)
601
- #elif remainder == 1:
602
- #else:
603
600
if number_of_people == 4 :
604
601
matchemail (emails [0 :2 ], locationstring , timeblock , day , uniqueCourse , True )
605
602
matchemail (emails [2 :4 ], locationstring , timeblock , day , uniqueCourse , True )
0 commit comments