Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Last active May 1, 2023 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gro-Tsen/453354156046b31547db92b300c40813 to your computer and use it in GitHub Desktop.
Save Gro-Tsen/453354156046b31547db92b300c40813 to your computer and use it in GitHub Desktop.
cd /tmp
(echo "SET TIME ZONE 'UTC' ;" ; printf "%s\n" '\pset format unaligned' ; printf "%s\n" '\pset fieldsep '\'','\''' ; printf "%s\n" '\pset t' ; printf "%s\n" '\o blog-stats.csv' ; echo 'SELECT id , cdate , length(content::text) FROM entries ORDER BY id ;') | psql weblog
gnuplot << '__EOF__'
set terminal pngcairo size 1280,960
set output "blog-stats-2023.png"
set datafile separator ","
stats "blog-stats.csv" using ($1):($3) name "st"
ratio=st_sum_y/1024./st_max_x
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y-%m"
set mxtics 4
set yrange [0:3000]
set ytics 500 nomirror
set mytics 5
set y2range [0:3000*ratio]
set y2tics 5000 nomirror
set my2tics 5
plot "blog-stats.csv" using 2:($1) with lines lw 2 title "entries (left scale)", "blog-stats.csv" using 2:($3/1024.) smooth cumulative with lines lw 2 title "kibichars (right scale)" axes x1y2
__EOF__
convert blog-stats-2023.png -resize 960x480 blog-stats-2023-small.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment