diff options
| author | Blake Romero <blake@blkrom.com> | 2024-11-03 17:48:11 +0000 |
|---|---|---|
| committer | Blake Romero <blake@blkrom.com> | 2024-11-03 17:48:11 +0000 |
| commit | 201497a648688c3f1c6f31ff213e4cbe0619b3db (patch) | |
| tree | 12946fc61e70fb79d8a3b6cd77f77904e33fce97 | |
| parent | 67c4df0cdce31076e6b91028a1e14c0567e4d7f9 (diff) | |
Add calendar heatmap script
| -rwxr-xr-x | cal-heatmap.py | 66 |
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) |
