Awhile ago I created a simple script to create bar charts on the command-line for when I published my running year in review, 2017 example here. I published the script on Github and surprisingly have received a few contributors over the years, recently a couple of students from Greece did a nice upgrade to numerous features which is awesome.

I also track my running data using a Javsacript heatmap chart, which is published here. Publishing requires generating the data, uploading, and then viewing on Codepen. This is too many steps, which got me thinking maybe I can create a terminal heatmap chart. Yes, I can.



Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Mon: ░ ░ ░░░ ░ ░ ░ Tue: ░ ░ ░ Wed: ░ ░ ░ ░░ ░ ░ ░ ░ ░░ Thu: ░ ░░ ░░ ░▒ Fri: ░ ░ ░ ░ ░ ░ Sat: ░░░ ░ ▒ ▒ ░ Sun: ░ ░ ░

The above is the example from the updated termgraph.py script. So to generate the data, first I store my data in a simple text file with the following format:

# date | distance | time | notes 2018-06-20 | 4.26 | 38:58 |

This needed to be massaged a little, since the script expects the data either comma or space seperated. Using the awk command it is straight forward to change the delimiter and print out the first two columns; which can then be piped straight to termgraph.py



awk 'BEGIN{FS="|"}{ print $1 $2 }' runs.data | termgraph.py --calendar

If you need an Awk refresher, check out An Awk Tutorial by Example.

So now I can see a quick calendar of my latest runs for the year, but the tool is also fairly flexible to work with any type of data you want to chart. It supports a color parameter, which looks like this in the terminal:



Fun things you can do charting on the command-line, take a look at the repo for other charting examples on Github: https://github.com/mkaz/termgraph

Bonus, I recently added emoji support to termgraph.py, this also works in the heatmap which is a little less accurate, but more fun.

