From bf768f6fc5e8dd267b0cb7ed323778bccbc9f7f4 Mon Sep 17 00:00:00 2001 From: mzen Date: Mon, 14 Oct 2024 15:56:28 +0200 Subject: [PATCH] INTERNSHIP-329 use position to balance internships assignment repartition in hospitals + fix selecting non mandatory internships --- business/assignment.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/business/assignment.py b/business/assignment.py index 7f1cd3615..71e6af336 100644 --- a/business/assignment.py +++ b/business/assignment.py @@ -198,7 +198,7 @@ def _assign_students_in_subcohorts(self): # shuffle interships, keeps on top specialties that are not available in all cohorts to prioritize on these internships = sorted( available_internships, - key=lambda i: (self.internships_availability_occurence[i], random.random()) + key=lambda i: (self.internships_availability_occurence[i], i.position, random.random()) ) for internship in internships: _assign_student(self, student, internship) @@ -423,7 +423,9 @@ def _assign_student(assignment, student, internship): affectations = assign_choices_to_student(assignment, student, choices, internship) # Deal with internship at choice else: - if isinstance(internship, Iterable) and not _has_affected_non_mandatory_internship(student_affectations): + if not _has_affected_non_mandatory_internship(student_affectations): + if not isinstance(internship, Iterable): + internship = [internship] for chosen_internship in internship: if affectations is None or affectations == []: last = chosen_internship == list(internship)[:-1]