summaryrefslogtreecommitdiff
path: root/cal-heatmap.py
diff options
context:
space:
mode:
Diffstat (limited to 'cal-heatmap.py')
-rwxr-xr-xcal-heatmap.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/cal-heatmap.py b/cal-heatmap.py
new file mode 100755
index 0000000..0c07b98
--- /dev/null
+++ b/cal-heatmap.py
@@ -0,0 +1,66 @@
+#
+# CALENDAR HEATMAP
+#
+# DESCRIPTION
+# Creates a calendar heatmap from a git commit frequency list.
+# The frequency list must be in JSON and formatted as 'YYYY-MM-DD: FREQ'.
+#
+# ARGS
+# 1nd arg: path to JSON frequency list
+# 2st arg (optional): output file path
+#
+# REQUIREMENTS
+# matplotlib july
+#
+# NOTE
+# If receiving Matplotlib warning, install patch:
+# pip install -U git+https://github.com/thoellrich/july.git@fix-mpl.cbook.MatplotlibDepreciationWarning
+#
+
+import os
+import sys
+import json
+import july
+import matplotlib.pyplot as plt
+
+from datetime import datetime as dtime
+from july.utils import date_range as drange
+
+if len(sys.argv) == 1:
+ print("Error: commits file not specified")
+ quit()
+
+freqlist = sys.argv[1]
+
+if len(sys.argv) == 2:
+ print("Output file not specified; defaulting to current directory")
+ outfile = "activity.png"
+else:
+ outfile = sys.argv[2]
+
+if not os.path.exists(freqlist):
+ print("Error: file '{}' does not exists".format(freqlist))
+ quit()
+
+commits = json.load(open(freqlist,'r'))
+
+# Create this years calendar
+start='{}-01-01'.format(dtime.now().year)
+end='{}-12-31'.format(dtime.now().year)
+calendar = [ d.strftime("%F") for d in drange(start,end) ]
+
+# Populate calendar with commits
+cal = {}
+for date in calendar:
+ cal[date] = commits[date] if date in commits else 0
+
+# Create heatmap
+july.heatmap(cal.keys(),
+ cal.values(),
+ month_grid=True,
+ weekday_label=True,
+ title="Activity",
+ cmap="github")
+
+# Save image
+plt.savefig(outfile, bbox_inches='tight', pad_inches=0.0)