Advertisement
ridleygarnier

Untitled

Feb 19th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1.  def make_grouping(self, course: Course, survey: Survey) -> Grouping:
  2.         """
  3.        Return a grouping for all students in <course>.
  4.  
  5.        Starting with a tuple of all students in <course> obtained by calling
  6.        the <course>.get_students() method, create groups of students using the
  7.        following algorithm:
  8.  
  9.        1. Get the windows of the list of students who have not already been
  10.           put in a group.
  11.        2. For each window in order, calculate the current window's score as
  12.           well as the score of the next window in the list. If the current
  13.           window's score is greater than or equal to the next window's score,
  14.           make a group out of the students in current window and start again at
  15.           step 1. If the current window is the last window, compare it to the
  16.           first window instead.
  17.  
  18.        In step 2 above, use the <survey>.score_students to determine the score
  19.        of each window (list of students).
  20.  
  21.        In step 1 and 2 above, use the windows function to get the windows of
  22.        the list of students.
  23.  
  24.        If there are any remaining students who have not been put in a group
  25.        after repeating steps 1 and 2 above, put the remaining students into a
  26.        new group.
  27.        """
  28.         students = list(course.get_students())
  29.         s = students.copy()
  30.         master = Grouping()
  31.  
  32.         for students in s:
  33.             window = windows(s, self.group_size)
  34.             for i in range(len(window)):
  35.                 if i + 1 != len(window):
  36.                     if survey.score_students(window[i]) > \
  37.                             survey.score_students(window[i+1]):
  38.                         x = []
  39.                         for lst in window[i:i+2]:
  40.                             for student in lst:
  41.                                 x.append(student)
  42.                                 s.remove(student)
  43.                         master.add_group(Group(x))
  44.                 else:
  45.                     if survey.score_students(window[i]) > \
  46.                             survey.score_students(window[0]):
  47.                         x = []
  48.                         for lst in window[i:i+2]:
  49.                             for student in lst:
  50.                                 x.append(student)
  51.                                 s.remove(student)
  52.                     master.add_group(Group(x))
  53.         return master
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement