File:  [LON-CAPA] / loncom / interface / statistics / lonproblemstatistics.pm
Revision 1.12: download - view: text, annotated - select for diffs
Mon Aug 5 18:10:08 2002 UTC (21 years, 11 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
Edited the Statistics table to resort the table. (It needs more work)

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

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