File:  [LON-CAPA] / loncom / interface / statistics / lonproblemstatistics.pm
Revision 1.22: download - view: text, annotated - select for diffs
Tue Aug 13 15:01:07 2002 UTC (21 years, 11 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Now the degree of difficulty and percent wrong graphs work correctly.  There
data is based off of the cached statistical data.

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonproblemstatistics.pm,v 1.22 2002/08/13 15:01:07 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: my $jr;
   47: 
   48: sub BuildProblemStatisticsPage {
   49:     my ($cacheDB, $students, $courseID, $c, $r)=@_;
   50:     my %cache;
   51: 
   52:     $jr = $r;
   53: 
   54:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
   55:         $r->print('Unable to tie database.');
   56:         return;
   57:     }
   58: 
   59:     my $Ptr = '';
   60:     $Ptr .= '<table border="0"><tbody>';
   61:     $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
   62:     $Ptr .= '<td align="left">';
   63:     $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
   64:                                                'Statistics');
   65:     $Ptr .= '</td></tr>'."\n";
   66:     $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
   67:     $Ptr .= '<td align="left">'."\n";
   68:     $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
   69:                                             $cache{'ProblemStatisticsAscend'}, 
   70:                                             'ProblemStatistics',
   71:                                             'Statistics');
   72:     $Ptr .= '</td></tr>'."\n";
   73:     $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}, 
   74:                                       $cache{'DisplayLegend'});
   75:     $Ptr .= '</table>';
   76:     if($cache{'DisplayLegend'} eq 'Show Legend') {
   77:         $Ptr .= &ProblemStatisticsLegend();
   78:     }
   79:     $r->print($Ptr);
   80:     $r->rflush();
   81: 
   82:     my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
   83:                   "Mean","#YES","#yes","%Wrng","DoDiff",
   84:                   "S.D.","Skew.","D.F.1st","D.F.2nd","Disc.");
   85:     my $color=&setbgcolor(0);
   86: 
   87: #    my %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);
   88: #    my ($upper, $lower) = &Discriminant(\%discriminant,$r);
   89:     if(!defined($cache{'StatisticsCached'})) {
   90:         untie(%cache);
   91:         &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
   92:                                                                   'true',
   93:                                                                   $cacheDB,
   94:                                                                   'true', 
   95:                                                                   'true',
   96:                                                                   $courseID,
   97:                                                                   $r, $c);
   98:         if($c->aborted()) { return; }
   99: 
  100:         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  101:             $r->print('Unable to tie database.');
  102:             return;
  103:         }
  104:         my ($problemData) = &ExtractStudentData(\%cache, $students);
  105:         &CalculateStatistics($problemData);
  106:         untie(%cache);
  107: 
  108:         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
  109:             $r->print('Unable to tie database.');
  110:             return;
  111:         }
  112:         foreach(keys(%$problemData)) {
  113:             $cache{$_} = $problemData->{$_};
  114:         }
  115:         $cache{'StatisticsCached'} = 'true';
  116:         untie(%cache);
  117: 
  118:         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  119:             $r->print('Unable to tie database.');
  120:             return;
  121:         }
  122:     }
  123:     my $orderedProblems = &SortProblems(\%cache, 
  124:                                         $cache{'ProblemStatisticsSort'},
  125:                                         $cache{'ProblemStatisticsAscend'});
  126:     &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, $orderedProblems, 
  127:                           \@Header, $r, $color);
  128:     untie(%cache);
  129: 
  130:     return;
  131: }
  132: 
  133: 
  134: #---- Problem Statistics Web Page ---------------------------------------
  135: 
  136: sub CreateProblemStatisticsTableHeading {
  137:     my ($headings,$r)=@_;
  138: 
  139:     my $Str='';
  140:     $Str .= '<tr>'."\n";
  141:     $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
  142:     foreach(@$headings) {
  143: 	$Str .= '<th bgcolor="#ffffe6">'.'<a href="/adm/statistics?reportSelected=';
  144:         $Str .= &Apache::lonnet::escape('Problem Statistics');
  145:         $Str .= '&ProblemStatisticsSort=';
  146:         $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a>&nbsp</th>'."\n";
  147:     }
  148:     $Str .= "\n".'</tr>'."\n";    
  149: 
  150:     return $Str;
  151: }
  152: 
  153: sub BuildStatisticsTable {
  154:     my ($cache,$displayFormat,$orderedProblems,$headings,$r,$color)=@_;
  155: 
  156: #6666666
  157: #    my $file="/home/httpd/perl/tmp/183d.txt";
  158: #    open(OUT, ">$file");
  159: #6666666
  160: ##     &Apache::lonstatistics::Create_PrgWin($r);
  161: ##777777
  162: ##    my (%Activity) = &LoadActivityLog();
  163: ##    $r->print('<script>popwin.document.popremain.remaining.value="'.
  164: ##              'Loading Discussion...";</script>');
  165: ##    my ($doDiffFile) = &LoadDoDiffFile();
  166: 
  167: ##777777
  168: ##    $Str .= &Classify($discriminantFactor, $students);
  169: 
  170:      if($displayFormat ne 'Display CSV Format') {
  171:         $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
  172:         $r->print('<table border="0" cellpadding="3">'."\n");
  173:         $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
  174:     } else {
  175:         $r->print('<br>');
  176:     }
  177: 
  178:     my $count = 1;
  179:     foreach(@$orderedProblems) {
  180:         my ($sequence,$problem,$part)=split(':', $_);
  181: #        if($cache->{'ProblemStatisticsMaps'} ne 'All Maps'  &&
  182: #           $cache->{'ProblemStatisticsMaps'} ne $cache->{$sequence.':title'}) {
  183: #            next;
  184: #        }
  185: 
  186: 
  187:         my $ref = '<a href="'.$cache->{$problem.':source'}.
  188:                   '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
  189: #        my $ref = $cache->{$problem.':title'};
  190:         my $title = $cache->{$problem.':title'};
  191:         my $source = 'source';
  192:         my $tableData = join('&', $ref, $title, $source,
  193:                        $cache->{$_.':studentCount'},
  194:                        $cache->{$_.':totalTries'},
  195:                        $cache->{$_.':maxTries'},
  196:                        sprintf("%.2f", $cache->{$_.':mean'}),
  197:                        $cache->{$_.':correct'},
  198:                        $cache->{$_.':correctByOverride'},
  199:                        sprintf("%.1f", $cache->{$_.':percentWrong'}),
  200:                        sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}),
  201:                        sprintf("%.1f", $cache->{$_.':standardDeviation'}),
  202:                        sprintf("%.1f", $cache->{$_.':skewness'}),
  203:                        sprintf("%.2f", $cache->{$_.':discriminationFactor1'}),
  204:                        sprintf("%.2f", $cache->{$_.':discriminationFactor2'}),
  205:                        0); # 0 is for discussion, need to figure out
  206: 
  207: #6666666
  208: #	    $r->print('<br>'.$out.'&'.$DoD);
  209: #            print (OUT $out.'@'.$DoD.'&');
  210: #6666666
  211: 
  212: #check with Gerd
  213: #        $urlres=~/^(\w+)\/(\w+)/;
  214: #        if ($StdNo) {
  215: #            &Apache::lonnet::put('nohist_resevaldata',\%storestats,
  216: #                                 $1,$2);
  217: #        }
  218: #-------------------------------- Row of statistical table
  219:         &TableRow($displayFormat,$tableData,$count,$r,$color);
  220:         $count++;
  221:     }
  222:     if($cache->{'DisplayFormat'} ne 'Display CSV Format') {
  223:         $r->print('</table>'."\n");
  224:     }
  225:     $r->print('</td></tr></table>');
  226: #6666666
  227: #    close( OUT );
  228: #666666
  229:     return;
  230: }
  231: 
  232: sub TableRow {
  233:     my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
  234:     my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
  235:        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);	
  236:     my $Ptr;
  237:     if($displayFormat eq 'Display CSV Format') {
  238:         $Ptr="\n".'<br>'.
  239:              "\n".'"'.$RealIdx.'",'.
  240:              "\n".'"'.$title.'",'.
  241:              "\n".'"'.$source.'",'.
  242:              "\n".'"'.$StdNo.'",'.
  243:              "\n".'"'.$TotalTries.'",'.
  244:              "\n".'"'.$MxTries.'",'.
  245:              "\n".'"'.$Avg.'",'.
  246:              "\n".'"'.$YES.'",'.
  247:              "\n".'"'.$Override.'",'.
  248:              "\n".'"'.$Wrng.'",'.
  249:              "\n".'"'.$DoD.'",'.
  250:              "\n".'"'.$SD.'",'.
  251:              "\n".'"'.$Sk.'",'.
  252:              "\n".'"'.$_D1.'",'.
  253: 	     "\n".'"'.$_D2.'"'.
  254: 	     "\n".'"'.$DiscNo.'"';
  255: 
  256:         $r->print("\n".$Ptr);
  257:     } else {
  258:         $Ptr="\n".'<tr>'.
  259:              "\n".'<td bgcolor="#ffffe6">'.$RealIdx.'</td>'.
  260:              "\n".'<td bgcolor="#ffffe6">'.$ref.'</td>'.
  261:              "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'.
  262:              "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'.
  263:              "\n".'<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'.
  264:              "\n".'<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'.
  265:              "\n".'<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'.
  266:              "\n".'<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'.
  267:              "\n".'<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'.
  268:              "\n".'<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'.
  269:              "\n".'<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'.
  270:              "\n".'<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'.
  271:              "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'.
  272: 	     "\n".'<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'.
  273:              "\n".'<td bgcolor='.$color->{"yellow"}.'> '.$DiscNo.'</td>';
  274:         $r->print("\n".$Ptr.'</tr>' );
  275:     }
  276: 
  277:     return;
  278: }
  279: 
  280: # For loading the colored table for display or un-colored for print
  281: sub setbgcolor {
  282:     my $PrintTable=shift;
  283:     my %color;
  284:     if ($PrintTable){
  285: 	$color{"gb"}="#FFFFFF";
  286: 	$color{"red"}="#FFFFFF";
  287: 	$color{"yellow"}="#FFFFFF";
  288: 	$color{"green"}="#FFFFFF";
  289: 	$color{"purple"}="#FFFFFF";
  290:     } else {
  291: 	$color{"gb"}="#DDFFFF";
  292: 	$color{"red"}="#FFDDDD";
  293: 	$color{"yellow"}="#EEFFCC";
  294: 	$color{"green"}="#DDFFDD";
  295: 	$color{"purple"}="#FFDDFF";
  296:     }
  297: 
  298:     return \%color;
  299: }
  300: 
  301: sub ProblemStatisticsButtons {
  302:     my ($displayFormat, $displayLegend)=@_;
  303: 
  304:     my $Ptr = '<tr><td></td><td align="left">';
  305:     $Ptr .= '<input type="submit" name="DoDiffGraph" ';
  306:     $Ptr .= 'value="DoDiff Graph" />'."\n";
  307:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  308:     $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
  309:     $Ptr .= 'value="%Wrong Graph" />'."\n";
  310:     $Ptr .= '</td></tr><tr><td></td><td>'."\n";
  311:     $Ptr .= '<input type="submit" name="DisplayLegend" ';
  312:     if($displayLegend eq 'Show Legend') {
  313:         $Ptr .= 'value="Hide Legend" />'."\n";
  314:     } else {
  315:         $Ptr .= 'value="Show Legend" />'."\n";
  316:     }
  317:     $Ptr .= '&nbsp;&nbsp;&nbsp;';
  318:     $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
  319:     if($displayFormat eq 'Display CSV Format') {
  320:         $Ptr .= 'value="Display Table Format" />'."\n";
  321:     } else {
  322:         $Ptr .= 'value="Display CSV Format" />'."\n";
  323:     }
  324:     $Ptr .= '</td></tr>';
  325: 
  326:     return $Ptr;
  327: }
  328: 
  329: sub ProblemStatisticsLegend {
  330:     my $Ptr = '';
  331:     $Ptr = '<table border="0">';
  332:     $Ptr .= '<tr><td>';
  333:     $Ptr .= '<b>#Stdnts</b></td>';
  334:     $Ptr .= '<td>Total number of students attempted the problem.';
  335:     $Ptr .= '</td></tr><tr><td>';
  336:     $Ptr .= '<b>Tries</b></td>';
  337:     $Ptr .= '<td>Total number of tries for solving the problem.';
  338:     $Ptr .= '</td></tr><tr><td>';
  339:     $Ptr .= '<b>Mod</b></td>';
  340:     $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
  341:     $Ptr .= '</td></tr><tr><td>';
  342:     $Ptr .= '<b>Mean</b></td>';
  343:     $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
  344:     $Ptr .= '</td></tr><tr><td>';
  345:     $Ptr .= '<b>#YES</b></td>';
  346:     $Ptr .= '<td>Number of students solved the problem correctly.';
  347:     $Ptr .= '</td></tr><tr><td>';
  348:     $Ptr .= '<b>#yes</b></td>';
  349:     $Ptr .= '<td>Number of students solved the problem by override.';
  350:     $Ptr .= '</td></tr><tr><td>';
  351:     $Ptr .= '<b>%Wrong</b></td>';
  352:     $Ptr .= '<td>Percentage of students who tried to solve the problem ';
  353:     $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
  354:     $Ptr .= '</td></tr><tr><td>';
  355:     $Ptr .= '<b>DoDiff</b></td>';
  356:     $Ptr .= '<td>Degree of Difficulty of the problem.  ';
  357:     $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
  358:     $Ptr .= '</td></tr><tr><td>';
  359:     $Ptr .= '<b>S.D.</b></td>';
  360:     $Ptr .= '<td>Standard Deviation of the tries.  ';
  361:     $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
  362:     $Ptr .= 'where Xi denotes every student\'s tries ]';
  363:     $Ptr .= '</td></tr><tr><td>';
  364:     $Ptr .= '<b>Skew.</b></td>';
  365:     $Ptr .= '<td>Skewness of the students tries.';
  366:     $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
  367:     $Ptr .= '</td></tr><tr><td>';
  368:     $Ptr .= '<b>Dis.F.</b></td>';
  369:     $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
  370:     $Ptr .= 'problem according to a Criterion<br>';
  371:     $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
  372:     $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
  373:     $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
  374:     $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
  375:     $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
  376:     $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
  377:     $Ptr .= '</td></tr>';
  378:     $Ptr .= '<tr><td><b>Disc.</b></td>';
  379:     $Ptr .= '<td>Number of Students had at least one discussion.';
  380:     $Ptr .= '</td></tr></table>';
  381: 
  382:     return $Ptr;
  383: }
  384: 
  385: #------- Processing upperlist and lowerlist according to each problem
  386: 
  387: sub ExtractStudentData {
  388:     my ($cache, $students)=@_;
  389: 
  390: #$Apache::lonxml::debug=1;
  391: #&Apache::lonhomework::showhash(%$cache);
  392: #$Apache::lonxml::debug=0;
  393: 
  394:     my @problemList=();
  395:     my %problemData;
  396:     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
  397:         foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
  398:             foreach my $part (split(/\:/,$cache->{$sequence.':'.
  399:                                                   $problemID.
  400:                                                   ':parts'})) {
  401:                 my $id = $sequence.':'.$problemID.':'.$part;
  402:                 push(@problemList, $id);
  403:                 my $totalTries = 0;
  404:                 my $totalAwarded = 0;
  405:                 my $correct = 0;
  406:                 my $correctByOverride = 0;
  407:                 my $studentCount = 0;
  408:                 my $maxTries = 0;
  409:                 my $totalFirst = 0;
  410:                 my @studentTries=();
  411:                 foreach(@$students) {
  412:                     my $code = $cache->{"$_:$problemID:$part:code"};
  413: 
  414:                     if(defined($cache->{$_.':error'}) || $code eq ' ' ||
  415:                        $cache->{"$_:$problemID:NoVersion"} eq 'true') {
  416:                         next;
  417:                     }
  418: 
  419:                     $studentCount++;
  420:                     my $tries =  $cache->{"$_:$problemID:$part:tries"};
  421:                     if($maxTries < $tries) {
  422:                         $maxTries = $tries;
  423:                     }
  424:                     $totalTries += $tries;
  425:                     push(@studentTries, $tries);
  426: 
  427:                     my $awarded = $cache->{"$_:$problemID:$part:awarded"};
  428:                     $totalAwarded += $awarded;
  429: 
  430:                     if($code eq '*') {
  431:                         $correct++;
  432:                         if($tries == 1) {
  433:                             $totalFirst++;
  434:                         }
  435:                     } elsif($code eq '+') {
  436:                         $correctByOverride++;
  437:                     }
  438:                 }
  439: 
  440:                 $problemData{$id.':sequenceTitle'} = 
  441:                     $cache->{$sequence.':title'};
  442:                 $problemData{$id.':studentCount'} = $studentCount;
  443:                 $problemData{$id.':totalTries'} = $totalTries;
  444:                 $problemData{$id.':studentTries'} = \@studentTries;
  445:                 $problemData{$id.':totalAwarded'} = $totalAwarded;
  446:                 $problemData{$id.':correct'} = $correct;
  447:                 $problemData{$id.':correctByOverride'} = $correctByOverride;
  448:                 $problemData{$id.':wrong'} = $studentCount - 
  449:                                              ($correct + $correctByOverride);
  450:                 $problemData{$id.':maxTries'} = $maxTries;
  451:                 $problemData{$id.':totalFirst'} = $totalFirst;
  452:             }
  453:         }
  454:     }
  455: 
  456:     $problemData{'problemList'} = join(':::', @problemList);
  457: #                $Discussed=0;
  458: #                if($Discuss->{"$name:$problem"}) {
  459: #		    $TotDiscuss++;
  460: #                    $Discussed=1;
  461: #                }
  462: 
  463:     return \%problemData;
  464: }
  465: 
  466: sub SortProblems {
  467:     my ($problemData,$sortBy,$ascend)=@_;
  468: 
  469:     my @problems = split(':::', $problemData->{'problemList'});
  470:     if($sortBy eq "Homework Sets Order") {
  471:         return \@problems;
  472:     }
  473: 
  474:     my $data;
  475: 
  476:     if   ($sortBy eq "#Stdnts") { $data = ':studentCount'; }
  477:     elsif($sortBy eq "Tries")   { $data = ':totalTries'; }
  478:     elsif($sortBy eq "Mod")     { $data = ':maxTries'; }
  479:     elsif($sortBy eq "Mean")    { $data = ':mean'; }
  480:     elsif($sortBy eq "#YES")    { $data = ':correct'; }
  481:     elsif($sortBy eq "#yes")    { $data = ':correctByOverride'; }
  482:     elsif($sortBy eq "%Wrng")   { $data = ':percentWrong'; }
  483:     elsif($sortBy eq "DoDiff")  { $data = ':degreeOfDifficulty'; }
  484:     elsif($sortBy eq "S.D.")    { $data = ':standardDeviation'; }
  485:     elsif($sortBy eq "Skew.")   { $data = ':skewness'; }
  486:     elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; }
  487:     elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; }
  488:     elsif($sortBy eq "Disc.")   { $data = ''; }
  489:     else                        { return \@problems; }
  490: 
  491:     my @orderedProblems = 
  492:         sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
  493:              @problems;
  494:     if($ascend eq 'Descending') {
  495:         @orderedProblems = reverse(@orderedProblems);
  496:     }
  497: 
  498:     return \@orderedProblems;
  499: }
  500: 
  501: sub CalculateStatistics {
  502:     my ($data)=@_;
  503: 
  504:     my @problems = split(':::', $data->{'problemList'});
  505:     foreach(@problems) {
  506:         # Mean
  507:         $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ? 
  508:             ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
  509: 
  510:         # %Wrong
  511:         $data->{$_.':percentWrong'} = ($data->{$_.':studentCount'}) ?
  512:             (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) : 
  513:             100.0;
  514: 
  515:         # Degree of Difficulty
  516:         $data->{$_.':degreeOfDifficulty'} = ($data->{$_.':totalTries'}) ?
  517:             (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
  518:                   $data->{$_.':totalTries'})) : 0;
  519: 
  520:         # Factor in mean
  521:         my $studentTries = $data->{$_.':studentTries'};
  522:         foreach(my $index=0; $index < scalar(@$studentTries); $index++) {
  523:             $studentTries->[$index] -= $data->{$_.':mean'};
  524:         }
  525:         my $sumSquared = 0;
  526:         my $sumCubed = 0;
  527:         foreach(@$studentTries) {
  528:             my $squared = ($_ * $_);
  529:             my $cubed = ($squared * $_);
  530:             $sumSquared += $squared;
  531:             $sumCubed += $cubed;
  532:         }
  533: 
  534:         # Standard deviation
  535:         $data->{$_.':standardDeviation'} = ($data->{$_.':studentCount'} - 1) ?
  536:             ((sqrt($sumSquared)) / ($data->{$_.':studentCount'} - 1)) : 0;
  537: 
  538:         # Skewness
  539:         my $standardDeviation = $data->{$_.':standardDeviation'};
  540:         $data->{$_.':skewness'} = ($data->{$_.':standardDeviation'}) ?
  541:             (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) / 
  542:              ($standardDeviation * $standardDeviation * $standardDeviation)) :
  543:              0;
  544: 
  545:         # Discrimination Factor 1
  546:         $data->{$_.':discriminationFactor1'} = 0;
  547: 
  548:         # Discrimination Factor 2
  549:         $data->{$_.':discriminationFactor2'} = 0;
  550:     }
  551: 
  552:     return;
  553: }
  554: 
  555: sub ProcessDiscriminant {
  556:     my ($List) = @_;
  557:     my @sortedList = sort (@$List);
  558:     my $Count = scalar @sortedList;
  559:     my $Problem;
  560:     my @Dis;
  561:     my $Slvd=0;
  562:     my $tmp;
  563:     my $Sum1=0;
  564:     my $Sum2=0;
  565:     my $nIndex=0;
  566:     my $nStudent=0;
  567:     my %Proc=undef;
  568:     while ($nIndex<$Count) {
  569: #        $jr->print("<br> $nIndex) $sortedList[$nIndex]");
  570: 	($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
  571: 	@Dis=split(/\+/,$tmp);
  572: 	my $Temp = $Problem;
  573: 	do {
  574: 	    $nIndex++;
  575: 	    $nStudent++;
  576: 	    $Sum1 += $Dis[0];
  577: 	    $Sum2 += $Dis[1];
  578: 	    ($Problem,$tmp)=split(/\=/,$sortedList[$nIndex]);
  579: 	    @Dis=split(/\+/,$tmp);
  580: 	} while ( $Problem eq $Temp && $nIndex < $Count );
  581: 	$Proc{$Temp}=($Sum1/$nStudent).':'.($Sum2/$nStudent);
  582: #        $jr->print("<br> $nIndex) $Temp --> ($nStudent) $Proc{$Temp}");
  583: 	$Sum1=0;
  584: 	$Sum2=0;
  585: 	$nStudent=0;
  586:     }
  587: 
  588:     return %Proc;
  589: }
  590: 
  591: #------- Creating Discimination factor   
  592: sub Discriminant {
  593:     my ($discriminant)=@_;
  594:     my @discriminantKeys=keys(%$discriminant);
  595:     my $Count = scalar @discriminantKeys;
  596: 
  597:     my $UpCnt = int(0.27*$Count);
  598:     my $low=0;
  599:     my $up=$Count-$UpCnt;
  600:     my @UpList=();
  601:     my @LowList=();
  602: 
  603:     $Count=0;
  604:     foreach my $key (sort(@discriminantKeys)) { 
  605: 	$Count++;    
  606: 	if($low < $UpCnt || $Count > $up) {
  607:             $low++;
  608:             my $str=$discriminant->{$key};
  609:             foreach(split(/\&/,$str)){
  610:                 if($_) {
  611:                     if($low<$UpCnt) { push(@LowList,$_); }
  612:                     else            { push(@UpList,$_);  }
  613:                 }
  614:             }
  615:         }
  616:     }
  617:     my %DisUp =  &ProcessDiscriminant(\@UpList);
  618:     my %DisLow = &ProcessDiscriminant(\@LowList);
  619: 
  620:     return (\%DisUp, \%DisLow);
  621: }   
  622: 
  623: #---- END Problem Statistics Web Page ----------------------------------------
  624: 
  625: #---- Problem Statistics Graph Web Page --------------------------------------
  626: 
  627: # ------------------------------------------- Prepare data for Graphical chart
  628: 
  629: sub BuildGraphicChart {
  630:     my ($graph,$cacheDB,$courseDescription,$r)=@_;
  631:     my %cache;
  632:     my $max = 0;
  633: 
  634:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  635:         return '<html><body>Unable to tie database.</body></html>';
  636:     }
  637:    
  638:     my @problems = split(':::', $cache{'problemList'});
  639:     my @values = ();
  640:     foreach (@problems) {
  641:         my $data = 0;
  642:         if($graph eq 'DoDiffGraph') {
  643:             $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
  644:         } else {
  645:             $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
  646:         }
  647:         if($max < $data) {
  648:             $max = $data;
  649:         }
  650:         push(@values, $data);
  651:     }
  652:     untie(%cache);
  653: 
  654:     my $sendValues = join(',', @values);
  655: #    my $sendCount = $#values;
  656:     my $sendCount = scalar(@values);
  657: 
  658:     my $title = '';
  659:     if($graph eq 'DoDiffGraph') {
  660: 	$title = 'Degree-of-Difficulty';
  661:     } else {
  662: 	$title = 'Wrong-Percentage';
  663:     }
  664:     my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount, 
  665:                  $sendValues);
  666: 
  667:     $r->print('</form>'."\n");
  668:     $r->print('<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData)).'" border="1" />');
  669:     $r->print('<form>'."\n");
  670: 
  671:     return;
  672: }
  673: 
  674: 1;
  675: __END__

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