Annotation of capa/capa51/CapaTools/examanalysis.pl, revision 1.1.1.1

1.1       albertel    1: #!/usr/local/bin/perl
                      2: 
                      3: #
                      4: # June 17 1997 by Isaac Tsai
                      5: #
                      6: 
                      7:   require('getopts.pl');
                      8:   $Usage = "USAGE: examanalysis.pl [-s start_set][-t end_set]";
                      9: #
                     10: # ask user to enter the absolute path to the class
                     11: #
                     12:   sub  S_Enterpath {
                     13:     local($set,$to)=@_;
                     14:     local($notdone,$path);
                     15:     local($cfullpath);
                     16:     
                     17:     $notdone = 1;
                     18:     while ($notdone) {
                     19:       print "Please enter the CLASS absolute path:\n";
                     20:       $path = <>; chomp($path);
                     21:       if( $path =~ /\/$/ ) {            # check if the path entered contains a trailing /
                     22:         $Cfullpath = "$path" . "classl";
                     23:         $Rfullpath = "$path" . "records";
                     24:         $Sfullpath = "$path" . "records/set$set.db";
                     25:       } else {
                     26:         $Cfullpath = "$path" . "/classl";
                     27:         $Rfullpath = "$path" . "/records";
                     28:         $Sfullpath = "$path" . "/records/set$set.db";
                     29:       }
                     30:       if( -d $path ) {           # check if the class directory exists
                     31:         if( -d $Rfullpath ) {    # check if the records directory exists
                     32:           if( -f $Sfullpath ) {  # check if the setX.db file exists
                     33:             $notdone = 0;
                     34:           } else {
                     35:             print "File [$Sfullpath] does not exist!\n";
                     36:           }
                     37:         } else {
                     38:           print "Directory [$Rfullpath] does not exist!\n";
                     39:         }
                     40:       } else {
                     41:         print "Directory [$path] does not exist!\n";
                     42:       }
                     43:     
                     44:     }
                     45:     return ($path);
                     46:   }
                     47: 
                     48: #
                     49: #  scan the setX.db file
                     50: #
                     51:   sub S_ScanDB  {
                     52:     local($filename,$idx)=@_;
                     53:     local($line_cnt)=0;
                     54:     local($valid_cnt)=0;
                     55:     local($valid);
                     56:     local($ii);
                     57:     local($head,$s_num,$ans_str,$rest);
                     58:     local(@ans_char,@tries);
                     59:     local($score,$Snum);
                     60:     
                     61:     open(IN, "<$filename") || die "Cannot open $filename file!";
                     62:     while (<IN>) {
                     63:       $line_cnt++;             # line count in setX.db file
                     64:       if( $line_cnt == 2 ) {   # the second line is the weight information
                     65:         chomp();   
                     66:         (@Weight) = split(/ */);  # split the weight string into an integer array
                     67:       }
                     68:       if( $line_cnt > 3) {     # valid student record begins with the fourth line
                     69:         chomp();               # remove the trailing \n
                     70:         ($head,$rest) = split(/,/,$_,2); #  split the entry based on the first comma
                     71:         ($s_num,$ans_str) = split(/ /,$head,2); # split the head part based on space char
                     72:         
                     73:         (@ans_char) = split(/ */,$ans_str);   # split the answer string into an array of chars
                     74:         (@tries)    = split(/,/,$rest);       # split the number of tries string into an array of integer
                     75:         for($valid = 'N', $ii=0;$ii<=$#ans_char;$ii++) {  # if all char in the answer is '-', mark it as invalid
                     76:             $valid = 'Y'  if $ans_char[$ii] ne '-';
                     77:         }
                     78:         if( $valid eq 'Y' ) {                 # a valid entry, contains some scoring info  
                     79:           for($score=0,$ii=0;$ii<=$#ans_char;$ii++) {  # number of elements in the answer char array
                     80:             if($ans_char[$ii] eq 'Y') {       # big Y, score adds the weight of that problem
                     81:               $score += $Weight[$ii];
                     82:             }
                     83:             if($ans_char[$ii] eq 'y') {       # small y, score adds the weight of that problem
                     84:               $score += $Weight[$ii];
                     85:             }
                     86:             if( $ans_char[$ii] >= 0 && $ans_char[$ii] <= 9) { # hand graded problem has numerical value
                     87:               $score += $ans_char[$ii];
                     88:             }
                     89:           }
                     90:           $Snum = uc($s_num);     # uppercase the student number
                     91:           $$Snum[$idx] = $score;  # put the score into an array named as the student number and indexed by
                     92:           $valid_cnt++;           #   offset of set in the scoring report
                     93:         }
                     94:       }
                     95:     }
                     96:     close(IN) || die "Cannot close $filename file!";
                     97:     return ($#tries+1,$valid_cnt);
                     98:   }
                     99: #        1         2         3         4     -   5         6         7         8
                    100: #2345678901234567890123456789012345678901234567890123456789012345678901234567890
                    101: #nnnnnnnnnnnnnnnnn aaaaaaaaa sec                 scor    scor    scor
                    102: #
                    103: # produce the scoring report based on entries from classl file
                    104: #
                    105:   sub S_ClassRpt {
                    106:     local($filename)=@_;
                    107:     local($code,$cn,$sec,$sid,$sname);
                    108:     local($a_line,$cnt,$i);
                    109:     local($score,$len,$pad);
                    110:     local($sm,$Snum);
                    111:     
                    112:     open(IN, "<$filename") || die "cannot open file $filename!\n";
                    113:     while(<IN>) { 
                    114:       $a_line = $_;    # each line in the classl file
                    115:       ($code,$cn,$sec,$sid,$sname) =  split(/\s+/,$a_line,5);  # use space to divide each field
                    116:       chomp($sname); # chop off the last \n
                    117:       $len = length($sname); # student name length
                    118:       if( $len < 18 ) {      # if name is less than 18 characters, padded to 18 chars
                    119:         $pad = 18 - $len;
                    120:         $sm = "$sname" . " " x $pad;
                    121:       } else {               # more than 18 chars, take the first 18 characters
                    122:         $sm = substr("$sname",0,18); # take the first 18 characters
                    123:       }
                    124:       printf "%s %s %03d             ", $sm,$sid,$sec; # print out student name, student number, section
                    125:       $Snum = uc($sid);  # uppercase the student number
                    126:       if( defined @{$Snum} ) { # if we have the scores for this student
                    127:         $cnt = $#{$Snum};      #   the number of sets in this scoring array
                    128:         for($i=0;$i<=$cnt;$i++) {  # loop through the number of sets
                    129:           $score = $$Snum[$i];     # assign the score to a variable, (extra step)
                    130:           printf "    %4d", $score;
                    131:         }
                    132:       }
                    133:       print "\n";   # at the end of the record, place an \n
                    134:     }
                    135:     close(IN) || die "cannot close file $filename!\n";
                    136:   }
                    137:   
                    138:   
                    139:   if(! &Getopts('s:t:') ) {
                    140:      print STDERR "$Usage\n";
                    141:      exit 2;
                    142:   }
                    143:   
                    144:   if( (!$opt_s) || ($opt_s <= 0 )  ) {
                    145:     $opt_s = 1;
                    146:   }
                    147:   if( (!$opt_t) || ($opt_t <= 0 ) ) {
                    148:     $opt_t = 1;
                    149:   }
                    150:   if( $opt_t < $opt_s ) {
                    151:     $tmp   = $opt_t;
                    152:     $opt_t = $opt_s;
                    153:     $opt_s = $tmp;
                    154:   }
                    155:   $CPath = S_Enterpath($opt_s,$opt_t);  # get the class path
                    156:   
                    157:   for($set_idx=$opt_s;$set_idx<=$opt_t;$set_idx++) {  # loop through each set
                    158:     $set_offset = $set_idx - $opt_s;
                    159:     $fullpath = "$CPath" . "/records/set$set_idx.db";
                    160:     S_ScanDB("$fullpath",$set_offset);
                    161:   }
                    162:   
                    163:   S_ClassRpt("$Cfullpath");   # produce the scoring report
                    164:   
                    165:   
                    166:   
                    167:   

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>