#! /bin/bash
# Last edited on 2019-10-27 19:13:33 by jstolfi

# Show the time intervals spanned by datafiles.
# Arguments 
# 
#   {DIR} {EX} {CR} {TU} {TITLE} {PINIDATE} {PFINDATE}
# 
# where 
# 
#   {DIR} is the dierctory containing the files.
#   {EX} is the exchaneg code, e.g. "BSTP".
#   {CR} is the currency code, e.g. "USD", "CNY".
#   {TU} is sampling time interval, e.g. "01h", "01d", etc.
#   {TITLE} is a title for the plot.
#   {PINIDATE} {PFINDATE} are the X-axis range end in the format "{yyyy}-{mm}-{dd}".
#
# The data files must have names "{TDLO}--{TDHI}-{EX}-{CR}-{TU}.txt
# where {TDLO} and {TDHI} are the start and end datetimes. Each of them
# must be "{yyyy}-{mm}-{dd}" if {TU} is "01d" of multiple thereof;
# of "{yyyy}-{mm}-{dd}-{HH}{MM}" if {TU} is "01h", "01m", or multiple thereof.
#
# The plot (a PNG image) is written to {stdout}.

dir="$1"; shift
ex="$1"; shift
cr="$1"; shift
tu="$1"; shift
title="$1"; shift
pinidate="$1"; shift
pfindate="$1"; shift

show=SHOW
tmp="/tmp/$$"

dfile="${tmp}.dat"

( cd ${dir} && ls 20*--20*-${ex}-${cr}-${tu}.txt ) \
  | file_names_to_dates_for_plot.gawk \
  > ${dfile}
  
cat ${dfile} 1>&2

pfile="plots/date-intervals-${ex}-${cr}-${tu}.png"
${HOME}/projects/bitcoin/00-DATA/plot_time_intervals.sh \
    ${show} \
    "${title}" "${pinidate}" "${pfindate}" \
    ${dfile} "${tu}" \
  > ${pfile}
