-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrb_stats.py
86 lines (67 loc) · 2.99 KB
/
rb_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from collections import defaultdict
import argparse
import requests
import matplotlib.pyplot as plt
import numpy as np
def parse_req_params(pargs):
rb_api_args = ['from-user', 'max-results', 'status']
dparams = {}
for key, value in pargs.iteritems():
converted_key = key.replace('_', '-')
if converted_key in rb_api_args:
if value:
dparams[converted_key] = value
return dparams
def run_main():
parser = argparse.ArgumentParser(description='Review Board Stats')
parser.add_argument('base_api_url', help='The ReviewBoard base API URL')
parser.add_argument('--from-user',
help='Only Review Requests by this user')
parser.add_argument('--max-results', type=int,
help=('Maximum number of Review Requests to '
'retrieve (default: %(default)s)'),
default=200)
parser.add_argument('--status',
choices=['discarded', 'pending', 'submitted'],
help=('Only retrieve Review Requests with '
'this status (default: %(default)s)'),
default='submitted')
parser.add_argument('--colormap',
help=('The colormap that should be used for '
'the plotting (default: %(default)s)'),
default='jet')
parser.add_argument('--interpolation',
help=('Interpolation method to use '
'(default: %(default)s'),
default='gaussian',
choices=['none', 'nearest', 'bilinear', 'bicubic',
'hanning', 'hamming', 'gaussian'])
args = parser.parse_args()
req_params = parse_req_params(vars(args))
ret = requests.get(args.base_api_url + '/review-requests',
params=req_params)
graph_data = defaultdict(int)
for review in ret.json['review_requests']:
submitter = review['links']['submitter']['title']
for people in review['target_people']:
reviewer = people['title']
graph_data[(submitter, reviewer)] += 1.0
xaxis = sorted(set(x[0] for x in graph_data.iterkeys()), reverse=True)
yaxis = sorted(set(x[1] for x in graph_data.iterkeys()))
arr = np.zeros((len(xaxis), len(yaxis)))
for k, v in graph_data.iteritems():
x, y = k
arr[xaxis.index(x), yaxis.index(y)] = v
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
im = ax.imshow(arr, cmap=plt.get_cmap(args.colormap),
interpolation=args.interpolation)
ax.set_yticklabels(xaxis)
tick_locs = range(len(yaxis))
plt.xticks(tick_locs, yaxis, rotation='vertical')
tick_locs = range(len(xaxis))
plt.yticks(tick_locs, xaxis)
plt.colorbar(im)
plt.show()
if __name__ == "__main__":
run_main()