comparison python/repostats.py2 @ 121:347d7d8b96c0

Cleanup
author Windel Bouwman
date Sat, 12 Jan 2013 12:35:02 +0100
parents bb08633510bf
children aaa4939a7942
comparison
equal deleted inserted replaced
120:bb08633510bf 121:347d7d8b96c0
1 #!/usr/bin/python2 1 #!/usr/bin/python2
2 2
3 from mercurial import ui, hg 3 from mercurial import ui, hg
4 import numpy
5 import matplotlib.pyplot as plt
4 import datetime 6 import datetime
5 7
6 u = ui.ui() 8 u = ui.ui()
7 repo = hg.repository(u, '..') 9 repo = hg.repository(u, '..')
8 10
9 stamps = [] 11 stamps = []
10 nds = repo.changelog.nodesbetween() 12 nds = repo.changelog.nodesbetween()
11 print len(nds), nds
12 for hexid in nds[0]: 13 for hexid in nds[0]:
13 cset = repo.changelog.read(hexid) 14 cset = repo.changelog.read(hexid)
14 print cset 15 stamps.append(cset[2][0])
15 ts = cset[2][0]
16 stamps.append(ts)
17 16
18 print len(stamps)
19 dts = [datetime.datetime.fromtimestamp(st) for st in stamps] 17 dts = [datetime.datetime.fromtimestamp(st) for st in stamps]
20 print dts 18 print dts
21 19
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