#!/bin/sh

#=======================================================
#
# 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
nova_bin=/project/C420/s/npac_http/tools/stats
docroot=/e/p/C420/p/html
logroot=/e/p/C067

statsdir=$docroot/stats

thisyear=`date +%y`

#
# THESE ARE REQUIRED BECAUSE NOVA DOES NOT HAVE A /usr/local/servers
# MOUNT POINT for /project/C420/s/
#
bindir=$nova_bin

wwwresult=$statsdir/wwwstats_28.html
wwwmonth=$statsdir/wwwstats.html
wwwyear=$statsdir/archive/$thisyear.wwwstats.html

gwstat="$bindir/gwstat"
gwstat_new="$bindir/gwstat_new"
combine="$bindir/combine"

#
# generate gwstat *.gifs
# 
# For gwstat to work the executables must be in the path!
# The easiest way to achieve this is to cd to the $bindir
#
echo '['`date`'] Starting: gwstat.sh'
cd $bindir

nice -9 $gwstat -i $wwwresult -R recent -b blue -f yellow
nice -9 $gwstat_new -i $wwwresult -D daily -b RosyBrown -f brown -o RosyBrown
nice -9 $gwstat -i $wwwresult -H hourly -b gray -f brown -o brown
nice -9 $gwstat -i $wwwresult -W weekly -b turquoise -f DarkViolet
nice -9 $gwstat -i $wwwyear -M monthly -b gray  -f blue
nice -9 $gwstat -i $wwwmonth -C country -A archive
nice -9 $gwstat -i $wwwmonth -S $statsdir/archive.conf -T selected
nice -9 $gwstat_new -i $wwwyear -M yearly -b gray -f blue

cd $statsdir
#
#  Built new base background gif if one doesn't exist.
#
#  $bindir/montage \
# -tile 3 -geometry 100x100 -title "Clickable Traffic graph" \
# -label "by archive" $statsdir/archive-chip.gif \
# -label "by subject" $statsdir/selected-chip.gif \
# -label "by domain" $statsdir/country-chip.gif \
# -label "by hour" $statsdir/hourly-chip.gif \
# -label "by day" $statsdir/daily-chip.gif \
# -label "by week" $statsdir/weekly-chip.gif \
# -label "last year" $statsdir/yearly-chip.gif \
# -label "by month" $statsdir/monthly-chip.gif \
# -label "last 7 days" $statsdir/recent-chip.gif \
# base.gif

### compose the chip files into stats.gif
all=/tmp/gif.$$

if ( test -f archive-chip.gif ) then
  nice -9 $combine +display -geometry +32+97 -size 100x100 \
    -compose replace archive-chip.gif $statsdir/base.gif $all
else
  cp $statsdir/base.gif $all
fi

nice -9 $combine +display -geometry +196+97 -size 100x100 \
-compose replace selected-chip.gif $all $all

nice -9 $combine +display -geometry +360+97 -size 100x100 \
-compose replace country-chip.gif $all $all

nice -9 $combine +display -geometry +32+281 -size 100x100  \
-compose replace hourly-chip.gif  $all $all

nice -9 $combine +display -geometry +196+281 -size 100x100  \
-compose replace daily-chip.gif  $all $all

nice -9 $combine +display -geometry +360+281 -size 100x100  \
-compose replace weekly-chip.gif $all $all

nice -9 $combine +display -geometry +32+465 -size 100x100  \
-compose replace monthly-chip.gif $all $all

nice -9 $combine +display -geometry +196+465 -size 100x100  \
-compose replace recent-chip.gif $all $all

mv -f $all stats.gif
chmod 664 stats.gif archive*.gif selected*.gif country*.gif hourly*.gif \
          daily*.gif weekly*.gif yearly*.gif monthly*.gif recent*.gif

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

