1616 get_default_filter_re ,
1717 latest_review_assignments_for_reviewers )
1818
19+ """
20+ This file contains policies regarding reviewer queues.
21+ The policies are documented in more detail on:
22+ https://trac.tools.ietf.org/tools/ietfdb/wiki/ReviewerQueuePolicy
23+ Terminology used here should match terminology used in that document.
24+ """
1925
20- def policy_for_team (team ):
21- return RotateWithSkipReviewerPolicy (team )
2226
27+ def get_reviewer_queue_policy (team ):
28+ return RotateWithSkipReviewerQueuePolicy (team )
2329
24- class AbstractReviewerPolicy :
30+
31+ class AbstractReviewerQueuePolicy :
2532 def __init__ (self , team ):
2633 self .team = team
2734
@@ -32,6 +39,12 @@ def default_reviewer_rotation_list(self, skip_unavailable=False, dont_skip=[]):
3239 """
3340 raise NotImplementedError
3441
42+ def update_policy_state_for_assignment (self , assignee_person_id , add_skip = False ):
43+ """
44+ Update the internal state of a policy to reflect an assignment.
45+ """
46+ raise NotImplementedError
47+
3548 # TODO : Change this field to deal with multiple already assigned reviewers???
3649 def setup_reviewer_field (self , field , review_req ):
3750 """
@@ -57,7 +70,7 @@ def _recommended_assignment_order(self, email_queryset, review_req):
5770 returning Email objects.
5871 """
5972 if review_req .team != self .team :
60- raise ValueError ('Reviewer policy was passed review request belonging to different team.' )
73+ raise ValueError ('Reviewer queue policy was passed review request belonging to different team.' )
6174 resolver = AssignmentOrderResolver (email_queryset , review_req , self .default_reviewer_rotation_list ())
6275 return resolver .determine_ranking ()
6376
@@ -90,7 +103,7 @@ def __init__(self, email_queryset, review_req, rotation_list):
90103 self ._collect_context ()
91104
92105 def _collect_context (self ):
93- # Collect all relevant data about this team, document and review request.
106+ """ Collect all relevant data about this team, document and review request."""
94107
95108 self .doc_aliases = DocAlias .objects .filter (docs = self .doc ).values_list ("name" , flat = True )
96109
@@ -109,6 +122,10 @@ def _collect_context(self):
109122 self .assignment_data_for_reviewers = latest_review_assignments_for_reviewers (self .team )
110123
111124 def determine_ranking (self ):
125+ """
126+ Determine the ranking of reviewers.
127+ Returns a list of tuples, each tuple containing an Email pk and an explanation label.
128+ """
112129 ranking = []
113130 for e in self .possible_emails :
114131 ranking .append (self ._ranking_for_email (e ))
@@ -118,6 +135,12 @@ def determine_ranking(self):
118135 return [(r ["email" ].pk , r ["label" ]) for r in ranking ]
119136
120137 def _ranking_for_email (self , email ):
138+ """
139+ Determine the ranking for a specific Email.
140+ Returns a dict with an email object, the scores and an explanation label.
141+ The scores are a list of individual scores, i.e. they are prioritised, not
142+ cumulative.
143+ """
121144 settings = self .reviewer_settings .get (email .person_id )
122145 scores = []
123146 explanations = []
@@ -183,6 +206,7 @@ def format_period(p):
183206 }
184207
185208 def _collect_reviewer_stats (self , email ):
209+ """Collect statistics on past reviews for a particular Email."""
186210 stats = []
187211 assignment_data = self .assignment_data_for_reviewers .get (email .person_id , [])
188212 currently_open = sum (1 for d in assignment_data if d .state in ["assigned" , "accepted" ])
@@ -206,8 +230,13 @@ def _collect_reviewer_stats(self, email):
206230 return stats
207231
208232 def _connections_with_doc (self , doc , person_ids ):
233+ """
234+ Collect any connections any Person in person_ids has with a document.
235+ Returns a dict containing Person IDs that have a connection as keys,
236+ values being an explanation string,
237+ """
209238 connections = {}
210- # examine the closest connections last to let them override
239+ # examine the closest connections last to let them override the label
211240 connections [doc .ad_id ] = "is associated Area Director"
212241 for r in Role .objects .filter (group = doc .group_id ,
213242 person__in = person_ids ).select_related ("name" ):
@@ -221,6 +250,10 @@ def _connections_with_doc(self, doc, person_ids):
221250 return connections
222251
223252 def _persons_with_previous_review (self , review_req , possible_person_ids ):
253+ """
254+ Collect anyone in possible_person_ids that have reviewed the request before.
255+ Returns a set with Person IDs of anyone who has.
256+ """
224257 has_reviewed_previous = ReviewRequest .objects .filter (
225258 doc = review_req .doc ,
226259 reviewassignment__reviewer__person__in = possible_person_ids ,
@@ -232,7 +265,7 @@ def _persons_with_previous_review(self, review_req, possible_person_ids):
232265 has_reviewed_previous = set (
233266 has_reviewed_previous .values_list ("reviewassignment__reviewer__person" , flat = True ))
234267 return has_reviewed_previous
235-
268+
236269 def _reviewer_settings_for_person_ids (self , person_ids ):
237270 reviewer_settings = {
238271 r .person_id : r
@@ -245,7 +278,7 @@ def _reviewer_settings_for_person_ids(self, person_ids):
245278 return reviewer_settings
246279
247280
248- class RotateWithSkipReviewerPolicy ( AbstractReviewerPolicy ):
281+ class RotateWithSkipReviewerQueuePolicy ( AbstractReviewerQueuePolicy ):
249282
250283 def update_policy_state_for_assignment (self , assignee_person_id , add_skip = False ):
251284 assert assignee_person_id is not None
0 commit comments