Mercurial > lcfOS
comparison python/repostats.py2 @ 122:aaa4939a7942
Improved repostats
author | Windel Bouwman |
---|---|
date | Sat, 12 Jan 2013 12:49:27 +0100 |
parents | 347d7d8b96c0 |
children |
comparison
equal
deleted
inserted
replaced
121:347d7d8b96c0 | 122:aaa4939a7942 |
---|---|
1 #!/usr/bin/python2 | 1 #!/usr/bin/python2 |
2 | |
3 import sys | |
4 # Use python 2 since mercurial does not support python 3 yet? | |
5 assert sys.version_info.major == 2 | |
2 | 6 |
3 from mercurial import ui, hg | 7 from mercurial import ui, hg |
4 import numpy | 8 import numpy |
5 import matplotlib.pyplot as plt | 9 import matplotlib.pyplot as plt |
6 import datetime | 10 import datetime |
7 | 11 |
8 u = ui.ui() | 12 u = ui.ui() |
9 repo = hg.repository(u, '..') | 13 repo = hg.repository(u, '..') |
10 | 14 |
11 stamps = [] | 15 stamps = [] |
12 nds = repo.changelog.nodesbetween() | 16 nds = repo.changelog.nodesbetween()[0] |
13 for hexid in nds[0]: | 17 for hexid in nds: |
14 cset = repo.changelog.read(hexid) | 18 cset = repo.changelog.read(hexid) |
15 stamps.append(cset[2][0]) | 19 stamps.append(cset[2][0]) |
16 | 20 |
17 dts = [datetime.datetime.fromtimestamp(st) for st in stamps] | 21 dts = [datetime.datetime.fromtimestamp(st) for st in stamps] |
18 print dts | |
19 | 22 |
20 stats = numpy.zeros( (7, 24) ) | 23 x = [dt.weekday() for dt in dts] |
24 y = [dt.hour for dt in dts] | |
21 | 25 |
22 for dt in dts: | 26 # plot it: |
23 d = dt.weekday() | 27 f = plt.figure() |
24 h = dt.hour | 28 #plt.hexbin(x, y) |
25 stats[d][h] += 1 | 29 plt.scatter(x, y) |
26 | 30 ax = plt.gca() |
27 print stats | 31 ax.set_ylim([0, 24]) |
28 def enclose(tag, content, options=''): | 32 ax.set_ylabel('hour of day') |
29 return '<{0} {2}>\n{1}\n</{0}>'.format(tag, content, options) | 33 ax.set_xlim([0, 7]) |
30 def merge(*args): | 34 ax.set_xlabel('day of week') |
31 print(args) | 35 ax.grid() |
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() | 36 plt.show() |
50 | 37 |