File:  [LON-CAPA] / capa / capa51 / CapaTools / capastat.pl
Revision 1.1: download - view: text, annotated - select for diffs
Tue Sep 28 21:25:35 1999 UTC (24 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
Initial revision

    1: #!/usr/local/bin/perl
    2: 
    3: #
    4: # Jan 30 1997 by Isaac Tsai based on code written by Lily Cheng 
    5: #
    6: 
    7:   require('getopts.pl');
    8: 
    9:   $MAX_TRIES = 99;
   10:   $Usage = "USAGE: capastat.pl [-s set][-t TryUpperLimit][-n NumberOfOccurrence]";
   11:   
   12:   sub  S_Enterpath {
   13:     local($set)=@_;
   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 =~ /\/$/ ) {
   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 ) {
   31:         if( -d $Rfullpath ) {
   32:           if( -f $Sfullpath ) {
   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:   sub S_ScanDB  {
   49:     local($filename)=@_;
   50:     local($line_cnt)=0;
   51:     local($valid_cnt)=0;
   52:     local($valid);
   53:     local($ii);
   54:     local($s_num,$ans_str,$rest);
   55:     local(@ans_char,@tries);
   56:     local($score);
   57:     
   58:     open(IN, "<$filename") || die "Cannot open $filename file!";
   59:     while (<IN>) {
   60:       $line_cnt++;
   61:       if( $line_cnt == 2 ) {
   62:         chomp();
   63:         (@Weight) = split(/ */);
   64:       }
   65:       if( $line_cnt > 3) {
   66:         chomp();
   67:         ($s_num,$ans_str,$rest) = split(/ /,$_,3);
   68:         chop($ans_str);  # chop off one extr ,
   69:         
   70:         (@ans_char) = split(/ */,$ans_str);
   71:         (@tries)    = split(/,/,$rest);
   72:         for($valid = 'N', $ii=0;$ii<=$#ans_char;$ii++) {
   73:             $valid = 'Y' if $ans_char[$ii] ne '-';
   74:         }
   75:         if( $valid eq 'Y' ) {
   76:           for($score=0,$ii=0;$ii<=$#tries;$ii++) {
   77:             $Student_cnt[$ii][$tries[$ii]]++;
   78:             $Student_try[$valid_cnt][$ii] = $tries[$ii];
   79:             $Total_try[$ii] += $tries[$ii];
   80:             $Total_weight   += $Weight[$ii];
   81:             if($ans_char[$ii] eq 'Y') {
   82:               $Yes_cnt[$ii]++;
   83:               $score += $Weight[$ii];
   84:             }
   85:             if($ans_char[$ii] eq 'y') {
   86:               $yes_cnt[$ii]++;
   87:               $score += $Weight[$ii];
   88:             }
   89:             if( $ans_char[$ii] >= 0 && $ans_char[$ii] <= 9) {
   90:               $score += $ans_char[$ii];
   91:             }
   92:           }
   93:           $Total_scores += $score;
   94:           $Entry{"$valid_cnt"} = "$s_num\n" . "$ans_str," . " $rest\n";
   95:           $Score{"$valid_cnt"} = $score;
   96:           $valid_cnt++;
   97:         }
   98:       }
   99:     }
  100:     close(IN) || die "Cannot close $filename file!";
  101:     return ($#tries+1,$valid_cnt);
  102:   }
  103:   
  104:   sub  S_Average {
  105:     local($q_cnt,$l_cnt)=@_;
  106:     local($ii,$jj);
  107:     local(@s_cnt,@avg);
  108:     local(@sd, $sum);
  109:     local($sq);
  110:     local(@sd3,$tmp1,$tmp2);
  111:     
  112:     for($ii=0;$ii<$q_cnt;$ii++) {
  113:       $s_cnt[$ii] = 0;
  114:       $avg[$ii]   = 0.0;
  115:       for($jj=1;$jj<$MAX_TRIES;$jj++) {  # ignore the 0 try entry
  116:         if( $Student_cnt[$ii][$jj] > 0 ) {
  117:           $avg[$ii]   +=  $jj*$Student_cnt[$ii][$jj];
  118:           $s_cnt[$ii] +=  $Student_cnt[$ii][$jj];
  119:         }
  120:       }
  121:       if( $s_cnt[$ii] > 0 ) {      # avoid division by zero
  122:         $avg[$ii] = $avg[$ii] / $s_cnt[$ii];
  123:       }
  124:     }
  125:     
  126:     for($ii=0;$ii<$q_cnt;$ii++) {
  127:       $sd[$ii] = 0.0;
  128:       $sum = 0.0;
  129:       for($jj=0;$jj<$l_cnt;$jj++) {
  130:         $Max_try[$ii] = ($Student_try[$jj][$ii] > $Max_try[$ii]? $Student_try[$jj][$ii] : $Max_try[$ii]);
  131:         if( $Student_try[$jj][$ii] > 0 ) {
  132:           $sq  = ($Student_try[$jj][$ii] - $avg[$ii])*($Student_try[$jj][$ii] - $avg[$ii]);
  133:           $sum += $sq;
  134:         }
  135:         if( $s_cnt[$ii] > 1 ) {
  136:           $sd[$ii] = $sum / ($s_cnt[$ii] - 1.0 );
  137:         }
  138:         if( $sd[$ii] > 0 ) {
  139:           $sd[$ii] = sqrt( $sd[$ii] );
  140:         }
  141:       }
  142:     }
  143:     
  144:     for($ii=0;$ii<$q_cnt;$ii++) {
  145:       $sd3[$ii] = 0.0;
  146:       $sum = 0.0;
  147:       for($jj=0;$jj<$l_cnt;$jj++) {
  148:         if( $Student_try[$jj][$ii] > 0 ) {
  149:           $tmp1 = $Student_try[$jj][$ii] - $avg[$ii];
  150:           $tmp2 = $tmp1*$tmp1*$tmp1;
  151:           $sum  = $sum + $tmp2;
  152:         }
  153:         if( $s_cnt[$ii] > 0 && $sd[$ii] != 0.0 ) {
  154:           $sd3[$ii] = $sum/$s_cnt[$ii] ;
  155:           $sd3[$ii] = $sd3[$ii] / ($sd[$ii]*$sd[$ii]*$sd[$ii]);
  156:         }
  157:       }
  158:     }
  159:     
  160:     print "\nThis is the statistics for each problem:\n";
  161:     print "Prob\#   MxTries   avg.     s.d.    s.k.   \#Stdnts ";
  162:     print "  \#Yes   \#yes   Tries  DoDiff\n";
  163:     for($ii=0;$ii<$q_cnt;$ii++) {
  164:       if( $Total_try[$ii] > 0 ) {
  165:         $dod = 1-($Yes_cnt[$ii] + $yes_cnt[$ii]) / $Total_try[$ii];
  166:       }
  167:       printf "P %2d:",$ii+1;
  168:       printf "%7d  %8.2f  %7.2f  %6.2f   %5d   %5d  %5d    %5d  %5.2f\n",
  169:               $Max_try[$ii],$avg[$ii],$sd[$ii],$sd3[$ii],$s_cnt[$ii],$Yes_cnt[$ii],$yes_cnt[$ii],
  170:               $Total_try[$ii],$dod;
  171:      
  172:     }
  173:   }
  174:   
  175:   sub  Percentage_Scores {
  176:     local($set)=@_;
  177:     local($ratio);
  178:     
  179:     if($Total_weight > 0 ) {
  180:       $ratio = $Total_scores / $Total_weight;
  181:       $ratio = $ratio * 100.0;
  182:     }
  183:     printf "\nThe percentage score for set%d.db is %7.2f%%\n",$set,$ratio;
  184:   
  185:   }
  186:   
  187:   sub  Large_Tries {
  188:     local($t,$n,$q_cnt,$l_cnt)=@_;
  189:     local($ii);
  190:     
  191:     print "\nHere is a list of students who attempts $t tries more than $n times: \n\n";
  192: 
  193:     for ($i=0;$i<$l_cnt;$i++){
  194:        $count=0;
  195:        $credit=0;
  196:        for ($j=0;$j<$q_cnt;$j++){
  197:            if ($Student_try[$i][$j]>= $t){
  198:               $count++;
  199:            }
  200:        }
  201:        if ($count >= $n){
  202:           print "($Score{$i})  $Entry{$i} \n";
  203:        }
  204:     }
  205:   
  206:   }
  207:  
  208:   if(! &Getopts('s:t:n:') ) {
  209:      print STDERR "$Usage\n";
  210:      exit 2;
  211:   }
  212:   $opt_s = 1  if ! $opt_s;
  213:   $opt_t = 99 if ! $opt_t;
  214:   $opt_n = 1  if ! $opt_n;
  215:   
  216:   S_Enterpath($opt_s);
  217:   ($Q_cnt,$L_cnt) = S_ScanDB("$Sfullpath");
  218:   Percentage_Scores($opt_s);
  219:   S_Average($Q_cnt,$L_cnt);
  220:   Large_Tries($opt_t,$opt_n,$Q_cnt,$L_cnt);
  221:   
  222:   
  223:   

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