-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsort.py
More file actions
48 lines (37 loc) · 2.26 KB
/
sort.py
File metadata and controls
48 lines (37 loc) · 2.26 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
#data structure; paralell between user dict and profile's dict values
# user = {
# "grade": int
# "subjects": ["array", "of", "strings"]
# "day_available": [
# [True, False, True, False],
# [False, True, False, True],
# [True, False, True, False]
# ] 2D array containing arrays of bools, representing hours available
def sort_compabitility(user, **profile): #user and profile are for the target and comparisons, respectively
comp_score = {} #stores compatibilty scores for each profile
for key in profile: #parses through all the profiles
localId = list(profile[key].keys())[0]
profile[key] = profile[key][localId]
shared_subjects = 0 #for tracking subjects shared
shared_times = 0
if dif := abs( user["grade"] - profile[key]["grade"] ) > 2: #assign dif variable as difference in grade, also checks if it's greater than 2
profile.pop(key) #removes people who are more than 2 grades apart
continue
for i in user["subjects"]: #should be parsing through subjects array of user
try:
profile[key]["subjects"].index(i) #we do a little try-catching
shared_subjects += 1
except:
pass #.index() returns ValueError if not found, meaning it skips the increment part
if shared_subjects == 0:
profile.pop(key) #removes the people who don't share a subject
continue
for i in range(7): #hardcode lol, original was range(len( user["day_available"] ))
for j in range(24): #range(len( user["day_available"][i] ))
if user["day_available"][i][j] and profile[key]["day_available"][i][j]: #great addresses; checks for if both people have matching times
shared_times += 1
if shared_times == 0:
profile.pop(key) #removes the people who don't share a time slot
continue
comp_score[key] = 1000*dif - 100*shared_subjects - shared_times #assigns score to profile based on grade difference; the lower the better
return comp_score #or something, in this state it's returning a dictionary with the same key but int values for compatibility scores