#!/bin/sh
# Extracts just timestamp and "Power" value from stdin
# and also corrects for the missing Z on the timestamp.
# Output should be suitable to feed to (eg) gnuplot.

# Sample input:
#2022-10-07T23:58:01 {"StatusSNS":{"Time":"2022-10-08T00:58:01","ENERGY":{"TotalStartTime":"2022-10-05T19:17:26","Total":0.694,"Yesterday":0.584,"Today":0.110,"Power":192,"ApparentPower":192,"ReactivePower": 0,"Factor":1.00,"Voltage":248,"Current":0.776}}}

# Sample output:
#2022-10-07T23:35:02Z 70
#2022-10-07T23:36:01Z 69
#2022-10-07T23:37:02Z 5
#2022-10-07T23:38:01Z 6
#2022-10-07T23:39:01Z 2
#2022-10-07T23:40:01Z 192
#2022-10-07T23:41:01Z 191

# Run something like:
#% gzip -d < LBplug-2022-10-07.log.gz | sh ./powerExtractZ.sh > LBplug-2022-10-07.power.dat

# Retain the timestamp (appending a 'Z'),
# and discard everything else other than the Power decimal.
exec sed -e 's/ {.*"Power": *\([0-9]*\),.*$/Z \1/'
