#!/bin/bash

export GNUPLOT_DEFAULT_GDFONT=inconsolata

job=$(realpath "$1")
confuga=$(realpath "$2")

data=$(mktemp)

echo $0
sqlite3 -separator $'\t' > "$data"  <<EOF
ATTACH 'file://${job}?immutable=1' as Job;
ATTACH 'file://${confuga}?immutable=1' as Confuga;

SELECT Job.id, Job.time_start, 1
	FROM Job.Job
UNION ALL
SELECT Job.id, Job.time_finish, -1
	FROM Job.Job;
EOF
cat "$data"

gnuplot <<EOF
set terminal postscript eps mono
set output 'concurrent.eps'

stats "$data" using 2 prefix "tj" nooutput

set rmargin 4

set xdata time
set timefmt "%s"
set format x "%H:%M"
set xlabel "Time (Minutes)"
set xtics rotate by -45 offset -.8,0

set ylabel "Concurrent Jobs"
set mytics

plot [][0:] "${data}" using (\$2-tj_min):3 title "Concurrent Jobs" smooth cumulative
EOF

# vim: set noexpandtab tabstop=4:
