Annotation of loncom/interface/lonstatistics.pm, revision 1.5

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # (Publication Handler
                      3: #
1.5     ! minaeibi    4: # $Id: lonstatistics.pm,v 1.4 2002/02/06 16:59:01 minaeibi Exp $
1.1       albertel    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
1.5     ! minaeibi   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
1.1       albertel   32: # YEAR=2002
1.5     ! minaeibi   33: # 1/22, 2/1, 2/6, 2/25 Behrouz Minaei
1.1       albertel   34: ###
                     35: 
1.3       minaeibi   36: package Apache::lonstatistics; 
1.1       albertel   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;
1.3       minaeibi   44: #use Benchmark;
1.1       albertel   45: 
                     46: # -------------------------------------------------------------- Module Globals
                     47: my %hash;
                     48: my %CachData;
                     49: my %GraphDat;
                     50: my %maps;
1.5     ! minaeibi   51: my %mapsort;
1.1       albertel   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;
1.5     ! minaeibi   75: my $DiscFlag;
        !            76: my $HWN;
        !            77: my $P_Order;
        !            78: my %Header = (0,"Homework Problems",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");
1.1       albertel   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;
1.5     ! minaeibi   99:     my $PrOrd;
1.1       albertel  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\:/) {
1.5     ! minaeibi  119:         foreach (split(/\&/,$reply)){
1.1       albertel  120:             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
                    121:             $result{$name}=$value;
1.5     ! minaeibi  122:         }
        !           123:         foreach my $CurCol (@cols) {
        !           124: 	    if (!$CurCol){
1.1       albertel  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: 	    }
1.5     ! minaeibi  139: 	    ($PrOrd,$ResId)=split(/\:/,$CurCol);
1.1       albertel  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;
1.5     ! minaeibi  149: 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))){
1.1       albertel  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"} = '-';  
1.5     ! minaeibi  156: 			$TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;  
1.1       albertel  157: 			$PartNo++;
                    158: 		    }
                    159: 		}
1.5     ! minaeibi  160:             }
1.1       albertel  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: 
1.5     ! minaeibi  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: }
1.1       albertel  233: 
1.5     ! minaeibi  234: sub CloseTable {
        !           235:     $r->print("\n".'</table>'."\n");
        !           236:     $r->rflush();
        !           237: }
        !           238:  
1.1       albertel  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:     $r->print('<br><input type="submit" name="sort" value="Recalculate Statistics" />');
                    248: 
                    249:     my $Ptr = '';
                    250: 
                    251:     $Ptr .= '<br><b> Sorting Type: &nbsp; </b>'."\n".
                    252:             '<select name="order"> <option '.$OpSel1.' >Ascending</option>'."\n".
                    253: 	    '<option '.$OpSel2.'>Descending</option> </select> '."\n";
                    254:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                    255:     $Ptr .= '<input type="submit" name="sort" value="DoDiff Graph" />'."\n";
                    256:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                    257:     $Ptr .= '<input type="submit" name="sort" value="%Wrong Graph" />'."\n";
                    258: 
                    259:     $Ptr .= '<pre>'.
                    260:     '  #Stdnts: Total Number of Students opened the problem.<br>'. 
                    261:     '  Tries  : Total Number of Tries for solving the problem.<br>'. 
                    262:     '  Mod    : Maximunm Number of Tries for solving the problem.<br>'. 
1.5     ! minaeibi  263:     '  Mean   : Average Number of the tries. [ Tries / #Stdnts ]<br>'.
1.1       albertel  264:     '  #YES   : Number of students solved the problem correctly.<br>'. 
                    265:     '  #yes   : Number of students solved the problem by override.<br>'.
1.2       minaeibi  266:     '  %Wrng  : Percentage of students tried to solve the problem but'.
                    267:     ' still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]<br>'.
1.5     ! minaeibi  268: #    '  DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ]<br>'.
        !           269:     '  DoDiff : Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ]<br>'.
1.2       minaeibi  270:     '  S.D.   : Standard Deviation of the tries.'.
                    271:     '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'.
1.5     ! minaeibi  272:     ' where Xi denotes every student\'s tries ]<br>'.
1.2       minaeibi  273:     '  Skew.  : Skewness of the students tries.'.
                    274:     ' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ]<br>'.
1.5     ! minaeibi  275: 
1.1       albertel  276: #    '  Dis.F. : Discrimination Factor. [ Sum of Partial Credits Awarded / Total Number of Tries in %27 upper and lower students]</b>'.	
                    277:             '</pre>';
                    278: 
                    279:     $r->print($Ptr);
                    280:     $r->rflush();	
                    281: 
                    282:     if ((-e "$CacheDB")&&($ENV{'form.sort'} ne 'Recalculate Statistics')) {
                    283: 	if (tie(%CachData,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
                    284: 	    tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
                    285: 	    &Cache_Statistics();
                    286:         }
                    287:         else {
                    288: 	    $r->print("Unable to tie hash to db file");
                    289:         }
                    290:     }
                    291:     else {
                    292: 	if (tie(%CachData,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
                    293: 	    tie(%DiscFac,'GDBM_File',$CachDisFac,&GDBM_WRCREAT,0640);
                    294: 	    tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
                    295: 	    foreach (keys %DiscFac) {delete $CachData{$_};}
                    296: 	    foreach (keys %CachData) {delete $CachData{$_};}
                    297: 	    $DiscFlag=0;
                    298: 	    &Build_Statistics();
                    299: 	}
                    300:         else {
                    301: 	    $r->print("Unable to tie hash to db file");
                    302:         }
                    303:     }
                    304:     #$r->print('Total instances of the problems : '.($p_count*($#students+1)));
                    305: 
                    306:     untie(%CachData);
                    307:     untie(%GraphDat);
1.5     ! minaeibi  308:     untie(%DiscFac);       
1.1       albertel  309: }
                    310: 
                    311: 
                    312: # ------------------------------------- Find the section of student in a course
                    313: 
                    314: sub usection {
                    315:     my ($udom,$unam,$courseid)=@_;
                    316:     $courseid=~s/\_/\//g;
                    317:     $courseid=~s/^(\w)/\/$1/;
                    318:     map {
                    319:         my ($key,$value)=split(/\=/,$_);
                    320:         $key=&Apache::lonnet::unescape($key);
                    321:         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
                    322:             my $section=$1;
                    323:             if ($key eq $courseid.'_st') { $section=''; }
                    324: 	    my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));
                    325:             $section=($section) ? $section : '(none)';
1.4       minaeibi  326: #            $section=(int($section)) ? int($section) : $section;
1.1       albertel  327: #            $r->print($unam.'...'.$section.'<br>');
                    328: 	    return $section;
                    329:         }
                    330:     } split(/\&/,&Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles',
                    331:                         &Apache::lonnet::homeserver($unam,$udom)));
                    332:     return '';
                    333: }
                    334: 
                    335: 
                    336: # ------ Dump the Student's DB file and handling the data for statistics table 
                    337: 
                    338: sub ExtractStudentData {
                    339:     my ($student,$coid)=@_;
                    340:     my ($sname,$sdom) = split( /\:/, $student );
                    341:     my $shome=&Apache::lonnet::homeserver( $sname,$sdom );          
                    342:     my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );
                    343:     my %result = ();
                    344:     my $ResId;
1.5     ! minaeibi  345:     my $PrOrd;
1.1       albertel  346:     my $Dis = '';
                    347:     my $Code;
                    348:     my $Tries;
                    349:     my $ParCr;
                    350:     my $TotalTries = 0;
                    351:     my $TotalOpend = 0;
                    352:     my $ProbSolved = 0;
                    353:     my $ProbTot = 0;
                    354:     my $TimeTot = 0;
                    355:     my $TotParCr = 0;
                    356:     my $Wrongs;
                    357:     my %TempHash;
                    358:     my $Version;
                    359:     my $LatestVersion;
                    360:     my $SecLimit;
                    361:     my $MapLimit;
                    362:     unless ($reply=~/^error\:/) {
1.5     ! minaeibi  363:         foreach (split(/\&/,$reply)) {
1.1       albertel  364:             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
                    365:             $result{$name}=$value;
1.5     ! minaeibi  366:         }
        !           367:         foreach my $CurCol(@cols) {
        !           368: 	    ($PrOrd,$ResId)=split(/\:/,$CurCol);
        !           369: 	    if ( !$CurCol ) { next; }
1.1       albertel  370:             $ResId=~/(\d+)\.(\d+)/;
1.5     ! minaeibi  371: 	    my $MapId=$1;
        !           372: 	    my $PrbId=$2;
        !           373:             my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$MapId} );
1.1       albertel  374:             if ( $CurMap ne 'All Maps' ) {
                    375: 		my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
                    376: 		if ( $Map ne $ResMap ) { next; }
                    377: 	    }
                    378: 	    my $meta=$hash{'src_'.$ResId};
                    379: 	    my $PartNo = 0;
                    380: 	    $Dis .= ':';
                    381: 	    undef %TempHash;
1.5     ! minaeibi  382: 	    foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
1.1       albertel  383: 		if ($_=~/^stores\_(\d+)\_tries$/) {
                    384:                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
                    385: 		    if ( $TempHash{"$Part"} eq '' ) { 
                    386: 			$TempHash{"$Part"} = $Part;
                    387: 			$TempHash{$PartNo}=$Part;
                    388: 			$TempHash{"$Part.Code"} = 'U';  
1.5     ! minaeibi  389: 			$TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
1.1       albertel  390: 			$PartNo++;
                    391: 		    }
                    392: 		}
1.5     ! minaeibi  393:             }
1.1       albertel  394: 
1.5     ! minaeibi  395:             my $Prob = $Map.'___'.$PrbId.'___'.
1.1       albertel  396:                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
                    397:             $Code='U';
                    398:             $Tries = 0;
                    399: 	    $ParCr = 0;
                    400:             $Wrongs = 0;
                    401:   	    $LatestVersion = $result{"version:$Prob"};       
                    402: 
                    403: 	    if ( $LatestVersion ) {
                    404: 		for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
                    405: 		    my $vkeys = $result{"$Version:keys:$Prob"};
                    406: 		    my @keys = split(/\:/,$vkeys);		
                    407:   
                    408: 		    foreach my $Key (@keys) {		  
                    409: 			if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
                    410: 			    my $Part = $1;
                    411: 			    $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
                    412: 			    $ParCr = $result{"$Version:$Prob:resource.$Part.awarded"};
                    413: 			    my $Time = $result{"$Version:$Prob:timestamp"};
                    414: 			    $TempHash{"$Part.Time"} = ($Time) ? $Time : 0;
                    415: 			    $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
                    416: 			    $TempHash{"$Part.ParCr"} = ($ParCr) ? $ParCr : 0;        
                    417: 			    $TotalTries += $TempHash{"$Part.Tries"};
                    418: 			    $TotParCr += $TempHash{"$Part.ParCr"};
                    419: #$r->print($Version.'---'.$Prob.'==='.$Time.'<br>');
                    420: 			    my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
                    421: 			    if ( $Val eq 'correct_by_student' )
                    422:                                { $Wrongs = $Tries - 1; $Code = 'C'; } 
                    423: 			    elsif ( $Val eq 'correct_by_override' )
                    424:                                { $Wrongs = $Tries - 1; $Code = 'O'; }                        
                    425: 			    elsif ( $Val eq 'incorrect_attempted' || 
                    426:                                 $Val eq 'incorrect_by_override' )
                    427: 		               { $Wrongs = $Tries; $Code = 'I'; }
                    428: 			    $TempHash{"$Part.Code"} = $Code;
                    429: 			    $TempHash{"$Part.Wrongs"} = $Wrongs;
                    430: 			}
                    431:      		    }
                    432:                 } 
                    433: 		for ( my $n = 0; $n < $PartNo; $n++ ) {		  
                    434: 		    my $part = $TempHash{$n};
                    435: 		    my $Yes = 0;
                    436:                     if ( $TempHash{$part.'.Code'} eq 'C' ||
                    437:                          $TempHash{$part.'.Code'} eq 'O'  ) 
                    438: 		       {$ProbSolved++;$Yes=1;}		    
1.5     ! minaeibi  439: #		    my $ptr = "$hash{'title_'.$ResId}";
        !           440: 		    my $ptr = $TempHash{$part.'.PrOrd'}.':'.$ResId;
1.1       albertel  441: 		    if ( $PartNo > 1 ) {                
1.5     ! minaeibi  442: 			$ptr .= "*(part $part)";
1.1       albertel  443: 			$Dis .= ':';
                    444: 		    }
                    445: 		    my $Fac = ($TempHash{"$part.Tries"}) ? 
                    446:                               ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
                    447: 		    my $DisF;
                    448: 		    if ( $Fac > 0 &&  $Fac < 1 ) { 
                    449: 			$DisF = sprintf( "%.4f", $Fac );
                    450: 		    }
                    451: 		    else {$DisF = $Fac;}
                    452: #		    $DisF .= '+'.$TempHash{"$part.Time"};
                    453: 		    $TimeTot += $TempHash{"$part.Time"};
                    454: 		    $Dis .= $ptr.'*'.$ResId.'='.$DisF.'+'.$Yes;
1.5     ! minaeibi  455: 		    $ptr .= ":$TempHash{$part.'.Tries'}".
1.1       albertel  456: 		            ":$TempHash{$part.'.Wrongs'}".
1.5     ! minaeibi  457:                             ":$TempHash{$part.'.Code'}";
1.1       albertel  458: 		    push (@list, $ptr);
                    459: 		    $TotalOpend++;
                    460: 		    $ProbTot++;
                    461: 		}
                    462:             }
1.5     ! minaeibi  463: 	    #else { 
        !           464: 		#for(my $n=0; $n<$PartNo; $n++) {
        !           465: 		#    push (@list, "$hash{'title_'.$ResId}*$ResId:0:0:U");
        !           466: 		#    $ProbTot++; 
        !           467: 		#}
        !           468: 	    #}
1.1       albertel  469:         }
                    470: 	if ( $TotalTries ) {
                    471: 	    my $DisFac = ( $TotalTries ) ? ($TotParCr/$TotalTries) : 0;
                    472: #	    my $DisFactor = int(sprintf( "%.4f", $DisFac ) * 100);
                    473: 	    my $DisFactor = sprintf( "%.4f", $DisFac );
                    474: 	    my $time;
                    475: 	    if ($ProbSolved){
1.5     ! minaeibi  476: 		$time = int(($TimeTot/$ProbSolved)-10000000);
1.1       albertel  477: 	    }
                    478: 	    $DiscFac{($DisFactor.':'.$sname.':'.$ProbTot.':'.$TotalOpend.':'.
                    479:                       $TotalTries.':'.$ProbSolved.':'.$time)}=$Dis;
                    480: #$r->print($DisFactor.$sname.'<br> --- Dis= '.$Dis.'<br>');
                    481: 	}
                    482:     }
                    483:     #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.'<br>');
                    484: }
                    485: 
                    486: 
                    487: # ------------------------------------------------------------ Build page table
                    488: sub tracetable {
                    489:     my ($rid,$beenhere)=@_;
                    490:     $rid=~/(\d+)\.(\d+)/;
                    491:     $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid}; 
1.5     ! minaeibi  492:     #$maps{$HWN}=$hash{'title_'.$rid}; 
1.1       albertel  493:     unless ($beenhere=~/\&$rid\&/) {
                    494:        $beenhere.=$rid.'&'; 
                    495:        if (defined($hash{'is_map_'.$rid})) {
                    496: 	   my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
                    497:            if ( $cmap eq 'sequence' || $cmap eq 'page' ) { 
                    498:                $cols[$#cols+1]=0;
1.5     ! minaeibi  499: 	       $P_Order++;
        !           500: 	       $HWN=$P_Order;
        !           501:                $mapsort{$HWN} = $rid.':'; 
1.1       albertel  502:                #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}= 
                    503:                #      $hash{'title_'.$rid}; 
                    504:            }
                    505:            if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
                    506:                (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
1.5     ! minaeibi  507: 	       my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
1.1       albertel  508: 
1.5     ! minaeibi  509:                &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
        !           510: 			   '&'.$frid.'&');
1.1       albertel  511: 
1.5     ! minaeibi  512: 	       $cols[$#cols+1]=($P_Order+1).':'.$frid;
        !           513:       
        !           514: 	       my $meta=$hash{'src_'.$frid};
        !           515: 	       my $PartNo = 0;
        !           516:                if ($meta) {
        !           517: 		   if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
        !           518: 		       foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
        !           519: 			   if ($_=~/^stores\_(\d+)\_tries$/) {
        !           520: 			       &Apache::lonnet::metadata($meta,$_.'.part');
        !           521: 			       $P_Order++;
        !           522: 			       $mapsort{$HWN} .= '&'.$P_Order;
        !           523: 			       $PartNo++;
        !           524: 			       $r->print('<br>'.$PartNo.'---'.$P_Order);
        !           525: 			   }
        !           526: 		       }
        !           527: 		   }
        !           528:                }
1.1       albertel  529: 	   }
                    530:        } else {
1.5     ! minaeibi  531: 	   $cols[$#cols+1]=($P_Order+1).':'.$rid;
        !           532: 	   my $meta=$hash{'src_'.$rid};
        !           533: 	   my $PartNo = 0;
        !           534:            if ($meta) {
        !           535: 	       if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
        !           536: 		   foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
        !           537: 		       if ($_=~/^stores\_(\d+)\_tries$/) {
        !           538: 			   &Apache::lonnet::metadata($meta,$_.'.part');
        !           539: 			   $P_Order++;
        !           540: 			   $mapsort{$HWN} .= '&'.$P_Order;
        !           541: 			   $PartNo++;
        !           542: 		       }
        !           543: 		   }
        !           544: 	       }
        !           545: 	   }
1.1       albertel  546:        }
                    547:        if (defined($hash{'to_'.$rid})) {
1.5     ! minaeibi  548:           foreach (split(/\,/,$hash{'to_'.$rid})){
1.1       albertel  549:               &tracetable($hash{'goesto_'.$_},$beenhere);
1.5     ! minaeibi  550:           }
1.1       albertel  551:        }
                    552:     }
                    553: }
                    554: 
                    555: sub MySort {          
                    556:     if ( $Pos > 0 && $Pos < 11 ) {
                    557: 	if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
                    558: 	else { $a <=> $b; }
                    559:     }
                    560:     else {
                    561: 	if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
                    562: 	else { $a cmp $b; }
                    563:     }
                    564: }
                    565: 
                    566: sub Build_Statistics {
                    567:     $r->print(<<ENDPOP);
1.5     ! minaeibi  568:     <script>
1.1       albertel  569:     popwin=open('','popwin','width=400,height=100');
1.5     ! minaeibi  570:     popwin.document.writeln('<html><body bgcolor="#7777EE">'+
1.1       albertel  571:       '<title>LON-CAPA Statistics</title>'+
                    572:       '<h4>Computation Progress</h4>'+
                    573:       '<form name=popremain>'+
                    574:       '<input type=text size=35 name=remaining value=Starting></form>'+
                    575:       '</body></html>');
                    576:     popwin.document.close();
1.5     ! minaeibi  577:     </script>
1.1       albertel  578: ENDPOP
                    579: 
                    580:     $r->rflush();
                    581: # ---------------------------- Gathering the Data of students' tries
                    582:     my $index;
                    583:     for ($index=0;$index<=$#students;$index++) {
                    584: #----------- update progress
                    585:         $r->print('<script>popwin.document.popremain.remaining.value="'.
                    586:                   'Computing '.($index+1).'/'.($#students+1).': '.
                    587:                   $students[$index].'";</script>');
                    588:         $r->rflush();
                    589: 
                    590:         &ExtractStudentData($students[$index],$cid);
                    591:     }
                    592: #--------------------- close Progress Line
                    593:     $r->print('<script>popwin.close()</script>');
                    594:     $r->rflush(); 
                    595: # -------------------- sorting the Data
1.5     ! minaeibi  596:     @list = sort (@list);
        !           597: 
1.1       albertel  598:     $OpSel2='';
                    599:     $OpSel1='selected';
                    600:  		   
                    601:     $p_count = 0; 
                    602:     my $nIdx = 0;
                    603:     my $dummy; 
                    604:     my $p_val;
                    605:     my $ResId;
                    606:     my $NoElements = $#list + 1;
                    607: #-------------------------------- loop for data representation
1.5     ! minaeibi  608:     foreach (sort keys %mapsort) {
        !           609: 	my ($Hid,$pr)=split(/\:/,$mapsort{$_});
        !           610: 	my @lpr=split(/\&/,$pr);
        !           611: 	&CreateTable(1,$Hid);
        !           612: 	for (my $i=1; $i<=$#lpr; $i++) {
        !           613: 	    my %storestats=();
        !           614: 	    my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
        !           615: 	    my $Temp = $Prob;
        !           616: 	    my $MxTries = 0;
        !           617: 	    my $TotalTries = 0;
        !           618: 	    my $YES = 0;
        !           619: 	    my $Incorrect = 0;
        !           620: 	    my $Override = 0;
        !           621: 	    my $StdNo = 0;
        !           622: 	    my @StdLst;
        !           623: 	    while ( $PrOrd == $lpr[$i] ) 
        !           624: 	    {
        !           625: 		$nIdx++;
        !           626: 		$StdNo++;
        !           627: 		$StdLst[ $StdNo ] = $Tries;
        !           628: 		$TotalTries += $Tries;
        !           629: 		if ( $MxTries < $Tries ) { $MxTries = $Tries; } 
        !           630: 		if ( $Code eq 'C' ){ $YES++; }
        !           631: 		elsif( $Code eq 'I' ) { $Incorrect++; }
        !           632: 		elsif( $Code eq 'O' ) { $Override++; }
        !           633: 		elsif( $Code eq 'U' ) { $StdNo--; }
        !           634: 		($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);
        !           635: 	    }	
        !           636: 
        !           637: 	    $p_count++;
        !           638: 	    my $Dummy;
        !           639: 	    ($ResId,$Dummy)=split(/\*/,$Temp);
1.1       albertel  640: 
1.5     ! minaeibi  641: 	    $Temp = '<a href="'.$hash{'src_'.$ResId}.
        !           642:                 '" target="_blank">'.$hash{'title_'.$ResId}.$Dummy.'</a>';
1.1       albertel  643:     
1.5     ! minaeibi  644: 	    my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});
        !           645: 	    my $urlres=$res;
1.1       albertel  646: 
1.5     ! minaeibi  647: 	    $ResId=~/(\d+)\.(\d+)/;
        !           648: 	    my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );
        !           649: 	    $urlres=$Map;
1.1       albertel  650:  
1.5     ! minaeibi  651: 	    $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';
        !           652: 	    #$Map = '<a href="'.$Map.'">'.$res.'</a>';
1.1       albertel  653: 
                    654: #------------------------ Compute the Average of Tries about one problem
1.5     ! minaeibi  655: 	    my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;
1.1       albertel  656: 
1.5     ! minaeibi  657: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;       
        !           658: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;
        !           659: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;
1.1       albertel  660:    
                    661: #-------------------------------- Compute percentage of Wrong tries
1.5     ! minaeibi  662: 	    my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;
1.1       albertel  663: 
                    664: #-------------------------------- Compute Standard Deviation
1.5     ! minaeibi  665: 	    my $StdDev = 0; 
        !           666: 	    if ( $StdNo > 1 ) {
        !           667: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
        !           668: 		    my $Dif = $StdLst[ $n ]-$Average;
        !           669: 		    $StdDev += $Dif*$Dif;
        !           670: 		} 
        !           671: 		$StdDev /= ( $StdNo - 1 );
        !           672: 		$StdDev = sqrt( $StdDev );
        !           673: 	    }
1.1       albertel  674: 
                    675: #-------------------------------- Compute Degree of Difficulty
1.5     ! minaeibi  676: 	    my $DoDiff = 0;
        !           677: 	    if( $TotalTries > 0 ) {
        !           678: 		$DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );
1.1       albertel  679: #	    $DoDiff =  ($TotalTries)/($YES + $Override+ 0.1);	    
1.5     ! minaeibi  680: 	    }
1.1       albertel  681:        
1.5     ! minaeibi  682: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;
1.1       albertel  683: 
                    684: #-------------------------------- Compute the Skewness
1.5     ! minaeibi  685: 	    my $Skewness = 0;
        !           686: 	    my $Sum = 0; 
        !           687: 	    if ( $StdNo > 0 && $StdDev > 0 ) {
        !           688: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
        !           689: 		    my $Dif = $StdLst[ $n ]-$Average;
        !           690: 		    $Skewness += $Dif*$Dif*$Dif;
        !           691: 		} 
        !           692: 		$Skewness /= $StdNo;
1.1       albertel  693: 	    $Skewness /= $StdDev*$StdDev*$StdDev;
1.5     ! minaeibi  694: 	    }
1.1       albertel  695: #-----------------  Some restition in presenting the float numbers
1.5     ! minaeibi  696: 	    my $Avg = sprintf( "%.2f", $Average );
        !           697: 	    my $Wrng = sprintf( "%.1f", $Wrong );
        !           698: 	    my $SD = sprintf( "%.1f", $StdDev );
        !           699: 	    my $DoD = sprintf( "%.2f", $DoDiff );
        !           700: 	    my $Sk = sprintf( "%.1f", $Skewness );
        !           701: 	    my $join = $PrOrd.':'.$Temp.':'.$StdNo.':'.
        !           702:                        $TotalTries.':'.$MxTries.':'.$Avg.':'.
        !           703:                        $YES.':'.$Override.':'.$Wrng.':'.$DoD.':'.
        !           704: 		       $SD.':'.$Sk.':'.$Map.':'.$Prob;
        !           705: 	    $CachData{($p_count-1)}=$join;
        !           706: 
        !           707: 	    $urlres=~/^(\w+)\/(\w+)/;
        !           708: 	    if ($StdNo) { 
        !           709: 		&Apache::lonnet::put('resevaldata',\%storestats,$1,$2); 
        !           710: 	    }
1.1       albertel  711: #-------------------------------- Row of statistical table
1.5     ! minaeibi  712: 	    if ( $DiscFlag == 0 ) {
        !           713: 		&TableRow($join,$i,($p_count-1));
        !           714: 	    } 
        !           715: 	}
        !           716: 	&CloseTable();
1.1       albertel  717:     }
                    718: }
                    719: 
                    720: sub Cache_Statistics {
                    721:     my @list = ();
                    722:     my $Useful;
                    723:     my $UnUseful;
                    724:     my %myHeader = reverse( %Header );
                    725:     $Pos = $myHeader{$ENV{'form.sort'}};
1.5     ! minaeibi  726:     if ($Pos > 0) {$Pos++;}
1.1       albertel  727:     $p_count = 0;
                    728:     foreach my $key( keys %CachData) { 
                    729: 	my @Temp=split(/\:/,$CachData{$key});
                    730: 	if ( $Pos == 0 || $Pos == 11 ) {
                    731: 	    ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);
                    732: 	}
                    733: 	else {
                    734: 	    $Useful = $Temp[$Pos];
                    735: 	}   
                    736: 	$list[$p_count]=$Useful.'&'.$CachData{$key};
                    737:         $p_count++;
                    738:     }
                    739: 
                    740:     @list = sort MySort (@list);
                    741: 
1.5     ! minaeibi  742:     my $nIdx=0;
        !           743: 
        !           744:     if ( $Pos == 0 ) {
        !           745: 	foreach (sort keys %mapsort) {
        !           746: 	    my ($Hid,$pr)=split(/\:/,$mapsort{$_});
        !           747: 	    &CreateTable(1,$Hid);
        !           748: 	    my @lpr=split(/\&/,$pr);
        !           749: 	    for (my $i=1; $i<=$#lpr; $i++) {
        !           750: 		my($Pre, $Post) = split(/\&/,$list[$nIdx]); 
        !           751: 		&TableRow($Post,$i,$nIdx);
        !           752: 		$nIdx++;
        !           753: 	    }
        !           754: 	    &CloseTable();
        !           755: 	}
        !           756:     }
        !           757:     else {
        !           758: 	&CreateTable(0);
        !           759: 	for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {
        !           760: 	    my($Pre, $Post) = split(/\&/,$list[$nIdx]); 
        !           761: 	    &TableRow($Post,$nIdx,$nIdx);
        !           762: 	} 
        !           763: 	&CloseTable();
        !           764:     }
        !           765: }
        !           766: 
        !           767: sub TableRow {
        !           768:     my ($Str,$Idx,$RealIdx)=@_;
        !           769:     my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,
        !           770:        $Override,$Wrng,$DoD,$SD,$Sk,$res,$Prob)=split(/\:/,$Str);	
        !           771:     $r->print( "\n".'<tr>'.
        !           772:                "\n".'<td>'.($RealIdx+1).'</td>'.
        !           773:                "\n".'<td bgcolor="#FFFFFF">'.$Temp.'</td>'.
        !           774:                "\n".'<td bgcolor="#EEFFDD"> '.$StdNo.'</td>'.
        !           775:                "\n".'<td bgcolor="#EEFFDD">'.$TotalTries.'</td>'.
        !           776:                "\n".'<td bgcolor="#EEFFDD">'.$MxTries.'</td>'.
        !           777:                "\n".'<td bgcolor="#DDFFFF">'.$Avg.'</td>'.
        !           778:                "\n".'<td bgcolor="#DDFFFF"> '.$YES.'</td>'.
        !           779:                "\n".'<td bgcolor="#DDFFFF"> '.$Override.'</td>'.
        !           780:                "\n".'<td bgcolor="#FFDDDD"> '.$Wrng.'</td>'.
        !           781:                "\n".'<td bgcolor="#FFDDDD">'.$DoD.'</td>'.
        !           782:                "\n".'<td bgcolor="#DDFFDD"> '.$SD.'</td>'.
        !           783:                "\n".'<td bgcolor="#DDFFDD"> '.$Sk.'</td>'.
        !           784: #               "\n".'<td>'.$res.'</td>'.
1.1       albertel  785:                "\n".'</tr>' );
1.5     ! minaeibi  786:     $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
1.1       albertel  787: }
                    788: 
                    789: # ------------------------------------------- Prepare data for Graphical chart
                    790: 
                    791: sub GetGraphData {
                    792:     my $Tag = shift;
                    793:     my $Col;
                    794:     my $data='';
                    795:     my $count = 0;
                    796:     my $Max = 0;
                    797:     my $cid=$ENV{'request.course.id'};
                    798:     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                    799:                   "_$ENV{'user.domain'}_$cid\_graph.db";
                    800:     foreach (keys %GraphDat) {delete $GraphDat{$_};}
                    801:     if (-e "$GraphDB") {
                    802: 	if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
                    803: 	    if ( $Tag eq 'DoDiff Graph' ) {
                    804: 		$Tag = 'Degree-of-Difficulty';
                    805: 		$Col = 0;
                    806: 	    }
                    807: 	    else {
                    808: 		$Tag = 'Wrong-Percentage';
                    809: 		$Col = 1;
                    810: 	    }
                    811: 	    foreach (sort NumericSort keys %GraphDat) { 
                    812: 		my @Temp=split(/\:/,$GraphDat{$_});
                    813:                 my $inf = $Temp[$Col]; 
                    814: 		if ( $Max < $inf ) {$Max = $inf;}
                    815: 		$data .= $inf.',';
                    816: 		$count++;
                    817: 	    }
                    818:             untie(%GraphDat);
                    819: 	    my $Course = $ENV{'course.'.$cid.'.description'};
                    820: 	    $Course =~ s/\ /"_"/eg;
                    821: 	    $GData=$Course.'&'.$Tag.'&'.$Max.'&'.$count.'&'.$data;
                    822: 
                    823: 	}
                    824: 	else {
                    825: 	    $r->print("Unable to tie hash to db file");
                    826: 	}
                    827:     }
                    828: }
                    829: 
                    830: 
                    831: sub initial {
                    832: # --------------------------------- Initialize the global varaibles
                    833:   undef @students;
                    834:   undef @cols;
                    835:   undef %maps;
                    836:   undef %section;
                    837:   undef %StuBox;
                    838:   undef @list;
                    839:   undef %CachData;
                    840:   undef %GraphDat;
                    841:   undef %DiscFac;
                    842:   undef $CurMap;
                    843:   undef $CurSec;
                    844:   undef $CurStu;
                    845:   undef $p_count;
                    846:   undef $Pos;
                    847:   undef $GData;
1.5     ! minaeibi  848:   $DiscFlag=0; 
        !           849:   $P_Order=100000;
        !           850:   $HWN=$P_Order;
1.1       albertel  851: }
                    852: 
                    853: 
                    854: sub ClassList {
                    855: 
                    856:     &GetStatus();
                    857: 
                    858:     $cid=$ENV{'request.course.id'};
                    859:     my $chome=$ENV{'course.'.$cid.'.home'};
                    860:     my ($cdom,$cnum)=split(/\_/,$cid);
                    861: # ----------------------- Get first and last resource, see if there is anything
                    862:     $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
                    863:     $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
                    864:     if (($firstres) && ($lastres)) {
                    865: # ----------------------------------------------------------------- Render page
                    866: 	my $classlst=&Apache::lonnet::reply
                    867:                  ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
                    868: 	my $StudNo = 0;
                    869: 	unless ($classlst=~/^error\:/) {
                    870: 	    foreach (sort split(/\&/,$classlst)) {
                    871: 		my ($name,$value)=split(/\=/,$_);
                    872: 		my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
                    873: 		$name=&Apache::lonnet::unescape($name);
                    874: 		my ($sname,$sdom)=split(/\:/,$name);
                    875: 		my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
                    876:                 if ($ssec==-1) {next;}
                    877: 		$ssec=($ssec) ? $ssec : '(none)';
1.4       minaeibi  878: 		#$ssec=(int($ssec)) ? int($ssec) : $ssec;
1.1       albertel  879: 		#$r->print($sname.'...'.$ssec.'<br>');
                    880: 		$section{$ssec}=$ssec;
                    881: 		if ($CurSec eq 'All Sections' || $ssec eq $CurSec) {
                    882: 		    $students[$StudNo]=$name;
                    883: 		    $StuBox{$sname}=$ssec;
                    884: 		}
                    885: 		$StudNo++;
                    886: 	    }
                    887: 	}
                    888: 	else {
                    889: 	    $r->print('<h1>Could not access course data</h1>');
1.2       minaeibi  890: 	} 
1.1       albertel  891:         $r->print("Total number of students : ".($#students+1));
                    892:         $r->rflush();
                    893: # --------------- Find all assessments and put them into some linear-like order
                    894: 	&tracetable($firstres,'&'.$lastres.'&');
1.2       minaeibi  895: 
1.5     ! minaeibi  896: #    my $c=0;
        !           897: #    foreach (sort keys %mapsort) {
        !           898: #	$r->print('<br>'.$c.')'.$_.' ... '.$mapsort{$_});
        !           899: #	$c++;
        !           900: #    }
        !           901: #foreach(@cols) {
1.2       minaeibi  902: #    $c++;
1.5     ! minaeibi  903: #    $r->print('<br>'.$cols[$c]);
1.2       minaeibi  904: #}
                    905: #$r->print('<br> Count = '.$c);
                    906: 
1.1       albertel  907:     }
                    908: 
                    909: # ------------------------------------------------------------- End render page 
                    910:     else {
                    911: 	$r->print('<h3>Undefined course sequence</h3>');
                    912:     }
                    913:     &MapSecOptions();
                    914: }
                    915: 
                    916: 
                    917: sub Menu {
                    918:     my $InpStr = $ENV{'form.sort'};
                    919:     if ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) {      
                    920: 	&GetGraphData($InpStr);
                    921:     	$r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');
                    922:     }
                    923:     else {
                    924: 	$r->print('<html><head><title>LON-CAPA Statistics</title></head>');
                    925: 
                    926: 
                    927:         $r->print('<body bgcolor="#FFFFFF">'.
                    928:                   '<script>window.focus(); window.width=500;window.height=500; </script>'.
                    929:                   '<img align=right src=/adm/lonIcons/lonlogos.gif>');
                    930: # ---------------------------------------------------------------- Course title
                    931:         $r->print('<h1> Course : "'.
                    932:                   $ENV{'course.'.$ENV{'request.course.id'}.
                    933:                   '.description'}.'"</h1><h2>'.localtime().'</h2>');
                    934: # ------------------------------- This is going to take a while, produce output
                    935:         $r->rflush();	
                    936: 
                    937: 	$r->print("\n".'<form name=stat method=post action="/adm/statistics" >');
                    938: 
                    939: 	my $content = $ENV{'form.sort'};
                    940: 	if ($content eq '' || $content eq 'Return to Menu') {
                    941: 	    my $Ptr = '<h3>';
                    942: 	    $Ptr .= '<input type=submit name=sort value="Problem Evaluation"/>';#General Statistics"/>';
                    943: 	    $Ptr .= '<br><br>';
                    944: 	    $Ptr .= '<input type=submit name=sort value="Student Assessment"/>';
                    945: 	    $Ptr .= '<br><br>';
                    946: #	    $Ptr .= '<input type=submit name=sort value=Discrimination>';#"Problem Evaluation"/>';
                    947: 	    $Ptr .= '</h3>';
                    948: 	    $r->print( $Ptr );
                    949:       	}
                    950: 	else {
                    951: 	    &initial();
                    952: 	    &ClassList();
                    953: 	    if ( $content eq 'Discrimination' || #'Problem Evaluation' ||
                    954:                  $content eq 'Recalculate Discrimintion Factor' ) {
                    955: 		&CreateDiscFac();
                    956: 	    }
                    957: 	    elsif ( $content eq 'Student Assessment' || 
                    958:                     $content eq 'Create Student Report' ) {
                    959: 		&StudentOptions();
                    960: 		&StudentReport($CurStu,$StuBox{"$CurStu"});
                    961: 	    }
                    962: 	    else {
                    963: 		&PreStatTable();
                    964: 	    }
                    965: 	}
                    966: 	$r->print("\n".'</form>'.
                    967:                   "\n".'</body>'.
                    968:                   "\n".'</html>');
                    969: 	$r->rflush();
                    970:     }
                    971: }
                    972: 
                    973: sub StudentOptions {
                    974:     my $OpSel5='';
                    975:     $CurStu = $ENV{'form.student'};
                    976:     if ( $CurStu eq '' ) { 
                    977:         $CurStu = 'All Students';
                    978:         $OpSel5 = 'selected';
                    979:     }
                    980:     my $Ptr ='';
                    981: # ----------------------------------- Loading the Students Combobox
                    982:     $Ptr .= '<br><b>Select Student</b>'."\n".
                    983:        	    '<select name="student">'."\n". 
                    984: 	    '<option '.$OpSel5.'>All Students</option>';                     	     	     
                    985:     foreach my $key ( sort keys %StuBox ) {	          
                    986: 	$Ptr .= '<option';
                    987: 	if ($CurStu eq $key) {$Ptr .= ' selected';}     
                    988:         $Ptr .= '>'.$key."</option>\n";	     
                    989:     }
                    990:     $Ptr .= '</select>';
                    991:     $Ptr .= '<br><input type="submit" name="sort" value="Create Student Report" />';
                    992:     $r->print( $Ptr );
                    993:     $r->rflush();	
                    994: }
                    995: 
                    996: sub GetStatus {
                    997: 
                    998:     $OpSelDis1='';
                    999:     $OpSelDis2='';
                   1000:     $OpSel1='';
                   1001:     $OpSel2='';
                   1002:     $OpSel3='';
                   1003:     $OpSel4='';
                   1004: 
                   1005: #    if ( $ENV{'form.DisType'} eq 'Total Number of Correct Answers' ) { 
                   1006: #	$OpSelDis1='selected'; 
                   1007: #	$CurDis=0;
                   1008: #    }
                   1009: #    else { $OpSel2 = 'selected'; $CurDis = 1;}
                   1010: 
                   1011:     if ( $ENV{'form.order'} eq 'Descending' ) { $OpSel2='selected'; }
                   1012:     else { $OpSel1 = 'selected'; }
1.5     ! minaeibi 1013: 
        !          1014:     my %myHeader = reverse( %Header );
        !          1015:     $Pos = $myHeader{$ENV{'form.sort'}};
        !          1016:     if ($Pos == 0) {
        !          1017: 	$OpSel1 = 'selected';
        !          1018: 	$ENV{'form.order'}='Ascendig';
        !          1019:     }
        !          1020: 
1.1       albertel 1021:     $CurMap = $ENV{'form.maps'};
                   1022:     if ( $CurMap eq '' ) { 
                   1023: 	$CurMap = 'All Maps';
                   1024: 	$OpSel3 = 'selected';
                   1025:     }
                   1026:     $CurSec = $ENV{'form.section'};
                   1027:     if ( $CurSec eq '' ) { 
                   1028: 	$CurSec = 'All Sections';
                   1029:         $OpSel4 = 'selected';
                   1030:     }
                   1031: }
                   1032: 
                   1033: 
                   1034: sub MapSecOptions {
                   1035: # ----------------------------------- Loading the Maps Combobox
                   1036:     my $Ptr = '<br>';
                   1037:     $Ptr .= '<br><input type="submit" name="sort" value="Return to Menu" />';
                   1038:     $Ptr .= '<br><b> Select &nbsp; Map &nbsp; &nbsp; </b>'."\n".
                   1039:        	    '<select name="maps">'."\n". 
                   1040: 	    '<option '.$OpSel3.'>All Maps</option>';                     	     	     
                   1041:     foreach my $key ( sort keys %maps ) {	          
                   1042: 	$Ptr .= '<option';
                   1043:         if ($CurMap eq $key) {$Ptr .= ' selected';}	     
                   1044: 	$Ptr .= '>'.$key."</option>\n";	     
                   1045:     }
                   1046:     $Ptr .= '</select>';
                   1047:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
                   1048: 
                   1049: # ----------------------------------- Loading the Sections Combobox
                   1050:     $Ptr .= '<br><b>Select Section</b>'."\n".
                   1051:        	    '<select name="section">'."\n". 
                   1052: 	    '<option '.$OpSel4.'>All Sections</option>';                     	     	     
                   1053:     foreach my $key ( sort keys %section ) {	          
                   1054: 	$Ptr .= '<option';
                   1055:         if ($CurSec eq $key) {$Ptr .= ' selected';}     
                   1056: 	$Ptr .= '>'.$key."</option>"."\n";	     
                   1057:     }
                   1058:     $Ptr .= '</select>'."\n";
                   1059: 
                   1060:     $r->print( $Ptr );
                   1061:     $r->rflush();
                   1062: }
                   1063: 
                   1064: 
                   1065: # ================================================================ Main Handler
                   1066: 
                   1067: sub handler {
                   1068:     $r=shift;
                   1069: 
                   1070:     if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
                   1071: # ------------------------------------------- Set document type for header only
                   1072: 	if ($r->header_only) {
                   1073: 	    if ($ENV{'browser.mathml'}) {
                   1074: 		$r->content_type('text/xml');
                   1075: 	    } 
                   1076: 	    else {
                   1077: 		$r->content_type('text/html');
                   1078: 	    }
                   1079: 	    $r->send_http_header;
                   1080: 	    return OK;
                   1081: 	}    
                   1082: 	my $requrl=$r->uri;
                   1083: # ----------------------------------------------------------------- Tie db file
                   1084: 
                   1085: 	undef %hash;
                   1086: 
                   1087: 	if ($ENV{'request.course.fn'}) {
                   1088: 	    my $fn=$ENV{'request.course.fn'};
                   1089: 	    if (-e "$fn.db") {
                   1090: 		if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
                   1091: # ------------------------------------------------------------------- Hash tied
                   1092: 		    $r->content_type('text/html');
                   1093: 		    $r->send_http_header;
                   1094: 		    &Menu();
                   1095: 		}
                   1096: 		else {
                   1097: 		    $r->content_type('text/html');
                   1098: 		    $r->send_http_header;
                   1099: 		    $r->print('<html><body>Coursemap undefined.</body></html>');
                   1100: 		}
                   1101: # ------------------------------------------------------------------ Untie hash
                   1102: 		unless (untie(%hash)) {
                   1103: 		    &Apache::lonnet::logthis("<font color=blue>WARNING: ".
                   1104:                             "Could not untie coursemap $fn (browse).</font>"); 
                   1105: 		}
                   1106: 
                   1107: # -------------------------------------------------------------------- All done
                   1108: 		return OK;
                   1109: # ----------------------------------------------- Errors, hash could no be tied
                   1110: 	    }
                   1111: 	} 
                   1112: 	else {
                   1113: 	    $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                   1114: 	    return HTTP_NOT_ACCEPTABLE; 
                   1115: 	}
                   1116:     }
                   1117:     else {
                   1118:         $ENV{'user.error.msg'}=
                   1119:         $r->uri.":vgr:0:0:Cannot view grades for complete course";
                   1120: 
                   1121:         return HTTP_NOT_ACCEPTABLE; 
                   1122:     }
                   1123: }
                   1124: 1;
                   1125: __END__
                   1126: 
                   1127: 
                   1128: 

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