summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-04-01 13:05:13 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-04-01 13:05:13 (GMT)
commit5aa2c45f8b66c5820310e6c31e430e183260497c (patch)
treed4a3bc90624e58246a14ad415e3e775152f3bf47
Initial commit.
-rw-r--r--gwh.py74
-rw-r--r--requirements.txt2
2 files changed, 76 insertions, 0 deletions
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