#!/usr/bin/env bash # GRADER for p2 CSCI 311 Spring 2006 # assumes: (1) that tests/ is one level higher # (2) the script is placed into the same directory # as the student directories # (3) students do not put their files into sub directories # (4) there is a csv file named students.lst exec_name=btree start_dir=`pwd` # student directories are up two levels, pwd=student diretory test_dir=../tests COMPILE_POINTS=25 POINTS_FOR_TESTS=1 # if a single student directory is given from the command line # else grade all students if [ $# != 0 ] then student_directories=$@ else # count ONLY directories student_directories=`ls -F | grep \/` fi cat << END /////////////////////////////////////////////////////////// // `date | awk '{"print $1 $2 $3, $6"}'` final// /////////////////////////////////////////////////////////// END #echo $student_directories rm -f final_p2_grade.csv echo "user,name,secret_id,phase1,phase2,phase3,extra_credit,compile,\ t01,t02,t03,t04,t05,t06,t07,t11,t12,t13,t14,t15,t16,\ t21,t22,t23,t24,t25,t26,t27,t28,t29,\ t31,t32,t33,t34,\ t51,t52,t53,t54,t55,t56,t57,t58,\ t61,t62,t63,t64,t65,t66,\ t71,t72,t73,t74,\ t81,t82,t83,\ _t01,_t02,_t03,_t04,_t05,_t06,_t07,_t11,_t12,_t13,_t14,_t15,_t16,\ total,files,lines,\ <------------------------------------------------------------------------------\ COMMENT\ ------------------------------------------------------------------------------> " >> final_p2_grade.csv for student in $student_directories do echo -n "$student: " student=`echo $student | sed -e 's/.$//' 2> /dev/null` grade=`grep ^$student students.lst` echo `grep ^$student students.lst` points=0; # pwd will be inside the students directory if cd $student then # count the number of files num_of_files=0; for cur_file in `ls *.h *.cpp *akefile 2> /dev/null` do (( num_of_files++ )) done # count the number of lines num_of_lines=`wc -l *.h *.cpp *akefile 2> /dev/null | awk '/total/ {print $1}' 2> /dev/null` # remove old output files if any rm -f *.temp_out *.o btree # compile and then run the tests if make >& /dev/null && file $exec_name >& /dev/null then grade=${grade},$COMPILE_POINTS points=`expr $COMPILE_POINTS + $points` for test_file in $test_dir/t[0-9][0-9]; do student_file=`basename $test_file` echo -n "$student_file " ./$exec_name < $test_file > $student_file.temp_out 2> /dev/null if diff $student_file.temp_out ${test_file}.out >& /dev/null; then echo "passed" grade=${grade},$POINTS_FOR_TESTS points=`expr $POINTS_FOR_TESTS + $points` else echo "failed" grade=${grade},0 fi done for test_file in $test_dir/_t[0-9][0-9]; do student_file=`basename $test_file` echo -n "$student_file " ./$exec_name < $test_file > $student_file.temp_out 2> /dev/null if diff $student_file.temp_out ${test_file}.out >& /dev/null; then echo "passed" grade=${grade},$POINTS_FOR_TESTS points=`expr $POINTS_FOR_TESTS + $points` else echo "failed" grade=${grade},0 fi done # clean up rm -f *.o btree >& /dev/null else # no executable echo "$student has no executable built" # 0 points for compilation grade=${grade},0 # assign zero for each test for test_file in $test_dir/t[0-9][0-9] $test_dir/_t[0-9][0-9] do grade=${grade},0 done fi ################################################### # add on the points ################################################### phase1_points=`cat ../students.lst | grep "$student" | awk -F, '{ print $4 }'` phase2_points=`cat ../students.lst | grep "$student" | awk -F, '{ print $5 }'` phase3_points=`cat ../students.lst | grep "$student" | awk -F, '{ print $6 }'` extra_points=`cat ../students.lst | grep "$student" | awk -F, '{ print $7 }'` points=`expr $points + $phase1_points + $phase2_points + $phase3_points + $extra_points` grade=${grade},$points #add on the number of files grade=${grade},$num_of_files #add on the number of lines grade=${grade},$num_of_lines else echo "wtf: can't cd to student directory: $student" fi # add the comment file if [ -f COMMENT ]; then grade=${grade},`cat COMMENT` else grade="${grade},NO COMMENT" fi cd $start_dir # write to the file echo $grade >> final_p2_grade.csv done