#!/bin/sh                          
# Print results after conformance.sh executed              #
# Created: Alexandra Reznik ext298                         #  
# The script called by conformance.sh or                   #
# Usage: ./conf_results.sh<file_name.txt>_results_<date>   #
############################################################   
file=$1;
if test ! -f $file; then
   echo"";
   echo "ERROR !! $file not exists !!";
   echo"";
   exit 1;
fi 
calc()
{
 pass=`grep $1 $file|grep PASS |grep -v grep|wc -l`;
 fail=`grep $1 $file|grep FAIL |grep -v grep|wc -l`;
 unkn=`grep $1 $file|grep UNKNOWN|grep -v grep|wc -l`;
 total=`expr $pass + $fail + $unkn`; 
 pass_pr=`expr $pass '*' 100 / $total`;
 pass_pr1=`expr $pass '*' 100 % $total '*' 10 / $total`;
 fail_pr=`expr $fail '*' 100 / $total`;
 fail_pr1=`expr $fail '*' 100 % $total '*' 10 / $total`;
}

calc uac;
  pass_uac=$pass;
  fail_uac=$fail;
  fail_pr_uac=$fail_pr.$fail_pr1;
  pass_pr_uac=$pass_pr.$pass_pr1;
  total_uac=$total;
  unkn_uac=$unkn;  
calc uas;
  pass_uas=$pass;
  fail_uas=$fail;
  fail_pr_uas=$fail_pr.$fail_pr1;
  pass_pr_uas=$pass_pr.$pass_pr1; 
  unkn_uas=$unkn;
  total_uas=$total;

echo "==================================================" >> $file;
echo "               uac      ||          uas         ||" >> $file; 
echo "==================================================" >> $file;
echo "Pass    $pass_uac              $pass_uas     " >> $file;
echo " %            $pass_pr_uac                 $pass_pr_uas   " >> $file;
echo "Fail    $fail_uac              $fail_uas     " >> $file;
echo "  %           $fail_pr_uac                  $fail_pr_uas   " >> $file;
echo "Unknown $unkn_uac              $unkn_uas     " >> $file;
echo "==================================================" >> $file;
echo "Total          $total_uac                     $total_uas    " >> $file;
echo "" >> $file;
cat $file;
exit;
