#!/bin/sh 

#=======================================================
#
# These three definitions specify the binary paths for
# nova and clyde and the writable document root for the
# web server.
#
#=======================================================
#
#=======================================================
#
# These four definitions specify the binary paths for
# nova and clyde and the writable document and log root
# for the web server.
#
#=======================================================
#
#clyde_bin=/usr/local/servers/npac_http/tools/stats   NOT USED HERE!
nova_bin=/project/npac_srvtools/bin/stats
docroot=/usr/local/archives/public/html
#logroot=/project/C067
logroot=/project/www_npac_log
tmp=/var/tmp

#
#	Setup
#	=====
#

# Maximum value for Y axis on monthly graphs.
#
ymax=1000000

#
# Directories for stats files and binaries.
#
statsdir=$docroot/stats

#
# Binary names
#
gwstat="$nova_bin/gwstat"
#gwstat_new="$nova_bin/gwstat_new"
combine="$nova_bin/combine"

LD_LIBRARY_PATH=/usr/dt/lib:/usr/X11R6/lib:/usr/ucblib:/usr/openwin/lib
export LD_LIBRARY_PATH
#
#	For each year generate access gif if file desn't exist
#	======================================================
#
echo '['`date`'] Starting: gwstat_month.sh'
cd $nova_bin
for year in 97 96 95 94
do
  if ( test ! -f $statsdir/archive/$year.monthly.gif ) then
    nice -9 $gwstat -i $statsdir/archive/$year.wwwstats.html \
     -M $year.monthly \
     -b gray -f blue -t 12/31/$year -m $ymax
    mv $statsdir/$year.monthly*.gif $statsdir/archive
  fi
done

#
#	Create imagemap gif from chips
#	==============================
#
all=$tmp/gif.$$
cd $nova_bin
#
#	Create base gif if required.  The X display must be available to
#	do this.
#
if ( test -f $statsdir/archive/base.gif ) then
  echo "Using existing base.gif" > /dev/null 
else
  echo "Creating new base.gif" > /dev/null
  $nova_bin/montage \
   -tile 3x1 -geometry 100x100 -title "Clickable Traffic graph" \
   -label "1994" $statsdir/archive/NA.gif \
   -label "1995" $statsdir/archive/NA.gif \
   -label "1996" $statsdir/archive/NA.gif \
   -label "1997" $statsdir/archive/NA.gif \
   $statsdir/archive/base.gif
fi

#
#	Create imagemap gif from base and chip gifs.
#
nice -9 $combine +display -geometry +32+97 -size 100x100 \
 -compose replace $statsdir/archive/94.monthly-chip.gif \
 $statsdir/archive/base.gif $all
nice -9 $combine +display -geometry +196+97 -size 100x100 \
 -compose replace $statsdir/archive/95.monthly-chip.gif $all $all
nice -9 $combine +display -geometry +360+97 -size 100x100 \
 -compose replace $statsdir/archive/96.monthly-chip.gif $all $all
nice -9 $combine +display -geometry +524+97 -size 100x100 \
 -compose replace $statsdir/archive/97.monthly-chip.gif $all $all

#
#	Make sure all files are in archive and are world readable.
#
mv -f $all $statsdir/archive/yearly_stats.gif
chmod 664 $statsdir/archive/*.monthly*.gif $statsdir/archive/yearly_stats.gif

echo '['`date`'] Finished: gwstat_month.sh'
exit
