120
|
1 #!/usr/bin/python2
|
|
2
|
|
3 from mercurial import ui, hg
|
121
|
4 import numpy
|
|
5 import matplotlib.pyplot as plt
|
120
|
6 import datetime
|
|
7
|
|
8 u = ui.ui()
|
|
9 repo = hg.repository(u, '..')
|
|
10
|
|
11 stamps = []
|
|
12 nds = repo.changelog.nodesbetween()
|
|
13 for hexid in nds[0]:
|
|
14 cset = repo.changelog.read(hexid)
|
121
|
15 stamps.append(cset[2][0])
|
120
|
16
|
|
17 dts = [datetime.datetime.fromtimestamp(st) for st in stamps]
|
|
18 print dts
|
|
19
|
121
|
20 stats = numpy.zeros( (7, 24) )
|
|
21
|
|
22 for dt in dts:
|
|
23 d = dt.weekday()
|
|
24 h = dt.hour
|
|
25 stats[d][h] += 1
|
|
26
|
|
27 print stats
|
|
28 def enclose(tag, content, options=''):
|
|
29 return '<{0} {2}>\n{1}\n</{0}>'.format(tag, content, options)
|
|
30 def merge(*args):
|
|
31 print(args)
|
|
32 return '\n'.join(args)
|
|
33
|
|
34 head = enclose('head', enclose('title', 'repo stats'))
|
|
35
|
|
36 r1 = [enclose('td', td) for td in ['','Monday','Tuesday', 'Wed', 'Thur', 'Friday', 'S', 'S']]
|
|
37 r1 = enclose('tr', merge(*r1))
|
|
38
|
|
39 tc = merge(r1)
|
|
40
|
|
41 table = enclose('table', tc, options='border="2"')
|
|
42 body = enclose('body', enclose('h1', 'repo stats') + table)
|
|
43 html = enclose('html', head + body)
|
|
44
|
|
45 #with open('repostats.html', 'w') as f:
|
|
46 # f.write(html)
|
|
47
|
|
48 plt.scatter(stats)
|
|
49 plt.show()
|
|
50
|