File:  [LON-CAPA] / loncom / interface / lonstatistics.pm
Revision 1.15: download - view: text, annotated - select for diffs
Mon May 13 13:50:45 2002 UTC (22 years ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
Worked on FIE paper
Added problem analysis for option response problems.

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonstatistics.pm,v 1.15 2002/05/13 13:50:45 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/5,7/9,7/25/1,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,3/6,3/17,3/21,3/22,3/26,4/7,5/6,5/12 Behrouz Minaei
   34: #
   35: ###
   36: 
   37: package Apache::lonstatistics; 
   38: 
   39: use strict; 
   40: use Apache::Constants qw(:common :http);
   41: use Apache::lonnet();
   42: use Apache::lonhomework;
   43: use Apache::loncommon;
   44: use HTML::TokeParser;
   45: use GDBM_File;
   46: 
   47: # -------------------------------------------------------------- Module Globals
   48: my %hash;
   49: my %CachData;
   50: my %GraphDat;
   51: my %OpResp;
   52: my %maps;
   53: my %mapsort;
   54: my %section;
   55: my %StuBox;
   56: my %DiscFac;
   57: my %DisUp;
   58: my %DisLow;
   59: my $UpCnt;
   60: my $CurMap;
   61: my $CurSec;
   62: my $CurStu;
   63: my @cols;
   64: my @list;
   65: my @students;
   66: my $p_count;
   67: my $Pos;
   68: my $r;
   69: my $OpSel1;
   70: my $OpSel2;
   71: my $OpSel3;
   72: my $OpSel4;
   73: my $GData;
   74: my $cid;
   75: my $firstres;
   76: my $lastres;
   77: my $DiscFlag;
   78: my $HWN;
   79: my $P_Order;
   80: my %foil_to_concept;
   81: my @Concepts;
   82: my %ConceptData;
   83: my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
   84:               4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
   85:               9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");
   86: my %Answer = ();
   87: my @shown;
   88: 
   89: sub InitAnalysis {
   90:     my ($rid, $student)=@_;
   91:     my ($uname,$udom)=split(/\:/,$student);
   92:     $rid=~/(\d+)\.(\d+)/;
   93:     my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
   94: 	     &Apache::lonnet::declutter($hash{'src_'.$rid});
   95:     my $URI = $hash{'src_'.$rid};
   96:     my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
   97:                                   'grade_username' => $uname,
   98:                                   'grade_domain' => $udom,
   99:                                   'grade_courseid' => $cid,
  100:                                   'grade_symb' => $symb));
  101: #    my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze'));
  102: 
  103:     (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
  104:     %Answer=();
  105:     %Answer=&Apache::lonnet::str2hash($Answ);
  106: 
  107:     my $parts='';
  108:     foreach my $elm (@{$Answer{"parts"}}) {
  109: 	$parts.="$elm,";
  110:     }
  111:     chop($parts);
  112:     my $conc='';
  113:     foreach my $elm (@{$Answer{"$parts.concepts"}}) {
  114: 	$conc.="$elm@";
  115:     }
  116:     chop($conc);
  117: 
  118:     @Concepts=split(/\@/,$conc);
  119:     my $show='';
  120:     foreach my $elm (@{$Answer{"$parts.shown"}}) {
  121: 	$show.="$elm@";
  122:     }
  123:     chop($show);
  124:     @shown=split(/\@/,$show);
  125: #    $r->print("<br> shown:".$show);
  126: #    $r->rflush();
  127: 
  128:     foreach my $concept (@{$Answer{"$parts.concepts"}}) {
  129: 	foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
  130: 	    $foil_to_concept{$foil} = $concept;
  131: 	}
  132:     }
  133:     return $symb;
  134: }
  135: 
  136: 
  137: sub Interval {
  138:     my $symb=shift;
  139:     my $Int=$ConceptData{"Interval"};
  140:     my $due = &Apache::lonnet::EXT('resource.0.duedate',$symb)+1;
  141:     my $opn = &Apache::lonnet::EXT('resource.0.opendate',$symb);
  142:     my $add=int(($due-$opn)/$Int);
  143: #    $r->print("<br> $opn, to $due add=$add  int=$Int");
  144:     #$r->rflush();
  145:     $ConceptData{"Int.0"}=$opn;
  146:     for (my $i=1;$i<$Int;$i++) {
  147: 	$ConceptData{"Int.$i"}=$opn+$i*$add;
  148:     }
  149:     $ConceptData{"Int.$Int"}=$due;     
  150:     for (my $i=0;$i<$Int;$i++) {
  151: 	for (my $n=0; $n<=$#Concepts; $n++ ) {
  152: 	    my $tmp=$Concepts[$n];
  153: 	    $ConceptData{"$tmp.$i.true"}=0;
  154: 	    $ConceptData{"$tmp.$i.false"}=0;
  155: 	}
  156:     }
  157: }
  158: 
  159: 
  160: sub ShowOpGraph {
  161: 
  162:     my ($InpStr, $Int_No)=@_;
  163: 
  164:     $r->print(<<ENDPOP);
  165:     <script language="JavaScript">
  166: 
  167:     function display(name) {
  168: 	document.forms.displayform.elements.dis.value=name;
  169: 	window.status=name;
  170:     }
  171:     function cleardisplay() {
  172: 	document.forms.displayform.elements.dis.value='';
  173: 	window.status='No Concept in particular';
  174:     }
  175: 
  176:     </script>
  177: ENDPOP
  178: 
  179:     &Create_PrgWin();
  180:     &Update_PrgWin("Starting to analyze problem");
  181:     my $rid=substr($InpStr,8);
  182:     $ConceptData{"Interval"}=$Int_No;
  183:     &Interval(&InitAnalysis($rid,$students[0]));
  184:     my $URI = $hash{'src_'.$rid};
  185:     my $Src = $hash{'title_'.$rid};
  186:     $Src =~ s/\ /"_"/eg;
  187:     $r->print('<br><b>'.$URI.'</b>');
  188:     for (my $n=1; $n<=$#Concepts+1; $n++ ) {
  189: 	my $tmp=$Concepts[$n-1];
  190: 	$tmp =~ s/</" less than "/eg;
  191: 	$r->print("<br><b>Concept $n</b>:$tmp");
  192:     }
  193:     
  194:     $r->rflush();
  195:     
  196:     for (my $index=0;$index<=$#students;$index++) {
  197: 	&Update_PrgWin($index);
  198: 	&OpStatus($rid,$students[$index]);
  199:     }
  200:     &Close_PrgWin();
  201: 
  202: #$Apache::lonxml::debug=1;
  203: #&Apache::lonhomework::showhash(%ConceptData);
  204: #$Apache::lonxml::debug=0;
  205: 
  206:     for (my $k=0; $k<$Int_No; $k++ ) {
  207:  	my $data1=''; 
  208: 	my $data2='';
  209: 	&DrawGraph(&AdjustData($k).'+'.$Src.'+'.($k+1));
  210:     }
  211:     my $Answ=&Apache::lonnet::ssi($URI);
  212:     $r->print("<br><b>Here you can see the Problem:</b><br>$Answ");
  213: }
  214: 
  215: sub AdjustData {
  216:     my $k=shift;
  217:     my $Max=0;
  218:     my @data1;
  219:     my @data2;
  220:     for (my $n=0; $n<=$#Concepts; $n++ ) {
  221: 	my $tmp=$Concepts[$n];
  222: 	$data1[$n]=$ConceptData{"$tmp.$k.true"};
  223: 	$data2[$n]=$ConceptData{"$tmp.$k.false"};
  224: 	my $Sum=$data1[$n]+$data2[$n];
  225: 	if ( $Max<$Sum ) {$Max=$Sum;}
  226:     }
  227:     for (my $n=0; $n<=$#Concepts; $n++ ) {
  228: 	if ($data1[$n]+$data2[$n]<$Max) {
  229: 	    $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
  230: 	}
  231:     }
  232:     return join(',',@data1).'+'.
  233:            join(',',@data2).'+'.
  234:            $Max.'+'.($#data1+1);
  235: }
  236: 
  237: 
  238: sub DrawGraph {
  239:     my $data=shift;
  240:     my($data1,$data2,$Max,$P_No,$Src,$k)=split(/\+/,$data);
  241: 
  242:     my $Str="\n".'<table border=1>'.
  243:             "\n".'<tr>'.
  244: 	    "\n".'<th> Correct Answers </th>'.
  245: 	    "\n".'<th> Wrong Answers </th>'.
  246: 	    "\n".'<th> From </th>'.
  247: 	    "\n".'<th> To </th>'.
  248: 	    "\n".'</tr>'.
  249: 	    "\n"."<tr>".
  250: 	    "\n"."<td> $data1 </td>".
  251:             "\n"."<td> $data2 </td>".
  252:             "\n"."<td> ".localtime($ConceptData{'Int.'.($k-1)})." </td>".
  253:             "\n"."<td> ".localtime($ConceptData{'Int.'.$k}-1)." </td>".
  254:             "\n"."</tr></table>";
  255:     $r->print($Str);
  256: 
  257: #    $r->print('<br><b>Correct Answers:</b> '.$data1.
  258: #              '<br><b>Wrong Answers: </b>'.$data2); 
  259: #    $r->print('<br><b>From: </b>'.localtime($ConceptData{'Int.'.($k-1)}).
  260: #              '<br><b>To: </b>'.localtime($ConceptData{"Int.$k"})); 
  261: 
  262: #   if ( $Max > 1 ) { 
  263: #	$Max += (10 - $Max % 10);
  264: #	$Max = int($Max);
  265: #   }
  266: #   else { $Max = 1; }
  267:     my $Titr=($ConceptData{'Interval'}>1) ? $Src.'_interval_'.$k : $Src;
  268:     $GData=$Titr.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
  269:     if($ConceptData{'Interval'}>1){
  270: 	$r->print('<br><IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
  271: 	return;
  272:     }
  273:     $r->print('<br>Move your mouse over a bar to find out the concept'); 
  274:     my $ptr='';
  275:     $ptr.="\n".'<form method="post" action="" name="displayform"> <input type=text name="dis" size=80> </form>';
  276:     $ptr.="\n".'<p><img src=/cgi-bin/graph.gif?'.$GData.
  277:           ' usemap="#Map" border=1>'.
  278:           "\n".'<map name="Map">';
  279:     my $gap=12;
  280:     my $Size=340;
  281:     my $barsize=($P_No) ? int($Size/$P_No) : 1;
  282:     for (my $i=0; $i<$P_No; $i++) {
  283: 	my $x1=80+$gap*$i+($i*$barsize);
  284: 	my $x2=$x1+$barsize;
  285: 	my $y1=25;
  286: 	my $y2=350;
  287: 	my $j=$i+1;
  288: 	$ptr.="\n".'<area shape="rect" coords='.$x1.','.$y1.','.$x2.','.$y2.' onMouseOver="display('."'Concept $j: $Concepts[$i]'".'); " href="javascript:alert('."'Concept $j: $Concepts[$i]'".');">';
  289:     } 
  290:     $ptr.="\n".'<area shape="default" onMouseOver="cleardisplay(); " href="javascript:alert('.'No Concept  in particular'.');">';
  291:     $ptr.="\n".'</map></p>';
  292:     $r->print('<br>'.$ptr.'<br>');
  293: }
  294: 
  295: 
  296: sub AnalyzeProblem {
  297: # -------------------------------- Selecting the number of intervals
  298:     my $OpSel='';
  299:     my $CurInt = $ENV{'form.interval'};
  300:     if ($CurInt eq '') {$CurMap = '1';}
  301:     my $Ptr = '<b>Select number of intervals</b>'."\n".
  302:        	      '<select name="interval">'."\n";                     	     	     
  303:     for (my $n=1;$n<=7;$n++) {	          
  304: 	$Ptr .= '<option';
  305:         if ($CurInt eq $n) {$Ptr .= ' selected';}     
  306: 	$Ptr .= '>'.$n."</option>"."\n";	     
  307:     }
  308:     $Ptr .= '</select>'."\n";
  309:     $r->print( $Ptr );
  310: 
  311:     $r->print('<br><b> Option Response Problems in this course:</b><br><br>');
  312:     my $Str = "\n".'<table border=2>'.
  313:               "\n".'<tr>'.
  314:               "\n".'<th> # </th>'.
  315: 	      "\n".'<th> Problem Title </th>'.
  316: 	      "\n".'<th> Resouse </th>'.
  317: 	      "\n".'<th> Address </th>'.
  318: 	      "\n".'</tr>';
  319: 
  320:      my $P_No=1;
  321:      foreach (sort keys %OpResp) {
  322: 	 my $Temp = '<a href="'.$hash{'src_'.$OpResp{$_}}.
  323:                     '" target="_blank">'.$hash{'title_'.$OpResp{$_}}.'</a>';
  324: 	 $Str .= "\n"."<tr>".
  325: 	         "\n"."<td> $P_No </td>".
  326:                  "\n"."<td bgcolor=#DDFFDD> ".$Temp." </td>".
  327:                  "\n"."<td bgcolor=#EEFFCC> ".$hash{'src_'.$OpResp{$_}}." </td>".
  328: 	         "\n"."<td> ".'<input type="submit" name="sort" value="'.'Analyze_'.$OpResp{$_}.'" />'.'</td>'.
  329:                  "\n"."</tr>";
  330: 	 $P_No++;
  331:      }
  332:      $Str .= "\n".'</table>';
  333:      $Str .= "\n".'</form>';
  334:      $r->print($Str);
  335:      $r->rflush();	
  336: }
  337: 
  338: 
  339: sub Decide {
  340:     my ($type,$foil,$time)=@_; 
  341:     my $k=0;
  342:     while ($time>$ConceptData{'Int.'.($k+1)} && 
  343:            $k<$ConceptData{'Interval'}) {$k++;}
  344:     $ConceptData{"$foil_to_concept{$foil}.$k.$type"}++;
  345: }
  346: 
  347: 
  348: sub OpStatus {
  349:     my ($rid,$student)=@_;
  350:     my ($uname,$udom)=split(/\:/,$student);
  351:     my $code='U';
  352:     $rid=~/(\d+)\.(\d+)/;
  353:     my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
  354: 	     &Apache::lonnet::declutter($hash{'src_'.$rid});
  355:     my %reshash=&Apache::lonnet::restore($symb,$cid,$udom,$uname);
  356:     my @True = ();
  357:     my @False = ();
  358:     my $flag=0;
  359:     @shown=();
  360:     if ($reshash{'version'}) {
  361: 	for (my $version=1;$version<=$reshash{'version'};$version++) {
  362: 	    my $time=$reshash{"$version:timestamp"};
  363: 	    foreach (sort(split(/\:/,$reshash{$version.':keys'}))) {
  364: 		if (($_=~/\.(\w+)\.(\w+)\.submission$/)) {
  365: 		    my $Id1 = $1;
  366: 		    my $Id2 = $2;
  367: 		    my $Resp = $reshash{$_};
  368: 		    my %submission=&Apache::lonnet::str2hash($Resp);
  369: 		    foreach (keys %submission) {
  370: 			my $Ansr = $Answer{"$Id1.$Id2.foil.value.$_"};
  371: 			#$r->print("<br>shown: ".join(',',@shown)." size=$#shown");     
  372: 			if ($submission{$_}) {
  373: 			    #if($#shown==-1){
  374: 				#my @str=split(/\&/,$Resp);
  375: 				#my $garb;
  376: 				#for(my $j=0;$j<=$#str;$j++){
  377: 				#    ($shown[$j],$garb)=split(/\=/,$str[$j]);
  378: 				#}
  379: 				##$r->print("<br>shown: ".join(',',@shown)." size=$#shown");     
  380: 			    #}
  381: 			    if ($submission{$_} eq $Ansr) {
  382: 				&Decide("true",$_,$time );
  383: 			    }
  384: 			    else {&Decide("false",$_,$time );}
  385: 			}
  386: 			#else {
  387: 			#    if ($#shown==-1 && $flag==0) {
  388: 			#	$flag++;
  389: 			#	&InitAnalysis($rid,$student);
  390: 			#    }
  391: 			#    my @erl=split(/\:/,$_);
  392: 			#    for (my $i=0;$i<=$#shown; $i++){
  393: 			#	my $Ans=$Answer{"$Id1.$Id2.foil.value.$shown[$i]"};
  394: 			#	if ($erl[$i] eq $Ans) {
  395: 			#	    &Decide("true",$shown[$i],$time);
  396: 			#	}
  397: 			#	else {&Decide("false",$shown[$i],$time);}
  398: 			#    }
  399: 			#}
  400: 		    }
  401: 	        }	  
  402: 	    }
  403:         }
  404:     }
  405: }
  406: 
  407: 
  408: #------- Processing upperlist and lowerlist according to each problem
  409: sub ProcessDisc {
  410:     my @List = @_;
  411:     @List = sort (@List);
  412:     my $Count = $#List+1;
  413:     my $Prb;
  414:     my @Dis;
  415:     my $Slvd=0;
  416:     my $tmp;
  417:     my $Sum1=0;
  418:     my $Sum2=0;
  419:     my $nIdx=0;
  420:     my $nStud=0;
  421:     my %Proc;
  422:     undef %Proc;
  423:     while ($nIdx<$Count) {
  424: 	($Prb,$tmp)=split(/\=/,$List[$nIdx]);
  425: 	@Dis=split(/\+/,$tmp);
  426: 	my $Temp = $Prb;
  427: 	do {
  428: 	    $nIdx++;
  429: 	    $nStud++;
  430: 	    $Sum1 += $Dis[0];
  431: 	    $Sum2 += $Dis[1];
  432: 	    ($Prb,$tmp)=split(/\=/,$List[$nIdx]);
  433: 	    @Dis=split(/\+/,$tmp);
  434: 	} while ( $Prb eq $Temp && $nIdx < $Count );
  435: #	$Proc{$Temp}=($Sum1/$nStud).':'.$nStud;
  436: 	$Proc{$Temp}=($Sum1/$nStud).':'.($Sum2/$nStud);
  437: #       $r->print("$nIdx) $Temp --> ($nStud) $Proc{$Temp} <br>");
  438: 	$Sum1=0;
  439: 	$Sum2=0;
  440: 	$nStud=0;
  441:     }
  442:     return %Proc;
  443: }
  444: 
  445: 
  446: #------- Creating Discimination factor   
  447: sub Discriminant {
  448:     my $Count=0;
  449:     foreach (keys(%DiscFac)){ 
  450: 	$Count++;
  451:     }
  452:     $UpCnt = int(0.27*$Count);
  453:     my $low=0;
  454:     my $up=$Count-$UpCnt;
  455:     my @UpList=();
  456:     my @LowList=();
  457:     $Count=0;
  458:     foreach my $key (sort(keys(%DiscFac))){ 
  459: 	$Count++;    
  460:         #$r->print("<br>$Count) $key = $DiscFac{$key}");
  461: 	if ($low < $UpCnt || $Count > $up) {
  462: 	    $low++;
  463: 	    my $str=$DiscFac{$key};
  464: 	    foreach(split(/\:/,$str)){
  465: 		if ($_) {
  466: 		    if ($low<$UpCnt){push(@LowList,$_);}
  467: 		    else {push(@UpList,$_);}
  468: 		}
  469: 	    }
  470: 	}
  471:     }
  472:     %DisUp=&ProcessDisc(@UpList);
  473:     %DisLow=&ProcessDisc(@LowList);
  474: }
  475: 
  476:    
  477: sub NumericSort {          
  478:     $a <=> $b;
  479: }
  480: 
  481: # ------ Create different Student Report 
  482: sub StudentReport {
  483:     my ($sname,$sdom)=@_;
  484:     if ( $sname eq 'All Students' ) {
  485: 	$r->print( '<h3><font color=blue>WARNING: 
  486:                     Please select a student</font></h3>' );
  487: 	return;
  488:     }
  489:     my %result = &Apache::lonnet::dump($cid,$sdom,$sname);
  490:     my $ResId;
  491:     my $PrOrd;
  492:     my $Code;
  493:     my $Tries;
  494:     my $TotalTries = 0;
  495:     my $ParCr = 0;
  496:     my $Wrongs;
  497:     my %TempHash;
  498:     my $Version;
  499:     my $LatestVersion;
  500:     my $PtrTry='';
  501:     my $PtrCod='';
  502:     my $SetNo=0;
  503:     my $Str = "\n".'<table border=2>'.
  504:               "\n".'<tr>'.
  505:               "\n".'<th> # </th>'.
  506: 	      "\n".'<th> Set Title </th>'.
  507: 	      "\n".'<th> Results </th>'.
  508: 	      "\n".'<th> Tries </th>'.
  509: 	      "\n".'</tr>';
  510:     my ($temp)=keys(%result);
  511:     unless ($temp=~/^error\:/) {
  512:         foreach my $CurCol (@cols) {
  513: 	    if (!$CurCol){
  514: 		my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1});
  515: 		if ( $Set ) {
  516: 		    $SetNo++;
  517: 		    $Str .= "\n"."<tr>".
  518: 			    "\n"."<td> $SetNo </td>".
  519:                             "\n"."<td> $Set </td>".
  520:                             "\n"."<td> $PtrCod </td>".
  521:                             "\n"."<td> $PtrTry</td>".
  522:                             "\n"."</tr>";
  523: 		}
  524: 		$PtrTry='';
  525: 		$PtrCod='';
  526: 		next; 
  527: 	    }
  528: 	    ($PrOrd,$ResId)=split(/\:/,$CurCol);
  529:             $ResId=~/(\d+)\.(\d+)/;
  530:             my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
  531:             if ( $CurMap ne 'All Maps' ) {
  532: 		my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
  533: 		if ( $Map ne $ResMap ) { next; }
  534: 	    }
  535: 	    my $meta=$hash{'src_'.$ResId};
  536: 	    my $PartNo = 0;
  537: 	    undef %TempHash;
  538: 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))){
  539: 		if ($_=~/^stores\_(\w+)\_tries$/) {
  540:                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
  541: 		    if ( $TempHash{"$Part"} eq '' ) { 
  542: 			$TempHash{"$Part"} = $Part;
  543: 			$TempHash{$PartNo}=$Part;
  544: 			$TempHash{"$Part.Code"} = '-';  
  545: 			$TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;  
  546: 			$PartNo++;
  547: 		    }
  548: 		}
  549:             }
  550: 
  551:             my $Prob = $Map.'___'.$2.'___'.
  552:                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
  553:             $Code='U';
  554:             $Tries = 0;
  555:             $Wrongs = 0;
  556:   	    $LatestVersion = $result{"version:$Prob"};
  557: 	    if ( $LatestVersion ) {
  558: 		for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
  559: 		    my $vkeys = $result{"$Version:keys:$Prob"};
  560: 		    my @keys = split(/\:/,$vkeys);		
  561:   
  562: 		    foreach my $Key (@keys) {		  
  563: 			if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
  564: 			    my $Part = $1;
  565: 			    $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
  566: 			    $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0; 
  567: 			    $TotalTries += $Tries;
  568: 			    my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
  569: 			    if ( $Val eq 'correct_by_student' )
  570:                                 { $Wrongs = $Tries - 1; $Code = 'Y'; } 
  571: 			    elsif ( $Val eq 'correct_by_override' )
  572:                                 { $Wrongs = $Tries - 1; $Code = 'y'; }                        
  573: 			    elsif ( $Val eq 'incorrect_attempted' || 
  574:                                 $Val eq 'incorrect_by_override' )
  575: 		                { $Wrongs = $Tries; $Code = 'N'; }
  576: 			    $TempHash{"$Part.Code"} = $Code;
  577: 			    $TempHash{"$Part.Wrongs"} = $Wrongs;
  578: 			}
  579:      		    }
  580:                 }
  581: 		for ( my $n = 0; $n < $PartNo; $n++ ) {		  
  582: 		    my $part = $TempHash{$n};
  583: 		    if ($PtrTry ne '') {$PtrTry .= ',';}
  584: 		    $PtrTry .= "$TempHash{$part.'.Tries'}";
  585:                     $PtrCod .= "$TempHash{$part.'.Code'}";    
  586: 		}
  587:             }
  588: 	    else { 
  589: 		for(my $n=0; $n<$PartNo; $n++) { 
  590: 		    if ($PtrTry ne '') {$PtrTry .= ',';}
  591: 		    $PtrTry .= "0";
  592:                     $PtrCod .= "-"; 
  593: 		}
  594: 	    }
  595:         }
  596:     }
  597:     $Str .= "\n".'</table>';
  598:     $r->print($Str);
  599:     $r->rflush();
  600: }
  601: 
  602: sub CreateTable {
  603:     my $ColNo=0;
  604:     foreach (keys(%Header)){ 
  605: 	$ColNo++;
  606:     } 
  607:     my ($Hd, $Hid)=@_;
  608:     if ( $Hd == 1 ) {
  609: 	$r->print('<br><a href="'.$hash{'src_'.$Hid}.
  610:                   '" target="_blank">'.$hash{'title_'.$Hid}.'</a>');
  611:     }
  612:     my $Result = "\n".'<table border=2>';
  613:     $Result .= '<tr><th>P#</th>'."\n";
  614:     for ( my $nIdx=0; $nIdx < $ColNo; $nIdx++ ) { 
  615: 	$Result .= '<th>'.'<input type="submit" name="sort" value="'.
  616:                    $Header{$nIdx}.'" />'.'</th>'."\n";
  617:     }
  618:     $Result .= "\n".'</tr>'."\n";    
  619:     $r->print( $Result );
  620:     $r->rflush();
  621: }
  622: 
  623: sub CloseTable {
  624:     $r->print("\n".'</table>'."\n");
  625:     $r->rflush();
  626: }
  627:  
  628: # ------------------------------------------- Prepare Statistics Table
  629: sub PreStatTable {
  630:     my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  631:                   "_$ENV{'user.domain'}_$cid\_statistics.db";
  632:     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  633:                   "_$ENV{'user.domain'}_$cid\_graph.db";
  634:     my $OpSel11='';
  635:     my $OpSel12='';
  636:     my $OpSel13='';
  637:     my $Status = $ENV{'form.status'};
  638:     if ( $Status eq 'Any' ) { $OpSel13='selected'; }
  639:     elsif ($Status eq 'Expired' ) { $OpSel12 = 'selected'; }
  640:     else { $OpSel11 = 'selected'; }
  641: 
  642:     my $Ptr = '';
  643:     $Ptr .= '<br><b> Student Status: &nbsp; </b>'."\n".
  644:             '<select name="status">'. 
  645:             '<option '.$OpSel11.' >Active</option>'."\n".
  646:             '<option '.$OpSel12.' >Expired</option>'."\n".
  647: 	    '<option '.$OpSel13.' >Any</option> </select> '."\n";
  648:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  649:     $Ptr .= '<input type=submit name=sort value="Recalculate Statistics"/>'."\n";
  650: 
  651:     $Ptr .= '<br><b> Sorting Type: &nbsp; </b>'."\n".
  652:             '<select name="order"> <option '.$OpSel1.' >Ascending</option>'."\n".
  653: 	    '<option '.$OpSel2.'>Descending</option> </select> '."\n";
  654:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  655:     $Ptr .= '<input type="submit" name="sort" value="DoDiff Graph" />'."\n";
  656:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  657:     $Ptr .= '<input type="submit" name="sort" value="%Wrong Graph" />'."\n";
  658: 
  659:     $Ptr .= '<pre>'.
  660:     '<b>  #Stdnts</b>: Total Number of Students opened the problem.<br>'. 
  661:     '<b>  Tries  </b>: Total Number of Tries for solving the problem.<br>'. 
  662:     '<b>  Mod   </b> : Maximunm Number of Tries for solving the problem.<br>'. 
  663:     '<b>  Mean   </b>: Average Number of the tries. [ Tries / #Stdnts ]<br>'.
  664:     '<b>  #YES   </b>: Number of students solved the problem correctly.<br>'. 
  665:     '<b>  #yes   </b>: Number of students solved the problem by override.<br>'.
  666:     '<b>  %Wrng  </b>: Percentage of students tried to solve the problem but'.
  667:     ' still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]<br>'.
  668: #    '  DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ]<br>'. Kashy formula
  669:     '<b>  DoDiff </b>: Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ]<br>'. #Gerd formula
  670:     '<b>  S.D.  </b> : Standard Deviation of the tries.'.
  671:     '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'.
  672:     ' where Xi denotes every student\'s tries ]<br>'.
  673:     '<b>  Skew.  </b>: Skewness of the students tries.'.
  674: 	' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ]<br>'.
  675:     '<b>  Dis.F. </b>: Discrimination Factor: A Standard for '.
  676: 	'evaluating the problem according to a Criterion<br>'.
  677: 	'<b>           [Applied Criterion in %27 Upper Students - '.
  678: 	'Applied the same Criterion in %27 Lower Students]</b><br>'.
  679:     '<b>           1st Criterion</b> for Sorting the Students: '.
  680: 	'<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>'.
  681:     '<b>           2nd Criterion</b> for Sorting the Students: '.
  682: 	'<b>Total number of Correct Answers / Total Number of Tries</b>'.	
  683:             '</pre>';
  684: 
  685:     $r->print($Ptr);
  686:     $r->rflush();	
  687: 
  688:     if ((-e "$CacheDB")&&($ENV{'form.sort'} ne 'Recalculate Statistics')) {
  689: 	if (tie(%CachData,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
  690: 	    tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
  691: 	    &Cache_Statistics();
  692:         }
  693:         else {
  694: 	    $r->print("Unable to tie hash to db file");
  695:         }
  696:     }
  697:     else {
  698: 	if (tie(%CachData,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
  699: 	    tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
  700: 	    foreach (keys %DiscFac) {delete $CachData{$_};}
  701: 	    foreach (keys %CachData) {delete $CachData{$_};}
  702: 	    $DiscFlag=0;
  703: 	    &Build_Statistics();
  704: 	}
  705:         else {
  706: 	    $r->print("Unable to tie hash to db file");
  707:         }
  708:     }
  709: 
  710: #    $r->print('Total instances of the problems : '.($p_count*($#students+1)));
  711:     untie(%CachData);
  712:     untie(%GraphDat);
  713: }
  714: 
  715: 
  716: # ------------------------------------- Find the section of student in a course
  717: 
  718: sub usection {
  719:     my ($udom,$unam,$courseid,$ActiveFlag)=@_;
  720:     $courseid=~s/\_/\//g;
  721:     $courseid=~s/^(\w)/\/$1/;
  722:     foreach (split(/\&/,&Apache::lonnet::reply('dump:'.
  723:              $udom.':'.$unam.':roles',
  724:              &Apache::lonnet::homeserver($unam,$udom)))){
  725:         my ($key,$value)=split(/\=/,$_);
  726:         $key=&Apache::lonnet::unescape($key);
  727:         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
  728:             my $section=$1;
  729:             if ($key eq $courseid.'_st') { $section=''; }
  730: 	    my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));
  731: 	    if ( $ActiveFlag ne 'Any' ) {
  732: 		my $now=time;
  733: 		my $notactive=0;
  734: 		if ($start) {
  735: 		    if ($now<$start) { $notactive=1; }
  736: 		}
  737: 		if ($end) {
  738: 		    if ($now>$end) { $notactive=1; }
  739: 		}
  740: 		if ((($ActiveFlag eq 'Expired') && $notactive == 1) || 
  741:                     (($ActiveFlag eq 'Active') && $notactive == 0 ) ) {
  742: 		    return $section;
  743: 		}
  744: 		else { return '-1'; } 
  745: 	    }
  746: 	    return $section;
  747:         }
  748:     }
  749:     return '-1';
  750: }
  751: 
  752: 
  753: # ------ Dump the Student's DB file and handling the data for statistics table 
  754: sub ExtractStudentData {
  755:     my $student=shift;
  756:     my ($sname,$sdom) = split( /\:/, $student );
  757:     my %result = &Apache::lonnet::dump($cid,$sdom,$sname);
  758:     my $ResId;
  759:     my $PrOrd;
  760:     my $Dis = '';
  761:     my $Code;
  762:     my $Tries;
  763:     my $ParCr;
  764:     my $TotalTries = 0;
  765:     my $TotalOpend = 0;
  766:     my $ProbSolved = 0;
  767:     my $ProbTot = 0;
  768:     my $TimeTot = 0;
  769:     my $TotParCr = 0;
  770:     my $Wrongs;
  771:     my %TempHash;
  772:     my $Version; 
  773:     my $LatestVersion;
  774:     my $SecLimit;
  775:     my $MapLimit;
  776:     my ($temp)=keys(%result);
  777:     unless ($temp=~/^error\:/) {
  778:         foreach my $CurCol(@cols) {
  779: 	    ($PrOrd,$ResId)=split(/\:/,$CurCol);
  780: 	    if ( !$CurCol ) { next; }
  781:             $ResId=~/(\d+)\.(\d+)/;
  782: 	    my $MapId=$1;
  783: 	    my $PrbId=$2;
  784:             my $MapOrg = $hash{'map_id_'.$MapId};
  785:             my $Map = &Apache::lonnet::declutter($MapOrg);
  786:             if ( $CurMap ne 'All Maps' ) {
  787: 		my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
  788: 		if ( $Map ne $ResMap ) { next; }
  789: 	    }
  790: 	    my $meta=$hash{'src_'.$ResId};
  791: 	    my $PartNo = 0;
  792: 	    $Dis .= ':';
  793: 	    undef %TempHash;
  794: 
  795: 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) { 
  796: 		if ($_=~/^stores\_(\w+)\_tries$/) {
  797:                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
  798: 		    if ( $TempHash{"$Part"} eq '' ) { 
  799: 			$TempHash{"$Part"} = $Part;
  800: 			$TempHash{$PartNo}=$Part;
  801: 			$TempHash{"$Part.Code"} = 'U';  
  802: 			$TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
  803: 			$PartNo++;
  804: 		    }
  805:                     #my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
  806: 		}
  807:             }
  808:             &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
  809: 	    my $URI = $hash{'src_'.$ResId};
  810:             my $Prob = $Map.'___'.$PrbId.'___'.
  811:                        &Apache::lonnet::declutter($URI);
  812:             $Code='U';
  813:             $Tries = 0;
  814: 	    $ParCr = 0;
  815:             $Wrongs = 0;
  816:   	    $LatestVersion = $result{"version:$Prob"};        
  817: 	    if ( $LatestVersion ) {
  818: 		for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
  819: 		    my $vkeys = $result{"$Version:keys:$Prob"};
  820: 		    my @keys = split(/\:/,$vkeys);		
  821: 		    foreach my $Key (@keys) {		  
  822: 			if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
  823: 			    my $Part = $1;
  824: 			    $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
  825: 			    $ParCr = $result{"$Version:$Prob:resource.$Part.awarded"};
  826: 			    my $Time = $result{"$Version:$Prob:timestamp"};
  827: 			    $TempHash{"$Part.Time"} = ($Time) ? $Time : 0;
  828: 			    $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
  829: 			    $TempHash{"$Part.ParCr"} = ($ParCr) ? $ParCr : 0;        
  830: 			    $TotalTries += $TempHash{"$Part.Tries"};
  831: 			    $TotParCr += $TempHash{"$Part.ParCr"};
  832: 			    my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
  833: 			    if ( $Val eq 'correct_by_student' )
  834:                                { $Wrongs = $Tries - 1; $Code = 'C'; } 
  835: 			    elsif ( $Val eq 'correct_by_override' )
  836:                                { $Wrongs = $Tries - 1; $Code = 'O'; }                        
  837: 			    elsif ( $Val eq 'incorrect_attempted' || 
  838:                                 $Val eq 'incorrect_by_override' )
  839: 		               { $Wrongs = $Tries; $Code = 'I'; }
  840: 			    $TempHash{"$Part.Code"} = $Code;
  841: 			    $TempHash{"$Part.Wrongs"} = $Wrongs;
  842: 			}
  843:      		    }
  844:                 } 
  845: 		for ( my $n = 0; $n < $PartNo; $n++ ) {		  
  846: 		    my $part = $TempHash{$n};
  847: 		    my $Yes = 0;
  848:                     if ( $TempHash{$part.'.Code'} eq 'C' ||
  849:                          $TempHash{$part.'.Code'} eq 'O'  ) 
  850: 		       {$ProbSolved++;$Yes=1;}		
  851: 
  852:  #		    my $ptr = "$hash{'title_'.$ResId}";
  853: 		    my $ptr = $TempHash{$part.'.PrOrd'}.'&'.$ResId;
  854: 
  855: 		    if ( $PartNo > 1 ) {                
  856: 			$ptr .= "*(part $part)";
  857: 			$Dis .= '&';
  858: 		    }
  859: 		    my $Fac = ($TempHash{"$part.Tries"}) ? 
  860:                               ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
  861: 		    my $DisF;
  862: 		    if ( $Fac > 0 &&  $Fac < 1 ) { 
  863: 			$DisF = sprintf( "%.4f", $Fac );
  864: 		    }
  865: 		    else {$DisF = $Fac;}
  866: #		    $DisF .= '+'.$TempHash{"$part.Time"};33333333
  867: 		    $TimeTot += $TempHash{"$part.Time"};
  868: 		    $Dis .= $TempHash{$part.'.PrOrd'}.'='.$DisF.'+'.$Yes;
  869: 		    $ptr .= "&$TempHash{$part.'.Tries'}".
  870: 		            "&$TempHash{$part.'.Wrongs'}".
  871:                             "&$TempHash{$part.'.Code'}";
  872: 		    push (@list, $ptr);
  873: 		    $TotalOpend++;
  874: 		    $ProbTot++;
  875: 		}
  876:             }
  877: 	    #else { 
  878: 		#for(my $n=0; $n<$PartNo; $n++) {
  879: 		#    push (@list, "$TempHash{'0'.'.PrOrd'}.':'.$ResId:0:0:U");
  880: 		#    $ProbTot++; 
  881: 		#}
  882: 	    #}
  883:         }
  884: 	if ( $TotalTries ) {
  885: 	    my $DisFac = ( $TotalTries ) ? ($TotParCr/$TotalTries) : 0;
  886: 	    my $DisFactor = sprintf( "%.4f", $DisFac );
  887: 	    $DiscFac{$DisFactor}=$Dis;
  888: 	    #my $time;
  889: 	    #if ($ProbSolved){
  890: 		#$time = int(($TimeTot/$ProbSolved)-10000000);
  891: 	    #}
  892: 	    #$DiscFac{($DisFactor.':'.$sname.':'.$ProbTot.':'.$TotalOpend.':'.
  893:             #          $TotalTries.':'.$ProbSolved.':'.$time)}=$Dis;
  894: 	}
  895:     }
  896:     #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.'<br>');
  897: }
  898: 
  899: 
  900: # ------------------------------------------------------------ Build page table
  901: sub tracetable {
  902:     my ($rid,$beenhere)=@_;
  903:     my $IsMap=0;
  904:     $rid=~/(\d+)\.(\d+)/;
  905:     $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid}; 
  906:     #$maps{$HWN}=$hash{'title_'.$rid}; 
  907:     unless ($beenhere=~/\&$rid\&/) {
  908:        $beenhere.=$rid.'&'; 
  909:        if (defined($hash{'is_map_'.$rid})) {
  910: 	   my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
  911:            if ( $cmap eq 'sequence' || $cmap eq 'page' ) { 
  912:                $cols[$#cols+1]=0;
  913: 	       $P_Order++;
  914: 	       $HWN=$P_Order;
  915:                $mapsort{$HWN} = $rid.':';
  916: 	       $IsMap=1;
  917:  
  918:                #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}= 
  919:                #      $hash{'title_'.$rid}; 
  920:            }
  921:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
  922:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
  923: 	       my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
  924: 
  925:                &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
  926: 			   '&'.$frid.'&');
  927: 
  928: 	       $cols[$#cols+1]=($P_Order+1).':'.$frid;
  929:       
  930: 	       my $meta=$hash{'src_'.$frid};
  931: 	       my $PartNo = 0;
  932: 	       my $Part;
  933: 	#       if ($IsMap==0){
  934:                if ($meta) {
  935: 		   if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  936: 		       foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
  937: 			   if ($_=~/^stores\_(\w+)\_tries$/) {
  938: 			       $Part=&Apache::lonnet::metadata($meta,$_.'.part');
  939: 			       $P_Order++;
  940: 			       $mapsort{$HWN} .= '&'.$P_Order;
  941: 			       $PartNo++;
  942: 			       #$r->print('<br>'.$PartNo.'---'.$P_Order);
  943: 			   }
  944: 			   foreach my $K(split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
  945: 			       if ($K=~/^optionresponse\_($Part)\_(\w+)$/) {
  946: 				   #$r->print('<br>'.$_.'...'.$P_Order.'---'.$Part);
  947: 				   $OpResp{$P_Order}=$frid;
  948: 			       } 
  949: 		   
  950: 			   }
  951: 		       }
  952: 		   }
  953:                }
  954: 	   }
  955: 	 #  }
  956:        } else {
  957: 	   $cols[$#cols+1]=($P_Order+1).':'.$rid;
  958: 	   my $meta=$hash{'src_'.$rid};
  959: 	   my $PartNo = 0;
  960: 	   if ($meta) {
  961: 	       if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  962: 		   foreach my $Key(split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
  963: 		       if ($Key=~/^stores\_(\w+)\_tries$/) {
  964: 			   my $Part=&Apache::lonnet::metadata($meta,$Key.'.part');
  965: 			   $P_Order++;
  966: 			   $mapsort{$HWN} .= '&'.$P_Order;
  967: 			   $PartNo++;
  968: 			   foreach (split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
  969: 			       if ($_=~/^optionresponse\_($Part)\_(\w+)$/) {
  970: 				   #$r->print('<br>'.$_.'...'.$P_Order.'---'.$Part);
  971: 				   $OpResp{$P_Order}=$rid;
  972: 			       } 
  973: 		   
  974: 			   }
  975: 
  976: 		       }
  977: 		   }
  978: 	       }
  979: 	   }       
  980:        }
  981:        if (defined($hash{'to_'.$rid})) {
  982:           foreach (split(/\,/,$hash{'to_'.$rid})){
  983:               &tracetable($hash{'goesto_'.$_},$beenhere);
  984:           }
  985:        }
  986:     }
  987: }
  988: 
  989: sub MySort {          
  990:     if ( $Pos > 0 ) {
  991: 	if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
  992: 	else { $a <=> $b; }
  993:     }
  994:     else {
  995: 	if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
  996: 	else { $a cmp $b; }
  997:     }
  998: }
  999: 
 1000: sub Create_PrgWin {
 1001: #----------- Create progress
 1002:     $r->print(<<ENDPOP);
 1003:     <script>
 1004:     popwin=open('','popwin','width=400,height=100');
 1005:     popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
 1006:       '<title>LON-CAPA Statistics</title>'+
 1007:       '<h4>Computation Progress</h4>'+
 1008:       '<form name=popremain>'+
 1009:       '<input type=text size=35 name=remaining value=Starting></form>'+
 1010:       '</body></html>');
 1011:     popwin.document.close();
 1012:     </script>
 1013: ENDPOP
 1014: 
 1015:     $r->rflush();
 1016: }
 1017: 
 1018: 
 1019: sub Update_PrgWin {
 1020: #----------- update progress
 1021:     my $index = shift;
 1022:     $r->print('<script>popwin.document.popremain.remaining.value="'.
 1023:               'Computing '.($index+1).'/'.($#students+1).': '.
 1024:               $students[$index].'";</script>');
 1025:     $r->rflush();
 1026: }
 1027: 
 1028: sub Close_PrgWin {
 1029: #--------------------- close Progress Line
 1030:     $r->print('<script>popwin.close()</script>');
 1031:     $r->rflush(); 
 1032: }
 1033: 
 1034: sub Build_Statistics {
 1035:     &Create_PrgWin();
 1036: # ---------------------------- Gathering the Data of students' tries
 1037:     for (my $index=0;$index<=$#students;$index++) {
 1038: 	&Update_PrgWin($index);
 1039:         &ExtractStudentData($students[$index]);
 1040:     }
 1041: 
 1042: # -------------------- sorting the Data
 1043:     $r->print('<script>popwin.document.popremain.remaining.value="'.
 1044:               'Calculating Discrimination Factors...";</script>');
 1045: 
 1046:     @list = sort (@list);
 1047: 
 1048: 
 1049:     &Discriminant();
 1050: 
 1051:     $OpSel2='';
 1052:     $OpSel1='selected';
 1053:  		   
 1054:     $p_count = 0; 
 1055:     my $nIdx = 0;
 1056:     my $dummy; 
 1057:     my $p_val;
 1058:     my $ResId;
 1059:     my $NoElements = $#list + 1;
 1060: #-------------------------------- loop for data representation
 1061:     foreach (sort keys %mapsort) {
 1062: 	my ($Hid,$pr)=split(/\:/,$mapsort{$_});
 1063: 	my @lpr=split(/\&/,$pr);
 1064: 	&CreateTable(1,$Hid);
 1065: 	for (my $i=1; $i<=$#lpr; $i++) {
 1066: 	    my %storestats=();
 1067: 	    my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
 1068: 	    my $Temp = $Prob;
 1069: 	    my $MxTries = 0;
 1070: 	    my $TotalTries = 0;
 1071: 	    my $YES = 0;
 1072: 	    my $Incorrect = 0;
 1073: 	    my $Override = 0;
 1074: 	    my $StdNo = 0;
 1075: 	    my @StdLst;
 1076: 	    while ( $PrOrd == $lpr[$i] ) 
 1077: 	    {
 1078: 		$nIdx++;
 1079: 		$StdNo++;
 1080: 		$StdLst[ $StdNo ] = $Tries;
 1081: 		$TotalTries += $Tries;
 1082: 		if ( $MxTries < $Tries ) { $MxTries = $Tries; } 
 1083: 		if ( $Code eq 'C' ){ $YES++; }
 1084: 		elsif( $Code eq 'I' ) { $Incorrect++; }
 1085: 		elsif( $Code eq 'O' ) { $Override++; }
 1086: 		elsif( $Code eq 'U' ) { $StdNo--; }
 1087: 		($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list[$nIdx]);
 1088: 	    }	
 1089: 
 1090: 	    $p_count++;
 1091: 	    my $Dummy;
 1092: 	    ($ResId,$Dummy)=split(/\*/,$Temp);
 1093: 
 1094: 	    $Temp = '<a href="'.$hash{'src_'.$ResId}.
 1095:                 '" target="_blank">'.$hash{'title_'.$ResId}.$Dummy.'</a>';
 1096: 
 1097: 	    my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});
 1098: 	    my $urlres=$res;
 1099: 
 1100: 	    $ResId=~/(\d+)\.(\d+)/;
 1101: 	    my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
 1102: 	    $urlres=$Map;
 1103:  
 1104: 	    $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';
 1105: 	    #$Map = '<a href="'.$Map.'">'.$res.'</a>';
 1106: 
 1107: #------------------------ Compute the Average of Tries about one problem
 1108: 	    my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;
 1109: 
 1110: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;       
 1111: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;
 1112: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;
 1113:    
 1114: #-------------------------------- Compute percentage of Wrong tries
 1115: 	    my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;
 1116: 
 1117: #-------------------------------- Compute Standard Deviation
 1118: 	    my $StdDev = 0; 
 1119: 	    if ( $StdNo > 1 ) {
 1120: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
 1121: 		    my $Dif = $StdLst[ $n ]-$Average;
 1122: 		    $StdDev += $Dif*$Dif;
 1123: 		} 
 1124: 		$StdDev /= ( $StdNo - 1 );
 1125: 		$StdDev = sqrt( $StdDev );
 1126: 	    }
 1127: 
 1128: #-------------------------------- Compute Degree of Difficulty
 1129: 	    my $DoDiff = 0;
 1130: 	    if( $TotalTries > 0 ) {
 1131: 		$DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );
 1132: #	    $DoDiff =  ($TotalTries)/($YES + $Override+ 0.1);	    
 1133: 	    }
 1134:        
 1135: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;
 1136: 
 1137: #-------------------------------- Compute the Skewness
 1138: 	    my $Skewness = 0;
 1139: 	    my $Sum = 0; 
 1140: 	    if ( $StdNo > 0 && $StdDev > 0 ) {
 1141: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
 1142: 		    my $Dif = $StdLst[ $n ]-$Average;
 1143: 		    $Skewness += $Dif*$Dif*$Dif;
 1144: 		} 
 1145: 		$Skewness /= $StdNo;
 1146: 		$Skewness /= $StdDev*$StdDev*$StdDev;
 1147: 	    }
 1148: 
 1149: #--------------------- Compute the Discrimination Factors
 1150: 	    my ($Up1,$Up2)=split(/\:/,$DisUp{$lpr[$i]});
 1151: 	    my ($Lw1,$Lw2)=split(/\:/,$DisLow{$lpr[$i]});
 1152: 	    my $Dis1 = $Up1 - $Lw1;
 1153: 	    my $Dis2 = $Up2 - $Lw2;
 1154: 	    my $_D1 = sprintf("%.2f", $Dis1);
 1155: 	    my $_D2 = sprintf("%.2f", $Dis2);
 1156: 
 1157: #-----------------  Some restition in presenting the float numbers
 1158: 	    my $Avg = sprintf( "%.2f", $Average );
 1159: 	    my $Wrng = sprintf( "%.1f", $Wrong );
 1160: 	    my $SD = sprintf( "%.1f", $StdDev );
 1161: 	    my $DoD = sprintf( "%.2f", $DoDiff );
 1162: 	    my $Sk = sprintf( "%.1f", $Skewness );
 1163: 	    my $join = $lpr[$i].'&'.$Temp.'&'.$StdNo.'&'.
 1164:                        $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.
 1165:                        $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
 1166: 		       $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.
 1167:                        $Prob;
 1168: 	    $CachData{($p_count-1)}=$join;
 1169: 
 1170: 	    $urlres=~/^(\w+)\/(\w+)/;
 1171: 	    if ($StdNo) { 
 1172: 		&Apache::lonnet::put('resevaldata',\%storestats,$1,$2); 
 1173: 	    }
 1174: #-------------------------------- Row of statistical table
 1175: 	    if ( $DiscFlag == 0 ) {
 1176: 		&TableRow($join,$i,($p_count-1));
 1177: 	    } 
 1178: 	}
 1179: 	&CloseTable();
 1180:     }
 1181:     &Close_PrgWin();
 1182: }
 1183: 
 1184: sub Cache_Statistics {
 1185:     my @list = ();
 1186:     my $Useful;
 1187:     my $UnUseful;
 1188:     my %myHeader = reverse( %Header );
 1189:     $Pos = $myHeader{$ENV{'form.sort'}};
 1190:     if ($Pos > 0) {$Pos++;}
 1191:     $p_count = 0;
 1192:     foreach my $key( keys %CachData) { 
 1193: 	my @Temp=split(/\&/,$CachData{$key});
 1194: 	if ( $Pos == 0 ) {
 1195: 	    ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
 1196: 	}
 1197: 	else {
 1198: 	    $Useful = $Temp[$Pos];
 1199: 	}   
 1200: 	$list[$p_count]=$Useful.'@'.$CachData{$key};
 1201:         $p_count++;
 1202:     }
 1203: 
 1204:     @list = sort MySort (@list);
 1205: 
 1206:     my $nIdx=0;
 1207: 
 1208:     if ( $Pos == 0 ) {
 1209: 	foreach (sort keys %mapsort) {
 1210: 	    my ($Hid,$pr)=split(/\:/,$mapsort{$_});
 1211: 	    &CreateTable(1,$Hid);
 1212: 	    my @lpr=split(/\&/,$pr);
 1213: 	    for (my $i=1; $i<=$#lpr; $i++) {
 1214: 		my($Pre, $Post) = split(/\@/,$list[$nIdx]); 
 1215: 		#$r->print('<br>'.$Pre.'---'.$Post);
 1216: 		&TableRow($Post,$i,$nIdx);
 1217: 		$nIdx++;
 1218: 	    }
 1219: 	    &CloseTable();
 1220: 	}
 1221:     }
 1222:     else {
 1223: 	&CreateTable(0);
 1224: 	for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {
 1225: 	    my($Pre, $Post) = split(/\@/,$list[$nIdx]); 
 1226: 	    &TableRow($Post,$nIdx,$nIdx);
 1227: 	} 
 1228: 	&CloseTable();
 1229:     }
 1230: }
 1231: 
 1232: sub TableRow {
 1233:     my ($Str,$Idx,$RealIdx)=@_;
 1234:     my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
 1235:        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$Prob)=split(/\&/,$Str);	
 1236:     my $Ptr =  "\n".'<tr>'.
 1237:                "\n".'<td>'.($RealIdx+1).'</td>'.
 1238:           #     "\n".'<td>'.$PrOrd.$Temp.'</td>'.
 1239:                "\n".'<td>'.$Temp.'</td>'.
 1240:                "\n".'<td bgcolor="#EEFFCC"> '.$StdNo.'</td>'.
 1241:                "\n".'<td bgcolor="#EEFFCC">'.$TotalTries.'</td>'.
 1242:                "\n".'<td bgcolor="#EEFFCC">'.$MxTries.'</td>'.
 1243:                "\n".'<td bgcolor="#DDFFFF">'.$Avg.'</td>'.
 1244:                "\n".'<td bgcolor="#DDFFFF"> '.$YES.'</td>'.
 1245:                "\n".'<td bgcolor="#DDFFFF"> '.$Override.'</td>'.
 1246:                "\n".'<td bgcolor="#FFDDDD"> '.$Wrng.'</td>'.
 1247:                "\n".'<td bgcolor="#FFDDDD">'.$DoD.'</td>'.
 1248:                "\n".'<td bgcolor="#DDFFDD"> '.$SD.'</td>'.
 1249:                "\n".'<td bgcolor="#DDFFDD"> '.$Sk.'</td>'.
 1250:                "\n".'<td bgcolor="#FFDDFF"> '.$_D1.'</td>'.
 1251: 	       "\n".'<td bgcolor="#FFDDFF"> '.$_D2.'</td>';
 1252:     $r->print("\n".$Ptr.'</tr>' );
 1253:     $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
 1254: }
 1255: 
 1256: # ------------------------------------------- Prepare data for Graphical chart
 1257: 
 1258: sub GetGraphData {
 1259:     my $Tag = shift;
 1260:     my $Col;
 1261:     my $data='';
 1262:     my $count = 0;
 1263:     my $Max = 0;
 1264:     my $cid=$ENV{'request.course.id'};
 1265:     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
 1266:                   "_$ENV{'user.domain'}_$cid\_graph.db";
 1267:     foreach (keys %GraphDat) {delete $GraphDat{$_};}
 1268:     if (-e "$GraphDB") {
 1269: 	if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
 1270: 	    if ( $Tag eq 'DoDiff Graph' ) {
 1271: 		$Tag = 'Degree-of-Difficulty';
 1272: 		$Col = 0;
 1273: 	    }
 1274: 	    else {
 1275: 		$Tag = 'Wrong-Percentage';
 1276: 		$Col = 1;
 1277: 	    }
 1278: 	    foreach (sort NumericSort keys %GraphDat) { 
 1279: 		my @Temp=split(/\:/,$GraphDat{$_});
 1280:                 my $inf = $Temp[$Col]; 
 1281: 		if ( $Max < $inf ) {$Max = $inf;}
 1282: 		$data .= $inf.',';
 1283: 		$count++;
 1284: 	    }
 1285: 	    if ( $Max > 1 ) { 
 1286: 		$Max += (10 - $Max % 10);
 1287: 		$Max = int($Max);
 1288: 	    }
 1289: 	    else { $Max = 1; }
 1290:             untie(%GraphDat);
 1291: 	    my $Course = $ENV{'course.'.$cid.'.description'};
 1292: 	    $Course =~ s/\ /"_"/eg;
 1293: 	    $GData=$Course.'&'.$Tag.'&'.$Max.'&'.$count.'&'.$data;
 1294: 	}
 1295: 	else {
 1296: 	    $r->print("Unable to tie hash to db file");
 1297: 	}
 1298:     }
 1299: }
 1300: 
 1301: 
 1302: sub initial {
 1303: # --------------------------------- Initialize the global varaibles
 1304:   undef @students;
 1305:   undef @cols;
 1306:   undef %maps;
 1307:   undef %section;
 1308:   undef %StuBox;
 1309:   undef @list;
 1310:   undef %CachData;
 1311:   undef %GraphDat;
 1312:   undef %DiscFac;
 1313:   undef %OpResp;
 1314:   undef %ConceptData;
 1315:   undef $CurMap;
 1316:   undef $CurSec;
 1317:   undef $CurStu;
 1318:   undef $p_count;
 1319:   undef $Pos;
 1320:   undef $GData;
 1321:   $DiscFlag=0; 
 1322:   $P_Order=100000;
 1323:   $HWN=$P_Order;
 1324: }
 1325: 
 1326: 
 1327: sub ClassList {
 1328: 
 1329:     &GetStatus();
 1330: 
 1331:     $cid=$ENV{'request.course.id'};
 1332:     my $chome=$ENV{'course.'.$cid.'.home'};
 1333:     my ($cdom,$cnum)=split(/\_/,$cid);
 1334: # ----------------------- Get first and last resource, see if there is anything
 1335:     $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
 1336:     $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
 1337:     if (($firstres) && ($lastres)) {
 1338: # ----------------------------------------------------------------- Render page
 1339: 	my $classlst=&Apache::lonnet::reply
 1340:                  ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
 1341: 	my $StudNo = 0;
 1342: 	my $now=time;
 1343: 	unless ($classlst=~/^error\:/) {
 1344: 	    foreach (sort split(/\&/,$classlst)) {
 1345: 		my ($name,$value)=split(/\=/,$_);
 1346: 		my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
 1347: 		$name=&Apache::lonnet::unescape($name);
 1348: 		my ($sname,$sdom)=split(/\:/,$name);
 1349: 		my $active=1;
 1350: 		my $Status=$ENV{'form.status'};
 1351: 		$Status = ($Status) ? $Status : 'Active';
 1352: 		if ( ( ($end) && $now > $end ) && 
 1353:                      ( ($Status eq 'Active') ) ) { $active=0; }
 1354: 		if ( ($Status eq 'Expired') && 
 1355:                      ($end == 0 || $now < $end) ) { $active=0; }
 1356: #//new
 1357: #		$Status = 'Any';
 1358: #end new
 1359: 		if ($active) {
 1360: 		    my $thisindex=$#students+1;
 1361: 		    $name=&Apache::lonnet::unescape($name);
 1362: 		    $students[$thisindex]=$name;
 1363: 		    my ($sname,$sdom)=split(/\:/,$name);
 1364: 		    #my %reply=&Apache::lonnet::idrget($sdom,$sname);
 1365: 		    #my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
 1366: 		    #         ':environment:lastname&generation&firstname&middlename',
 1367: 		    #         &Apache::lonnet::homeserver($sname,$sdom));
 1368: 		    my $ssec=&usection($sdom,$sname,$cid,$Status);
 1369: #		    if ($ssec==-1 ) {next;}
 1370: 		    if ($ssec==-1 || $ssec eq 'adm' ) {next;}
 1371: 		    $ssec=($ssec) ? $ssec : '(none)';
 1372: 		    #$ssec=(int($ssec)) ? int($ssec) : $ssec;
 1373: 		    $section{$ssec}=$ssec;
 1374: 		    if ($CurSec eq 'All Sections' || $ssec eq $CurSec) {
 1375: 			$students[$StudNo]=$name;
 1376: 			$StuBox{$sname}=$sdom;
 1377: 		    }
 1378: 		    $StudNo++;
 1379: 	        }
 1380: 	    }
 1381: 	}
 1382: 	else {
 1383: 	    $r->print('<h1>Could not access course data</h1>');
 1384: 	} 
 1385:         $r->print("Total number of students : ".($#students+1));
 1386:         $r->rflush();
 1387: # --------------- Find all assessments and put them into some linear-like order
 1388: 	&tracetable($firstres,'&'.$lastres.'&');
 1389: #    my $c=0;
 1390: #    foreach (sort keys %mapsort) {
 1391: #	$r->print('<br>'.$c.')'.$_.' ... '.$mapsort{$_});
 1392: #	$c++;
 1393: #    }
 1394: #	my $c=1;
 1395: #	foreach (sort keys %OpResp) {
 1396: #	    $r->print('<br>'.$c.')'.$_.' ... '.$OpResp{$_}.' ... '.$hash{'src_'.$OpResp{$_}});
 1397: #	    $c++;
 1398: #	}
 1399: 
 1400:     }
 1401: 
 1402: # ------------------------------------------------------------- End render page 
 1403:     else {
 1404: 	$r->print('<h3>Undefined course sequence</h3>');
 1405:     }
 1406: }
 1407: 
 1408: 
 1409: sub Title {
 1410:     $r->print('<html><head><title>LON-CAPA Statistics</title></head>');
 1411:     $r->print('<body bgcolor="#FFFFFF">'.
 1412:               '<script>window.focus(); window.width=500;window.height=500;</script>'.
 1413:               '<img align=right src=/adm/lonIcons/lonlogos.gif>');
 1414: # ---------------------------------------------------------------- Course title
 1415:     $r->print('<h1> Course : "'.
 1416:               $ENV{'course.'.$ENV{'request.course.id'}.
 1417:               '.description'}.'"</h1><h2>'.localtime().'</h2>');
 1418: # ------------------------------- This is going to take a while, produce output
 1419:     $r->rflush();	
 1420: }
 1421: 
 1422: sub CreateForm {
 1423:     $r->print("\n".'<form name=stat method=post action="/adm/statistics" >');
 1424:     my $content = $ENV{'form.sort'};
 1425:     if ($content eq '' || $content eq 'Return to Menu') {
 1426: 	my $Ptr = '<h3>';
 1427: 	$Ptr .= '<input type=submit name=sort value="Problem Stats"/>';
 1428: 	$Ptr .= '<br><br>';
 1429: 	$Ptr .= '<input type=submit name=sort value="Problem Analysis"/>';
 1430: 	$Ptr .= '<br><br>';
 1431: 	$Ptr .= '<input type=submit name=sort value="Student Assessment"/>';
 1432: 	$Ptr .= '</h3>';
 1433: 	$r->print( $Ptr );
 1434:     }
 1435:     else {
 1436: 	if ( $content eq 'Student Assessment' || 
 1437: 	     $content eq 'Create Student Report' ) {
 1438: 	    &MapSecOptions();
 1439: 	    &StudentOptions();
 1440: 	    &StudentReport($CurStu,$StuBox{"$CurStu"});
 1441: 	}
 1442: 	elsif ( $content eq 'Problem Analysis' ) {
 1443: 	    &AnalyzeProblem();
 1444: 	}
 1445: 	else {
 1446: 	    &MapSecOptions();
 1447: 	    &PreStatTable();
 1448: 	}
 1449:     }
 1450: }
 1451: 
 1452: 
 1453: sub Menu {
 1454:     &initial();
 1455:     &Title();
 1456:     &ClassList();
 1457:     my $InpStr = $ENV{'form.sort'};
 1458:     if ($InpStr=~/^Analyze\_/) {
 1459: 	&ShowOpGraph($InpStr,$ENV{'form.interval'});
 1460:     }
 1461:     #elsif ($InpStr=~/^View\_/) {
 1462: #	&ShowStG();
 1463:  #   }
 1464:     elsif ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) {      
 1465: 	&GetGraphData($InpStr);
 1466:     	$r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
 1467:     }
 1468:     else {
 1469: 	&CreateForm();
 1470: 	$r->print("\n".'</form>');
 1471:     }
 1472:     $r->print("\n".'</body>'.
 1473: 	      "\n".'</html>');
 1474:     $r->rflush();
 1475: }
 1476: 
 1477: sub StudentOptions {
 1478:     my $OpSel5='';
 1479:     $CurStu = $ENV{'form.student'};
 1480:     if ( $CurStu eq '' ) { 
 1481:         $CurStu = 'All Students';
 1482:         $OpSel5 = 'selected';
 1483:     }
 1484:     my $Ptr ='';
 1485: # ----------------------------------- Loading the Students Combobox
 1486:     $Ptr .= '<br><b>Select Student</b>'."\n".
 1487:        	    '<select name="student">'."\n". 
 1488: 	    '<option '.$OpSel5.'>All Students</option>';                     	     	     
 1489:     foreach my $key ( sort keys %StuBox ) {	          
 1490: 	$Ptr .= '<option';
 1491: 	if ($CurStu eq $key) {$Ptr .= ' selected';}     
 1492:         $Ptr .= '>'.$key."</option>\n";	     
 1493:     }
 1494:     $Ptr .= '</select>';
 1495:     $Ptr .= '<br><input type="submit" name="sort" value="Create Student Report" />';
 1496:     $r->print( $Ptr );
 1497:     $r->rflush();	
 1498: }
 1499: 
 1500: 
 1501: sub GetStatus {
 1502:     $OpSel1='';
 1503:     $OpSel2='';
 1504:     $OpSel3='';
 1505:     $OpSel4='';
 1506: 
 1507:     if ( $ENV{'form.order'} eq 'Descending' ) { $OpSel2='selected'; }
 1508:     else { $OpSel1 = 'selected'; }
 1509: 
 1510:     my %myHeader = reverse( %Header );
 1511:     $Pos = $myHeader{$ENV{'form.sort'}};
 1512:     if ($Pos == 0) {
 1513: 	$OpSel1 = 'selected';
 1514: 	$ENV{'form.order'}='Ascendig';
 1515:     }
 1516: 
 1517:     $CurMap = $ENV{'form.maps'};
 1518:     if ( $CurMap eq '' ) { 
 1519: 	$CurMap = 'All Maps';
 1520: 	$OpSel3 = 'selected';
 1521:     }
 1522:     $CurSec = $ENV{'form.section'};
 1523:     if ( $CurSec eq '' ) { 
 1524: 	$CurSec = 'All Sections';
 1525:         $OpSel4 = 'selected';
 1526:     }
 1527: }
 1528: 
 1529: 
 1530: sub MapSecOptions {
 1531: # ----------------------------------- Loading the Maps Combobox
 1532:     my $Ptr = '<br>';
 1533:     $Ptr .= '<br><input type="submit" name="sort" value="Return to Menu" />';
 1534:     $Ptr .= '<br><b> Select &nbsp; Map &nbsp; &nbsp; </b>'."\n".
 1535:        	    '<select name="maps">'."\n". 
 1536: 	    '<option '.$OpSel3.'>All Maps</option>';                     	     	     
 1537:     foreach my $key ( sort keys %maps ) {	          
 1538: 	$Ptr .= '<option';
 1539:         if ($CurMap eq $key) {$Ptr .= ' selected';}	     
 1540: 	$Ptr .= '>'.$key."</option>\n";	     
 1541:     }
 1542:     $Ptr .= '</select>';
 1543:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
 1544: 
 1545: # ----------------------------------- Loading the Sections Combobox
 1546:     $Ptr .= '<br><b>Select Section</b>'."\n".
 1547:        	    '<select name="section">'."\n". 
 1548: 	    '<option '.$OpSel4.'>All Sections</option>';                     	     	     
 1549:     foreach my $key ( sort keys %section ) {	          
 1550: 	$Ptr .= '<option';
 1551:         if ($CurSec eq $key) {$Ptr .= ' selected';}     
 1552: 	$Ptr .= '>'.$key."</option>"."\n";	     
 1553:     }
 1554:     $Ptr .= '</select>'."\n";
 1555: 
 1556:     $r->print( $Ptr );
 1557:     $r->rflush();
 1558: }
 1559: 
 1560: 
 1561: # ================================================================ Main Handler
 1562: 
 1563: sub handler {
 1564:     $r=shift;
 1565: 
 1566:     if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
 1567: # ------------------------------------------- Set document type for header only
 1568: 	if ($r->header_only) {
 1569: 	    if ($ENV{'browser.mathml'}) {
 1570: 		$r->content_type('text/xml');
 1571: 	    } 
 1572: 	    else {
 1573: 		$r->content_type('text/html');
 1574: 	    }
 1575: 	    $r->send_http_header;
 1576: 	    return OK;
 1577: 	}    
 1578: 	my $requrl=$r->uri;
 1579: # ----------------------------------------------------------------- Tie db file
 1580: 
 1581: 	undef %hash;
 1582: 
 1583: 	if ($ENV{'request.course.fn'}) {
 1584: 	    my $fn=$ENV{'request.course.fn'};
 1585: 	    if (-e "$fn.db") {
 1586: 		if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
 1587: # ------------------------------------------------------------------- Hash tied
 1588: 		    $r->content_type('text/html');
 1589: 		    $r->send_http_header;
 1590: 		    &Menu();
 1591: 		}
 1592: 		else {
 1593: 		    $r->content_type('text/html');
 1594: 		    $r->send_http_header;
 1595: 		    $r->print('<html><body>Coursemap undefined.</body></html>');
 1596: 		}
 1597: # ------------------------------------------------------------------ Untie hash
 1598: 		unless (untie(%hash)) {
 1599: 		    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
 1600:                             "Could not untie coursemap $fn (browse).</font>"); 
 1601: 		}
 1602: 
 1603: # -------------------------------------------------------------------- All done
 1604: 		return OK;
 1605: # ----------------------------------------------- Errors, hash could no be tied
 1606: 	    }
 1607: 	} 
 1608: 	else {
 1609: 	    $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
 1610: 	    return HTTP_NOT_ACCEPTABLE; 
 1611: 	}
 1612:     }
 1613:     else {
 1614:         $ENV{'user.error.msg'}=
 1615:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
 1616: 
 1617:         return HTTP_NOT_ACCEPTABLE; 
 1618:     }
 1619: }
 1620: 1;
 1621: __END__

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