annotate python/repostats.py2 @ 121:347d7d8b96c0

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