#! /bin/bash 
# Last edited on 2014-12-04 16:45:56 by stolfilocal

# Reads a list of wallet operations, generates a plot of 
# the wallet's evolution through time.

wallet="$1"; shift
iniDate="$1"; shift # First date to consider.
finDate="$1"; shift # Last date to consider.

# The wallet operations are read from "txt/${wallet}/monthly/20??-??-?.txt".
# The daily summary is written to "out/${wallet}/${iniDate}--${finDate}-daily.txt"
# The plots are written to "out/${wallet}/${iniDate}--${finDate}-{num,btc}-{day,cum}.{png,jpg}"

tdir="txt/${wallet}/monthly"
pdir="out/${wallet}"

mkdir -p ${pdir}

tmp=/tmp/$$

cfile="${tmp}-all.dat"                            # Detailed transaction file.
dfile="${pdir}/${iniDate}--${finDate}-daily.txt"  # File with per-day counts and totals.

cat `ls ${tdir}/20??-??-?.txt | sort` > ${cfile}

extract_wallet_daily_traffic.gawk \
    -v wallet="${wallet}" \
    -v iniDate="${iniDate}" \
    -v finDate="${finDate}" \
    ${cfile} \
  > ${dfile}

for cum in 0 1 ; do 
  for var in 0 1 ; do 
    plot_wallet_traffic.sh \
       "${dfile}" ${cum} ${var} \
       "${iniDate}" "${finDate}" \
       "${wallet}" "${pdir}"
  done
done
