Adds median waiting time

Adds ability to exclude changesets for stable branch
Shows 5 longest waiting changesests
This commit is contained in:
Chris Yeoh 2013-05-29 21:30:01 +09:30
parent 74e67bfe52
commit e23974f926
1 changed files with 28 additions and 4 deletions

View File

@ -33,6 +33,8 @@ optparser.add_option('-a', '--all', action='store_true',
help='Generate stats across all known projects (*.json)')
optparser.add_option('-u', '--user', default='russellb', help='gerrit user')
optparser.add_option('-k', '--key', default=None, help='ssh key for gerrit')
optparser.add_option('-n', '--no-stable', action='store_true',
help='Exclude changesets for stable branch)')
options, args = optparser.parse_args()
@ -51,9 +53,19 @@ waiting_on_reviewer = []
now = datetime.datetime.utcnow()
now_ts = calendar.timegm(now.timetuple())
def sec_to_period_string(seconds):
days = seconds / (3600 * 24)
hours = (seconds / 3600) - (days * 24)
minutes = (seconds / 60) - (days * 24 * 60) - (hours * 60)
return '%d days, %d hours, %d minutes' % (days, hours, minutes)
for change in changes:
if 'rowCount' in change:
continue
if options.no_stable and 'stable' in change['branch']:
continue
latest_patch = change['patchSets'][-1]
waiting_for_review = True
for review in latest_patch.get('approvals', []):
@ -74,10 +86,15 @@ def average_age(changes):
for change in changes:
total_seconds += change['age']
avg_age = total_seconds / len(changes)
days = avg_age / (3600 * 24)
hours = (avg_age / 3600) - (days * 24)
minutes = (avg_age / 60) - (days * 24 * 60) - (hours * 60)
return '%d days, %d hours, %d minutes' % (days, hours, minutes)
return sec_to_period_string(avg_age)
def median_age(changes):
changes = sorted(changes, key=lambda change: change['age'])
median_age = changes[len(changes)/2]['age']
return sec_to_period_string(median_age)
age_sorted_waiting_on_reviewer = sorted(waiting_on_reviewer,
key=lambda change: change['age'])
print 'Projects: %s' % [project['name'] for project in projects]
@ -86,3 +103,10 @@ print 'Total Open Reviews: %d' % (len(waiting_on_reviewer) +
print 'Waiting on Submitter: %d' % len(waiting_on_submitter)
print 'Waiting on Reviewer: %d' % len(waiting_on_reviewer)
print ' --> Average wait time: %s' % average_age(waiting_on_reviewer)
print ' --> Median wait time: %s' % median_age(waiting_on_reviewer)
print ' --> Longest waiting reviews:'
for change in age_sorted_waiting_on_reviewer[-5:]:
print ' --> %s %s \n (%s)' % (
sec_to_period_string(change['age']),
change['url'], change['subject'])