File:  [LON-CAPA] / loncom / interface / statistics / lonproblemstatistics.pm
Revision 1.13: download - view: text, annotated - select for diffs
Mon Aug 5 20:53:38 2002 UTC (21 years, 11 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Added in some flushes and changed where some of the modules print.  Also,
fixed download all so that if you stop it, and then select something
else it won't continue to download.

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonproblemstatistics.pm,v 1.13 2002/08/05 20:53:38 stredwic Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Navigate problems for statistical reports
   29: # YEAR=2001
   30: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
   31: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
   32: # YEAR=2002
   33: # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
   34: # 5/12,5/14,5/15,5/19,5/26,7/16,7/25,7/29,8/5  Behrouz Minaei
   35: #
   36: ###
   37: 
   38: package Apache::lonproblemstatistics; 
   39: 
   40: use strict;
   41: use Apache::lonnet();
   42: use Apache::lonhtmlcommon;
   43: use Apache::loncoursedata;
   44: use GDBM_File;
   45: 
   46: 
   47: sub BuildProblemStatisticsPage {
   48:     my ($cacheDB, $students, $courseID, $c, $r)=@_;
   49:     my %cache;
   50:     #my %DoDiff;
   51:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
   52:         return '<html><body>Unable to tie database.</body></html>';
   53:     }
   54: 
   55:     my $Ptr = '';
   56:     $Ptr .= '<table border="0"><tbody>';
   57:     $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
   58:     $Ptr .= '<td align="left">';
   59:     $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
   60:                                                'Statistics');
   61:     $Ptr .= '</td></tr>'."\n";
   62:     $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
   63:     $Ptr .= '<td align="left">'."\n";
   64:     $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
   65:                                             $cache{'ProblemStatisticsAscend'}, 
   66:                                             'ProblemStatistics',
   67:                                             'Statistics');
   68:     $Ptr .= '</td></tr>'."\n";
   69:     $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'});
   70:     $Ptr .= '</table>';
   71:     $Ptr .= &ProblemStatisticsLegend();
   72:     $r->print($Ptr);
   73:     $r->rflush();
   74: 
   75:     untie(%cache);
   76:     &Create_PrgWin($r);
   77:     my $count=0;
   78:     foreach (@$students) {
   79:         &Update_PrgWin(scalar(@$students),$count,$_,$r);
   80:         my $courseData = 
   81:             &Apache::loncoursedata::DownloadCourseInformation($_, $courseID);
   82:         last if ($c->aborted());
   83:         if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
   84:             &Apache::loncoursedata::ProcessStudentData(\%cache, 
   85:                                                        $courseData, $_);
   86:             untie(%cache);
   87:         }
   88:         $count++;
   89:     }
   90:     &Close_PrgWin($r);
   91:     if($c->aborted()) { return; }
   92: 
   93:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
   94:         return '<html><body>Unable to tie database.</body></html>';
   95:     }
   96: 
   97:     my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
   98:                   4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
   99:                   9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd", 13, "Disc.");
  100:     my $color=&setbgcolor(0);
  101: 
  102:     my $state=$ENV{'form.ProblemStatisticsHeading'}; 
  103: 
  104: #    my $state=&Apache::lonstatistics::CheckFormElement(\%cache,
  105: #                                                  'ProblemStatisticsHeading',
  106: #                                                  'ProblemStatisticsHeading',
  107: #                                                  'Homework Sets Order'); 
  108:     $r->print("<br>state=".$state);
  109: 
  110:     my $TempCache;
  111: 
  112:     if ($state) {
  113: 	$TempCache=&CacheStatisticsTable($state,\%cache,\%Header,
  114: 					 $r,$color);
  115:     } else {    
  116: 	my %discriminant=();
  117: 	my @list=();
  118: 	my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
  119: 	my $index=0;
  120: 	foreach (@$students) {
  121: 	    $index++;
  122: 	    #&Apache::lonstatistics::Update_PrgWin(++$index,$r);
  123: 	    &ExtractStudentData(\%cache, $_, \@list,\%Discuss, $r,
  124:                                 \%discriminant);
  125: 	}
  126: 	#&Apache::lonstatistics::Close_PrgWin($r);
  127: 	my ($upper, $lower) = &Discriminant(\%discriminant,$r);
  128: 	$TempCache= &BuildStatisticsTable(\%cache, $upper, $lower, 
  129: 					   \@list, \%Header, $students,
  130: 					   $r, $color);
  131:     }
  132:     untie(%cache);
  133: 
  134:     foreach (keys %$TempCache) {
  135:         last if ($c->aborted());
  136:         if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
  137: 	    $cache{$_}=$TempCache->{$_};
  138: 
  139:             untie(%cache);
  140:         }
  141:     }
  142:     if($c->aborted()) { return; }
  143:     untie(%cache);
  144: }
  145: 
  146: 
  147: #---- Problem Statistics Web Page ---------------------------------------
  148: 
  149: 
  150: sub NumericSort {          
  151:     $a <=> $b;
  152: }
  153: 
  154: 
  155: sub CreateProblemStatisticsTableHeading {
  156:     my ($displayFormat,$sequenceSource,$sequenceTitle,$headings,$r)=@_;
  157:     if($displayFormat eq 'Display CSV Format') {
  158:         $r->print('<br>"'.$sequenceTitle.'","');
  159:         $r->print($sequenceSource.'"');
  160: 	return;
  161:     }
  162: 
  163:     $r->print('<br><a href="'.$sequenceSource.
  164:               '" target="_blank">'.$sequenceTitle.'</a>');
  165: 
  166:     my $Result = "\n".'<table border=2><tr><th>P#</th>'."\n";
  167:     for(my $nIndex=0; $nIndex < (scalar (keys %$headings)); $nIndex++) { 
  168: 	$Result .= '<th>'.'<input type="submit" name="';
  169:         $Result .= 'ProblemStatisticsHeading" value="';
  170:         $Result .= $headings->{$nIndex}.'" />'.'</th>'."\n";
  171:     }
  172:     $Result .= "\n".'</tr>'."\n";    
  173:     $r->print($Result);
  174:     $r->rflush();
  175: }
  176: 
  177: sub CloseTable {
  178:     my ($cache,$r)=@_;
  179:     if($cache->{'DisplayFormat'} eq 'Display CSV Format') {
  180: 	return;
  181:     }    
  182:     $r->print("\n".'</table>'."\n");
  183:     $r->rflush();
  184: }
  185: 
  186: 
  187: # Create progress
  188: sub Create_PrgWin {
  189:     my ($r)=@_;
  190:     $r->print(<<ENDPOP);
  191:     <script>
  192:     popwin=open('','popwin','width=400,height=100');
  193:     popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
  194:       '<title>LON-CAPA Statistics</title>'+
  195:       '<h4>Computation Progress</h4>'+
  196:       '<form name=popremain>'+
  197:       '<input type=text size=35 name=remaining value=Starting></form>'+
  198:       '</body></html>');
  199:     popwin.document.close();
  200:     </script>
  201: ENDPOP
  202: 
  203:     $r->rflush();
  204: }
  205: 
  206: # update progress
  207: sub Update_PrgWin {
  208:     my ($totalStudents,$index,$name,$r)=@_;
  209:     $r->print('<script>popwin.document.popremain.remaining.value="'.
  210:               'Computing '.$index.'/'.$totalStudents.': '.
  211:               $name.'";</script>');
  212:     $r->rflush();
  213: }
  214: 
  215: # close Progress Line
  216: sub Close_PrgWin {
  217:     my ($r)=@_;
  218:     $r->print('<script>popwin.close()</script>');
  219:     $r->rflush(); 
  220: }
  221:  
  222: # ------ Dump the Student's DB file and handling the data for statistics table 
  223: sub ExtractStudentData {
  224:     my ($cache,$name,$list,$Discuss,$r,$discriminant)=@_;
  225:     my $totalTries = 0;
  226:     my $totalAwarded = 0;
  227:     my $spent=0;
  228:     my $spent_yes=0;
  229:     my $TotDiscuss=0;
  230:     my $TotalOpend = 0;
  231:     my $ProbSolved = 0;
  232:     my $ProbTot = 0;
  233:     my $TotFirst = 0;
  234:     my $TimeTot = 0;
  235:     my $Discussed=0;
  236:     my $discrim='';
  237:     my $tempSequenceOrder=100;
  238: 
  239: #$Apache::lonxml::debug=1;
  240: #&Apache::lonhomework::showhash(%$cache);
  241: #$Apache::lonxml::debug=0;
  242: 
  243:     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
  244: 	my $tempProblemOrder=100;
  245:         if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
  246:            $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
  247: #	    $r->print("<br>sequences=$cache->{'orderedSequences'}");
  248: #	    $r->print("<br>".$cache->{$sequence.':title'});
  249:             next;
  250:         }
  251: 	$tempSequenceOrder++;
  252: 
  253:         #$discrim .= '&';
  254:         foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
  255: #	    $r->print("<br>problems=$cache->{$sequence.':problems'}");
  256:             my $problem = $cache->{$problemID.':problem'};
  257: #	    $r->print("<br>$problemID === $problem");
  258:             my $LatestVersion = $cache->{$name.':version:'.$problem};
  259: 	    # Output dashes for all the parts of this problem if there
  260:             # is no version information about the current problem.
  261:             #if(!$LatestVersion) {
  262:             #    foreach my $part (split(/\:/,$cache->{$sequence.':'.
  263:             #                                          $problemID.
  264:             #                                          ':parts'})) {
  265:             #        $codes    .= "-,";
  266:             #        $attempts .= "0,"; 
  267:             #    }
  268:             #    next;
  269:             #}
  270: 
  271:             my %partData=undef;
  272: 	    $partData{'count'}=0;
  273:             # Initialize part data, display skips correctly
  274:             # Skip refers to when a student made no submissions on that
  275:             # part/problem.
  276:             foreach my $part (split(/\:/,$cache->{$sequence.':'.
  277:                                                   $problemID.
  278:                                                   ':parts'})) {
  279: 		$tempProblemOrder++;
  280: 		$partData{'count'}++;
  281: #		$r->print("<br>parts=$cache->{$sequence.':'.$problemID.':parts'}");
  282:                 $partData{$part.':order'}=$tempProblemOrder;
  283:                 $partData{$part.':tries'}=0;
  284:                 $partData{$part.':code'}='-';
  285:             }
  286: 
  287:             # Looping through all the versions of each part, starting with the
  288:             # oldest version.  Basically, it gets the most recent 
  289:             # set of grade data for each part.
  290: 	    for(my $Version=1; $Version<=$LatestVersion; $Version++) {
  291: 		foreach my $part (split(/\:/,$cache->{$sequence.':'.
  292:                                                       $problemID.
  293:                                                       ':parts'})) {
  294: 
  295:                     if(!defined($cache->{$name.":$Version:$problem".
  296:                                                ":resource.$part.solved"})) {
  297:                         # No grade for this submission, so skip
  298:                         next;
  299:                     }
  300: 
  301:                     my $tries=0;
  302:                     my $time=0;
  303:                     my $awarded=0;
  304: 		    $Discussed=0;
  305:                     my $code='-';
  306: 
  307:                     $awarded = $cache->{"$name:$Version:$problem:resource.".
  308:                                         "$part.awarded"};
  309:                     $partData{$part.':awarded'} = ($awarded) ? $awarded : 0;
  310:                     $totalAwarded += $awarded;
  311: 
  312:                     $tries = $cache->{"$name:$Version:$problem".
  313:                                       ":resource.$part.tries"};
  314:                     $partData{$part.':tries'} = ($tries) ? $tries : 0;
  315:                     $partData{$part.':wrong'} = $partData{$part.':tries'};
  316:                     $totalTries += $tries;
  317: 
  318:                     my $val = $cache->{$name.":$Version:$problem".
  319:                                        ":resource.$part.solved"};
  320:                     if    ($val eq 'correct_by_student')   {$code = 'C';} 
  321:                     elsif ($val eq 'correct_by_override')  {$code = 'O';}
  322:                     elsif ($val eq 'incorrect_attempted')  {$code = 'I';} 
  323:                     elsif ($val eq 'incorrect_by_override'){$code = 'I';}
  324:                     elsif ($val eq 'excused')              {$code = 'x';}
  325:                     $partData{$part.':code'}=$code;
  326:                     if($partData{$part.':wrong'} ne 0 && 
  327:                        ($code eq 'C' || $code eq 'O')) {
  328:                         $partData{$part.':wrong'}--;
  329:                     }
  330:                 }
  331:             }
  332: 
  333: #$Apache::lonxml::debug=1;
  334: #&Apache::lonhomework::showhash(%partData);
  335: #$Apache::lonxml::debug=0;
  336: 
  337:             # Loop through all the parts for the current problem in the 
  338:             # correct order and prepare the output
  339: 	    my $partCounter=0;
  340:             foreach (split(/\:/,$cache->{$sequence.':'.$problemID.
  341:                                          ':parts'})) {
  342: 		$partCounter++;
  343:                 my $Yes = 0;
  344:                 if($partData{$_.':code'} eq 'C' || 
  345:                    $partData{$_.':code'} eq 'O') {
  346:                     $Yes=1;
  347:                 }
  348:                 my $pOrder=$partData{$_.':order'};
  349:                 my $ptr = $tempSequenceOrder.':'.$pOrder.':'.$problemID;
  350: 
  351:                 if($partData{'count'} > 1) {
  352:                     $ptr .= "*(part $_)";
  353:                 }
  354:                 #if($partCounter > 1) {
  355:                     $discrim .= '&';
  356:                 #}
  357: 
  358: 		my ($pr_no,$dod)=split('&',$ptr);
  359: #		my $DoDiff=$DoDiff->{$dod};
  360: #               $r->print('<br>'.$name.'---'.$ptr.'==='.$DoDiff);
  361: 
  362:                 my $Fac = ($partData{$_.':tries'}) ? 
  363:                     ($partData{$_.':awarded'}/$partData{$_.':tries'}) : 0;
  364:                 my $DisF;
  365:                 if($Fac > 0 &&  $Fac < 1) { 
  366:                     $DisF = sprintf( "%.4f", $Fac );
  367:                 } else {
  368:                     $DisF = $Fac;
  369:                 }
  370: 
  371:                 if ($Discuss->{"$name:$problem"}) {
  372: 		    $TotDiscuss++;
  373:                     $Discussed=1;
  374:                 }
  375:                 my $time = $cache->{"$name:$LatestVersion:$problem:timestamp"};
  376:                 $discrim .= $tempSequenceOrder.'@'.$pOrder.'='.$DisF.'+'.$Yes;
  377:                 $ptr .= '&'.$partData{$_.':tries'}.
  378:                         '&'.$partData{$_.':wrong'}.
  379:                         '&'.$partData{$_.':code'};
  380:                 push (@$list, $ptr."&$Discussed");
  381: #                $r->print('<br>'.$_.$name.'---'.$ptr);
  382: 		
  383: ####		if ($DoDiff>0.85) {
  384: 
  385:                 $TimeTot += $time;
  386: 
  387:                 if ($Yes==1 && $partData{$_.':tries'}==1) {
  388: 		    $TotFirst++;
  389:                 }
  390: #		my $Acts= $Activity->{$name.':'.$problem};
  391: #		if ($Acts) {
  392: #		    my $Pt=&ProcAct( $Acts, $time );
  393: 		    #my ($spe,$beg) = split(/\+/,$Pt);
  394: #                    my $spe= $Pt;
  395: #		    if ($Yes==1) {$spent_yes += $spe;}
  396: #		    $spent += $spe;
  397: 		    #$Beg += $beg;
  398: #                   $r->print('<br>'.$name.'---'.$problem.'---'.$spe);
  399: #		}
  400: 		$TotalOpend++;
  401: 		$ProbTot++;
  402: 
  403:                 $tempProblemOrder++;
  404:             }
  405:         }
  406:     }
  407:     my $pstr;
  408:     if($totalTries) {
  409: 	my $DisFac = ($totalAwarded/$totalTries);
  410: 	my $DisFactor = sprintf( "%.4f", $DisFac );
  411:         my $TS = sprintf( "%.2f", $spent );
  412:         my $TS_yes = sprintf( "%.2f", $spent_yes );
  413: 	$pstr=$DisFactor.':'.$name.':'.$ProbTot.':'.$TotalOpend.':'.
  414:               $totalTries.':'.$ProbSolved.':'.$TotFirst.':'.
  415:               $TS_yes.':'.$TS.':'.$TotDiscuss;
  416: 	(%$discriminant)->{$pstr}=$discrim;
  417:     }
  418: }
  419: 
  420: 
  421: 
  422: sub MySort {
  423:     my $pos=shift;
  424:     if ( $pos > 0 ) {
  425: 	if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
  426: 	else { $a <=> $b; }
  427:     }
  428:     else {
  429: #	if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
  430: #	else { $a cmp $b; }
  431: 	$a cmp $b;
  432:     }
  433: }
  434: 
  435: 
  436: 
  437: sub BuildStatisticsTable {
  438:     my ($cache,$upper,$lower,$list,$headings,$students,$r,$color)=@_;
  439:     my $NoElements = scalar @$list;
  440:     my @list=sort(@$list);
  441: 
  442: #6666666
  443: #    my $file="/home/httpd/perl/tmp/183d.txt";
  444: #    open(OUT, ">$file");
  445: #6666666
  446: ##     &Apache::lonstatistics::Create_PrgWin($r);
  447: ##777777
  448: ##    my (%Activity) = &LoadActivityLog();
  449: ##    $r->print('<script>popwin.document.popremain.remaining.value="'.
  450: ##              'Loading Discussion...";</script>');
  451: ##    my ($doDiffFile) = &LoadDoDiffFile();
  452: 
  453: ##777777
  454: ##    $Str .= &Classify($discriminantFactor, $students);
  455: 
  456:     my $p_count = 0;
  457:     my $dummy;
  458:     my $p_val;
  459:     my $ResId;
  460:     my %TempCache;
  461:     my $cIdx=0;
  462: 
  463:     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
  464:         if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
  465:            $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
  466:             next;
  467:         }
  468:         &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 
  469:                                              $cache->{$sequence.':source'},
  470:                                              $cache->{$sequence.':title'}, 
  471:                                              $headings,$r);
  472: 	my ($tar,$Tries,$Wrongs,$Code,$Disc)=split(/\&/,
  473:                                                    $list[$cIdx]);
  474:         my ($SqOrd,$PrOrd,$Prob)=split(/\:/,$tar);
  475: 	$sequence+=100;
  476: 	while ($SqOrd==$sequence && $cIdx<$NoElements) {
  477: 	    my %storestats=();
  478: 	    my $pOrd=$PrOrd;
  479: 	    my $Temp = $Prob;
  480: 	    my $MxTries = 0;
  481: 	    my $TotalTries = 0;
  482: 	    my $YES = 0;
  483: 	    my $Incorrect = 0;
  484: 	    my $Override = 0;
  485: 	    my $StdNo = 0;
  486: 	    my $DiscNo=0;
  487: 	    my @StdLst;
  488: 	    while ($pOrd==$PrOrd && $cIdx<$NoElements)
  489: 	    {
  490: 		$cIdx++;
  491: 		$StdNo++;
  492: 		$StdLst[ $StdNo ] = $Tries;
  493: 		$TotalTries += $Tries;
  494: 		if ( $MxTries < $Tries ) { $MxTries = $Tries; } 
  495: 		if ( $Code eq 'C' ){ $YES++; }
  496: 		elsif( $Code eq 'I' ) { $Incorrect++; }
  497: 		elsif( $Code eq 'O' ) { $Override++; }
  498: 		elsif( $Code eq '-' ) { $StdNo--; }
  499: 		($tar,$Tries,$Wrongs,$Code,$Disc)=split(/\&/,
  500:                                                      $list[$cIdx]);
  501: 	        ($SqOrd,$PrOrd,$Prob)=split(/\:/,$tar);
  502: 	    }
  503: 
  504: 	    $p_count++;
  505: 	    my $Dummy;
  506: 	    ($ResId,$Dummy)=split(/\*/,$Temp);
  507: 
  508: ######################
  509: 	    $Temp = '<a href="'.$cache->{$ResId.':source'}.
  510:                 '" target="_blank">'.$cache->{$ResId.':title'}.$Dummy.'</a>';
  511: 
  512: 	    #$r->print('<br>rid='.$ResId);
  513: 	    #$r->print('<br>src='.$cache->{$ResId.':source'});
  514: 	    #$r->print('<br>tit='.$cache->{$ResId.':title'});
  515: 
  516: 	    my $res = &Apache::lonnet::declutter($cache->{$ResId.':source'});
  517: 	    my $urlres=$res;
  518: 
  519: 	    $ResId=~/(\d+)\.(\d+)/;
  520: 	    my $Map = &Apache::lonnet::declutter( $cache->{'map_id_'.$1} );
  521: 	    $urlres=$Map;
  522: #######################
  523: 
  524: #	    $res = '<a href="'.$cache->{$ResId.':source'}.'">'.$res.'</a>';
  525: 	    #$Map = '<a href="'.$Map.'">'.$res.'</a>';
  526: 
  527: #------------------------ Compute the Average of Tries about one problem
  528: 	    my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;
  529: 
  530: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;
  531: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;
  532: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;
  533:    
  534: #-------------------------------- Compute percentage of Wrong tries
  535: 	    my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;
  536: 
  537: #-------------------------------- Compute Standard Deviation
  538: 	    my $StdDev = 0; 
  539: 	    if ( $StdNo > 1 ) {
  540: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
  541: 		    my $Dif = $StdLst[ $n ]-$Average;
  542: 		    $StdDev += $Dif*$Dif;
  543: 		} 
  544: 		$StdDev /= ( $StdNo - 1 );
  545: 		$StdDev = sqrt( $StdDev );
  546: 	    }
  547: 
  548: #-------------------------------- Compute Degree of Difficulty
  549: 	    my $DoDiff = 0;
  550: 	    if( $TotalTries > 0 ) {
  551: 		$DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );
  552: #	    $DoDiff =  ($TotalTries)/($YES + $Override+ 0.1);	    
  553: 	    }
  554:        
  555: 	    $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;
  556: 
  557: #-------------------------------- Compute the Skewness
  558: 	    my $Skewness = 0;
  559: 	    my $Sum = 0; 
  560: 	    if ( $StdNo > 0 && $StdDev > 0 ) {
  561: 		for ( my $n = 0; $n < $StdNo; $n++ ) {
  562: 		    my $Dif = $StdLst[ $n ]-$Average;
  563: 		    $Skewness += $Dif*$Dif*$Dif;
  564: 		} 
  565: 		$Skewness /= $StdNo;
  566: 		$Skewness /= $StdDev*$StdDev*$StdDev;
  567: 	    }
  568: 
  569: #--------------------- Compute the Discrimination Factors
  570:             my ($Up1,$Up2)=split(/\:/,$upper->{$sequence.'@'.$pOrd});
  571: 	    my ($Lw1,$Lw2)=split(/\:/,$lower->{$sequence.'@'.$pOrd});
  572: 
  573: 	    my $Dis1 = $Up1 - $Lw1;
  574: 	    my $Dis2 = $Up2 - $Lw2;
  575: 	    my $_D1 = sprintf("%.2f", $Dis1);
  576: 	    my $_D2 = sprintf("%.2f", $Dis2);
  577: 
  578: #-----------------  Some restition in presenting the float numbers
  579: 	    my $Avg = sprintf( "%.2f", $Average );
  580: 	    my $Wrng = sprintf( "%.1f", $Wrong );
  581: 	    my $SD = sprintf( "%.1f", $StdDev );
  582: 	    my $DoD = sprintf( "%.2f", $DoDiff );
  583: 	    my $Sk = sprintf( "%.1f", $Skewness );
  584: 	    my $join = $sequence.'@'.$pOrd.'&'.$Temp.'&'.$StdNo.'&'.
  585:                        $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.
  586:                        $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
  587: 		       $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.
  588:                        $DiscNo.'&'.$Prob;
  589: 
  590: #####{$sequence.'@'.$pOrd}
  591: 	    $TempCache{'CacheTable:'.($p_count-1)}=$join;
  592: 
  593: #6666666
  594: #	    $r->print('<br>'.$out.'&'.$DoD);
  595: #            print (OUT $out.'@'.$DoD.'&');
  596: #6666666
  597: 
  598: 	    $urlres=~/^(\w+)\/(\w+)/;
  599: 	    if ($StdNo) { 
  600: 		&Apache::lonnet::put('resevaldata',\%storestats,$1,$2); 
  601: 	    }
  602: #-------------------------------- Row of statistical table
  603:             &TableRow($cache,$join,$cIdx,($p_count-1),$r,$color,
  604:                       \%TempCache);
  605: 	}
  606: 	$TempCache{'ProblemCount'}=$p_count;
  607: 	&CloseTable($cache,$r);
  608:     }
  609: ###    &Close_PrgWin();
  610: #666666
  611: #    close( OUT );
  612: #666666
  613:     return \%TempCache;
  614: }
  615: 
  616: 
  617: sub CacheStatisticsTable {
  618:     my ($state,$cache,$Header,$r,$color)=@_;
  619:     my @list = ();
  620:     my $Useful;
  621:     my $UnUseful; 
  622:     my %TempCache;
  623:     my %myHeader = reverse( %$Header );
  624:     my $pos = $myHeader{$state};
  625:     if ($pos > 0) {$pos++;}
  626:     my $p_count = $cache->{'ProblemCount'};
  627: 
  628:     for ( my $k=0; $k<$p_count;$k++) {
  629: 	my $key=$cache->{'CacheTable:'.$k};
  630: 	my @Temp=split(/\&/,$key);
  631: 	if ( $pos == 0 ) {
  632: 	    ($UnUseful,$Useful)=split(/\>/,$Temp[$pos]);
  633: 	}
  634: 	else {
  635: 	    $Useful = $Temp[$pos];
  636: 	}   
  637: 	$list[$k]=$Useful.'@'.$key;
  638: 	$r->print('<br>'.$list[$k]);
  639:     }
  640: 
  641: 
  642:     @list = sort MySort (@list);
  643: 
  644:     my $nIndex=0;
  645: 
  646:     return \%TempCache;
  647: }
  648: 
  649: 
  650: =pod
  651: 
  652:     if ( $Pos == 0 ) {
  653: 	foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
  654: 	    if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
  655: 	       $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
  656: 		next;
  657: 	    }
  658: 	    &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 
  659:                                              $cache->{$sequence.':source'},
  660:                                              $cache->{$sequence.':title'}, 
  661:                                              $headings,$r);
  662: 
  663: 	    my ($tar,$Tries,$Wrongs,$Code,$Disc)=split(/\&/,
  664:                                                        $list[$cIdx]);
  665: 	    my ($SqOrd,$PrOrd,$Prob)=split(/\:/,$tar);
  666: 	    $sequence+=100;
  667: 	while ($SqOrd==$sequence && $cIdx<$NoElements) {
  668: 	    my %storestats=();
  669: 	    my @lpr=split(/\&/,$pr);
  670: 	    for (my $i=1; $i<=$#lpr; $i++) {
  671: 		my($Pre, $Post) = split(/\@/,$list[$nIndex]); 
  672: 		#$r->print('<br>'.$Pre.'---'.$Post);
  673: 		&TableRow($cache,$Post,$i,$nIndex,$color,\%GraphDat);
  674: 		$nIndex++;
  675: 	    }
  676: 	    &CloseTable($cache);
  677: 	}
  678:     }
  679:     else {
  680:         &CreateProblemStatisticsTableHeading($cache->{'DisplayFormat'}, 
  681:                                              $cache->{$sequence.':source'},
  682:                                              $cache->{$sequence.':title'}, 
  683:                                              $headings,$r);
  684: 	for ( my $nIndex = 0; $nIndex < $p_count; $nIndex++ ) {
  685: 	    my($Pre, $Post) = split(/\@/,$list[$nIndex]); 
  686: 	    &TableRow($cache,$Post,$nIndex,$nIndex,$color,\%GraphDat);
  687: 	} 
  688: 	&CloseTable($cache);
  689:     }
  690: 
  691:     return \%TempCache;
  692: }
  693: 
  694: =cut
  695: 
  696: 
  697: sub TableRow {
  698:     my ($cache,$Str,$Idx,$RealIdx,$r,$color,$GraphDat)=@_;
  699:     my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
  700:        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);	
  701:     my $Ptr;
  702:     if($cache->{'DisplayFormat'} eq 'Display CSV Format') {
  703:         my ($ResId,$Dummy)=split(/\*/,$Prob);
  704:         $Ptr="\n".'<br>'.
  705:              "\n".'"'.($RealIdx+1).'",'.
  706:              "\n".'"'.$cache->{$ResId.':title'}.$Dummy.'",'.
  707:              "\n".'"'.$cache->{$ResId.':source'}.'",'.
  708:              "\n".'"'.$StdNo.'",'.
  709:              "\n".'"'.$TotalTries.'",'.
  710:              "\n".'"'.$MxTries.'",'.
  711:              "\n".'"'.$Avg.'",'.
  712:              "\n".'"'.$YES.'",'.
  713:              "\n".'"'.$Override.'",'.
  714:              "\n".'"'.$Wrng.'",'.
  715:              "\n".'"'.$DoD.'",'.
  716:              "\n".'"'.$SD.'",'.
  717:              "\n".'"'.$Sk.'",'.
  718:              "\n".'"'.$_D1.'",'.
  719: 	     "\n".'"'.$_D2.'"'.
  720: 	     "\n".'"'.$DiscNo.'"';
  721: 
  722:         $r->print("\n".$Ptr);
  723:     } else {
  724:         $Ptr="\n".'<tr>'.
  725:              "\n".'<td>'.($RealIdx+1).'</td>'.
  726:           #  "\n".'<td>'.$PrOrd.$Temp.'</td>'.
  727:              "\n".'<td>'.$Temp.'</td>'.
  728:              "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
  729:              "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
  730:              "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
  731:              "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
  732:              "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
  733:              "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
  734:              "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
  735:              "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
  736:              "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
  737:              "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
  738:              "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
  739: 	     "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
  740:              "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
  741:         $r->print("\n".$Ptr.'</tr>' );
  742:     }
  743:     $GraphDat->{'graph_gif:'.$RealIdx}=$DoD.':'.$Wrng;
  744: }
  745: 
  746: 
  747: # For loading the colored table for display or un-colored for print
  748: sub setbgcolor {
  749:     my $PrintTable=shift;
  750:     my %color;
  751:     if ($PrintTable){
  752: 	$color{"gb"}="#FFFFFF";
  753: 	$color{"red"}="#FFFFFF";
  754: 	$color{"yellow"}="#FFFFFF";
  755: 	$color{"green"}="#FFFFFF";
  756: 	$color{"purple"}="#FFFFFF";
  757:     } else {
  758: 	$color{"gb"}="#DDFFFF";
  759: 	$color{"red"}="#FFDDDD";
  760: 	$color{"yellow"}="#EEFFCC";
  761: 	$color{"green"}="#DDFFDD";
  762: 	$color{"purple"}="#FFDDFF";
  763:     }
  764: 
  765:     return \%color;
  766: }
  767: 
  768: sub ProblemStatisticsButtons {
  769:     my ($displayFormat)=@_;
  770: 
  771:     my $Ptr = '<tr><td></td><td align="left">';
  772:     $Ptr .= '<input type="submit" name="DoDiffGraph" ';
  773:     $Ptr .= 'value="DoDiff Graph" />'."\n";
  774:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  775:     $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
  776:     $Ptr .= 'value="%Wrong Graph" />'."\n";
  777:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  778:     $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
  779:     if($displayFormat eq 'Display CSV Format') {
  780:         $Ptr .= 'value="Display Table Format" />'."\n";
  781:     } else {
  782:         $Ptr .= 'value="Display CSV Format" />'."\n";
  783:     }
  784:     $Ptr .= '</td></tr>';
  785: 
  786:     return $Ptr;
  787: }
  788: 
  789: sub ProblemStatisticsLegend {
  790:     my $Ptr = '';
  791:     $Ptr = '<table border="0">';
  792:     $Ptr .= '<tr><td>';
  793:     $Ptr .= '<b>#Stdnts</b></td>';
  794:     $Ptr .= '<td>Total Number of Students opened the problem.';
  795:     $Ptr .= '</td></tr><tr><td>';
  796:     $Ptr .= '<b>Tries</b></td>';
  797:     $Ptr .= '<td>Total Number of Tries for solving the problem.';
  798:     $Ptr .= '</td></tr><tr><td>';
  799:     $Ptr .= '<b>Mod</b></td>';
  800:     $Ptr .= '<td>Maximunm Number of Tries for solving the problem.';
  801:     $Ptr .= '</td></tr><tr><td>';
  802:     $Ptr .= '<b>Mean</b></td>';
  803:     $Ptr .= '<td>Average Number of the tries. [ Tries / #Stdnts ]';
  804:     $Ptr .= '</td></tr><tr><td>';
  805:     $Ptr .= '<b>#YES</b></td>';
  806:     $Ptr .= '<td>Number of students solved the problem correctly.';
  807:     $Ptr .= '</td></tr><tr><td>';
  808:     $Ptr .= '<b>#yes</b></td>';
  809:     $Ptr .= '<td>Number of students solved the problem by override.';
  810:     $Ptr .= '</td></tr><tr><td>';
  811:     $Ptr .= '<b>%Wrng</b></td>';
  812:     $Ptr .= '<td>Percentage of students tried to solve the problem ';
  813:     $Ptr .= 'but still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
  814:     $Ptr .= '</td></tr><tr><td>';
  815:     $Ptr .= '<b>DoDiff</b></td>';
  816:     $Ptr .= '<td>Degree of Difficulty of the problem.  ';
  817:     $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
  818:     $Ptr .= '</td></tr><tr><td>';
  819:     $Ptr .= '<b>S.D.</b></td>';
  820:     $Ptr .= '<td>Standard Deviation of the tries.  ';
  821:     $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
  822:     $Ptr .= 'where Xi denotes every student\'s tries ]';
  823:     $Ptr .= '</td></tr><tr><td>';
  824:     $Ptr .= '<b>Skew.</b></td>';
  825:     $Ptr .= '<td>Skewness of the students tries.';
  826:     $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
  827:     $Ptr .= '</td></tr><tr><td>';
  828:     $Ptr .= '<b>Dis.F.</b></td>';
  829:     $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
  830:     $Ptr .= 'problem according to a Criterion<br>';
  831:     $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
  832:     $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
  833:     $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
  834:     $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
  835:     $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
  836:     $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
  837:     $Ptr .= '</td></tr>';
  838:     $Ptr .= '<tr><td><b>Disc.</b></td>';
  839:     $Ptr .= '<td>Number of Students had at least one discussion.';
  840:     $Ptr .= '</td></tr></table>';
  841: 
  842:     return $Ptr;
  843: }
  844: 
  845: #------- Processing upperlist and lowerlist according to each problem
  846: sub ProcessDiscriminant {
  847:     my ($List,$r) = @_;
  848:     my @sortedList = sort (@$List);
  849:     my $Count = scalar @sortedList;
  850:     my $Problem;
  851:     my @Dis;
  852:     my $Slvd=0;
  853:     my $tmp;
  854:     my $Sum1=0;
  855:     my $Sum2=0;
  856:     my $nIndex=0;
  857:     my $nStudent=0;
  858:     my %Proc=undef;
  859:     while ($nIndex<$Count) {
  860: #        $r->print("<br> $nIndex) $sortedList[$nIndex]");
  861: 	($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
  862: 	@Dis=split(/\+/,$tmp);
  863: 	my $Temp = $Problem;
  864: 	do {
  865: 	    $nIndex++;
  866: 	    $nStudent++;
  867: 	    $Sum1 += $Dis[0];
  868: 	    $Sum2 += $Dis[1];
  869: 	    ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
  870: 	    @Dis=split(/\+/,$tmp);
  871: 	} while ( $Problem eq $Temp && $nIndex < $Count );
  872: 	$Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
  873: #        $r->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
  874: 	$Sum1=0;
  875: 	$Sum2=0;
  876: 	$nStudent=0;
  877:     }
  878: 
  879:     return %Proc;
  880: }
  881: 
  882: #------- Creating Discimination factor   
  883: sub Discriminant {
  884:     my ($discriminant,$r)=@_;
  885: #$Apache::lonxml::debug=1;
  886: #&Apache::lonhomework::showhash(%$discriminant);
  887: #$Apache::lonxml::debug=0;
  888:     my @discriminantKeys=keys(%$discriminant);
  889:     my $Count = scalar @discriminantKeys;
  890: 
  891:     my $UpCnt = int(0.27*$Count);
  892:     my $low=0;
  893:     my $up=$Count-$UpCnt;
  894:     my @UpList=();
  895:     my @LowList=();
  896: 
  897:     $Count=0;
  898:     foreach my $key (sort(@discriminantKeys)) { 
  899: 	$Count++;    
  900: 	if($low < $UpCnt || $Count > $up) {
  901:             $low++;
  902:             my $str=$discriminant->{$key};
  903:             foreach(split(/\&/,$str)){
  904:                 if($_) {
  905:                     if($low<$UpCnt) { push(@LowList,$_); }
  906:                     else            { push(@UpList,$_);  }
  907:                 }
  908:             }
  909:         }
  910:     }
  911:     my %DisUp =  &ProcessDiscriminant(\@UpList,$r);
  912:     my %DisLow = &ProcessDiscriminant(\@LowList,$r);
  913: 
  914:     return (\%DisUp, \%DisLow);
  915: }   
  916: 
  917: #---- END Problem Statistics Web Page ----------------------------------------
  918: 
  919: #---- Problem Statistics Graph Web Page --------------------------------------
  920: 
  921: # ------------------------------------------- Prepare data for Graphical chart
  922: 
  923: sub BuildDiffGraph {
  924:     my ($r)=@_;
  925: 
  926:     my $graphData = &GetGraphData('DiffGraph', $r);
  927:     $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />');
  928: 
  929:     return;
  930: }
  931: 
  932: sub BuildWrongGraph {
  933:     my ($r)=@_;
  934: 
  935:     my $graphData = &GetGraphData('WrongGraph', $r);
  936:     $r->print('<IMG src="/cgi-bin/graph.gif?'.$graphData.'" />');
  937: 
  938:     return;
  939: }
  940: 
  941: 
  942: sub GetGraphData {
  943:     my ($ylab,$r,%GraphDat)=@_;
  944:     my $Col;
  945:     my $data='';
  946:     my $count = 0;
  947:     my $Max = 0;
  948:     my $cid=$ENV{'request.course.id'};
  949:     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
  950:                   "_$ENV{'user.domain'}_$cid\_graph.db";
  951:     foreach (keys %GraphDat) {delete $GraphDat{$_};}
  952:     if (-e "$GraphDB") {
  953: 	if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
  954: 	    if ( $ylab eq 'DoDiff Graph' ) {
  955: 		$ylab = 'Degree-of-Difficulty';
  956: 		$Col = 0;
  957: 	    }
  958: 	    else {
  959: 		$ylab = 'Wrong-Percentage';
  960: 		$Col = 1;
  961: 	    }
  962: 	    foreach (sort NumericSort keys %GraphDat) { 
  963: 		my @Temp=split(/\:/,$GraphDat{$_});
  964:                 my $inf = $Temp[$Col]; 
  965: 		if ( $Max < $inf ) {$Max = $inf;}
  966: 		$data .= $inf.',';
  967: 		$count++;
  968: 	    }
  969: 	    if ( $Max > 1 ) { 
  970: 		$Max += (10 - $Max % 10);
  971: 		$Max = int($Max);
  972: 	    }
  973: 	    else { $Max = 1; }
  974:             untie(%GraphDat);
  975: 	    my $Course = $ENV{'course.'.$cid.'.description'};
  976: 	    $Course =~ s/\ /"_"/eg;
  977: 	    my $GData=$Course.'&'.'Problems'.'&'.$ylab.'&'.
  978: 		      $Max.'&'.$count.'&'.$data;
  979: 	}
  980: 	else {
  981: 	    $r->print("Unable to tie hash to db file");
  982: 	}
  983:     }
  984: }
  985: 
  986: 
  987: 1;
  988: __END__

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