Created
March 26, 2018 18:48
-
-
Save ctindall/0ec76ed45bd9742113f0423206800b4a 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
#!/usr/bin/env bash | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
function trampcp { | |
src="$1" | |
dest="$2" | |
emacs -q \ | |
--batch \ | |
--eval "(copy-file \"$src\" \"$dest\" t)" | |
} | |
function org2csv { | |
src="$1" | |
dest="$2" | |
emacs -q \ | |
--batch \ | |
--file "$src" \ | |
--eval "(org-table-export \"$dest\" \"orgtbl-to-csv\")" | |
sed -i 's/^\[//' $dest | |
sed -i 's/\ [A-Z][a-z][a-z]\]//' $dest | |
} | |
function csv2png { | |
#usage: csv2png SRC DEST | |
python3 -c " | |
import sys | |
import pandas as pd | |
import matplotlib | |
#use a noninteractive backend (this must happen before we import pyplot) | |
matplotlib.use('agg') | |
import matplotlib.pyplot as plt | |
src=sys.argv[1] | |
dest=sys.argv[2] | |
data = pd.read_csv(src, header=0) | |
data['date'] = pd.to_datetime(data['date']) | |
data = data.set_index('date') | |
data.resample('M') | |
for col in data.columns: | |
plt.plot(data.index, data[col], '-', label=col) | |
plt.legend() | |
plt.grid(True) | |
matplotlib.pyplot.savefig(dest, bbox='tight', pad_inches=2) | |
" $@ | |
} | |
function org2graph { | |
orgfile="$1" | |
csvfile=$(mktemp).csv | |
pngfile=$(mktemp).png | |
destfile="$2" | |
org2csv "$orgfile" "$csvfile" | |
csv2png "$csvfile" "$pngfile" | |
trampcp "$pngfile" "$destfile" | |
rm "$csvfile" "$pngfile" | |
} | |
org2graph "$1" "$2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment