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

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

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