OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Get rietveld stats about the review you done, or forgot to do. | 6 """Get rietveld stats about the review you done, or forgot to do. |
7 | 7 |
8 Example: | 8 Example: |
9 - my_reviews.py -r me@chromium.org -Q for stats for last quarter. | 9 - my_reviews.py -r me@chromium.org -Q for stats for last quarter. |
10 """ | 10 """ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 class Stats(object): | 60 class Stats(object): |
61 def __init__(self): | 61 def __init__(self): |
62 self.total = 0 | 62 self.total = 0 |
63 self.actually_reviewed = 0 | 63 self.actually_reviewed = 0 |
64 self.average_latency = 0. | 64 self.average_latency = 0. |
65 self.number_latency = 0 | 65 self.number_latency = 0 |
66 self.lgtms = 0 | 66 self.lgtms = 0 |
67 self.multiple_lgtms = 0 | 67 self.multiple_lgtms = 0 |
68 self.drive_by = 0 | 68 self.drive_by = 0 |
69 self.not_requested = 0 | 69 self.not_requested = 0 |
| 70 self.self_review = 0 |
70 | 71 |
71 self.percent_done = 0. | 72 self.percent_done = 0. |
72 self.percent_lgtm = 0. | 73 self.percent_lgtm = 0. |
73 self.percent_drive_by = 0. | 74 self.percent_drive_by = 0. |
74 self.percent_not_requested = 0. | 75 self.percent_not_requested = 0. |
75 self.days = None | 76 self.days = 0 |
76 self.review_per_day = 0. | 77 self.review_per_day = 0. |
77 self.review_done_per_day = 0. | 78 self.review_done_per_day = 0. |
78 | 79 |
79 def add_latency(self, latency): | 80 def add_latency(self, latency): |
80 self.average_latency = ( | 81 self.average_latency = ( |
81 (self.average_latency * self.number_latency + latency) / | 82 (self.average_latency * self.number_latency + latency) / |
82 (self.number_latency + 1.)) | 83 (self.number_latency + 1.)) |
83 self.number_latency += 1 | 84 self.number_latency += 1 |
84 | 85 |
85 def finalize(self, first_day, last_day): | 86 def finalize(self, first_day, last_day): |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 msg['recipients'] = [username(r) for r in msg['recipients']] | 162 msg['recipients'] = [username(r) for r in msg['recipients']] |
162 # Convert all times to datetime instances. | 163 # Convert all times to datetime instances. |
163 msg['date'] = to_datetime(msg['date']) | 164 msg['date'] = to_datetime(msg['date']) |
164 issue['messages'].sort(key=lambda x: x['date']) | 165 issue['messages'].sort(key=lambda x: x['date']) |
165 | 166 |
166 | 167 |
167 def print_issue(issue, reviewer, stats): | 168 def print_issue(issue, reviewer, stats): |
168 """Process an issue and prints stats about it.""" | 169 """Process an issue and prints stats about it.""" |
169 stats.total += 1 | 170 stats.total += 1 |
170 _process_issue(issue) | 171 _process_issue(issue) |
171 if any(msg['sender'] == reviewer for msg in issue['messages']): | 172 if issue['owner_email'] == reviewer: |
| 173 stats.self_review += 1 |
| 174 latency = '<self review>' |
| 175 reviewed = '' |
| 176 elif any(msg['sender'] == reviewer for msg in issue['messages']): |
172 reviewed = _process_issue_lgtms(issue, reviewer, stats) | 177 reviewed = _process_issue_lgtms(issue, reviewer, stats) |
173 latency = _process_issue_latency(issue, reviewer, stats) | 178 latency = _process_issue_latency(issue, reviewer, stats) |
174 else: | 179 else: |
175 latency = 'N/A' | 180 latency = 'N/A' |
176 reviewed = '' | 181 reviewed = '' |
177 | 182 |
178 # More information is available, print issue.keys() to see them. | 183 # More information is available, print issue.keys() to see them. |
179 print '%7d %10s %3s %14s %-15s %s' % ( | 184 print '%7d %10s %3s %14s %-15s %s' % ( |
180 issue['issue'], | 185 issue['issue'], |
181 issue['created'][:10], | 186 issue['created'][:10], |
(...skipping 26 matching lines...) Expand all Loading... |
208 with_messages=True): | 213 with_messages=True): |
209 last_issue = issue | 214 last_issue = issue |
210 if not first_day: | 215 if not first_day: |
211 first_day = issue['created'][:10] | 216 first_day = issue['created'][:10] |
212 print_issue(issue, username(reviewer), stats) | 217 print_issue(issue, username(reviewer), stats) |
213 if last_issue: | 218 if last_issue: |
214 last_day = last_issue['created'][:10] | 219 last_day = last_issue['created'][:10] |
215 stats.finalize(first_day, last_day) | 220 stats.finalize(first_day, last_day) |
216 | 221 |
217 print >> sys.stderr, ( | 222 print >> sys.stderr, ( |
218 '%s reviewed %d issues out of %d (%1.1f%%).' % | 223 '%s reviewed %d issues out of %d (%1.1f%%). %d were self-review.' % |
219 (reviewer, stats.actually_reviewed, stats.total, stats.percent_done)) | 224 (reviewer, stats.actually_reviewed, stats.total, stats.percent_done, |
| 225 stats.self_review)) |
220 print >> sys.stderr, ( | 226 print >> sys.stderr, ( |
221 '%4.1f review request/day during %3d days (%4.1f r/d done).' % ( | 227 '%4.1f review request/day during %3d days (%4.1f r/d done).' % ( |
222 stats.review_per_day, stats.days, stats.review_done_per_day)) | 228 stats.review_per_day, stats.days, stats.review_done_per_day)) |
223 print >> sys.stderr, ( | 229 print >> sys.stderr, ( |
224 '%4d were drive-bys (%5.1f%% of reviews done).' % ( | 230 '%4d were drive-bys (%5.1f%% of reviews done).' % ( |
225 stats.drive_by, stats.percent_drive_by)) | 231 stats.drive_by, stats.percent_drive_by)) |
226 print >> sys.stderr, ( | 232 print >> sys.stderr, ( |
227 '%4d were requested over IM or irc (%5.1f%% of reviews done).' % ( | 233 '%4d were requested over IM or irc (%5.1f%% of reviews done).' % ( |
228 stats.not_requested, stats.percent_not_requested)) | 234 stats.not_requested, stats.percent_not_requested)) |
229 print >> sys.stderr, ( | 235 print >> sys.stderr, ( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 print_reviews( | 324 print_reviews( |
319 options.reviewer, | 325 options.reviewer, |
320 options.begin, | 326 options.begin, |
321 options.end, | 327 options.end, |
322 options.instance_url) | 328 options.instance_url) |
323 return 0 | 329 return 0 |
324 | 330 |
325 | 331 |
326 if __name__ == '__main__': | 332 if __name__ == '__main__': |
327 sys.exit(main()) | 333 sys.exit(main()) |
OLD | NEW |