#!/bin/bash

{
cat <<- Rscript
	log <- read.table(file = stdin())
Rscript
cat /dev/stdin
echo
cat <<- Rscript
	times <- strptime(paste(log[,1], log[,2]), format = "%Y-%m-%d %H:%M:%S")
	colors <- c("red", "green")

	# Choose output format:
	#postscript(file = "/dev/stdout", paper = "special", width = 10, height = 1, horizontal = FALSE)
	#pdf(file = "/dev/stdout", paper = "special", width = 10, height = 1, horizontal = FALSE)
	png(file = "/dev/stdout", width = 1920, height = 192)

	par(
		mgp = c(0, 0, 0),
		oma = c(0, 0, 0, 0),
		mar = c(8, 0, 0, 0) ### Reduce when switching to pdf/eps
	)
	plot(
		c(),
		xlab = NA, ylab = NA,
		xaxt = "n", yaxt = "n",
		xaxs = "i", yaxs = "i",
		ylim = c(0, 1),
		xlim = c(
			as.numeric(times[1]),
			as.numeric(times[length(times)])
		)
	)
	rect(
		times[1:(length(times) - 1)],
		rep(0, length(times) - 1),
		times[2:length(times)],
		rep(1, length(times) - 1),
		col = colors[log[,3] + 1],
		border = NA
	)

	axis(
		1,
		labels = times,
		at = as.numeric(times),
		cex.axis = 1, ### Reduce when switching to pdf/eps
		las = 2,
		tcl = 0
	)
	discard <- dev.off()
Rscript

} | R --slave

# vim:set ts=4 noet:
