CheckResults.sh 3.09 KB
#!/bin/bash

#################################
# File : CheckResults.sh        #
# Brief : Check the results     #
# Autohr : Jean-François Rey    #
# Date : 30/07/2013             #
# Version : 1.0                 #
#################################


# CheckDir( dir )
# dir : a directory path
# Brief : Check $dir results
function CheckDir()
{
    if [ $# -eq 1 ]
    then
        plp=$(ls $1/PLP/*.plp 2> /dev/null | wc -l)
        res_p1=$(ls $1/res_p1/*.res 2> /dev/null | wc -l)
        res_p2=$(ls $1/res_p2/*.treil 2> /dev/null | wc -l)
        res_p3=$(ls $1/res_p3/*.treil 2> /dev/null | wc -l)
        usf_p2=$1/$(basename $1).res_p2.usf
        usf_p3=$1/$(basename $1).res_p3.usf

        if [ -e $usf_p2 ]
        then
            casix=`grep -c -E 'confidence="0.600"' ${usf_p2}`
            call=`grep -c -E 'confidence=' ${usf_p2}`
            if [ $call -eq 0 ]
            then
                pourcentage_p2=100
            else
                pourcentage_p2=$((($casix*100)/$call))
            fi
            if [ $pourcentage_p2 -gt 49 ]
            then
                usf2="ERR"
            else
                usf2="OK"
            fi
        else
            usf2="NAN"
        fi
        if [ -e $usf_p3 ]
        then
            casix=`grep -c -E 'confidence="0.600"' ${usf_p3}`
            call=`grep -c -E 'confidence=' ${usf_p3}`
            if [ $call -eq 0 ]
            then
                pourcentage_p3=100
            else
                pourcentage_p3=$((($casix*100)/$call))
            fi
            if [ $pourcentage_p3 -gt 49 ]
            then
                usf3="ERR"
            else
                usf3="OK"
            fi
        else
            usf3="NAN"
        fi
    fi
    echo -e "$(basename $1)\t$plp\t$res_p1\t$res_p2\t\t$res_p3\t\t$usf2\t$usf3"

}


# Check OTMEDIA_HOME env var
if [ -z ${OTMEDIA_HOME} ]
then
    OTMEDIA_HOME=$(dirname $(dirname $(readlink -e $0)))
    export OTMEDIA_HOME=$OTMEDIA_HOME
fi

# where is CheckResults.sh
MAIN_SCRIPT_PATH=$(dirname $(readlink -e $0))


RECURSIVE=0

#---------------#
# Parse Options #
#---------------#
while getopts ":hr" opt
do
	case $opt in
		h)
			echo -e "$0 [OPTIONS] <DIRECTORY>\n"
            echo -e "\t Options:"
            echo -e "\t\t-h :\tprint this message"
            echo -e "\t\t-r :\trecursive mode"
			exit 1
			;;
        r)
            RECURSIVE=1
            ;;
		:)
			echo "Option -$OPTARG requires an argument." >&2
			exit 1
			;;
		\?)
			echo "BAD USAGE : unknow opton -$OPTARG"
			exit 1
			;;
	esac
done

# Check USAGE by arguments number
if [ $(($#-($OPTIND-1))) -ne 1 ]
then
	echo "BAD USAGE : FirstPass.sh [OPTIONS] <DIRECTORY>"
	echo "$0 -h for more info"
	exit 1
fi

shift $((OPTIND-1))
# check Directory - First argument
if [ -e $1 ] && [ -s $1 ]
then
    DIR=$(readlink -e $1)
else
    echo "ERROR : can't open directory $1"
    exit 1    
fi


# Check directory results
echo -e "Directory name\t\t#plp\t#res_p1\t#treil_p2\t#treil_p3\tusf_p2\tusf_p3"
if [ $RECURSIVE -eq 0 ]
then
    CheckDir "$DIR"
else
    for d in `ls $DIR`
    do
        if [ -d "$DIR/$d" ]; then CheckDir "$DIR/$d"; fi
    done
fi