From 4b0ed65a18173d90b0889d48129d3624b78ce1bc Mon Sep 17 00:00:00 2001 From: Christopher Bohn <bohn@unl.edu> Date: Thu, 9 Jul 2020 08:59:19 -0500 Subject: [PATCH] Bugfixes with blacklist and graylist - There was a bug involving students with blacklists make requests - is_blacklist_compatible & is_graylist_compatible always returned true --- api/composite_user.py | 4 ++-- prep_assignment.py | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/composite_user.py b/api/composite_user.py index c8f6eae..64505ec 100644 --- a/api/composite_user.py +++ b/api/composite_user.py @@ -97,7 +97,7 @@ class CompositeUser: your_past_partners: Set[str] = set() for assignment in self.graylist: if isinstance(self.graylist[assignment], set): - my_past_partners.union(self.graylist[assignment]) + my_past_partners.update(self.graylist[assignment]) elif isinstance(self.graylist[assignment], str): my_past_partners.add(str(self.graylist[assignment])) else: @@ -105,7 +105,7 @@ class CompositeUser: f'are recorded as a {self.graylist[assignment].__class__}') for assignment in other.graylist: if isinstance(other.graylist[assignment], set): - your_past_partners.union(other.graylist[assignment]) + your_past_partners.update(other.graylist[assignment]) elif isinstance(other.graylist[assignment], str): your_past_partners.add(str(other.graylist[assignment])) else: diff --git a/prep_assignment.py b/prep_assignment.py index 29bc55a..4a476e6 100644 --- a/prep_assignment.py +++ b/prep_assignment.py @@ -140,18 +140,18 @@ def create_pairs(students: Set[CompositeUser], groupset_name: str = 'Unknown Ass print('Next we shall assign partners to students with blacklists.') else: print('There are no students with blacklists.') - for student in students_with_blacklist: # TODO: there's a bug here when students with blacklists make requests - pair_number += 1 - if student in unassigned_students: # TODO: can probably fix bug by putting ALL the code under this "if" + for student in students_with_blacklist: + if student in unassigned_students: + pair_number += 1 unassigned_students.remove(student) - potential_partner: CompositeUser = random.choice(tuple(unassigned_students)) - while not (student.is_blacklist_compatible(potential_partner) and - student.is_graylist_compatible(potential_partner)): - # has the potential to run infinitely - potential_partner = random.choice(tuple(unassigned_students)) - unassigned_students.remove(potential_partner) - student_pairs.append((pair_number, student, potential_partner, None)) - print(f'\t{student.readable_name} partnered with {potential_partner.readable_name}') + potential_partner: CompositeUser = random.choice(tuple(unassigned_students)) + while not (student.is_blacklist_compatible(potential_partner) and + student.is_graylist_compatible(potential_partner)): + # has the potential to run infinitely + potential_partner = random.choice(tuple(unassigned_students)) + unassigned_students.remove(potential_partner) + student_pairs.append((pair_number, student, potential_partner, None)) + print(f'\t{student.readable_name} partnered with {potential_partner.readable_name}') print('Finally we shall assign partners to the remaining students.') odd_student: Optional[CompositeUser] = \ random.choice(tuple(unassigned_students)) if len(unassigned_students) % 2 == 1 else None -- GitLab