From 5aa2c45f8b66c5820310e6c31e430e183260497c Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 1 Apr 2024 15:05:13 +0200 Subject: Initial commit. --- gwh.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 2 files changed, 76 insertions(+) create mode 100644 gwh.py create mode 100644 requirements.txt diff --git a/gwh.py b/gwh.py new file mode 100644 index 0000000..a440393 --- /dev/null +++ b/gwh.py @@ -0,0 +1,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') diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..945d399 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +GitPython +matplotlib -- cgit v0.11.2-87-g4458