#!/bin/sh
# Crude attempt to extract significant (fast) rises in RH%.

# Pipe in .dat file, eg:
#     gzip -d < 201508-leaf3015.dat.gz
# Or direct from raw JSON as with:
#     cat .../remote/201510??.json | filterJSON 'H|%' 3015 | awk '{print $1, "-", "-", $3;}'
awk '
    (NF>=4) && ($4 != "-") {
	t=$1;
	gsub("[-T:]", " ", t);
	ts=mktime(t); # Time stamp in seconds (may be wrong timezone).
	h = ts/3600; # Crudely truncated to hours.
	# Store the value for this hour.
	rh = $4;
	stored[h] = $4;
	lasthRH = stored[h-1];
	if(lasthRH > 0) {
	    delta = rh - lasthRH;
	    if(delta > 2) { print $1, h, rh, delta; }
	    }
	}
    ' | uniq -f 1
