#!/bin/sh
list=
while read l; do
	case "$l" in
	*qi-hardware*)
		list=q;;
	*serverraum*)
		list=m;;
	20*)	set -- `echo "$l" | sed "s/    /   -/g"`
		y=$1
		for m in 1 2 3 4 5 6 7 8 9 10 11 12; do
			shift
			[ "$1" ] || break
			if [ "$1" = - ]; then
				v=
			else
				v=$1
			fi
			eval ${list}_${y}_${m}=$v
		done
	esac
done <ML

N=4
t=
>_out
n=0
off=2
for y in 10 11 12 13 14; do
	for m in 1 2 3 4 5 6 7 8 9 10 11 12; do
		mm=`printf "%02d" $m`
		qn=`eval echo \\$q_20${y}_${m}`
		mn=`eval echo \\$m_20${y}_${m}`
		[ -z "$qn" -a -z "$mn" ] && continue
		if [ `expr $n % $N` = 0 ]; then
			[ "$t" ] && t=$t,
			t="$t \"$m/$y\" $n"
		else
			t="$t, \"\" $n"
		fi
#		cat ${Q}_20${y}-${mm}-*.log.html | gzip -9 | wc -c >>_out
		echo ${qn:-0} ${mn:-0} >>_out
		n=`expr $n + 1`
	done
done

gnuplot -persist <<EOF
set xtics ($t)
set grid xtics
set title "Traffic on the Qi-Hardware Mailing Lists"
set xlabel "Month"
set ylabel "Traffic (kbytes gzip'ed)"
plot "_out" using (\$1) with lines title "qi-hardware" lw 2, \
  "_out" using (\$2) with lines title "m-labs" lw 2, \
  "_out" using :(\$1+\$2) with lines title "Both" lw 2
set term png
set output "out.png"
replot
EOF
