#!/bin/sh
#
# Generate a histogram of bucketed solar power generation samples such as:
#
# 20180621T19:55Z 19
# 20180621T19:56Z 17
# 20180621T19:57Z 17
#
# From stdin, nominally evenly spaced, though some samples may be missing,
# and runs of zeros may have been excluded.
#
# Eg for a whole month:
# gzip -d < data/SunnyBeam/201801.gz | sh script/genPowerHist.sh

# Default (linear) bucket width.
DEFAULT_BUCKET=250

# Discard all zeros.
# Round up to the next bucket.
awk '$2>0{print BUCKET*int(($2+BUCKET-1)/BUCKET)}' BUCKET=$DEFAULT_BUCKET | \
  sort | uniq -c | sort -n -k2 | awk '{print $2" "$1}'
