Created
September 26, 2019 20:13
-
-
Save matthieucan/a51d9c2c009655607fb0c387c16ea97b to your computer and use it in GitHub Desktop.
Plots python source lines of code (as counted by sloccount) and PEP8 warnings (as reported by flake8) over time.
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 | |
# Copyright 2019 Matthieu Caneill | |
# Licensed unter WTFPL <http://www.wtfpl.net/txt/copying/> | |
# Plots python source lines of code (as counted by sloccount) and PEP8 | |
# warnings (as reported by flake8) over time. | |
# It is meant to be used in a git repository. | |
# Usage: | |
# ./plot.sh <dir> | |
# ./plot.sh <dir> <start-timestamp> | |
# ./plot.sh <dir> <start-timestamp> <end-timestamp> | |
# <dir> is the folder in which code is looked for. It is often useful | |
# to not use "." to avoid code in virtual environments. | |
# <start-timestamp> and <end-timestamp> are optional, if given, the | |
# x-axis of the plot will fit within those values. | |
DIR=$1 | |
START=$2 | |
END=$3 | |
DATA="plot.dat" | |
DATACLEAN="plot.clean.dat" | |
PLOT="plot.png" | |
rm $DATA $DATACLEAN | |
while : | |
do | |
# loop stopped when code folder doesn't exist anymore | |
test -e $DIR || break | |
timestamp=$(git log --pretty=tformat:'%ad' --date='format:%s' | head -n 1) | |
sloc=$(sloccount $DIR | grep -E '^python:' | cut -d: -f 2 | xargs | cut -d' ' -f 1) | |
warn=$(flake8 $DIR | wc -l) | |
echo $timestamp $sloc $warn >> $DATA | |
# loop stopped when first git commit is reached | |
git checkout "HEAD^" || break | |
done | |
# reverse the file for chronological order and remove duplicate | |
# entries (happens when commits do something else than touching python | |
# code) | |
tac $DATA | uniq -f 1 > $DATACLEAN | |
cat << EOF | gnuplot | |
set title "Python SLOC/PEP-8 warnings" | |
set xlabel "time" offset 0.0,-2.0 | |
set ylabel "SLOC" | |
set y2label "Warnings" offset 4.0,0.0 | |
set rmargin 9.0 | |
set xdata time | |
set timefmt "%s" | |
set format x "%Y-%m" | |
set xrange [$START:$END] | |
set yrange [0:] | |
set y2range [0:] | |
set xtics rotate by 45 offset -4.0,-2.5 | |
set ytics nomirror axis | |
set y2tics nomirror axis | |
set key top left | |
set key box | |
set grid | |
set style line 1 lw 3 lt rgb "#287e9b" | |
set style line 2 lw 3 lt rgb "#f27d18" | |
set terminal pngcairo size 900, 600 | |
set output '$PLOT' | |
plot '$DATACLEAN' using 1:2 axes x1y1 with lines ls 1 title "SLOC", \ | |
'$DATACLEAN' using 1:3 axes x1y2 with lines ls 2 title "Warnings" | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment