File:  [LON-CAPA] / loncom / interface / statistics / lonproblemstatistics.pm
Revision 1.43: download - view: text, annotated - select for diffs
Wed Mar 26 16:26:35 2003 UTC (21 years, 3 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Changes to prevent the display of the problem part when all the problems
ONLY have a part 0.
Reworked the logic on sorting in &output_html_ungrouped.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lonproblemstatistics.pm,v 1.43 2003/03/26 16:26:35 matthew Exp $
    4: #
    5: # Copyright Michigan State University Board of Trustees
    6: #
    7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    8: #
    9: # LON-CAPA is free software; you can redistribute it and/or modify
   10: # it under the terms of the GNU General Public License as published by
   11: # the Free Software Foundation; either version 2 of the License, or
   12: # (at your option) any later version.
   13: #
   14: # LON-CAPA is distributed in the hope that it will be useful,
   15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17: # GNU General Public License for more details.
   18: #
   19: # You should have received a copy of the GNU General Public License
   20: # along with LON-CAPA; if not, write to the Free Software
   21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22: #
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: # (Navigate problems for statistical reports
   28: #
   29: ###
   30: 
   31: package Apache::lonproblemstatistics;
   32: 
   33: use strict;
   34: use Apache::lonnet();
   35: use Apache::lonhtmlcommon;
   36: use Apache::loncoursedata;
   37: use Apache::lonstatistics;
   38: 
   39: #######################################################
   40: #######################################################
   41: 
   42: sub CreateInterface {
   43:     my $Str = '';
   44:     $Str .= '<table cellspacing="5">'."\n";
   45:     $Str .= '<tr>';
   46:     $Str .= '<td align="center"><b>Sections</b></td>';
   47:     $Str .= '<td align="center"><b>Sequences and Folders</b></td>';
   48:     $Str .= '<td align="center"><b>Output</b></td>';
   49:     $Str .= '</tr>'."\n";
   50:     #
   51:     $Str .= '<tr><td align="center">'."\n";
   52:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
   53:     $Str .= '</td><td align="center">';
   54:     #
   55:     my $only_seq_with_assessments = sub { 
   56:         my $s=shift;
   57:         if ($s->{'num_assess'} < 1) { 
   58:             return 0;
   59:         } else { 
   60:             return 1;
   61:         }
   62:     };
   63:     $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
   64:                                               $only_seq_with_assessments);
   65:     $Str .= '</td><td>'."\n";
   66:     $Str .= &CreateAndParseOutputSelector();
   67:     $Str .= '</td></tr>'."\n";
   68:     $Str .= '</table>'."\n";
   69:     return $Str;
   70: }
   71: 
   72: #######################################################
   73: #######################################################
   74: 
   75: =pod
   76: 
   77: =item &CreateAndParseOutputSelector()
   78: 
   79: =cut
   80: 
   81: #######################################################
   82: #######################################################
   83: my $output_mode;
   84: my $show;
   85: 
   86: my @OutputOptions = 
   87:     (
   88:      { name  => 'problem statistics grouped by sequence',
   89:        value => 'HTML problem statistics grouped',
   90:        description => 'Output statistics for the problem parts.',
   91:        mode => 'html',
   92:        show => 'grouped',
   93:      },
   94:      { name  => 'problem statistics ungrouped',
   95:        value => 'HTML problem statistics ungrouped',
   96:        description => 'Output statistics for the problem parts.',
   97:        mode => 'html',
   98:        show => 'ungrouped',
   99:      },
  100:      { name  => 'problem statistics, Excel',
  101:        value => 'Excel problem statistics',
  102:        description => 'Output statistics for the problem parts '.
  103:            'in an Excel workbook',
  104:        mode => 'excel',
  105:        show => 'all',
  106:      },
  107:      { name  => 'Degree of Difficulty Plot',
  108:        value => 'plot deg diff',
  109:        description => 'Generate a plot of the degree of difficulty of each '.
  110:            'problem part.',
  111:        mode => 'plot',
  112:        show => 'deg of diff',
  113:      },
  114:      { name  => 'Percent Wrong Plot',
  115:        value => 'plot per wrong',
  116:        description => 'Generate a plot showing the percent of students who '.
  117:            'were unable to complete each problem part',
  118:        mode => 'plot',
  119:        show => 'per wrong',
  120:      },
  121:      );
  122: 
  123: sub OutputDescriptions {
  124:     my $Str = '';
  125:     $Str .= "<h2>Output Modes</h2>\n";
  126:     $Str .= "<dl>\n";
  127:     foreach my $outputmode (@OutputOptions) {
  128: 	$Str .="    <dt>".$outputmode->{'name'}."</dt>\n";
  129: 	$Str .="        <dd>".$outputmode->{'description'}."</dd>\n";
  130:     }
  131:     $Str .= "</dl>\n";
  132:     return $Str;
  133: }
  134: 
  135: sub CreateAndParseOutputSelector {
  136:     my $Str = '';
  137:     my $elementname = 'outputmode';
  138:     #
  139:     # Format for output options is 'mode, restrictions';
  140:     my $selected = 'html, with links';
  141:     if (exists($ENV{'form.'.$elementname})) {
  142:         if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
  143:             $selected = $ENV{'form.'.$elementname}->[0];
  144:         } else {
  145:             $selected = $ENV{'form.'.$elementname};
  146:         }
  147:     }
  148:     #
  149:     # Set package variables describing output mode
  150:     $output_mode = 'html';
  151:     $show        = 'all';
  152:     foreach my $option (@OutputOptions) {
  153:         next if ($option->{'value'} ne $selected);
  154:         $output_mode = $option->{'mode'};
  155:         $show        = $option->{'show'};
  156:     }
  157:     #
  158:     # Build the form element
  159:     $Str = qq/<select size="5" name="$elementname">/;
  160:     foreach my $option (@OutputOptions) {
  161:         $Str .= "\n".'    <option value="'.$option->{'value'}.'"';
  162:         $Str .= " selected " if ($option->{'value'} eq $selected);
  163:         $Str .= ">".$option->{'name'}."<\/option>";
  164:     }
  165:     $Str .= "\n</select>";
  166:     return $Str;
  167: }
  168: 
  169: ###############################################
  170: ###############################################
  171: 
  172: ###############################################
  173: ###############################################
  174: sub Gather_Student_Data {
  175:     my ($r) = @_;
  176:     my $c = $r->connection();
  177:     #
  178:     my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
  179:     #
  180:     my @Students = @Apache::lonstatistics::Students;
  181:     #
  182:     # Open the progress window
  183:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
  184:         ($r,'Statistics Compilation Status',
  185:          'Statistics Compilation Progress', scalar(@Students));
  186:     #
  187:     while (my $student = shift @Students) {
  188:         return if ($c->aborted());
  189:         my ($status,undef) = &Apache::loncoursedata::ensure_current_data
  190:             ($student->{'username'},$student->{'domain'},
  191:              $ENV{'request.course.id'});
  192:         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
  193:                                                  'last student');
  194:     }
  195:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  196:     $r->rflush();
  197: }
  198: 
  199: ###############################################
  200: ###############################################
  201: 
  202: ###############################################
  203: ###############################################
  204: sub BuildProblemStatisticsPage {
  205:     my ($r,$c)=@_;
  206:     #
  207:     $output_mode = 'html';
  208:     $show = 'grouped';
  209:     #
  210:     $r->print(&CreateInterface());
  211:     $r->print('<input type="hidden" name="statsfirstcall" value="no" />');
  212:     $r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}.
  213:               '" />');
  214:     if (! exists($ENV{'form.statsfirstcall'})) {
  215:         return;
  216:     }
  217:     #
  218:     &Gather_Student_Data($r);
  219:     #
  220:     #
  221:     if ($output_mode eq 'html') {
  222:         $r->print("<h2>".
  223:                   $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
  224:                   "</h2>\n");
  225:         $r->print("<h3>".localtime(time)."</h3>");
  226:         $r->rflush();
  227:         if ($show eq 'grouped') {
  228:             &output_html_grouped_by_sequence($r);
  229:         } elsif ($show eq 'ungrouped') {
  230:             &output_html_ungrouped($r);
  231:         }
  232:     } else {
  233:         $r->print("<h1>Not implemented</h1>");
  234:     }
  235:     return;
  236: }
  237: 
  238: sub output_html_grouped_by_sequence {
  239:     my ($r) = @_;
  240:     #$r->print(&ProblemStatisticsLegend());
  241:     my @Header = ("Title","Part","#Stdnts","Tries","Mod",
  242:                   "Mean","#YES","#yes","%Wrng","DoDiff",
  243:                   "S.D.","Skew.");#,"D.F.1st","D.F.2nd");
  244:     # #FFFFE6 #EEFFCC #DDFFFF FFDDDD #DDFFDD #FFDDFF
  245:     foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
  246:         my $show_part = 0;
  247:         next if ($sequence->{'num_assess'}<1);
  248:         $r->print("<h3>".$sequence->{'title'}."</h3>");
  249:         $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
  250:         $r->print('<table border="0" cellpadding="3">'."\n");
  251:         $r->print('<tr bgcolor="#FFFFE6"><th>'.
  252:                   join("</th><th>",@Header)."</th></tr>\n");
  253:         foreach my $resource (@{$sequence->{'contents'}}) {
  254:             next if ($resource->{'type'} ne 'assessment');
  255:             foreach my $part (@{$resource->{'parts'}}) {
  256:                 my ($num,$tries,$mod,$mean,$Solved,$solved,$DegOfDiff,$STD,
  257:                     $SKEW) = &Apache::loncoursedata::get_problem_statistics
  258:                         (undef,$resource->{'symb'},$part,
  259:                          $ENV{'request.course.id'});
  260:                 #
  261:                 $show_part = 1 if ($part ne '0');
  262:                 $part = '&nbsp;' if ($part == 0);
  263:                 #
  264:                 my $wrongpercent = 0;
  265:                 if (defined($num) && $num > 0) {
  266:                     $wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
  267:                 }
  268:                 $r->print('<tr>'.&statistics_html_table_data
  269:                           ($resource,$part,$num,$tries,$mod,$mean,$Solved,
  270:                            $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW,
  271:                            $show_part).
  272:                           "</tr>\n");
  273:             }
  274:         }
  275:         $r->print("</table>\n");
  276:         $r->print("</td></tr></table>\n");
  277:         $r->rflush();
  278:     }
  279:     #
  280:     return;
  281: }
  282: 
  283: 
  284: ###############################################
  285: ###############################################
  286: 
  287: ###############################################
  288: ###############################################
  289: sub output_html_ungrouped {
  290:     my ($r) = @_;
  291:     #
  292:     my $show_container = 0;
  293:     my $show_part = 0;
  294:     #$r->print(&ProblemStatisticsLegend());
  295:     my @Header = ("Title","Part","#Stdnts","Tries","Mod",
  296:                   "Mean","#YES","#yes","%Wrng","DoDiff",
  297:                   "S.D.","Skew");#,"D.F.1st","D.F.2nd");
  298:     #
  299:     my $sortby = undef;
  300:     foreach (@Header) {
  301:         if ($ENV{'form.sortby'} eq $_) {
  302:             $sortby = $_;
  303:         }
  304:     }
  305:     if (! defined($sortby) || $sortby eq '') {
  306:         $sortby = 'Container';
  307:     }
  308:     # #FFFFE6 #EEFFCC #DDFFFF FFDDDD #DDFFDD #FFDDFF
  309:     my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
  310:     if (@Sequences > 1) {
  311:         unshift(@Header,"Container");
  312:         $show_container = 1;
  313:     }
  314:     #
  315:     $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
  316:     $r->rflush();
  317:     #
  318:     # Compile the data
  319:     my @Statsarray;
  320:     foreach my $sequence (@Sequences) {
  321:         next if ($sequence->{'num_assess'}<1);
  322:         foreach my $resource (@{$sequence->{'contents'}}) {
  323:             next if ($resource->{'type'} ne 'assessment');
  324:             foreach my $part (@{$resource->{'parts'}}) {
  325:                 my ($num,$tries,$mod,$mean,$Solved,$solved,$DegOfDiff,$STD,
  326:                     $SKEW) = &Apache::loncoursedata::get_problem_statistics
  327:                         (undef,$resource->{'symb'},$part,
  328:                          $ENV{'request.course.id'});
  329:                 #
  330:                 $show_part = 1 if ($part ne '0');
  331:                 $part = '&nbsp;' if ($part == 0);
  332:                 #
  333:                 my $wrongpercent = 0;
  334:                 if (defined($num) && $num > 0) {
  335:                     $wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
  336:                 }
  337:                 push (@Statsarray,
  338:                       { 'sequence' => $sequence,
  339:                         'resource' => $resource,
  340:                         'Title' => $resource->{'title'},
  341:                         'Part'  => $part,
  342:                         '#Stdnts' => $num,
  343:                         'Tries' => $tries,
  344:                         'Mod' => $mod,
  345:                         'Mean' => $mean,
  346:                         '#YES' => $Solved,
  347:                         '#yes' => $solved,
  348:                         '%Wrng' => $wrongpercent,
  349:                         'DoDiff' => $DegOfDiff,
  350:                         'S.D.' => $STD,
  351:                         'Skew' => $SKEW,
  352:                       });
  353:             }
  354:         }
  355:     }
  356:     #
  357:     # Table Headers
  358:     $r->print('<table border="0" cellpadding="3">'."\n");
  359:     my $Str = '';
  360:     foreach (@Header) {
  361:         next if ($_ eq 'Part' && !$show_part);
  362:         # Do not allow sorting on some fields
  363:         if ($_ eq $sortby || /^(Part)$/) {  
  364:             $Str .= '<th>'.$_.'</th>';
  365:         } else {
  366:             $Str .= '<th>'.
  367:      '<a href="javascript:document.Statistics.sortby.value='."'$_'".
  368:          ';document.Statistics.submit();">'.
  369:              $_.'</a></th>';
  370:         }
  371:     }
  372:     $r->print('<tr bgcolor="#FFFFE6">'.$Str."</tr>\n");
  373:     #
  374:     # Sort the data
  375:     my @OutputOrder;
  376:     if ($sortby eq 'Container') {
  377:         @OutputOrder = @Statsarray;
  378:     } else {
  379:         # $sortby is already defined, so we can charge ahead
  380:         if ($sortby =~ /^(title|part)$/i) {
  381:             # Alpha comparison
  382:             @OutputOrder = sort {
  383:                 lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
  384:                     lc($a->{'Title'}) cmp lc($b->{'Title'}) ||
  385:                         lc($a->{'Part'}) cmp lc($b->{'Part'});
  386:             } @Statsarray;
  387:         } else {
  388:             # Numerical comparison
  389:             @OutputOrder = sort {
  390:                 my $retvalue = 0;
  391:                 if ($b->{$sortby} eq 'nan') {
  392:                     if ($a->{$sortby} ne 'nan') {
  393:                         $retvalue = -1;
  394:                     } else {
  395:                         $retvalue = 0;
  396:                     }
  397:                 }
  398:                 if ($a->{$sortby} eq 'nan') {
  399:                     if ($b->{$sortby} ne 'nan') {
  400:                         $retvalue = 1;
  401:                     }
  402:                 }
  403:                 if ($retvalue eq '0') {
  404:                     $retvalue = $b->{$sortby} <=> $a->{$sortby} ||
  405:                                 lc($a->{'Title'}) <=> lc($b->{'Title'}) ||
  406:                                 lc($a->{'Part'})  <=> lc($b->{'Part'});
  407:                 }
  408:                 $retvalue;
  409:             } @Statsarray;
  410:         }
  411:     }
  412:     foreach my $row (@OutputOrder) {
  413:         $r->print('<tr>');
  414:         if ($show_container) {
  415:             $r->print('<td bgcolor="#FFFFE6">'
  416:                       .$row->{'sequence'}->{'title'}.'</td>');
  417:         }
  418:         $r->print(&stats_row_from_hash($row,$show_part));
  419:         $r->print("</tr>\n");
  420:     }
  421:     $r->print("</table>\n");
  422:     $r->print("</td></tr></table>\n");
  423:     $r->rflush();
  424:     #
  425:     return;
  426: }
  427: 
  428: sub stats_row_from_hash {
  429:     my ($data,$show_part) = @_;
  430:     return &statistics_html_table_data($data->{'resource'},$data->{'Part'},
  431:                                        $data->{'#Stdnts'}, $data->{'Tries'},
  432:                                        $data->{'Mod'},     $data->{'Mean'},
  433:                                        $data->{'#YES'},    $data->{'#yes'},
  434:                                        $data->{"\%Wrng"},  $data->{'DoDiff'},
  435:                                        $data->{'S.D.'},    $data->{'Skew'},
  436:                                        $show_part);
  437: }
  438: 
  439: ###############################################
  440: ###############################################
  441: 
  442: ###############################################
  443: ###############################################
  444: sub statistics_html_table_data {
  445:     my ($resource,$part,$num,$tries,$mod,$mean,$Solved,$solved,$wrongpercent,
  446:         $DegOfDiff,$STD,$SKEW,$show_part) = @_;
  447:     my $row = '';
  448:     $row .= '<td bgcolor="#FFFFE6">'.
  449:         '<a href="'.$resource->{'src'}.'" target="_blank" >'.
  450:             $resource->{'title'}.'</a>'.
  451:                 '</td>';
  452:     $row .= '<td bgcolor="#FFFFE6">'.$part.'</td>' if ($show_part);
  453:     foreach ($num,$tries) {
  454:         $row .= '<td bgcolor="#EEFFCC" align="right">'.$_.'</td>';
  455:     }
  456:     foreach ($mod,$mean) {
  457:         $row .= '<td bgcolor="#DDFFFF" align="right">'.
  458:                   sprintf("%5.2f",$_).'</td>';
  459:     }
  460:     foreach ($Solved,$solved) {
  461:         $row .= '<td bgcolor="#DDFFFF" align="right">'.$_.'</td>';
  462:     }
  463:     foreach ($wrongpercent) {
  464:         $row .= '<td bgcolor="#DDFFFF" align="right">'.
  465:                   sprintf("%5.1f",$_).'</td>';
  466:     }
  467:     foreach ($DegOfDiff,$STD,$SKEW) {
  468:         $row .= '<td bgcolor="#FFDDDD" align="right">'.
  469:                   sprintf("%5.2f",$_).'</td>';
  470:     }
  471:     return $row;
  472: }
  473: 
  474: 
  475: ###############################################
  476: ###############################################
  477: 
  478: sub BuildGraphicChart {
  479:     my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
  480:     my %cache;
  481:     my $max;
  482:     my $title = '';
  483:     if($graph eq 'DoDiffGraph') {
  484: 	$title = 'Degree-of-Difficulty';
  485:     } else {
  486: 	$title = 'Wrong-Percentage';
  487:     }
  488:     my $currentSequence = -1;
  489:     my $sortProblems = 'Sort Within Sequence';
  490:     my ($result, $orderedProblems) =
  491:         &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
  492:     if($result ne 'OK') {
  493:         return;
  494:     }
  495:     my @values = ();
  496:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  497:         return 'Unable to tie database.7';
  498:     }
  499:     foreach(@$orderedProblems) {
  500:         my ($sequence,$problem,$part)=split(':', $_);
  501:         if($cache{'StatisticsMaps'} ne 'All Maps'  &&
  502:            $cache{'StatisticsMaps'} ne $cache{$sequence.':title'}) {
  503:              next;
  504:         }
  505:         if( $currentSequence == -1 ||
  506:             ($sortProblems eq 'Sort Within Sequence' &&
  507:             $currentSequence != $sequence)) {
  508: 	    if($currentSequence != -1) {
  509: 		&DrawGraph(\@values,$courseDescription,$title,$max,$r);
  510: 	    }
  511:             if($sortProblems eq 'Sort Within Sequence') {
  512:                 $r->print('<br><b>'.$cache{$sequence.':title'}.'</b>'."\n");
  513:             }
  514:             $currentSequence = $sequence;
  515:             @values = ();
  516: 	    $max=0;
  517:         }
  518:         my $data = 0;
  519:         if($graph eq 'DoDiffGraph') {
  520:             $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
  521:         } else {
  522:             $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
  523:         }
  524:         if($max < $data) {
  525:             $max = $data;
  526:         }
  527:         push(@values, $data);
  528:     }
  529:     untie(%cache);
  530:     &DrawGraph(\@values,$courseDescription,$title,$max,$r);
  531:     return;
  532: }
  533: 
  534: sub DrawGraph {
  535:     my ($values,$courseDescription,$title,$Max,$r)=@_;
  536:     my $sendValues = join(',', @$values);
  537:     my $sendCount = scalar(@$values);
  538:     $r->print("<br>The Maximum Value is: $Max");
  539:     if ( $Max > 1 ) {
  540: 	if ($Max % 10) {
  541:             if ( int($Max) < $Max ) {
  542: 	    	$Max++;
  543: 		$Max = int($Max);
  544: 	    }
  545: 	}
  546:     #(10 - $Max % 10);
  547:     } else { $Max = 1; }
  548:     my @GData = ('','Problem_number',$title,$Max,$sendCount,$sendValues);
  549: #    $r->print('</form>'."\n");
  550:     $r->print('<br>'."\n");
  551:     $r->print('<IMG src="/cgi-bin/graph.png?'.
  552:               (join('&', @GData)).'" border="1" />');
  553: #    $r->print('<form>'."\n");
  554:     $r->print('<br>'."\n");
  555: }
  556: 
  557: #---- Problem Statistics Web Page ---------------------------------------
  558: sub CreateProblemStatisticsTableHeading {
  559:     my ($headings,$r)=@_;
  560:     my $Str='';
  561:     $Str .= '<tr>'."\n";
  562:     $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
  563:     foreach(@$headings) {
  564: 	$Str .= '<th bgcolor="#ffffe6">';
  565:         $Str .= '<a href="/adm/statistics?reportSelected=';
  566:         $Str .= &Apache::lonnet::escape('Problem Statistics');
  567:         $Str .= '&ProblemStatisticsSort=';
  568:         $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a>&nbsp</th>'."\n";
  569:     }
  570:     $Str .= "\n".'</tr>'."\n";
  571:     return $Str;
  572: }
  573: 
  574: sub BuildStatisticsTable {
  575:     my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings,
  576:         $r,$color)=@_;
  577:     my $count = 1;
  578:     my $currentSequence = -1;
  579:     foreach(@$orderedProblems) {
  580:         my ($sequence,$problem,$part)=split(':', $_);
  581:         if($cache->{'StatisticsMaps'} ne 'All Maps'  &&
  582:            $cache->{'StatisticsMaps'} ne $cache->{$sequence.':title'}) {
  583:             next;
  584:         }
  585:         if($currentSequence == -1 ||
  586:            ($sortProblems eq 'Sort Within Sequence' &&
  587:             $currentSequence != $sequence)) {
  588:             if($displayFormat ne 'Display CSV Format') {
  589:                 if($currentSequence ne -1) {
  590:                     $r->print('</table>');
  591:                     $r->print('</td></tr></table><br>');
  592:                 }
  593:                 if($sortProblems eq 'Sort Within Sequence') {
  594:                     $r->print('<b>'.$cache->{$sequence.':title'}.'</b>');
  595:                 }
  596:                 $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
  597:                 $r->print('<table border="0" cellpadding="3">'."\n");
  598:                 $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
  599:             } else {
  600:                 if($sortProblems eq 'Sort Within Sequence') {
  601:                     $r->print('"'.$cache->{$sequence.':title'}.'"');
  602:                 }
  603:                 $r->print('<br>');
  604:             }
  605:             $currentSequence = $sequence;
  606:         }
  607:         my $ref = '<a href="'.$cache->{$problem.':source'}.
  608:                   '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
  609:         my $title = $cache->{$problem.':title'};
  610:         if($part != 0) {
  611:             $title .= ' Part '.$part;
  612:         }
  613:         my $source = $cache->{$problem.':source'};
  614:         my $tableData = join('&', $ref, $title, $source,
  615:                        $cache->{$_.':studentCount'},
  616:                        $cache->{$_.':totalTries'},
  617:                        $cache->{$_.':maxTries'},
  618:                        $cache->{$_.':mean'},
  619:                        $cache->{$_.':correct'},
  620:                        $cache->{$_.':correctByOverride'},
  621:                        $cache->{$_.':percentWrong'},
  622:                        $cache->{$_.':degreeOfDifficulty'},
  623:                        $cache->{$_.':standardDeviation'},
  624:                        $cache->{$_.':skewness'},
  625:                        $cache->{$_.':discriminationFactor1'},
  626:                        $cache->{$_.':discriminationFactor2'});
  627:         &TableRow($displayFormat,$tableData,$count,$r,$color);
  628:         $count++;
  629:     }
  630:     if($displayFormat ne 'Display CSV Format') {
  631:         $r->print('</table>'."\n");
  632:         $r->print('</td></tr></table>');
  633:     } else {
  634:         $r->print('<br>');
  635:     }
  636:     return;
  637: }
  638: 
  639: sub TableRow {
  640:     my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
  641:     my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
  642:        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2)=split(/\&/,$Str);	
  643:     my $Ptr;
  644:     if($displayFormat eq 'Display CSV Format') {
  645:         $Ptr='"'.$RealIdx.'",'."\n".
  646:              '"'.$title.'",'."\n".
  647:              '"'.$source.'",'."\n".
  648:              '"'.$StdNo.'",'."\n".
  649:              '"'.$TotalTries.'",'."\n".
  650:              '"'.$MxTries.'",'."\n".
  651:              '"'.$Avg.'",'."\n".
  652:              '"'.$YES.'",'."\n".
  653:              '"'.$Override.'",'."\n".
  654:              '"'.$Wrng.'",'."\n".
  655:              '"'.$DoD.'",'."\n".
  656:              '"'.$SD.'",'."\n".
  657:              '"'.$Sk.'",'."\n".
  658:              '"'.$_D1.'",'."\n".
  659:              '"'.$_D2.'"'."\n".
  660:              "<br>\n";
  661:         $r->print("\n".$Ptr);
  662:     } else {
  663:         $Ptr='<tr>'."\n".
  664:              '<td bgcolor="#ffffe6">'.$RealIdx.'</td>'."\n".
  665:              '<td bgcolor="#ffffe6">'.$ref.'</td>'."\n".
  666:              '<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'."\n".
  667:              '<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'."\n".
  668:              '<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'."\n".
  669:              '<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'."\n".
  670:              '<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'."\n".
  671:              '<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'."\n".
  672:              '<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'."\n".
  673:              '<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'."\n".
  674:              '<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'."\n".
  675:              '<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'."\n".
  676:              '<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'."\n".
  677: 	     '<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'."\n";
  678:         $r->print($Ptr.'</tr>'."\n");
  679:     }
  680:     return;
  681: }
  682: 
  683: # For loading the colored table for display or un-colored for print
  684: sub setbgcolor {
  685:     my $PrintTable=shift;
  686:     my %color;
  687:     if ($PrintTable){
  688: 	$color{"gb"}="#FFFFFF";
  689: 	$color{"red"}="#FFFFFF";
  690: 	$color{"yellow"}="#FFFFFF";
  691: 	$color{"green"}="#FFFFFF";
  692: 	$color{"purple"}="#FFFFFF";
  693:     } else {
  694: 	$color{"gb"}="#DDFFFF";
  695: 	$color{"red"}="#FFDDDD";
  696: 	$color{"yellow"}="#EEFFCC";
  697: 	$color{"green"}="#DDFFDD";
  698: 	$color{"purple"}="#FFDDFF";
  699:     }
  700:     return \%color;
  701: }
  702: 
  703: sub ProblemStatisticsButtons {
  704:     my ($displayFormat, $displayLegend, $sortProblems)=@_;
  705:     my $Ptr = '<tr><td></td><td align="left">';
  706:     $Ptr .= '<input type="submit" name="DoDiffGraph" ';
  707:     $Ptr .= 'value="Plot Degree of Difficulty" />'."\n";
  708:     $Ptr .= '</td><td align="left">';
  709:     $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
  710:     $Ptr .= 'value="Plot Percent Wrong" />'."\n";
  711:     $Ptr .= '</td></tr><tr><td></td><td>'."\n";
  712:     $Ptr .= '<input type="submit" name="SortProblems" ';
  713:     if($sortProblems eq 'Sort All Problems') {
  714:         $Ptr .= 'value="Sort Within Sequence" />'."\n";
  715:     } else {
  716:         $Ptr .= 'value="Sort All Problems" />'."\n";
  717:     }
  718:     $Ptr .= '</td><td align="left">';
  719:     $Ptr .= '<input type="submit" name="DisplayLegend" ';
  720:     if($displayLegend eq 'Show Legend') {
  721:         $Ptr .= 'value="Hide Legend" />'."\n";
  722:     } else {
  723:         $Ptr .= 'value="Show Legend" />'."\n";
  724:     }
  725:     $Ptr .= '</td><td align="left">';
  726:     $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
  727:     if($displayFormat eq 'Display CSV Format') {
  728:         $Ptr .= 'value="Display Table Format" />'."\n";
  729:     } else {
  730:         $Ptr .= 'value="Display CSV Format" />'."\n";
  731:     }
  732:     $Ptr .= '</td></tr>';
  733:     return $Ptr;
  734: }
  735: 
  736: sub ProblemStatisticsLegend {
  737:     my $Ptr = '';
  738:     $Ptr = '<table border="0">';
  739:     $Ptr .= '<tr><td>';
  740:     $Ptr .= '<b>#Stdnts</b></td>';
  741:     $Ptr .= '<td>Total number of students attempted the problem.';
  742:     $Ptr .= '</td></tr><tr><td>';
  743:     $Ptr .= '<b>Tries</b></td>';
  744:     $Ptr .= '<td>Total number of tries for solving the problem.';
  745:     $Ptr .= '</td></tr><tr><td>';
  746:     $Ptr .= '<b>Mod</b></td>';
  747:     $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
  748:     $Ptr .= '</td></tr><tr><td>';
  749:     $Ptr .= '<b>Mean</b></td>';
  750:     $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
  751:     $Ptr .= '</td></tr><tr><td>';
  752:     $Ptr .= '<b>#YES</b></td>';
  753:     $Ptr .= '<td>Number of students solved the problem correctly.';
  754:     $Ptr .= '</td></tr><tr><td>';
  755:     $Ptr .= '<b>#yes</b></td>';
  756:     $Ptr .= '<td>Number of students solved the problem by override.';
  757:     $Ptr .= '</td></tr><tr><td>';
  758:     $Ptr .= '<b>%Wrong</b></td>';
  759:     $Ptr .= '<td>Percentage of students who tried to solve the problem ';
  760:     $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
  761:     $Ptr .= '</td></tr><tr><td>';
  762:     $Ptr .= '<b>DoDiff</b></td>';
  763:     $Ptr .= '<td>Degree of Difficulty of the problem.  ';
  764:     $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
  765:     $Ptr .= '</td></tr><tr><td>';
  766:     $Ptr .= '<b>S.D.</b></td>';
  767:     $Ptr .= '<td>Standard Deviation of the tries.  ';
  768:     $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
  769:     $Ptr .= 'where Xi denotes every student\'s tries ]';
  770:     $Ptr .= '</td></tr><tr><td>';
  771:     $Ptr .= '<b>Skew.</b></td>';
  772:     $Ptr .= '<td>Skewness of the students tries.';
  773:     $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
  774:     $Ptr .= '</td></tr><tr><td>';
  775:     $Ptr .= '<b>Dis.F.</b></td>';
  776:     $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
  777:     $Ptr .= 'problem according to a Criterion<br>';
  778:     $Ptr .= '<b>[Criterion to group students into %27 Upper Students - ';
  779:     $Ptr .= 'and %27 Lower Students]</b><br>';
  780:     $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
  781:     $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
  782:     $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
  783:     $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
  784:     $Ptr .= '</td></tr>';
  785:     $Ptr .= '<tr><td><b>Disc.</b></td>';
  786:     $Ptr .= '<td>Number of Students had at least one discussion.';
  787:     $Ptr .= '</td></tr></table>';
  788:     return $Ptr;
  789: }
  790: 
  791: #---- END Problem Statistics Web Page ----------------------------------------
  792: 
  793: 1;
  794: __END__

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