| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 def finalize(self, first_day, last_day): | 111 def finalize(self, first_day, last_day): |
| 112 if self.actually_reviewed: | 112 if self.actually_reviewed: |
| 113 assert self.actually_reviewed > 0 | 113 assert self.actually_reviewed > 0 |
| 114 self.percent_lgtm = (self.lgtms * 100. / self.actually_reviewed) | 114 self.percent_lgtm = (self.lgtms * 100. / self.actually_reviewed) |
| 115 self.percent_drive_by = (self.drive_by * 100. / self.actually_reviewed) | 115 self.percent_drive_by = (self.drive_by * 100. / self.actually_reviewed) |
| 116 self.percent_not_requested = ( | 116 self.percent_not_requested = ( |
| 117 self.not_requested * 100. / self.actually_reviewed) | 117 self.not_requested * 100. / self.actually_reviewed) |
| 118 assert bool(first_day) == bool(last_day) | 118 assert bool(first_day) == bool(last_day) |
| 119 if first_day and last_day: | 119 if first_day and last_day: |
| 120 assert first_day < last_day | 120 assert first_day <= last_day |
| 121 self.days = (to_datetime(last_day) - to_datetime(first_day)).days + 1 | 121 self.days = (to_datetime(last_day) - to_datetime(first_day)).days + 1 |
| 122 assert self.days > 0 | 122 assert self.days > 0 |
| 123 | 123 |
| 124 | 124 |
| 125 def _process_issue_lgtms(issue, reviewer, stats): | 125 def _process_issue_lgtms(issue, reviewer, stats): |
| 126 """Calculates LGTMs stats.""" | 126 """Calculates LGTMs stats.""" |
| 127 stats.actually_reviewed += 1 | 127 stats.actually_reviewed += 1 |
| 128 reviewer_lgtms = len([ | 128 reviewer_lgtms = len([ |
| 129 msg for msg in issue['messages'] | 129 msg for msg in issue['messages'] |
| 130 if msg['approval'] and msg['sender'] == reviewer]) | 130 if msg['approval'] and msg['sender'] == reviewer]) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 begin_month += 12 | 299 begin_month += 12 |
| 300 begin = '%d-%02d-01' % (begin_year, begin_month) | 300 begin = '%d-%02d-01' % (begin_year, begin_month) |
| 301 return begin, end | 301 return begin, end |
| 302 | 302 |
| 303 | 303 |
| 304 def main(): | 304 def main(): |
| 305 # Silence upload.py. | 305 # Silence upload.py. |
| 306 rietveld.upload.verbosity = 0 | 306 rietveld.upload.verbosity = 0 |
| 307 today = datetime.date.today() | 307 today = datetime.date.today() |
| 308 begin, end = get_previous_quarter(today) | 308 begin, end = get_previous_quarter(today) |
| 309 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 309 default_email = os.environ.get('EMAIL_ADDRESS') |
| 310 if not default_email: |
| 311 user = os.environ.get('USER') |
| 312 if user: |
| 313 default_email = user + '@chromium.org' |
| 314 |
| 315 parser = optparse.OptionParser(description=__doc__) |
| 310 parser.add_option( | 316 parser.add_option( |
| 311 '--count', action='store_true', | 317 '--count', action='store_true', |
| 312 help='Just count instead of printing individual issues') | 318 help='Just count instead of printing individual issues') |
| 313 parser.add_option( | 319 parser.add_option( |
| 314 '-r', '--reviewer', metavar='<email>', | 320 '-r', '--reviewer', metavar='<email>', default=default_email, |
| 315 default=os.environ.get('EMAIL_ADDRESS'), | |
| 316 help='Filter on issue reviewer, default=%default') | 321 help='Filter on issue reviewer, default=%default') |
| 317 parser.add_option( | 322 parser.add_option( |
| 318 '-b', '--begin', metavar='<date>', | 323 '-b', '--begin', metavar='<date>', |
| 319 help='Filter issues created after the date') | 324 help='Filter issues created after the date') |
| 320 parser.add_option( | 325 parser.add_option( |
| 321 '-e', '--end', metavar='<date>', | 326 '-e', '--end', metavar='<date>', |
| 322 help='Filter issues created before the date') | 327 help='Filter issues created before the date') |
| 323 parser.add_option( | 328 parser.add_option( |
| 324 '-Q', '--last_quarter', action='store_true', | 329 '-Q', '--last_quarter', action='store_true', |
| 325 help='Use last quarter\'s dates, e.g. %s to %s' % ( | 330 help='Use last quarter\'s dates, e.g. %s to %s' % (begin, end)) |
| 326 begin, end)) | |
| 327 parser.add_option( | 331 parser.add_option( |
| 328 '-i', '--instance_url', metavar='<host>', | 332 '-i', '--instance_url', metavar='<host>', |
| 329 default='http://codereview.chromium.org', | 333 default='http://codereview.chromium.org', |
| 330 help='Host to use, default is %default') | 334 help='Host to use, default is %default') |
| 331 # Remove description formatting | 335 # Remove description formatting |
| 332 parser.format_description = ( | 336 parser.format_description = ( |
| 333 lambda _: parser.description) # pylint: disable=E1101 | 337 lambda _: parser.description) # pylint: disable=E1101 |
| 334 options, args = parser.parse_args() | 338 options, args = parser.parse_args() |
| 335 if args: | 339 if args: |
| 336 parser.error('Args unsupported') | 340 parser.error('Args unsupported') |
| 337 if not options.reviewer: | 341 if options.reviewer is None: |
| 338 parser.error('$EMAIL_ADDRESS is not set, please use -r') | 342 parser.error('$EMAIL_ADDRESS and $USER are not set, please use -r') |
| 343 |
| 339 print >> sys.stderr, 'Searching for reviews by %s' % options.reviewer | 344 print >> sys.stderr, 'Searching for reviews by %s' % options.reviewer |
| 340 if options.last_quarter: | 345 if options.last_quarter: |
| 341 options.begin = begin | 346 options.begin = begin |
| 342 options.end = end | 347 options.end = end |
| 343 print >> sys.stderr, 'Using range %s to %s' % ( | 348 print >> sys.stderr, 'Using range %s to %s' % ( |
| 344 options.begin, options.end) | 349 options.begin, options.end) |
| 350 else: |
| 351 if options.begin is None or options.end is None: |
| 352 parser.error('Please specify either --last_quarter or --begin and --end') |
| 345 | 353 |
| 346 # Validate dates. | 354 # Validate dates. |
| 347 try: | 355 try: |
| 348 to_datetime(options.begin) | 356 to_datetime(options.begin) |
| 349 to_datetime(options.end) | 357 to_datetime(options.end) |
| 350 except ValueError as e: | 358 except ValueError as e: |
| 351 parser.error('%s: %s - %s' % (e, options.begin, options.end)) | 359 parser.error('%s: %s - %s' % (e, options.begin, options.end)) |
| 352 | 360 |
| 353 if options.count: | 361 if options.count: |
| 354 print_count( | 362 print_count( |
| 355 options.reviewer, | 363 options.reviewer, |
| 356 options.begin, | 364 options.begin, |
| 357 options.end, | 365 options.end, |
| 358 options.instance_url) | 366 options.instance_url) |
| 359 else: | 367 else: |
| 360 print_reviews( | 368 print_reviews( |
| 361 options.reviewer, | 369 options.reviewer, |
| 362 options.begin, | 370 options.begin, |
| 363 options.end, | 371 options.end, |
| 364 options.instance_url) | 372 options.instance_url) |
| 365 return 0 | 373 return 0 |
| 366 | 374 |
| 367 | 375 |
| 368 if __name__ == '__main__': | 376 if __name__ == '__main__': |
| 369 sys.exit(main()) | 377 sys.exit(main()) |
| OLD | NEW |