-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfairproject.py
executable file
·47 lines (40 loc) · 1.32 KB
/
fairproject.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
#!/bin/python3
import data
import random
import pprint
selectedByProjects = dict()
selectedByStudent = dict()
projects = data.getProjects()
students = data.getStudents()
for s in students:
s["badPrefrences"] = []
s["assigned"] = False
for i in range(0, max(len(projects), len(students))):
random.shuffle(students)
for student in students:
if "assigned" in student.keys() and student["assigned"]:
continue
if len(student["Prefrences"]) == 0:
continue
firstChoice = student["Prefrences"][0]
studentName = student["Name"]
if firstChoice in projects:
selectedByProjects[firstChoice] = studentName
selectedByStudent[studentName] = firstChoice
projects.remove(firstChoice)
student["assigned"] = True
student["assignedProject"] = firstChoice
else:
student["badPrefrences"].append(student["Prefrences"].pop(0))
print()
print("========================")
pprint.pprint(selectedByProjects)
print("------------------------")
pprint.pprint(selectedByStudent)
# print("------------------------")
# print(projects)
# print("------------------------")
# print("------------------------")
# pprint.pprint(students, width=300)
# print("------------------------")
print("------------------------\n")