#!/bin/bash

filesystems="$(ls results/ | cut -d - -f 1 | sort -u)"
tests="$(ls results/ | cut -d - -f 2- | sort -u)"

for test in $tests; do
	title="`sed -n 's/^#  *Title:  *//p' tests/$test 2> /dev/null`"
	case $test in
	*create*) title="File-system creation" ;;
	*mount*) title="First mount time" ;;
	esac

	echo "$test: $title"

	for fs in $filesystems; do
		val="`tail -n 3 results/$fs-$test 2> /dev/null | sed -n 's/real  *//p'`"
		if [ "$val" ]; then
			echo "$fs,$val"
		fi
	done > temp.csv

	cat > temp.ploticus <<-EOT
#proc getdata
file: temp.csv
delimit: comma

#proc categories
  datafield: 1
  axis: y

#proc areadef
  title: $title
  titledetails: align=C
  rectangle: 1 1 5 $(( $(echo "$filesystems" | wc -w) / 2 - 1))
  yscaletype: categories
  xautorange: datafield=2 lowfix=0
  xaxis.stubs: incremental

#proc bars
  horizontalbars: yes
//  colorlist: powderblue purple redorange teal gray(0.4)
  colorlist: gray(0.1) gray(0.2) gray(0.3) gray(0.4) gray(0.5) gray(0.6) gray(0.7) gray(0.8) gray(0.9) gray(1.0)
  lenfield: 2
  barwidth: 0.15
  labeldetails: adjust=0,-0.03
  showvalues: yes

#proc xaxis
  //stubs: inc .20
  //stubformat: %0.2f
  label: Time in seconds (lower is better)
  labeldetails: size=9

#proc yaxis:
  stubs: usecategories
  tics: none
  stubdetails: align=R adjust=0,0
EOT
	ploticus -eps -o $test.eps temp.ploticus
        dpi=98
        convert -density ${dpi}x${dpi} $test.eps -type Palette $test.png

	# rm -f temp.{csv,ploticus}
done
