Created
June 3, 2019 20:58
-
-
Save davipatti/ef3ac010295af53b90b0e9e03c46a29d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# wc-timeseries.sh | |
# Plot word count over time for a latex project under git version control. | |
# Iterate over git commits | |
# Append date, word count and commit sha1 to a csv file | |
echo date,count,sha1 > /tmp/wc-timeseries.csv | |
for line in $(git log --decorate=no --reverse --format="format:%H,%aI") | |
do | |
sha1=$(echo $line | cut -f 1 -d ,) | |
date=$(echo $line | cut -f 2 -d ,) | |
git checkout --force --quiet $sha1 | |
wordcount=$(texcount $(find . -iname "*.tex") | grep "Words in text: " | tail -n 1 | cut -f 4 -d " ") | |
echo $date,$wordcount,$sha1 | |
done >> /tmp/wc-timeseries.csv 2> /tmp/wc-timeseries-stderr.txt | |
# Plot timeseries | |
python -c """ | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
df = pd.read_csv('/tmp/wc-timeseries.csv', index_col=0) | |
df.index = pd.to_datetime(df.index) | |
df['count'].plot(clip_on=False, zorder=20) | |
plt.ylim(0, plt.gca().get_ylim()[1]) | |
plt.ylabel('Word count') | |
plt.xlabel('Date') | |
plt.savefig('wc-timeseries.png', dpi=200) | |
plt.close() | |
""" | |
# Back to the original state of the repo | |
git checkout master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment