42
42
# List of days of the week
43
43
daysoftheweek = ["Sunday" , "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" ]
44
44
45
+ # course = [people emails]
46
+ '''duplicates = {
47
+
48
+ }'''
49
+
45
50
# dictionary that serves as a converter between times and indices
46
51
time_to_index = {
47
52
"12:00am" : 0 ,
@@ -316,13 +321,32 @@ def prefs():
316
321
return render_template ("prefs.html" , locations = locations , daysoftheweek = daysoftheweek , time_to_index = time_to_index )
317
322
318
323
def matchemail (people , locations , timeblock , day , uniqueCourse , matched ):
324
+ #https://www.programiz.com/python-programming/methods/string/count
325
+ places = {
326
+ "Cabot Library" : 0 ,
327
+ "Dorm Room" : 0 ,
328
+ "Lamont Library" : 0 ,
329
+ "Smith Center" : 0 ,
330
+ "Widener Library" : 0
331
+ }
332
+ for key in places :
333
+ places [key ] = locations .count (key )
334
+ locations = places
319
335
#people as a list
320
336
#locations as a dictionary
321
337
#uniquecourse as a integer valiue
322
338
#matched as a boolean
323
339
# day is one day because we are only matching for one day per week
324
340
# configuration of mail
325
-
341
+ '''print("UHH", duplicates)'''
342
+ #duplicates[uniqueCourse] = people
343
+ #noduplicates = True
344
+ '''for person in people:
345
+ if person in duplicates[uniqueCourse]:
346
+ print("HMMMMMMMMMMMMMMMMMMMM")
347
+ noduplicates = False
348
+ break
349
+ if noduplicates: '''
326
350
print ("LOOOOOOOOOOOOK" )
327
351
print (people )
328
352
count = len (people )
@@ -381,14 +405,14 @@ def matchemail(people, locations, timeblock, day, uniqueCourse, matched):
381
405
t = t + timetext
382
406
t = t + locationtext
383
407
msg .body (t )
384
- with app .app_context ():
385
- mail .send (msg )
408
+ # with app.app_context():
409
+ # mail.send(msg)
386
410
return 'Sent'
387
411
388
412
if matched :
389
413
locationtext = ""
390
414
for entry in locations :
391
- locationtext = locationtext + (locations [entry ]/ count ) + " of people prefer " + entry + ". "
415
+ locationtext = locationtext + str (locations [entry ]/ count ) + " of people prefer " + entry + ". "
392
416
names = ""
393
417
for person in people :
394
418
if names == "" :
@@ -410,10 +434,14 @@ def matchemail(people, locations, timeblock, day, uniqueCourse, matched):
410
434
t = t .replace ('course' , uniqueCourse )
411
435
t = t .replace ('day' , day )
412
436
timestring = ""
413
- for x in timeblock :
414
- timestring += x + ","
415
- print (timeblock )
416
- timestring = timestring [0 : len (timestring )- 1 ]
437
+ if len (timeblock ) == 2 and timeblock [0 ] == timeblock [1 ]:
438
+ timestring = timeblock [0 ]
439
+ else :
440
+ timestring = timeblock [0 ]+ "-" + timeblock [len (timeblock )- 1 ]
441
+
442
+ #for x in timeblock:
443
+ # timestring += x +","
444
+ #timestring = timestring[0: len(timestring)-1]
417
445
t = t .replace ("time" , timestring )
418
446
t = t + locationtext
419
447
print (names , uniqueCourse , day , timestring )
@@ -422,7 +450,7 @@ def matchemail(people, locations, timeblock, day, uniqueCourse, matched):
422
450
with app .app_context ():
423
451
mail .send (msg )
424
452
return 'Sent'
425
- #Code for generating and confirming token taken from https://realpython.com/handling-email-confirmation-in-flask/#generate-confirmation-token
453
+ # Code for generating and confirming token taken from https://realpython.com/handling-email-confirmation-in-flask/#generate-confirmation-token
426
454
def generate_confirmation_token (email ):
427
455
serializer = URLSafeTimedSerializer ('SECRET_KEY' )
428
456
return serializer .dumps (email , salt = 'SECURITY_PASSWORD_SALT' )
@@ -472,10 +500,11 @@ def verify(email, firstname):
472
500
473
501
def match ():
474
502
# Creates copy of preferences table called prefs to save preferences information
475
- # db.execute("SELECT * INTO prefs FROM preferences;")
476
- # db.execute("ALTER TABLE prefs ADD matched bit")
477
- #db.execute("UPDATE prefs SET matched = ?", 0)
503
+ # db.execute("SELECT * INTO prefs FROM preferences;")
504
+ # db.execute("ALTER TABLE prefs ADD matched bit")
505
+ # db.execute("UPDATE prefs SET matched = ?", 0)
478
506
# Runs timematch on every unique course in the prefs table
507
+ # duplicates = {}
479
508
uniqueCourses = db .execute ("SELECT DISTINCT course FROM prefs;" )
480
509
for uniqueCourse in uniqueCourses :
481
510
for day in daysoftheweek :
@@ -529,7 +558,7 @@ def timematch(uniqueCourse, day):
529
558
stackedTimelines [time_to_index [time ]][1 ]= time
530
559
531
560
stackedTimelines = sorted (stackedTimelines , key = lambda x : x [0 ], reverse = True )
532
-
561
+
533
562
# now stackedtimelines has the number of people who want a specific course at each time block
534
563
# https://careerkarma.com/blog/python-sort-a-dictionary-by-value/
535
564
#sortedStackedTimelines = sorted(stackedTimelines.items(), key=lambda x: x[1], reverse=True)
@@ -539,9 +568,11 @@ def timematch(uniqueCourse, day):
539
568
# stackedTimelinesValues = stackedTimelines.values()
540
569
541
570
#https://www.kite.com/python/answers/how-to-sort-a-multidimensional-list-by-column-in-python
542
- for key in range (len (stackedTimelines )):
571
+ key = 0
572
+ duplicates = []
573
+ while key < len (stackedTimelines ):
543
574
max_value = stackedTimelines [key ][0 ]
544
- if max_value == 0 :
575
+ if max_value == 0 or max_value == 1 :
545
576
break
546
577
# finds 30 minute blocks with max people
547
578
# https://www.programiz.com/python-programming/methods/list/index
@@ -560,22 +591,23 @@ def timematch(uniqueCourse, day):
560
591
am_timeblock .append (max_time )
561
592
else :
562
593
pm_timeblock .append (max_time )
563
- for left in range (time_to_index [max_time ]- 1 , - 1 , - 1 ):
564
- key2 = index_to_time [left ]
565
- peopledict2 = db .execute ("SELECT email FROM prefs WHERE course = ? AND times LIKE ? AND day = ?;" , uniqueCourse , "%" + key2 + "%" , day )
566
- people2 = []
567
- for x in peopledict2 :
568
- people2 .append (x ["email" ])
594
+ # for left in range(time_to_index[max_time]-1, -1, -1):
595
+ # key2 = index_to_time[left]
596
+ # peopledict2 = db.execute("SELECT email FROM prefs WHERE course = ? AND times LIKE ? AND day = ?;", uniqueCourse, "%"+key2+"%", day)
597
+ # people2 = []
598
+ # for x in peopledict2:
599
+ # people2.append(x["email"])
569
600
#https://thispointer.com/python-check-if-a-list-contains-all-the-elements-of-another-list/#:~:text=Check%20if%20list1%20contains%20all%20elements%20of%20list2%20using%20all()&text=Python%20all()%20function%20checks,if%20element%20exists%20in%20list1.
570
- contained = all (elem in people2 for elem in people )
571
- if not contained :
572
- break
573
- else :
574
- if key [len (key2 )- 2 ] == "am" :
575
- am_timeblock .append (key2 )
576
- else :
577
- pm_timeblock .append (key2 )
601
+ # contained = all(elem in people2 for elem in people)
602
+ # if not contained:
603
+ # break
604
+ # else:
605
+ # if key2 [len(key2)-2] == "am":
606
+ # am_timeblock.append(key2)
607
+ # else:
608
+ # pm_timeblock.append(key2)
578
609
max_index = time_to_index [max_time ]
610
+ count = 0
579
611
for right in range (max_index , len (stackedTimelines )):
580
612
key2 = index_to_time [right ]
581
613
peopledict2 = db .execute ("SELECT email FROM prefs WHERE course = ? AND times LIKE ? AND day = ?;" , uniqueCourse , "%" + key2 + "%" , day )
@@ -587,14 +619,29 @@ def timematch(uniqueCourse, day):
587
619
if not contained :
588
620
break
589
621
else :
622
+ count += 1
590
623
if key2 [len (key2 )- 2 ] == "am" :
591
624
am_timeblock .append (key2 )
592
625
else :
593
626
pm_timeblock .append (key2 )
594
627
am_timeblock .sort ()
595
628
pm_timeblock .sort ()
596
629
timeblock = am_timeblock + pm_timeblock
597
- grouped_people = grouper (uniqueCourse , timeblock , people , day )
630
+ #contained = any(elem in people for elem in duplicates)
631
+ for person in people :
632
+ if person in duplicates :
633
+ break
634
+ if not person in duplicates :
635
+
636
+ #if not contained:
637
+ grouper (uniqueCourse , timeblock , people , day )
638
+ for r in people :
639
+ duplicates .append (r )
640
+ print ("DUPLICATES: " , duplicates )
641
+ print ("COUNT: " , count )
642
+ key += 1
643
+ key += count
644
+ print ("KEY: " , key )
598
645
# Handle left over people
599
646
600
647
@@ -603,12 +650,18 @@ def timematch(uniqueCourse, day):
603
650
def grouper (uniqueCourse , timeblock , emails , day ):
604
651
timestring = ""
605
652
locationstring = ""
606
- for time in timeblock :
653
+ for i in range (1 , len (timeblock )):
654
+ time = timeblock [i ]
607
655
timestring += time + ","
608
- course_entries = db .execute ("SELECT * FROM prefs WHERE course = ? and times LIKE ? AND day = ?" , uniqueCourse , "%" + timestring + "%" , day )
609
- for course_entry in course_entries :
610
- locationstring += course_entry ["locations" ] + ","
656
+ timestring = timestring [0 : len (timestring )- 1 ]
657
+ course_entries = db .execute ("SELECT * FROM prefs WHERE course = ? AND times LIKE ? AND day = ?" , uniqueCourse , "%" + timestring + "%" , day )
658
+ course_locations = db .execute ("SELECT locations FROM prefs WHERE course = ? AND times LIKE ? AND day = ?" , uniqueCourse , "%" + timestring + "%" , day )
659
+ locationstring = ""
660
+ for x in course_locations :
661
+ locationstring += x ["locations" ]
611
662
number_of_people = len (course_entries )
663
+ #if number_of_people == 1:
664
+ # matchemail(emails, locationstring, timeblock, day, uniqueCourse, False)
612
665
if number_of_people <= 3 :
613
666
matchemail (emails , locationstring , timeblock , day , uniqueCourse , True )
614
667
elif number_of_people <= 6 and number_of_people >= 4 :
@@ -626,10 +679,10 @@ def grouper(uniqueCourse, timeblock, emails, day):
626
679
matchemail (emails [2 :4 ], locationstring , timeblock , day , uniqueCourse , True )
627
680
elif number_of_people == 5 :
628
681
matchemail (emails [0 :2 ], locationstring , timeblock , day , uniqueCourse , True )
629
- matchemail (emails [3 :5 ], locationstring , timeblock , day , uniqueCourse , True )
682
+ matchemail (emails [2 :5 ], locationstring , timeblock , day , uniqueCourse , True )
630
683
else :
631
684
matchemail (emails [0 :3 ], locationstring , timeblock , day , uniqueCourse , True )
632
- matchemail (emails [4 :6 ], locationstring , timeblock , day , uniqueCourse , True )
685
+ matchemail (emails [3 :6 ], locationstring , timeblock , day , uniqueCourse , True )
633
686
else :
634
687
matchemail (emails , locationstring , timeblock , day , uniqueCourse , True )
635
688
db .execute ("UPDATE prefs SET matched = 1 WHERE course = ? AND times LIKE ? AND day = ?" , uniqueCourse , "%" + timestring + "%" , day )
@@ -737,7 +790,7 @@ def grouper(uniqueCourse, timeblock, emails, day):
737
790
def sizeCount (course_entries , size ):
738
791
count = 0
739
792
for course_entry in course_entries :
740
- if course_entry ["size" ] == size :
793
+ if course_entry ["size" ] == size :
741
794
count += 1
742
795
return count
743
796
0 commit comments