#!/bin/sh +x

WD=`pwd`

DIR="$HOME/Archive"
TST=`basename $0`
OUT="$TST.`date +%m%d.%H%M`.out"

. set.bogodir > /dev/null

# T = True classification
# B = Bogofilter's class

printf "Parameters:\n" | tee -a $OUT
printf "       robs     robx    min_dev  spam_co  ham_co\n" | tee -a $OUT
for V in old new osa ; do
    printf "%-4s " $V | tee -a $OUT
    for P in robs robx min_dev spam_cutoff ham_cutoff ; do
	printf "%8.6f " `$WD/bogofilter -c $WD/bogo-$V.cf -Q | grep ^$P | tr "=" " " | awk '{print $2}'` | tee -a $OUT
    done
    printf "\n" | tee -a $OUT
done

printf "\n" | tee -a $OUT
printf "Classification Accuracy:\n" | tee -a $OUT
printf "%3s " "ver" | tee -a $OUT
for TBG in h.h.H h.u.U h.s.S s.h.H s.u.U s.s.S ; do
    T=`echo $TBG | tr "." " " | awk '{print $1}'` | tee -a $OUT
    B=`echo $TBG | tr "." " " | awk '{print $2}'` | tee -a $OUT
    printf " %6s" $T$B | tee -a $OUT
done
printf "\n" | tee -a $OUT

cd $DIR

for V in old new osa ; do
    printf "%3s " $V | tee -a $OUT
    for T in h s ; do
	DIRS=`ls -d 200?/200?.??.$T`
	FILE="$TST.$T.$V"
	if [ ! -f $WD/$FILE.out ] ; then
	    $WD/bogofilter -v -c $WD/bogo-$V.cf -k 20 -B $DIRS > $WD/$FILE.tmp
	    sort +4 < $WD/$FILE.tmp > $WD/$FILE.out
	    rm -f $WD/$FILE.tmp
	fi
	if [ "$T" == "h" ] ; then
	    LIST="h.h.H h.u.U h.s.S"
	else
	    LIST="s.h.H s.u.U s.s.S"
	fi
	for TBG in $LIST; do
	    T=`echo $TBG | tr "." " " | awk '{print $1}'` | tee -a $OUT
	    B=`echo $TBG | tr "." " " | awk '{print $2}'` | tee -a $OUT
	    G=`echo $TBG | tr "." " " | awk '{print $3}'` | tee -a $OUT
	    C=`grep "X-Bogosity: $G" $WD/$FILE.out | wc -l`
	    printf " %6d" $C | tee -a $OUT
	done
    done
    printf "\n" | tee -a $OUT
done
