#!/bin/sh
#	Created:	Mon Jul  5 15:37:33 CEST 2004	by M. Biermaier	on linuxorange
#	Version:	Mon Jul  5 15:54:15 CEST 2004	on linuxorange
#	$Id: GraphPrinter-InkLevel,v 1.1 2004/07/05 14:00:01 mbier Exp $

LOG_FILE=$HOME/logs/HP-PSC_2170-InkLevel_Log
LOG_DATA=/tmp/Log-InkLevel.DAT
PRINTER="HP-PSC 2175"

if [ $# -gt 0 ]
then
	START_INDEX=$1
	shift
fi
                                                                           
#Fre Jul  2 23:16:17 CEST 2004 Black: 71% Color: 51%

awk '
BEGIN   {
		FullDate        = 1;

		Month ["Jan"]   = 1;
		Month ["Feb"]   = 2;
		Month ["Mar"]   = 3;
		Month ["Apr"]   = 4;
		Month ["May"]   = 5;
		Month ["Jun"]   = 6;
		Month ["Jul"]   = 7;
		Month ["Aug"]   = 8;
		Month ["Sep"]   = 9;
		Month ["Oct"]   = 10;
		Month ["Nov"]   = 11;
		Month ["Dec"]   = 12;
	}
/.*:..:.*/{
		#printf ("%s", $0)
		#Mon Jan 13 09:00:00 CET 2003
		Dow			= $1;
		Mon			= $2;
		Day			= $3;
		Time		= $4;
		TimeZ		= $5;
		Year		= $6;

		InkLabel_1	= $7;
		InkLevel_1	= $8;
		InkLabel_2	= $9;
		InkLevel_2	= $10;

		if (NF >= 10) {
			printf ("%4d-%.2d-%.2d %s", Year, Month [Mon], Day, Time);
			printf (" %s %d", InkLabel_1, InkLevel_1);
			printf (" %s %d", InkLabel_2, InkLevel_2);
			printf ("\n");
		}
	}
' $LOG_FILE > $LOG_DATA

COL1=`cut -d" " -f 3 $LOG_DATA | head -1`
COL2=`cut -d" " -f 5 $LOG_DATA | head -1`

gnuplot -persist <<EOF
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%y-%m-%d"
set format y "%3.0f"
set xdata time
set xtics rotate
set grid
set title "InkLevel for $PRINTER"
set time
plot [${START_INDEX:+'$START_INDEX'}:]	"$LOG_DATA" using 1:4 title "$COL1" with lines, \
										"$LOG_DATA" using 1:6 title "$COL2" with lines
EOF

# vim: ts=4
