Annotation of capa/capa51/CapaTools/capastat.pl, revision 1.3

1.1       albertel    1: #!/usr/local/bin/perl
                      2: 
                      3: #
                      4: # Jan 30 1997 by Isaac Tsai based on code written by Lily Cheng 
1.2       albertel    5: # some simple statistics for CAPA
                      6: #  Copyright (C) 1992-2000 Michigan State University
                      7: #
                      8: #  The CAPA system is free software; you can redistribute it and/or
1.3     ! albertel    9: #  modify it under the terms of the GNU General Public License as
1.2       albertel   10: #  published by the Free Software Foundation; either version 2 of the
                     11: #  License, or (at your option) any later version.
                     12: #
                     13: #  The CAPA system is distributed in the hope that it will be useful,
                     14: #  but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1.3     ! albertel   16: #  General Public License for more details.
1.2       albertel   17: #
1.3     ! albertel   18: #  You should have received a copy of the GNU General Public
1.2       albertel   19: #  License along with the CAPA system; see the file COPYING.  If not,
                     20: #  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
                     21: #  Boston, MA 02111-1307, USA.
                     22: #
                     23: #  As a special exception, you have permission to link this program
                     24: #  with the TtH/TtM library and distribute executables, as long as you
                     25: #  follow the requirements of the GNU GPL in regard to all of the
                     26: #  software in the executable aside from TtH/TtM.
                     27: 
1.1       albertel   28: #
                     29: 
                     30:   require('getopts.pl');
                     31: 
                     32:   $MAX_TRIES = 99;
                     33:   $Usage = "USAGE: capastat.pl [-s set][-t TryUpperLimit][-n NumberOfOccurrence]";
                     34:   
                     35:   sub  S_Enterpath {
                     36:     local($set)=@_;
                     37:     local($notdone,$path);
                     38:     local($cfullpath);
                     39:     
                     40:     $notdone = 1;
                     41:     while ($notdone) {
                     42:       print "Please enter the CLASS absolute path:\n";
                     43:       $path = <>; chomp($path);
                     44:       if( $path =~ /\/$/ ) {
                     45:         $cfullpath = "$path" . "classl";
                     46:         $Rfullpath = "$path" . "records";
                     47:         $Sfullpath = "$path" . "records/set$set.db";
                     48:       } else {
                     49:         $cfullpath = "$path" . "/classl";
                     50:         $Rfullpath = "$path" . "/records";
                     51:         $Sfullpath = "$path" . "/records/set$set.db";
                     52:       }
                     53:       if( -d $path ) {
                     54:         if( -d $Rfullpath ) {
                     55:           if( -f $Sfullpath ) {
                     56:             $notdone = 0;
                     57:           } else {
                     58:             print "File [$Sfullpath] does not exist!\n";
                     59:           }
                     60:         } else {
                     61:           print "Directory [$Rfullpath] does not exist!\n";
                     62:         }
                     63:       } else {
                     64:         print "Directory [$path] does not exist!\n";
                     65:       }
                     66:     
                     67:     }
                     68:     return ($path);
                     69:   }
                     70:   
                     71:   sub S_ScanDB  {
                     72:     local($filename)=@_;
                     73:     local($line_cnt)=0;
                     74:     local($valid_cnt)=0;
                     75:     local($valid);
                     76:     local($ii);
                     77:     local($s_num,$ans_str,$rest);
                     78:     local(@ans_char,@tries);
                     79:     local($score);
                     80:     
                     81:     open(IN, "<$filename") || die "Cannot open $filename file!";
                     82:     while (<IN>) {
                     83:       $line_cnt++;
                     84:       if( $line_cnt == 2 ) {
                     85:         chomp();
                     86:         (@Weight) = split(/ */);
                     87:       }
                     88:       if( $line_cnt > 3) {
                     89:         chomp();
                     90:         ($s_num,$ans_str,$rest) = split(/ /,$_,3);
                     91:         chop($ans_str);  # chop off one extr ,
                     92:         
                     93:         (@ans_char) = split(/ */,$ans_str);
                     94:         (@tries)    = split(/,/,$rest);
                     95:         for($valid = 'N', $ii=0;$ii<=$#ans_char;$ii++) {
                     96:             $valid = 'Y' if $ans_char[$ii] ne '-';
                     97:         }
                     98:         if( $valid eq 'Y' ) {
                     99:           for($score=0,$ii=0;$ii<=$#tries;$ii++) {
                    100:             $Student_cnt[$ii][$tries[$ii]]++;
                    101:             $Student_try[$valid_cnt][$ii] = $tries[$ii];
                    102:             $Total_try[$ii] += $tries[$ii];
                    103:             $Total_weight   += $Weight[$ii];
                    104:             if($ans_char[$ii] eq 'Y') {
                    105:               $Yes_cnt[$ii]++;
                    106:               $score += $Weight[$ii];
                    107:             }
                    108:             if($ans_char[$ii] eq 'y') {
                    109:               $yes_cnt[$ii]++;
                    110:               $score += $Weight[$ii];
                    111:             }
                    112:             if( $ans_char[$ii] >= 0 && $ans_char[$ii] <= 9) {
                    113:               $score += $ans_char[$ii];
                    114:             }
                    115:           }
                    116:           $Total_scores += $score;
                    117:           $Entry{"$valid_cnt"} = "$s_num\n" . "$ans_str," . " $rest\n";
                    118:           $Score{"$valid_cnt"} = $score;
                    119:           $valid_cnt++;
                    120:         }
                    121:       }
                    122:     }
                    123:     close(IN) || die "Cannot close $filename file!";
                    124:     return ($#tries+1,$valid_cnt);
                    125:   }
                    126:   
                    127:   sub  S_Average {
                    128:     local($q_cnt,$l_cnt)=@_;
                    129:     local($ii,$jj);
                    130:     local(@s_cnt,@avg);
                    131:     local(@sd, $sum);
                    132:     local($sq);
                    133:     local(@sd3,$tmp1,$tmp2);
                    134:     
                    135:     for($ii=0;$ii<$q_cnt;$ii++) {
                    136:       $s_cnt[$ii] = 0;
                    137:       $avg[$ii]   = 0.0;
                    138:       for($jj=1;$jj<$MAX_TRIES;$jj++) {  # ignore the 0 try entry
                    139:         if( $Student_cnt[$ii][$jj] > 0 ) {
                    140:           $avg[$ii]   +=  $jj*$Student_cnt[$ii][$jj];
                    141:           $s_cnt[$ii] +=  $Student_cnt[$ii][$jj];
                    142:         }
                    143:       }
                    144:       if( $s_cnt[$ii] > 0 ) {      # avoid division by zero
                    145:         $avg[$ii] = $avg[$ii] / $s_cnt[$ii];
                    146:       }
                    147:     }
                    148:     
                    149:     for($ii=0;$ii<$q_cnt;$ii++) {
                    150:       $sd[$ii] = 0.0;
                    151:       $sum = 0.0;
                    152:       for($jj=0;$jj<$l_cnt;$jj++) {
                    153:         $Max_try[$ii] = ($Student_try[$jj][$ii] > $Max_try[$ii]? $Student_try[$jj][$ii] : $Max_try[$ii]);
                    154:         if( $Student_try[$jj][$ii] > 0 ) {
                    155:           $sq  = ($Student_try[$jj][$ii] - $avg[$ii])*($Student_try[$jj][$ii] - $avg[$ii]);
                    156:           $sum += $sq;
                    157:         }
                    158:         if( $s_cnt[$ii] > 1 ) {
                    159:           $sd[$ii] = $sum / ($s_cnt[$ii] - 1.0 );
                    160:         }
                    161:         if( $sd[$ii] > 0 ) {
                    162:           $sd[$ii] = sqrt( $sd[$ii] );
                    163:         }
                    164:       }
                    165:     }
                    166:     
                    167:     for($ii=0;$ii<$q_cnt;$ii++) {
                    168:       $sd3[$ii] = 0.0;
                    169:       $sum = 0.0;
                    170:       for($jj=0;$jj<$l_cnt;$jj++) {
                    171:         if( $Student_try[$jj][$ii] > 0 ) {
                    172:           $tmp1 = $Student_try[$jj][$ii] - $avg[$ii];
                    173:           $tmp2 = $tmp1*$tmp1*$tmp1;
                    174:           $sum  = $sum + $tmp2;
                    175:         }
                    176:         if( $s_cnt[$ii] > 0 && $sd[$ii] != 0.0 ) {
                    177:           $sd3[$ii] = $sum/$s_cnt[$ii] ;
                    178:           $sd3[$ii] = $sd3[$ii] / ($sd[$ii]*$sd[$ii]*$sd[$ii]);
                    179:         }
                    180:       }
                    181:     }
                    182:     
                    183:     print "\nThis is the statistics for each problem:\n";
                    184:     print "Prob\#   MxTries   avg.     s.d.    s.k.   \#Stdnts ";
                    185:     print "  \#Yes   \#yes   Tries  DoDiff\n";
                    186:     for($ii=0;$ii<$q_cnt;$ii++) {
                    187:       if( $Total_try[$ii] > 0 ) {
                    188:         $dod = 1-($Yes_cnt[$ii] + $yes_cnt[$ii]) / $Total_try[$ii];
                    189:       }
                    190:       printf "P %2d:",$ii+1;
                    191:       printf "%7d  %8.2f  %7.2f  %6.2f   %5d   %5d  %5d    %5d  %5.2f\n",
                    192:               $Max_try[$ii],$avg[$ii],$sd[$ii],$sd3[$ii],$s_cnt[$ii],$Yes_cnt[$ii],$yes_cnt[$ii],
                    193:               $Total_try[$ii],$dod;
                    194:      
                    195:     }
                    196:   }
                    197:   
                    198:   sub  Percentage_Scores {
                    199:     local($set)=@_;
                    200:     local($ratio);
                    201:     
                    202:     if($Total_weight > 0 ) {
                    203:       $ratio = $Total_scores / $Total_weight;
                    204:       $ratio = $ratio * 100.0;
                    205:     }
                    206:     printf "\nThe percentage score for set%d.db is %7.2f%%\n",$set,$ratio;
                    207:   
                    208:   }
                    209:   
                    210:   sub  Large_Tries {
                    211:     local($t,$n,$q_cnt,$l_cnt)=@_;
                    212:     local($ii);
                    213:     
                    214:     print "\nHere is a list of students who attempts $t tries more than $n times: \n\n";
                    215: 
                    216:     for ($i=0;$i<$l_cnt;$i++){
                    217:        $count=0;
                    218:        $credit=0;
                    219:        for ($j=0;$j<$q_cnt;$j++){
                    220:            if ($Student_try[$i][$j]>= $t){
                    221:               $count++;
                    222:            }
                    223:        }
                    224:        if ($count >= $n){
                    225:           print "($Score{$i})  $Entry{$i} \n";
                    226:        }
                    227:     }
                    228:   
                    229:   }
                    230:  
                    231:   if(! &Getopts('s:t:n:') ) {
                    232:      print STDERR "$Usage\n";
                    233:      exit 2;
                    234:   }
                    235:   $opt_s = 1  if ! $opt_s;
                    236:   $opt_t = 99 if ! $opt_t;
                    237:   $opt_n = 1  if ! $opt_n;
                    238:   
                    239:   S_Enterpath($opt_s);
                    240:   ($Q_cnt,$L_cnt) = S_ScanDB("$Sfullpath");
                    241:   Percentage_Scores($opt_s);
                    242:   S_Average($Q_cnt,$L_cnt);
                    243:   Large_Tries($opt_t,$opt_n,$Q_cnt,$L_cnt);
                    244:   
                    245:   
                    246:   

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