def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) exam_rooms = ExamRoom.objects.filter(available=True) context['student_count'] = Student.get_current(want_exam=True).order_by('name', 'prename').count() context['free_places_1'] = sum([exam_room.capacity(1) for exam_room in exam_rooms]) context['free_places_2'] = sum([exam_room.capacity(2) for exam_room in exam_rooms]) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) exam_rooms = ExamRoom.objects.filter(available=True) context['student_count'] = Student.get_current( want_exam=True).order_by('name', 'prename').count() context['free_places_1'] = sum( [exam_room.capacity(1) for exam_room in exam_rooms]) context['free_places_2'] = sum( [exam_room.capacity(2) for exam_room in exam_rooms]) return context
def assign(self): """ Do the real assignment based on object properties """ capacity_string = 'capacity_{:d}_free'.format(self.spacing) order_by_string = "-{:s}".format(capacity_string) exam_rooms = ExamRoom.objects.filter( available=True).order_by(order_by_string) exam_students = Student.get_current( tutor_group__group_category=self.group_category, want_exam=True) exam_students = exam_students.order_by('name', 'prename') student_count = exam_students.count() if exam_rooms.count() == 0 or student_count == 0: return 0 total_places = exam_rooms.aggregate( total_places=Sum(capacity_string)).get('total_places') # Set ratio so that all room gets equals percentage ratio = student_count / total_places # on minimal room mode and if the ratio is less then 90% the ratio is set to 90% # e.g. the first rooms get filled by 90%. The other rooms are not used if self.mode == 1 and ratio < 0.9: ratio = 0.9 exam_rooms_list = [] for exam_room in exam_rooms: places = math.ceil(exam_room.capacity(self.spacing) * ratio) # add each room as often to the list as places available in the room exam_rooms_list.extend((exam_room, ) * places) assign = partial(PersonToExamRoomAssignment, assignment=self) assignments = ( assign(person=student, room=room) for student, room in zip(exam_students, exam_rooms_list)) PersonToExamRoomAssignment.objects.bulk_create(assignments) return min(student_count, len(exam_rooms_list))
def assign(self): """ Do the real assignment based on object properties """ spacing = self.spacing capacity_string = 'capacity_{:d}_free'.format(spacing) order_by_string = "-{:s}".format(capacity_string) exam_rooms = ExamRoom.objects.filter( available=True).order_by(order_by_string) exam_students = Student.get_current( tutor_group__group_category=self.group_category, want_exam=True) exam_students = exam_students.order_by('name', 'prename') student_count = exam_students.count() if exam_rooms.count() == 0 or student_count == 0: return 0 maximum_capacity = exam_rooms.aggregate( maximum_capacity=Sum(capacity_string)).get('maximum_capacity') # Set ratio so that all room gets equals percentage ratio = student_count / maximum_capacity # on minimal room mode and if the ratio is less then 90% the ratio is set to 90% # e.g. the first rooms get filled by 90%. The other rooms are not used if self.mode == 1 and ratio < 0.9: ratio = 0.9 # returns each room as often as seats are available for the given ratio exam_seats = chain.from_iterable( repeat(room, room.seats(spacing, ratio)) for room in exam_rooms) assign = partial(PersonToExamRoomAssignment, assignment=self) assignments = (assign(person=student, room=seat) for student, seat in zip(exam_students, exam_seats)) result = PersonToExamRoomAssignment.objects.bulk_create(assignments) return len(result)
def assign(self): """ Do the real assignment based on object properties """ spacing = self.spacing capacity_string = 'capacity_{:d}_free'.format(spacing) order_by_string = "-{:s}".format(capacity_string) exam_rooms = ExamRoom.objects.filter(available=True).order_by(order_by_string) exam_students = Student.get_current(tutor_group__group_category=self.group_category, want_exam=True) exam_students = exam_students.order_by('name', 'prename') student_count = exam_students.count() if exam_rooms.count() == 0 or student_count == 0: return 0 maximum_capacity = exam_rooms.aggregate(maximum_capacity=Sum(capacity_string)).get('maximum_capacity') # Set ratio so that all room gets equals percentage ratio = student_count / maximum_capacity # on minimal room mode and if the ratio is less then 90% the ratio is set to 90% # e.g. the first rooms get filled by 90%. The other rooms are not used if self.mode == 1 and ratio < 0.9: ratio = 0.9 # returns each room as often as seats are available for the given ratio exam_room_list = chain.from_iterable(repeat(room, room.seats(spacing, ratio)) for room in exam_rooms) assign = partial(PersonToExamRoomAssignment, assignment=self) assignments = (assign(person=student, room=room) for student, room in zip(exam_students, exam_room_list)) result = PersonToExamRoomAssignment.objects.bulk_create(assignments) return len(result)
def _correct_count(self, assignment): return assignment.count == Student.get_current(want_exam=True, tutor_group__group_category=assignment.group_category).count()