File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.6: download - view: text, annotated - select for diffs
Sat Mar 2 23:22:32 2002 UTC (22 years, 4 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
Fixed bugs,
New interface with re-arranging the problems according to HW sets.
Added Student Status

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonstatistics.pm,v 1.6 2002/03/02 23:22:32 minaeibi Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Navigate problems for statistical reports
   29: # YEAR=2001
   30: # 5/05,7/09,7/25/01,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
   31: # 11/1, 11/4, 11/16, 12/14, 12/16, 12/18,12/20,12/31 Behrouz Minaei
   32: # YEAR=2002
   33: # 1/22, 2/1, 2/6, 2/25, 3/2 Behrouz Minaei
   34: ###
   35: 
   36: package Apache::lonstatistics; 
   37: 
   38: use strict;
   39: use Apache::Constants qw(:common :http);
   40: use Apache::lonnet();
   41: use Apache::lonhomework;
   42: use HTML::TokeParser;
   43: use GDBM_File;
   44: #use Benchmark;
   45: 
   46: # -------------------------------------------------------------- Module Globals
   47: my %hash;
   48: my %CachData;
   49: my %GraphDat;
   50: my %maps;
   51: my %mapsort;
   52: my %section;
   53: my %StuBox;
   54: my %DiscFac;
   55: my $CurMap;
   56: my $CurSec;
   57: my $CurStu;
   58: my @cols;
   59: my @list;
   60: my @students;
   61: my $p_count;
   62: my $Pos;
   63: my $r;
   64: my $OpSel1;
   65: my $OpSel2;
   66: my $OpSelDis1;
   67: my $OpSelDis2;
   68: my $CurDis=0;
   69: my $OpSel3;
   70: my $OpSel4;
   71: my $GData;
   72: my $cid;
   73: my $firstres;
   74: my $lastres;
   75: my $DiscFlag;
   76: my $HWN;
   77: my $P_Order;
   78: my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
   79:               4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
   80:               9,"S.D.",10,"Skew.",11,"Map");
   81: #             11,"Dis.F.",12,"Resourse URL");
   82: 
   83: sub NumericSort {          
   84:     $a <=> $b;
   85: }
   86: 
   87: # ------ Create different Student Report 
   88: sub StudentReport {
   89:     my ($sname,$sdom)=@_;
   90:     if ( $sname eq 'All Students' ) {
   91: 	$r->print( '<h3><font color=blue>WARNING: 
   92:                     Please select a student</font></h3>' );
   93: 	return;
   94:     }
   95:     my $shome=&Apache::lonnet::homeserver( $sname,$sdom );          
   96:     my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$cid,$shome );
   97:     my %result = ();
   98:     my $ResId;
   99:     my $PrOrd;
  100:     my $Code;
  101:     my $Tries;
  102:     my $TotalTries = 0;
  103:     my $ParCr = 0;
  104:     my $Wrongs;
  105:     my %TempHash;
  106:     my $Version;
  107:     my $LatestVersion;
  108:     my $PtrTry='';
  109:     my $PtrCod='';
  110:     my $SetNo=0;
  111:     my $Str = "\n".'<table border=2>'.
  112:               "\n".'<tr>'.
  113:               "\n".'<th> # </th>'.
  114: 	      "\n".'<th> Set Title </th>'.
  115: 	      "\n".'<th> Results </th>'.
  116: 	      "\n".'<th> Tries </th>'.
  117: 	      "\n".'</tr>';
  118:     unless ($reply=~/^error\:/) {
  119:         foreach (split(/\&/,$reply)){
  120:             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
  121:             $result{$name}=$value;
  122:         }
  123:         foreach my $CurCol (@cols) {
  124: 	    if (!$CurCol){
  125: 		my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1});
  126: 		if ( $Set ) {
  127: 		    $SetNo++;
  128: 		    $Str .= "\n"."<tr>".
  129: 			    "\n"."<td> $SetNo </td>".
  130:                             "\n"."<td> $Set </td>".
  131:                             "\n"."<td> $PtrCod </td>".
  132:                             "\n"."<td> $PtrTry</td>".
  133:                             "\n"."</tr>";
  134: 		}
  135: 		$PtrTry='';
  136: 		$PtrCod='';
  137: 		next; 
  138: 	    }
  139: 	    ($PrOrd,$ResId)=split(/\:/,$CurCol);
  140:             $ResId=~/(\d+)\.(\d+)/;
  141:             my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
  142:             if ( $CurMap ne 'All Maps' ) {
  143: 		my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
  144: 		if ( $Map ne $ResMap ) { next; }
  145: 	    }
  146: 	    my $meta=$hash{'src_'.$ResId};
  147: 	    my $PartNo = 0;
  148: 	    undef %TempHash;
  149: 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))){
  150: 		if ($_=~/^stores\_(\d+)\_tries$/) {
  151:                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
  152: 		    if ( $TempHash{"$Part"} eq '' ) { 
  153: 			$TempHash{"$Part"} = $Part;
  154: 			$TempHash{$PartNo}=$Part;
  155: 			$TempHash{"$Part.Code"} = '-';  
  156: 			$TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;  
  157: 			$PartNo++;
  158: 		    }
  159: 		}
  160:             }
  161: 
  162:             my $Prob = $Map.'___'.$2.'___'.
  163:                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
  164:             $Code='U';
  165:             $Tries = 0;
  166:             $Wrongs = 0;
  167:   	    $LatestVersion = $result{"version:$Prob"};       
  168: 
  169: 	    if ( $LatestVersion ) {
  170: 		for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
  171: 		    my $vkeys = $result{"$Version:keys:$Prob"};
  172: 		    my @keys = split(/\:/,$vkeys);		
  173:   
  174: 		    foreach my $Key (@keys) {		  
  175: 			if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
  176: 			    my $Part = $1;
  177: 			    $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
  178: 			    $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0; 
  179: 			    $TotalTries += $Tries;
  180: 			    my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
  181: 			    if ( $Val eq 'correct_by_student' )
  182:                                 { $Wrongs = $Tries - 1; $Code = 'Y'; } 
  183: 			    elsif ( $Val eq 'correct_by_override' )
  184:                                 { $Wrongs = $Tries - 1; $Code = 'y'; }                        
  185: 			    elsif ( $Val eq 'incorrect_attempted' || 
  186:                                 $Val eq 'incorrect_by_override' )
  187: 		                { $Wrongs = $Tries; $Code = 'N'; }
  188: 			    $TempHash{"$Part.Code"} = $Code;
  189: 			    $TempHash{"$Part.Wrongs"} = $Wrongs;
  190: 			}
  191:      		    }
  192:                 } 
  193: 		for ( my $n = 0; $n < $PartNo; $n++ ) {		  
  194: 		    my $part = $TempHash{$n};
  195: 		    if ($PtrTry ne '') {$PtrTry .= ',';}
  196: 		    $PtrTry .= "$TempHash{$part.'.Tries'}";
  197:                     $PtrCod .= "$TempHash{$part.'.Code'}";    
  198: 		}
  199:             }
  200: 	    else { 
  201: 		for(my $n=0; $n<$PartNo; $n++) { 
  202: 		    if ($PtrTry ne '') {$PtrTry .= ',';}
  203: 		    $PtrTry .= "0";
  204:                     $PtrCod .= "-"; 
  205: 		}
  206: 	    }
  207:         }
  208:     }
  209:     $Str .= "\n".'</table>';
  210:     $r->print($Str);
  211:     $r->rflush();
  212: }
  213: 
  214: sub CreateTable {
  215:     my ($Hd, $Hid)=@_;
  216:     if ( $Hd == 1 ) {
  217: #	$Hid=~/(\d+)\.(\d+)/;
  218: 	$r->print('<br><a href="'.$hash{'src_'.$Hid}.
  219:                   '" target="_blank">'.$hash{'title_'.$Hid}.'</a>'
  220: #                  .' ('.&Apache::lonnet::declutter($hash{'map_id_'.$1}).')'
  221:                  );
  222:     }
  223:     my $Result = "\n".'<table border=2>';
  224:     $Result .= '<tr><th>P#</th>'."\n";
  225:     for ( my $nIdx=0; $nIdx < 11; $nIdx++ ) { 
  226: 	$Result .= '<th>'.'<input type="submit" name="sort" value="'.
  227:                    $Header{$nIdx}.'" />'.'</th>'."\n";
  228:     }
  229:     $Result .= "\n".'</tr>'."\n";    
  230:     $r->print( $Result );
  231:     $r->rflush();
  232: }
  233: 
  234: sub CloseTable {
  235:     $r->print("\n".'</table>'."\n");
  236:     $r->rflush();
  237: }
  238:  
  239: # ------------------------------------------- Prepare Statistics Table
  240: sub PreStatTable {
  241:     my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  242:                   "_$ENV{'user.domain'}_$cid\_statistics.db";
  243:     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  244:                   "_$ENV{'user.domain'}_$cid\_graph.db";
  245:     my $CachDisFac = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  246: 		     "_$ENV{'user.domain'}_$cid\_DiscFactor.db";
  247:     my $OpSel11='';
  248:     my $OpSel12='';
  249:     my $OpSel13='';
  250:     my $Status = $ENV{'form.status'};
  251:     if ( $Status eq 'Any' ) { $OpSel13='selected'; }
  252:     elsif ($Status eq 'Expired' ) { $OpSel12 = 'selected'; }
  253:     else { $OpSel11 = 'selected'; }
  254: 
  255:     my $Ptr = '';
  256:     $Ptr .= '<br><b> Student Status: &nbsp; </b>'."\n".
  257:             '<select name="status">'. 
  258:             '<option '.$OpSel11.' >Active</option>'."\n".
  259:             '<option '.$OpSel12.' >Expired</option>'."\n".
  260: 	    '<option '.$OpSel13.' >Any</option> </select> '."\n";
  261:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  262:     $Ptr .= '<input type=submit name=sort value="Recalculate Statistics"/>'."\n";
  263: 
  264:     $Ptr .= '<br><b> Sorting Type: &nbsp; </b>'."\n".
  265:             '<select name="order"> <option '.$OpSel1.' >Ascending</option>'."\n".
  266: 	    '<option '.$OpSel2.'>Descending</option> </select> '."\n";
  267:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  268:     $Ptr .= '<input type="submit" name="sort" value="DoDiff Graph" />'."\n";
  269:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  270:     $Ptr .= '<input type="submit" name="sort" value="%Wrong Graph" />'."\n";
  271: 
  272:     $Ptr .= '<pre>'.
  273:     '  #Stdnts: Total Number of Students opened the problem.<br>'. 
  274:     '  Tries  : Total Number of Tries for solving the problem.<br>'. 
  275:     '  Mod    : Maximunm Number of Tries for solving the problem.<br>'. 
  276:     '  Mean   : Average Number of the tries. [ Tries / #Stdnts ]<br>'.
  277:     '  #YES   : Number of students solved the problem correctly.<br>'. 
  278:     '  #yes   : Number of students solved the problem by override.<br>'.
  279:     '  %Wrng  : Percentage of students tried to solve the problem but'.
  280:     ' still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]<br>'.
  281: #    '  DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ]<br>'.
  282:     '  DoDiff : Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ]<br>'.
  283:     '  S.D.   : Standard Deviation of the tries.'.
  284:     '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'.
  285:     ' where Xi denotes every student\'s tries ]<br>'.
  286:     '  Skew.  : Skewness of the students tries.'.
  287:     ' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ]<br>'.
  288: 
  289: #    '  Dis.F. : Discrimination Factor. [ Sum of Partial Credits Awarded / Total Number of Tries in %27 upper and lower students]</b>'.	
  290:             '</pre>';
  291: 
  292:     $r->print($Ptr);
  293:     $r->rflush();	
  294: 
  295:     if ((-e "$CacheDB")&&($ENV{'form.sort'} ne 'Recalculate Statistics')) {
  296: 	if (tie(%CachData,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
  297: 	    tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
  298: 	    &Cache_Statistics();
  299:         }
  300:         else {
  301: 	    $r->print("Unable to tie hash to db file");
  302:         }
  303:     }
  304:     else {
  305: 	if (tie(%CachData,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
  306: 	    tie(%DiscFac,'GDBM_File',$CachDisFac,&GDBM_WRCREAT,0640);
  307: 	    tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
  308: 	    foreach (keys %DiscFac) {delete $CachData{$_};}
  309: 	    foreach (keys %CachData) {delete $CachData{$_};}
  310: 	    $DiscFlag=0;
  311: 	    &Build_Statistics();
  312: 	}
  313:         else {
  314: 	    $r->print("Unable to tie hash to db file");
  315:         }
  316:     }
  317:     #$r->print('Total instances of the problems : '.($p_count*($#students+1)));
  318: 
  319:     untie(%CachData);
  320:     untie(%GraphDat);
  321:     untie(%DiscFac);       
  322: }
  323: 
  324: 
  325: # ------------------------------------- Find the section of student in a course
  326: 
  327: sub usection {
  328:     my ($udom,$unam,$courseid,$ActiveFlag)=@_;
  329:     $courseid=~s/\_/\//g;
  330:     $courseid=~s/^(\w)/\/$1/;
  331:     foreach (split(/\&/,&Apache::lonnet::reply('dump:'.
  332:              $udom.':'.$unam.':roles',
  333:              &Apache::lonnet::homeserver($unam,$udom)))){
  334:         my ($key,$value)=split(/\=/,$_);
  335:         $key=&Apache::lonnet::unescape($key);
  336:         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
  337:             my $section=$1;
  338:             if ($key eq $courseid.'_st') { $section=''; }
  339: 	    my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));
  340: 	    if ( $ActiveFlag ne 'Any' ) {
  341: 		my $now=time;
  342: 		my $notactive=0;
  343: 		if ($start) {
  344: 		    if ($now<$start) { $notactive=1; }
  345: 		}
  346: 		if ($end) {
  347: 		    if ($now>$end) { $notactive=1; }
  348: 		}
  349: 		if ((($ActiveFlag eq 'Expired') && $notactive == 1) || 
  350:                     (($ActiveFlag eq 'Active') && $notactive == 0 ) ) {
  351: 		    return $section;
  352: 		}
  353: 		else { return '-1'; } 
  354: 	    }
  355: 	    return $section;
  356:         }
  357:     }
  358:     return '-1';
  359: }
  360: 
  361: 
  362: # ------ Dump the Student's DB file and handling the data for statistics table 
  363: 
  364: sub ExtractStudentData {
  365:     my ($student,$coid)=@_;
  366:     my ($sname,$sdom) = split( /\:/, $student );
  367:     my $shome=&Apache::lonnet::homeserver( $sname,$sdom );          
  368:     my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );
  369:     my %result = ();
  370:     my $ResId;
  371:     my $PrOrd;
  372:     my $Dis = '';
  373:     my $Code;
  374:     my $Tries;
  375:     my $ParCr;
  376:     my $TotalTries = 0;
  377:     my $TotalOpend = 0;
  378:     my $ProbSolved = 0;
  379:     my $ProbTot = 0;
  380:     my $TimeTot = 0;
  381:     my $TotParCr = 0;
  382:     my $Wrongs;
  383:     my %TempHash;
  384:     my $Version;
  385:     my $LatestVersion;
  386:     my $SecLimit;
  387:     my $MapLimit;
  388:     unless ($reply=~/^error\:/) {
  389:         foreach (split(/\&/,$reply)) {
  390:             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
  391:             $result{$name}=$value;
  392:         }
  393:         foreach my $CurCol(@cols) {
  394: 	    ($PrOrd,$ResId)=split(/\:/,$CurCol);
  395: 	    if ( !$CurCol ) { next; }
  396:             $ResId=~/(\d+)\.(\d+)/;
  397: 	    my $MapId=$1;
  398: 	    my $PrbId=$2;
  399:             my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$MapId} );
  400:             if ( $CurMap ne 'All Maps' ) {
  401: 		my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
  402: 		if ( $Map ne $ResMap ) { next; }
  403: 	    }
  404: 	    my $meta=$hash{'src_'.$ResId};
  405: 	    my $PartNo = 0;
  406: 	    $Dis .= ':';
  407: 	    undef %TempHash;
  408: 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
  409: 		if ($_=~/^stores\_(\d+)\_tries$/) {
  410:                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
  411: 		    if ( $TempHash{"$Part"} eq '' ) { 
  412: 			$TempHash{"$Part"} = $Part;
  413: 			$TempHash{$PartNo}=$Part;
  414: 			$TempHash{"$Part.Code"} = 'U';  
  415: 			$TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
  416: 			$PartNo++;
  417: 		    }
  418: 		}
  419:             }
  420: 
  421:             my $Prob = $Map.'___'.$PrbId.'___'.
  422:                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
  423:             $Code='U';
  424:             $Tries = 0;
  425: 	    $ParCr = 0;
  426:             $Wrongs = 0;
  427:   	    $LatestVersion = $result{"version:$Prob"};       
  428: 
  429: 	    if ( $LatestVersion ) {
  430: 		for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
  431: 		    my $vkeys = $result{"$Version:keys:$Prob"};
  432: 		    my @keys = split(/\:/,$vkeys);		
  433:   
  434: 		    foreach my $Key (@keys) {		  
  435: 			if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
  436: 			    my $Part = $1;
  437: 			    $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
  438: 			    $ParCr = $result{"$Version:$Prob:resource.$Part.awarded"};
  439: 			    my $Time = $result{"$Version:$Prob:timestamp"};
  440: 			    $TempHash{"$Part.Time"} = ($Time) ? $Time : 0;
  441: 			    $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
  442: 			    $TempHash{"$Part.ParCr"} = ($ParCr) ? $ParCr : 0;        
  443: 			    $TotalTries += $TempHash{"$Part.Tries"};
  444: 			    $TotParCr += $TempHash{"$Part.ParCr"};
  445: #$r->print($Version.'---'.$Prob.'==='.$Time.'<br>');
  446: 			    my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
  447: 			    if ( $Val eq 'correct_by_student' )
  448:                                { $Wrongs = $Tries - 1; $Code = 'C'; } 
  449: 			    elsif ( $Val eq 'correct_by_override' )
  450:                                { $Wrongs = $Tries - 1; $Code = 'O'; }                        
  451: 			    elsif ( $Val eq 'incorrect_attempted' || 
  452:                                 $Val eq 'incorrect_by_override' )
  453: 		               { $Wrongs = $Tries; $Code = 'I'; }
  454: 			    $TempHash{"$Part.Code"} = $Code;
  455: 			    $TempHash{"$Part.Wrongs"} = $Wrongs;
  456: 			}
  457:      		    }
  458:                 } 
  459: 		for ( my $n = 0; $n < $PartNo; $n++ ) {		  
  460: 		    my $part = $TempHash{$n};
  461: 		    my $Yes = 0;
  462:                     if ( $TempHash{$part.'.Code'} eq 'C' ||
  463:                          $TempHash{$part.'.Code'} eq 'O'  ) 
  464: 		       {$ProbSolved++;$Yes=1;}		    
  465: #		    my $ptr = "$hash{'title_'.$ResId}";
  466: 		    my $ptr = $TempHash{$part.'.PrOrd'}.':'.$ResId;
  467: 		    if ( $PartNo > 1 ) {                
  468: 			$ptr .= "*(part $part)";
  469: 			$Dis .= ':';
  470: 		    }
  471: 		    my $Fac = ($TempHash{"$part.Tries"}) ? 
  472:                               ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
  473: 		    my $DisF;
  474: 		    if ( $Fac > 0 &&  $Fac < 1 ) { 
  475: 			$DisF = sprintf( "%.4f", $Fac );
  476: 		    }
  477: 		    else {$DisF = $Fac;}
  478: #		    $DisF .= '+'.$TempHash{"$part.Time"};
  479: 		    $TimeTot += $TempHash{"$part.Time"};
  480: 		    $Dis .= $ptr.'*'.$ResId.'='.$DisF.'+'.$Yes;
  481: 		    $ptr .= ":$TempHash{$part.'.Tries'}".
  482: 		            ":$TempHash{$part.'.Wrongs'}".
  483:                             ":$TempHash{$part.'.Code'}";
  484: 		    push (@list, $ptr);
  485: 		    $TotalOpend++;
  486: 		    $ProbTot++;
  487: 		}
  488:             }
  489: 	    #else { 
  490: 		#for(my $n=0; $n<$PartNo; $n++) {
  491: 		#    push (@list, "$hash{'title_'.$ResId}*$ResId:0:0:U");
  492: 		#    $ProbTot++; 
  493: 		#}
  494: 	    #}
  495:         }
  496: 	if ( $TotalTries ) {
  497: 	    my $DisFac = ( $TotalTries ) ? ($TotParCr/$TotalTries) : 0;
  498: #	    my $DisFactor = int(sprintf( "%.4f", $DisFac ) * 100);
  499: 	    my $DisFactor = sprintf( "%.4f", $DisFac );
  500: 	    my $time;
  501: 	    if ($ProbSolved){
  502: 		$time = int(($TimeTot/$ProbSolved)-10000000);
  503: 	    }
  504: 	    $DiscFac{($DisFactor.':'.$sname.':'.$ProbTot.':'.$TotalOpend.':'.
  505:                       $TotalTries.':'.$ProbSolved.':'.$time)}=$Dis;
  506: #$r->print($DisFactor.$sname.'<br> --- Dis= '.$Dis.'<br>');
  507: 	}
  508:     }
  509:     #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.'<br>');
  510: }
  511: 
  512: 
  513: # ------------------------------------------------------------ Build page table
  514: sub tracetable {
  515:     my ($rid,$beenhere)=@_;
  516:     $rid=~/(\d+)\.(\d+)/;
  517:     $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid}; 
  518:     #$maps{$HWN}=$hash{'title_'.$rid}; 
  519:     unless ($beenhere=~/\&$rid\&/) {
  520:        $beenhere.=$rid.'&'; 
  521:        if (defined($hash{'is_map_'.$rid})) {
  522: 	   my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
  523:            if ( $cmap eq 'sequence' || $cmap eq 'page' ) { 
  524:                $cols[$#cols+1]=0;
  525: 	       $P_Order++;
  526: 	       $HWN=$P_Order;
  527:                $mapsort{$HWN} = $rid.':'; 
  528:                #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}= 
  529:                #      $hash{'title_'.$rid}; 
  530:            }
  531:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
  532:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
  533: 	       my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
  534: 
  535:                &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
  536: 			   '&'.$frid.'&');
  537: 
  538: 	       $cols[$#cols+1]=($P_Order+1).':'.$frid;
  539:       
  540: 	       my $meta=$hash{'src_'.$frid};
  541: 	       my $PartNo = 0;
  542:                if ($meta) {
  543: 		   if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  544: 		       foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
  545: 			   if ($_=~/^stores\_(\d+)\_tries$/) {
  546: 			       &Apache::lonnet::metadata($meta,$_.'.part');
  547: 			       $P_Order++;
  548: 			       $mapsort{$HWN} .= '&'.$P_Order;
  549: 			       $PartNo++;
  550: 			       $r->print('<br>'.$PartNo.'---'.$P_Order);
  551: 			   }
  552: 		       }
  553: 		   }
  554:                }
  555: 	   }
  556:        } else {
  557: 	   $cols[$#cols+1]=($P_Order+1).':'.$rid;
  558: 	   my $meta=$hash{'src_'.$rid};
  559: 	   my $PartNo = 0;
  560:            if ($meta) {
  561: 	       if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  562: 		   foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
  563: 		       if ($_=~/^stores\_(\d+)\_tries$/) {
  564: 			   &Apache::lonnet::metadata($meta,$_.'.part');
  565: 			   $P_Order++;
  566: 			   $mapsort{$HWN} .= '&'.$P_Order;
  567: 			   $PartNo++;
  568: 		       }
  569: 		   }
  570: 	       }
  571: 	   }
  572:        }
  573:        if (defined($hash{'to_'.$rid})) {
  574:           foreach (split(/\,/,$hash{'to_'.$rid})){
  575:               &tracetable($hash{'goesto_'.$_},$beenhere);
  576:           }
  577:        }
  578:     }
  579: }
  580: 
  581: sub MySort {          
  582:     if ( $Pos > 0 ) {
  583: 	if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
  584: 	else { $a <=> $b; }
  585:     }
  586:     else {
  587: 	if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
  588: 	else { $a cmp $b; }
  589:     }
  590: }
  591: 
  592: sub Build_Statistics {
  593:     $r->print(<<ENDPOP);
  594:     <script>
  595:     popwin=open('','popwin','width=400,height=100');
  596:     popwin.document.writeln('<html><body bgcolor="#88CC88">'+
  597:       '<title>LON-CAPA Statistics</title>'+
  598:       '<h4>Computation Progress</h4>'+
  599:       '<form name=popremain>'+
  600:       '<input type=text size=35 name=remaining value=Starting></form>'+
  601:       '</body></html>');
  602:     popwin.document.close();
  603:     </script>
  604: ENDPOP
  605: 
  606:     $r->rflush();
  607: # ---------------------------- Gathering the Data of students' tries
  608:     my $index;
  609:     for ($index=0;$index<=$#students;$index++) {
  610: #----------- update progress
  611:         $r->print('<script>popwin.document.popremain.remaining.value="'.
  612:                   'Computing '.($index+1).'/'.($#students+1).': '.
  613:                   $students[$index].'";</script>');
  614:         $r->rflush();
  615: 
  616:         &ExtractStudentData($students[$index],$cid);
  617:     }
  618: #--------------------- close Progress Line
  619:     $r->print('<script>popwin.close()</script>');
  620:     $r->rflush(); 
  621: # -------------------- sorting the Data
  622:     @list = sort (@list);
  623: 
  624:     $OpSel2='';
  625:     $OpSel1='selected';
  626:  		   
  627:     $p_count = 0; 
  628:     my $nIdx = 0;
  629:     my $dummy; 
  630:     my $p_val;
  631:     my $ResId;
  632:     my $NoElements = $#list + 1;
  633: #-------------------------------- loop for data representation
  634:     foreach (sort keys %mapsort) {
  635: 	my ($Hid,$pr)=split(/\:/,$mapsort{$_});
  636: 	my @lpr=split(/\&/,$pr);
  637: 	&CreateTable(1,$Hid);
  638: 	for (my $i=1; $i<=$#lpr; $i++) {
  639: 	    my %storestats=();
  640: 	    my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
  641: 	    my $Temp = $Prob;
  642: 	    my $MxTries = 0;
  643: 	    my $TotalTries = 0;
  644: 	    my $YES = 0;
  645: 	    my $Incorrect = 0;
  646: 	    my $Override = 0;
  647: 	    my $StdNo = 0;
  648: 	    my @StdLst;
  649: 	    while ( $PrOrd == $lpr[$i] ) 
  650: 	    {
  651: 		$nIdx++;
  652: 		$StdNo++;
  653: 		$StdLst[ $StdNo ] = $Tries;
  654: 		$TotalTries += $Tries;
  655: 		if ( $MxTries < $Tries ) { $MxTries = $Tries; } 
  656: 		if ( $Code eq 'C' ){ $YES++; }
  657: 		elsif( $Code eq 'I' ) { $Incorrect++; }
  658: 		elsif( $Code eq 'O' ) { $Override++; }
  659: 		elsif( $Code eq 'U' ) { $StdNo--; }
  660: 		($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
  661: 	    }	
  662: 
  663: 	    $p_count++;
  664: 	    my $Dummy;
  665: 	    ($ResId,$Dummy)=split(/\*/,$Temp);
  666: 
  667: 	    $Temp = '<a href="'.$hash{'src_'.$ResId}.
  668:                 '" target="_blank">'.$hash{'title_'.$ResId}.$Dummy.'</a>';
  669:     
  670: 	    my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});
  671: 	    my $urlres=$res;
  672: 
  673: 	    $ResId=~/(\d+)\.(\d+)/;
  674: 	    my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
  675: 	    $urlres=$Map;
  676:  
  677: 	    $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';
  678: 	    #$Map = '<a href="'.$Map.'">'.$res.'</a>';
  679: 
  680: #------------------------ Compute the Average of Tries about one problem
  681: 	    my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;
  682: 
  683: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;       
  684: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;
  685: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;
  686:    
  687: #-------------------------------- Compute percentage of Wrong tries
  688: 	    my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;
  689: 
  690: #-------------------------------- Compute Standard Deviation
  691: 	    my $StdDev = 0; 
  692: 	    if ( $StdNo > 1 ) {
  693: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
  694: 		    my $Dif = $StdLst[ $n ]-$Average;
  695: 		    $StdDev += $Dif*$Dif;
  696: 		} 
  697: 		$StdDev /= ( $StdNo - 1 );
  698: 		$StdDev = sqrt( $StdDev );
  699: 	    }
  700: 
  701: #-------------------------------- Compute Degree of Difficulty
  702: 	    my $DoDiff = 0;
  703: 	    if( $TotalTries > 0 ) {
  704: 		$DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );
  705: #	    $DoDiff =  ($TotalTries)/($YES + $Override+ 0.1);	    
  706: 	    }
  707:        
  708: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;
  709: 
  710: #-------------------------------- Compute the Skewness
  711: 	    my $Skewness = 0;
  712: 	    my $Sum = 0; 
  713: 	    if ( $StdNo > 0 && $StdDev > 0 ) {
  714: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
  715: 		    my $Dif = $StdLst[ $n ]-$Average;
  716: 		    $Skewness += $Dif*$Dif*$Dif;
  717: 		} 
  718: 		$Skewness /= $StdNo;
  719: 	    $Skewness /= $StdDev*$StdDev*$StdDev;
  720: 	    }
  721: #-----------------  Some restition in presenting the float numbers
  722: 	    my $Avg = sprintf( "%.2f", $Average );
  723: 	    my $Wrng = sprintf( "%.1f", $Wrong );
  724: 	    my $SD = sprintf( "%.1f", $StdDev );
  725: 	    my $DoD = sprintf( "%.2f", $DoDiff );
  726: 	    my $Sk = sprintf( "%.1f", $Skewness );
  727: 	    my $join = $PrOrd.':'.$Temp.':'.$StdNo.':'.
  728:                        $TotalTries.':'.$MxTries.':'.$Avg.':'.
  729:                        $YES.':'.$Override.':'.$Wrng.':'.$DoD.':'.
  730: 		       $SD.':'.$Sk.':'.$Prob;
  731: 	    $CachData{($p_count-1)}=$join;
  732: 
  733: 	    $urlres=~/^(\w+)\/(\w+)/;
  734: 	    if ($StdNo) { 
  735: 		&Apache::lonnet::put('resevaldata',\%storestats,$1,$2); 
  736: 	    }
  737: #-------------------------------- Row of statistical table
  738: 	    if ( $DiscFlag == 0 ) {
  739: 		&TableRow($join,$i,($p_count-1));
  740: 	    } 
  741: 	}
  742: 	&CloseTable();
  743:     }
  744: }
  745: 
  746: sub Cache_Statistics {
  747:     my @list = ();
  748:     my $Useful;
  749:     my $UnUseful;
  750:     my %myHeader = reverse( %Header );
  751:     $Pos = $myHeader{$ENV{'form.sort'}};
  752:     if ($Pos > 0) {$Pos++;}
  753:     $p_count = 0;
  754:     foreach my $key( keys %CachData) { 
  755: 	my @Temp=split(/\:/,$CachData{$key});
  756: 	if ( $Pos == 0 ) {
  757: 	    ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
  758: 	}
  759: 	else {
  760: 	    $Useful = $Temp[$Pos];
  761: 	}   
  762: 	$list[$p_count]=$Useful.'&'.$CachData{$key};
  763:         $p_count++;
  764:     }
  765: 
  766:     @list = sort MySort (@list);
  767: 
  768:     my $nIdx=0;
  769: 
  770:     if ( $Pos == 0 ) {
  771: 	foreach (sort keys %mapsort) {
  772: 	    my ($Hid,$pr)=split(/\:/,$mapsort{$_});
  773: 	    &CreateTable(1,$Hid);
  774: 	    my @lpr=split(/\&/,$pr);
  775: 	    for (my $i=1; $i<=$#lpr; $i++) {
  776: 		my($Pre, $Post) = split(/\&/,$list[$nIdx]); 
  777: 		&TableRow($Post,$i,$nIdx);
  778: 		$nIdx++;
  779: 	    }
  780: 	    &CloseTable();
  781: 	}
  782:     }
  783:     else {
  784: 	&CreateTable(0);
  785: 	for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {
  786: 	    my($Pre, $Post) = split(/\&/,$list[$nIdx]); 
  787: 	    &TableRow($Post,$nIdx,$nIdx);
  788: 	} 
  789: 	&CloseTable();
  790:     }
  791: }
  792: 
  793: sub TableRow {
  794:     my ($Str,$Idx,$RealIdx)=@_;
  795:     my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,
  796:        $Override,$Wrng,$DoD,$SD,$Sk,$Prob)=split(/\:/,$Str);	
  797:     $r->print( "\n".'<tr>'.
  798:                "\n".'<td>'.($RealIdx+1).'</td>'.
  799:                "\n".'<td bgcolor="#FFFFFF">'.$Temp.'</td>'.
  800:                "\n".'<td bgcolor="#EEFFDD"> '.$StdNo.'</td>'.
  801:                "\n".'<td bgcolor="#EEFFDD">'.$TotalTries.'</td>'.
  802:                "\n".'<td bgcolor="#EEFFDD">'.$MxTries.'</td>'.
  803:                "\n".'<td bgcolor="#DDFFFF">'.$Avg.'</td>'.
  804:                "\n".'<td bgcolor="#DDFFFF"> '.$YES.'</td>'.
  805:                "\n".'<td bgcolor="#DDFFFF"> '.$Override.'</td>'.
  806:                "\n".'<td bgcolor="#FFDDDD"> '.$Wrng.'</td>'.
  807:                "\n".'<td bgcolor="#FFDDDD">'.$DoD.'</td>'.
  808:                "\n".'<td bgcolor="#DDFFDD"> '.$SD.'</td>'.
  809:                "\n".'<td bgcolor="#DDFFDD"> '.$Sk.'</td>'.
  810: #               "\n".'<td>'.$res.'</td>'.
  811:                "\n".'</tr>' );
  812:     $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
  813: }
  814: 
  815: # ------------------------------------------- Prepare data for Graphical chart
  816: 
  817: sub GetGraphData {
  818:     my $Tag = shift;
  819:     my $Col;
  820:     my $data='';
  821:     my $count = 0;
  822:     my $Max = 0;
  823:     my $cid=$ENV{'request.course.id'};
  824:     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  825:                   "_$ENV{'user.domain'}_$cid\_graph.db";
  826:     foreach (keys %GraphDat) {delete $GraphDat{$_};}
  827:     if (-e "$GraphDB") {
  828: 	if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
  829: 	    if ( $Tag eq 'DoDiff Graph' ) {
  830: 		$Tag = 'Degree-of-Difficulty';
  831: 		$Col = 0;
  832: 	    }
  833: 	    else {
  834: 		$Tag = 'Wrong-Percentage';
  835: 		$Col = 1;
  836: 	    }
  837: 	    foreach (sort NumericSort keys %GraphDat) { 
  838: 		my @Temp=split(/\:/,$GraphDat{$_});
  839:                 my $inf = $Temp[$Col]; 
  840: 		if ( $Max < $inf ) {$Max = $inf;}
  841: 		$data .= $inf.',';
  842: 		$count++;
  843: 	    }
  844:             untie(%GraphDat);
  845: 	    my $Course = $ENV{'course.'.$cid.'.description'};
  846: 	    $Course =~ s/\ /"_"/eg;
  847: 	    $GData=$Course.'&'.$Tag.'&'.$Max.'&'.$count.'&'.$data;
  848: 
  849: 	}
  850: 	else {
  851: 	    $r->print("Unable to tie hash to db file");
  852: 	}
  853:     }
  854: }
  855: 
  856: 
  857: sub initial {
  858: # --------------------------------- Initialize the global varaibles
  859:   undef @students;
  860:   undef @cols;
  861:   undef %maps;
  862:   undef %section;
  863:   undef %StuBox;
  864:   undef @list;
  865:   undef %CachData;
  866:   undef %GraphDat;
  867:   undef %DiscFac;
  868:   undef $CurMap;
  869:   undef $CurSec;
  870:   undef $CurStu;
  871:   undef $p_count;
  872:   undef $Pos;
  873:   undef $GData;
  874:   $DiscFlag=0; 
  875:   $P_Order=100000;
  876:   $HWN=$P_Order;
  877: }
  878: 
  879: 
  880: sub ClassList {
  881: 
  882:     &GetStatus();
  883: 
  884:     $cid=$ENV{'request.course.id'};
  885:     my $chome=$ENV{'course.'.$cid.'.home'};
  886:     my ($cdom,$cnum)=split(/\_/,$cid);
  887: # ----------------------- Get first and last resource, see if there is anything
  888:     $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
  889:     $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
  890:     if (($firstres) && ($lastres)) {
  891: # ----------------------------------------------------------------- Render page
  892: 	my $classlst=&Apache::lonnet::reply
  893:                  ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
  894: 	my $StudNo = 0;
  895: 	my $now=time;
  896: 	unless ($classlst=~/^error\:/) {
  897: 	    foreach (sort split(/\&/,$classlst)) {
  898: 		my ($name,$value)=split(/\=/,$_);
  899: 		my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
  900: 		$name=&Apache::lonnet::unescape($name);
  901: 		my ($sname,$sdom)=split(/\:/,$name);
  902: 		my $active=1;
  903: 		my $Status=$ENV{'form.status'};
  904: 		$Status = ($Status) ? $Status : 'Active';
  905: 		if ( ( ($end) && $now > $end ) && 
  906:                      ( ($Status eq 'Active') ) ) { $active=0; }
  907: 		if ( ($Status eq 'Expired') && 
  908:                      ($end == 0 || $now < $end) ) { $active=0; }
  909: 		if ($active) {
  910: 		    my $thisindex=$#students+1;
  911: 		    $name=&Apache::lonnet::unescape($name);
  912: 		    $students[$thisindex]=$name;
  913: 		    my ($sname,$sdom)=split(/\:/,$name);
  914: 
  915: 		    #my %reply=&Apache::lonnet::idrget($sdom,$sname);
  916: 		    #my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
  917: 		    #         ':environment:lastname&generation&firstname&middlename',
  918: 		    #         &Apache::lonnet::homeserver($sname,$sdom));
  919: 		    my $ssec=&usection($sdom,$sname,$cid,$Status);
  920: 		    if ($ssec==-1) {next;}
  921: 		    $ssec=($ssec) ? $ssec : '(none)';
  922: 		    #$ssec=(int($ssec)) ? int($ssec) : $ssec;
  923: 		    #$r->print($sname.'...'.$ssec.'<br>');
  924: 		    $section{$ssec}=$ssec;
  925: 		    if ($CurSec eq 'All Sections' || $ssec eq $CurSec) {
  926: 			$students[$StudNo]=$name;
  927: 			$StuBox{$sname}=$ssec;
  928: 		    }
  929: 		    $StudNo++;
  930: 	        }
  931: 	    }
  932: 	}
  933: 	else {
  934: 	    $r->print('<h1>Could not access course data</h1>');
  935: 	} 
  936:         $r->print("Total number of students : ".($#students+1));
  937:         $r->rflush();
  938: # --------------- Find all assessments and put them into some linear-like order
  939: 	&tracetable($firstres,'&'.$lastres.'&');
  940: 
  941: #    my $c=0;
  942: #    foreach (sort keys %mapsort) {
  943: #	$r->print('<br>'.$c.')'.$_.' ... '.$mapsort{$_});
  944: #	$c++;
  945: #    }
  946: #foreach(@cols) {
  947: #    $c++;
  948: #    $r->print('<br>'.$cols[$c]);
  949: #}
  950: #$r->print('<br> Count = '.$c);
  951: 
  952:     }
  953: 
  954: # ------------------------------------------------------------- End render page 
  955:     else {
  956: 	$r->print('<h3>Undefined course sequence</h3>');
  957:     }
  958:     &MapSecOptions();
  959: }
  960: 
  961: 
  962: sub Menu {
  963:     my $InpStr = $ENV{'form.sort'};
  964:     if ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) {      
  965: 	&GetGraphData($InpStr);
  966:     	$r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
  967:     }
  968:     else {
  969: 	$r->print('<html><head><title>LON-CAPA Statistics</title></head>');
  970: 
  971: 
  972:         $r->print('<body bgcolor="#FFFFFF">'.
  973:                   '<script>window.focus(); window.width=500;window.height=500; </script>'.
  974:                   '<img align=right src=/adm/lonIcons/lonlogos.gif>');
  975: # ---------------------------------------------------------------- Course title
  976:         $r->print('<h1> Course : "'.
  977:                   $ENV{'course.'.$ENV{'request.course.id'}.
  978:                   '.description'}.'"</h1><h2>'.localtime().'</h2>');
  979: # ------------------------------- This is going to take a while, produce output
  980:         $r->rflush();	
  981: 
  982: 	$r->print("\n".'<form name=stat method=post action="/adm/statistics" >');
  983: 
  984: 	my $content = $ENV{'form.sort'};
  985: 	if ($content eq '' || $content eq 'Return to Menu') {
  986: 	    my $Ptr = '<h3>';
  987: 	    $Ptr .= '<input type=submit name=sort value="Problem Evaluation"/>';#General Statistics"/>';
  988: 	    $Ptr .= '<br><br>';
  989: 	    $Ptr .= '<input type=submit name=sort value="Student Assessment"/>';
  990: 	    $Ptr .= '<br><br>';
  991: #	    $Ptr .= '<input type=submit name=sort value=Discrimination>';#"Problem Evaluation"/>';
  992: 	    $Ptr .= '</h3>';
  993: 	    $r->print( $Ptr );
  994:       	}
  995: 	else {
  996: 	    &initial();
  997: 	    &ClassList();
  998: 	    if ( $content eq 'Discrimination' || #'Problem Evaluation' ||
  999:                  $content eq 'Recalculate Discrimintion Factor' ) {
 1000: 		&CreateDiscFac();
 1001: 	    }
 1002: 	    elsif ( $content eq 'Student Assessment' || 
 1003:                     $content eq 'Create Student Report' ) {
 1004: 		&StudentOptions();
 1005: 		&StudentReport($CurStu,$StuBox{"$CurStu"});
 1006: 	    }
 1007: 	    else {
 1008: 		&PreStatTable();
 1009: 	    }
 1010: 	}
 1011: 	$r->print("\n".'</form>'.
 1012:                   "\n".'</body>'.
 1013:                   "\n".'</html>');
 1014: 	$r->rflush();
 1015:     }
 1016: }
 1017: 
 1018: sub StudentOptions {
 1019:     my $OpSel5='';
 1020:     $CurStu = $ENV{'form.student'};
 1021:     if ( $CurStu eq '' ) { 
 1022:         $CurStu = 'All Students';
 1023:         $OpSel5 = 'selected';
 1024:     }
 1025:     my $Ptr ='';
 1026: # ----------------------------------- Loading the Students Combobox
 1027:     $Ptr .= '<br><b>Select Student</b>'."\n".
 1028:        	    '<select name="student">'."\n". 
 1029: 	    '<option '.$OpSel5.'>All Students</option>';                     	     	     
 1030:     foreach my $key ( sort keys %StuBox ) {	          
 1031: 	$Ptr .= '<option';
 1032: 	if ($CurStu eq $key) {$Ptr .= ' selected';}     
 1033:         $Ptr .= '>'.$key."</option>\n";	     
 1034:     }
 1035:     $Ptr .= '</select>';
 1036:     $Ptr .= '<br><input type="submit" name="sort" value="Create Student Report" />';
 1037:     $r->print( $Ptr );
 1038:     $r->rflush();	
 1039: }
 1040: 
 1041: sub GetStatus {
 1042: 
 1043:     $OpSelDis1='';
 1044:     $OpSelDis2='';
 1045:     $OpSel1='';
 1046:     $OpSel2='';
 1047:     $OpSel3='';
 1048:     $OpSel4='';
 1049: 
 1050: #    if ( $ENV{'form.DisType'} eq 'Total Number of Correct Answers' ) { 
 1051: #	$OpSelDis1='selected'; 
 1052: #	$CurDis=0;
 1053: #    }
 1054: #    else { $OpSel2 = 'selected'; $CurDis = 1;}
 1055: 
 1056:     if ( $ENV{'form.order'} eq 'Descending' ) { $OpSel2='selected'; }
 1057:     else { $OpSel1 = 'selected'; }
 1058: 
 1059:     my %myHeader = reverse( %Header );
 1060:     $Pos = $myHeader{$ENV{'form.sort'}};
 1061:     if ($Pos == 0) {
 1062: 	$OpSel1 = 'selected';
 1063: 	$ENV{'form.order'}='Ascendig';
 1064:     }
 1065: 
 1066:     $CurMap = $ENV{'form.maps'};
 1067:     if ( $CurMap eq '' ) { 
 1068: 	$CurMap = 'All Maps';
 1069: 	$OpSel3 = 'selected';
 1070:     }
 1071:     $CurSec = $ENV{'form.section'};
 1072:     if ( $CurSec eq '' ) { 
 1073: 	$CurSec = 'All Sections';
 1074:         $OpSel4 = 'selected';
 1075:     }
 1076: }
 1077: 
 1078: 
 1079: sub MapSecOptions {
 1080: # ----------------------------------- Loading the Maps Combobox
 1081:     my $Ptr = '<br>';
 1082:     $Ptr .= '<br><input type="submit" name="sort" value="Return to Menu" />';
 1083:     $Ptr .= '<br><b> Select &nbsp; Map &nbsp; &nbsp; </b>'."\n".
 1084:        	    '<select name="maps">'."\n". 
 1085: 	    '<option '.$OpSel3.'>All Maps</option>';                     	     	     
 1086:     foreach my $key ( sort keys %maps ) {	          
 1087: 	$Ptr .= '<option';
 1088:         if ($CurMap eq $key) {$Ptr .= ' selected';}	     
 1089: 	$Ptr .= '>'.$key."</option>\n";	     
 1090:     }
 1091:     $Ptr .= '</select>';
 1092:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
 1093: 
 1094: # ----------------------------------- Loading the Sections Combobox
 1095:     $Ptr .= '<br><b>Select Section</b>'."\n".
 1096:        	    '<select name="section">'."\n". 
 1097: 	    '<option '.$OpSel4.'>All Sections</option>';                     	     	     
 1098:     foreach my $key ( sort keys %section ) {	          
 1099: 	$Ptr .= '<option';
 1100:         if ($CurSec eq $key) {$Ptr .= ' selected';}     
 1101: 	$Ptr .= '>'.$key."</option>"."\n";	     
 1102:     }
 1103:     $Ptr .= '</select>'."\n";
 1104: 
 1105:     $r->print( $Ptr );
 1106:     $r->rflush();
 1107: }
 1108: 
 1109: 
 1110: # ================================================================ Main Handler
 1111: 
 1112: sub handler {
 1113:     $r=shift;
 1114: 
 1115:     if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
 1116: # ------------------------------------------- Set document type for header only
 1117: 	if ($r->header_only) {
 1118: 	    if ($ENV{'browser.mathml'}) {
 1119: 		$r->content_type('text/xml');
 1120: 	    } 
 1121: 	    else {
 1122: 		$r->content_type('text/html');
 1123: 	    }
 1124: 	    $r->send_http_header;
 1125: 	    return OK;
 1126: 	}    
 1127: 	my $requrl=$r->uri;
 1128: # ----------------------------------------------------------------- Tie db file
 1129: 
 1130: 	undef %hash;
 1131: 
 1132: 	if ($ENV{'request.course.fn'}) {
 1133: 	    my $fn=$ENV{'request.course.fn'};
 1134: 	    if (-e "$fn.db") {
 1135: 		if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
 1136: # ------------------------------------------------------------------- Hash tied
 1137: 		    $r->content_type('text/html');
 1138: 		    $r->send_http_header;
 1139: 		    &Menu();
 1140: 		}
 1141: 		else {
 1142: 		    $r->content_type('text/html');
 1143: 		    $r->send_http_header;
 1144: 		    $r->print('<html><body>Coursemap undefined.</body></html>');
 1145: 		}
 1146: # ------------------------------------------------------------------ Untie hash
 1147: 		unless (untie(%hash)) {
 1148: 		    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
 1149:                             "Could not untie coursemap $fn (browse).</font>"); 
 1150: 		}
 1151: 
 1152: # -------------------------------------------------------------------- All done
 1153: 		return OK;
 1154: # ----------------------------------------------- Errors, hash could no be tied
 1155: 	    }
 1156: 	} 
 1157: 	else {
 1158: 	    $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
 1159: 	    return HTTP_NOT_ACCEPTABLE; 
 1160: 	}
 1161:     }
 1162:     else {
 1163:         $ENV{'user.error.msg'}=
 1164:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
 1165: 
 1166:         return HTTP_NOT_ACCEPTABLE; 
 1167:     }
 1168: }
 1169: 1;
 1170: __END__
 1171: 
 1172: 
 1173: 

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