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
|
import sys
from datetime import datetime
from git import Repo
from matplotlib import dates as mdates, pyplot as plt
if __name__ == '__main__':
"""Script entrypoint."""
name = sys.argv[1]
repo = Repo.init(name)
mail = sys.argv[2] if len(sys.argv) > 2 else None
# Data collect
tree = repo.head.commit.tree
trange = []
hours = []
days = []
for commit in repo.iter_commits(all=True): #, max_count=100):
dt = datetime.fromtimestamp(commit.authored_date, tz=None)
if mail and mail != commit.author.email:
continue
trange.append(dt)
hours.append(dt.hour + dt.minute / 60)
days.append(6 - dt.weekday())
# Create graph
fig, ax = plt.subplots(nrows=2, ncols=1)
fig.set_figwidth(fig.get_figwidth() * 2)
fig.set_figheight(fig.get_figheight() * 2)
# Hour of day
ax[0].plot(trange, hours, 'o', color='orange', ms=5, mec='black', mew=1)
allhours = [ '%u:00' % x for x in range(0, 25, 4) ]
ax[0].set_yticks([ x for x in range(0, 25, 4) ], allhours)
fmt = mdates.DateFormatter('%m/%y')
ax[0].xaxis.set_major_formatter(fmt)
# Day of week
ax[1].plot(trange, days, 'o', color='orange', ms=5, mec='black', mew=1)
alldays = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ]
ax[1].set_yticks([ x for x in range(7) ], reversed(alldays))
fmt = mdates.DateFormatter('%m/%y')
ax[1].xaxis.set_major_formatter(fmt)
# Output
if mail:
ax[0].title.set_text('Git working hours for %s (filtered for %s)' % (name, mail))
else:
ax[0].title.set_text('Git working hours for %s' % name)
plt.savefig('stats.png', bbox_inches='tight')
|