Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def make_grouping(self, course: Course, survey: Survey) -> Grouping:
- """
- Return a grouping for all students in <course>.
- Starting with a tuple of all students in <course> obtained by calling
- the <course>.get_students() method, create groups of students using the
- following algorithm:
- 1. Get the windows of the list of students who have not already been
- put in a group.
- 2. For each window in order, calculate the current window's score as
- well as the score of the next window in the list. If the current
- window's score is greater than or equal to the next window's score,
- make a group out of the students in current window and start again at
- step 1. If the current window is the last window, compare it to the
- first window instead.
- In step 2 above, use the <survey>.score_students to determine the score
- of each window (list of students).
- In step 1 and 2 above, use the windows function to get the windows of
- the list of students.
- If there are any remaining students who have not been put in a group
- after repeating steps 1 and 2 above, put the remaining students into a
- new group.
- """
- students = list(course.get_students())
- s = students.copy()
- master = Grouping()
- while not not s:
- window = windows(s, self.group_size)
- for i in range(len(window)):
- if i + 1 != len(window):
- if survey.score_students(window[i]) > \
- survey.score_students(window[i+1]):
- x = []
- for lst in window[i:i+2]:
- for student in lst:
- x.append(student)
- s.remove(student)
- master.add_group(Group(x))
- else:
- if survey.score_students(window[i]) > \
- survey.score_students(window[0]):
- x = []
- for lst in window[i] + window[0]:
- for student in lst:
- x.append(student)
- s.remove(student)
- master.add_group(Group(x))
- return master
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement