File:  [LON-CAPA] / loncom / interface / statistics / lonproblemstatistics.pm
Revision 1.27: download - view: text, annotated - select for diffs
Wed Aug 14 20:42:49 2002 UTC (21 years, 10 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Fixed a problem with statistics calculations, acts funny when testing near
zero.  Fixed sequence displays for problem statistics so that the sequences
are in the proper order.  Same with problem analysis.  Also removed
discussion column from statistics.

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonproblemstatistics.pm,v 1.27 2002/08/14 20:42:49 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 InitializeProblemStatistics {
   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 ('ERROR', undef);
   57:     }
   58: 
   59:     # Remove students who don't have the proper section.
   60:     my @sectionsSelected = split(':',$cache{'sectionsSelected'});
   61:     for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
   62:         $studentIndex--) {
   63:         my $value = $cache{$students->[$studentIndex].':section'};
   64:         my $found = 0;
   65:         foreach (@sectionsSelected) {
   66:             if($_ eq 'none') {
   67:                 if($value eq '' || !defined($value) || $value eq ' ') {
   68:                     $found = 1;
   69:                     last;
   70:                 }
   71:             } else {
   72:                 if($value eq $_) {
   73:                     $found = 1;
   74:                     last;
   75:                 }
   76:             }
   77:         }
   78:         if($found == 0) {
   79:             splice(@$students, $studentIndex, 1);
   80:         }
   81:     }
   82: 
   83:     my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?
   84:                      $cache{'StatisticsLastStatus'} : 'Nothing';
   85:     my $whichStudents = join(':::',sort(@$students));
   86:     if(!defined($cache{'StatisticsCached'}) || 
   87:        $lastStatus ne $cache{'Status'} ||
   88:        $whichStudents ne $cache{'StatisticsWhichStudents'}) {
   89:         if(defined($cache{'StatisticsCached'})) {
   90:             untie(%cache);
   91:             unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
   92:                 $r->print('Unable to tie database.');
   93:                 return ('ERROR', undef);
   94:             }
   95:             my @statkeys = split(':::', $cache{'StatisticsKeys'});
   96:             delete $cache{'StatisticsKeys'};
   97:             delete $cache{'StatisticsCached'};
   98:             foreach(@statkeys) {
   99:                 delete $cache{$_};
  100:             }
  101:         }
  102:         untie(%cache);
  103:         &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
  104:                                                                   'true',
  105:                                                                   $cacheDB,
  106:                                                                   'true', 
  107:                                                                   'true',
  108:                                                                   $courseID,
  109:                                                                   $r, $c);
  110:         if($c->aborted()) { return ('ERROR', undef); }
  111: 
  112:         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  113:             $r->print('Unable to tie database.');
  114:             return ('ERROR', undef);
  115:         }
  116:         my ($problemData) = &ExtractStudentData(\%cache, $students);
  117:         &CalculateStatistics($problemData, \%cache);
  118:         untie(%cache);
  119: 
  120:         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
  121:             $r->print('Unable to tie database.');
  122:             return ('ERROR', undef);
  123:         }
  124:         foreach(keys(%$problemData)) {
  125:             $cache{$_} = $problemData->{$_};
  126:         }
  127:         $cache{'StatisticsKeys'} = join(':::', keys(%$problemData));
  128:         $cache{'StatisticsCached'} = 'true';
  129:         $cache{'StatisticsLastStatus'} = $cache{'Status'};
  130:         $cache{'StatisticsWhichStudents'} = $whichStudents;
  131:         untie(%cache);
  132: 
  133:         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  134:             $r->print('Unable to tie database.');
  135:             return ('ERROR', undef);
  136:         }
  137:     }
  138: 
  139:     my $orderedProblems = &SortProblems(\%cache, 
  140:                                         $cache{'ProblemStatisticsSort'},
  141:                                         $cache{'SortProblems'},
  142:                                         $cache{'ProblemStatisticsAscend'});
  143:     return ('OK', $orderedProblems);
  144: }
  145: 
  146: sub BuildProblemStatisticsPage {
  147:     my ($cacheDB, $students, $courseID, $c, $r)=@_;
  148: 
  149:     my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
  150:                   "Mean","#YES","#yes","%Wrng","DoDiff",
  151:                   "S.D.","Skew.","D.F.1st","D.F.2nd");
  152:     my $color=&setbgcolor(0);
  153:     my %cache;
  154: 
  155:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  156:         $r->print('Unable to tie database.');
  157:         return;
  158:     }
  159:     my $Ptr = '';
  160:     $Ptr .= '<table border="0" cellspacing="5"><tbody>';
  161:     $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
  162:     $Ptr .= '<td align="left">';
  163:     $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',
  164:                                                'Statistics');
  165:     $Ptr .= '</td></tr>'."\n";
  166:     $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
  167:     $Ptr .= '<td align="left">'."\n";
  168:     $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
  169:                                             $cache{'ProblemStatisticsAscend'}, 
  170:                                             'ProblemStatistics',
  171:                                             'Statistics');
  172:     $Ptr .= '</td></tr>'."\n";
  173:     $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
  174:     $Ptr .= '</td>'."\n";
  175:     $Ptr .= '<td align="left">'."\n";
  176:     my @sections = split(':',$cache{'sectionList'});
  177:     my @sectionsSelected = split(':',$cache{'sectionsSelected'});
  178:     $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
  179:                                                           \@sectionsSelected,
  180:                                                           'Statistics');
  181:     $Ptr .= '</td></tr>'."\n";
  182:     $Ptr .= &ProblemStatisticsButtons($cache{'DisplayFormat'}, 
  183:                                       $cache{'DisplayLegend'},
  184:                                       $cache{'SortProblems'});
  185:     $Ptr .= '</table>';
  186:     if($cache{'DisplayLegend'} eq 'Show Legend') {
  187:         $Ptr .= &ProblemStatisticsLegend();
  188:     }
  189:     $r->print($Ptr);
  190:     $r->rflush();
  191:     untie(%cache);
  192: 
  193:     my ($result, $orderedProblems) =
  194:         &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
  195:     if($result ne 'OK') {
  196:         return;
  197:     }
  198: 
  199:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  200:         $r->print('Unable to tie database.');
  201:         return;
  202:     }
  203:     &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, 
  204:                           $cache{'SortProblems'}, $orderedProblems, 
  205:                           \@Header, $r, $color);
  206:     untie(%cache);
  207: 
  208:     return;
  209: }
  210: 
  211: sub BuildGraphicChart {
  212:     my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
  213:     my %cache;
  214:     my $max = 0;
  215: 
  216:     my ($result, undef) = 
  217:         &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
  218:     if($result ne 'OK') {
  219:         return;
  220:     }
  221: 
  222:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  223:         return 'Unable to tie database.';
  224:     }
  225:    
  226:     my @problems = split(':::', $cache{'problemList'});
  227:     my @values = ();
  228:     foreach (@problems) {
  229:         my $data = 0;
  230:         if($graph eq 'DoDiffGraph') {
  231:             $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
  232:         } else {
  233:             $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
  234:         }
  235:         if($max < $data) {
  236:             $max = $data;
  237:         }
  238:         push(@values, $data);
  239:     }
  240:     untie(%cache);
  241: 
  242:     my $sendValues = join(',', @values);
  243:     my $sendCount = scalar(@values);
  244: 
  245:     my $title = '';
  246:     if($graph eq 'DoDiffGraph') {
  247: 	$title = 'Degree-of-Difficulty';
  248:     } else {
  249: 	$title = 'Wrong-Percentage';
  250:     }
  251:     my @GData = ($courseDescription, 'Problems', $title, $max, $sendCount, 
  252:                  $sendValues);
  253: 
  254:     $r->print('</form>'."\n");
  255:     $r->print('<IMG src="/cgi-bin/graph.gif?'.(join('&', @GData)).
  256:               '" border="1" />');
  257:     $r->print('<form>'."\n");
  258: 
  259:     return;
  260: }
  261: 
  262: #---- Problem Statistics Web Page ---------------------------------------
  263: 
  264: sub CreateProblemStatisticsTableHeading {
  265:     my ($headings,$r)=@_;
  266: 
  267:     my $Str='';
  268:     $Str .= '<tr>'."\n";
  269:     $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
  270:     foreach(@$headings) {
  271: 	$Str .= '<th bgcolor="#ffffe6">';
  272:         $Str .= '<a href="/adm/statistics?reportSelected=';
  273:         $Str .= &Apache::lonnet::escape('Problem Statistics');
  274:         $Str .= '&ProblemStatisticsSort=';
  275:         $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a>&nbsp</th>'."\n";
  276:     }
  277:     $Str .= "\n".'</tr>'."\n";    
  278: 
  279:     return $Str;
  280: }
  281: 
  282: sub BuildStatisticsTable {
  283:     my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings,
  284:         $r,$color)=@_;
  285: 
  286:     my $count = 1;
  287:     my $currentSequence = -1;
  288:     foreach(@$orderedProblems) {
  289:         my ($sequence,$problem,$part)=split(':', $_);
  290:         if($cache->{'StatisticsMaps'} ne 'All Maps'  &&
  291:            $cache->{'StatisticsMaps'} ne $cache->{$sequence.':title'}) {
  292:             next;
  293:         }
  294: 
  295:         if($currentSequence == -1 || 
  296:            ($sortProblems eq 'Sort Within Sequence' && 
  297:             $currentSequence != $sequence)) {
  298:             if($displayFormat ne 'Display CSV Format') {
  299:                 if($currentSequence ne -1) {
  300:                     $r->print('</table>');
  301:                     $r->print('</td></tr></table><br>');
  302:                 }
  303:                 if($sortProblems eq 'Sort Within Sequence') {
  304:                     $r->print('<b>'.$cache->{$sequence.':title'}.'</b>');
  305:                 }
  306:                 $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
  307:                 $r->print('<table border="0" cellpadding="3">'."\n");
  308:                 $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
  309:             } else {
  310:                 if($sortProblems eq 'Sort Within Sequence') {
  311:                     $r->print('"'.$cache->{$sequence.':title'}.'"');
  312:                 }
  313:                 $r->print('<br>');
  314:             }
  315:             $currentSequence = $sequence;
  316:         }
  317: 
  318:         my $ref = '<a href="'.$cache->{$problem.':source'}.
  319:                   '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
  320:         my $title = $cache->{$problem.':title'};
  321:         if($part != 0) {
  322:             $title .= ' Part '.$part;
  323:         }
  324:         my $source = $cache->{$problem.':source'};
  325:         my $tableData = join('&', $ref, $title, $source,
  326:                        $cache->{$_.':studentCount'},
  327:                        $cache->{$_.':totalTries'},
  328:                        $cache->{$_.':maxTries'},
  329:                        $cache->{$_.':mean'},
  330:                        $cache->{$_.':correct'},
  331:                        $cache->{$_.':correctByOverride'},
  332:                        $cache->{$_.':percentWrong'},
  333:                        $cache->{$_.':degreeOfDifficulty'},
  334:                        $cache->{$_.':standardDeviation'},
  335:                        $cache->{$_.':skewness'},
  336:                        $cache->{$_.':discriminationFactor1'},
  337:                        $cache->{$_.':discriminationFactor2'});
  338: 
  339:         &TableRow($displayFormat,$tableData,$count,$r,$color);
  340: 
  341:         $count++;
  342:     }
  343:     if($displayFormat ne 'Display CSV Format') {
  344:         $r->print('</table>'."\n");
  345:         $r->print('</td></tr></table>');
  346:     } else {
  347:         $r->print('<br>');
  348:     }
  349: 
  350:     return;
  351: }
  352: 
  353: sub TableRow {
  354:     my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
  355:     my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
  356:        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2)=split(/\&/,$Str);	
  357:     my $Ptr;
  358:     if($displayFormat eq 'Display CSV Format') {
  359:         $Ptr='"'.$RealIdx.'",'."\n".
  360:              '"'.$title.'",'."\n".
  361:              '"'.$source.'",'."\n".
  362:              '"'.$StdNo.'",'."\n".
  363:              '"'.$TotalTries.'",'."\n".
  364:              '"'.$MxTries.'",'."\n".
  365:              '"'.$Avg.'",'."\n".
  366:              '"'.$YES.'",'."\n".
  367:              '"'.$Override.'",'."\n".
  368:              '"'.$Wrng.'",'."\n".
  369:              '"'.$DoD.'",'."\n".
  370:              '"'.$SD.'",'."\n".
  371:              '"'.$Sk.'",'."\n".
  372:              '"'.$_D1.'",'."\n".
  373:              '"'.$_D2.'"'."\n".
  374:              "<br>\n";
  375: 
  376:         $r->print("\n".$Ptr);
  377:     } else {
  378:         $Ptr='<tr>'."\n".
  379:              '<td bgcolor="#ffffe6">'.$RealIdx.'</td>'."\n".
  380:              '<td bgcolor="#ffffe6">'.$ref.'</td>'."\n".
  381:              '<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'."\n".
  382:              '<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'."\n".
  383:              '<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'."\n".
  384:              '<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'."\n".
  385:              '<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'."\n".
  386:              '<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'."\n".
  387:              '<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'."\n".
  388:              '<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'."\n".
  389:              '<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'."\n".
  390:              '<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'."\n".
  391:              '<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'."\n".
  392: 	     '<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'."\n";
  393:         $r->print($Ptr.'</tr>'."\n");
  394:     }
  395: 
  396:     return;
  397: }
  398: 
  399: # For loading the colored table for display or un-colored for print
  400: sub setbgcolor {
  401:     my $PrintTable=shift;
  402:     my %color;
  403:     if ($PrintTable){
  404: 	$color{"gb"}="#FFFFFF";
  405: 	$color{"red"}="#FFFFFF";
  406: 	$color{"yellow"}="#FFFFFF";
  407: 	$color{"green"}="#FFFFFF";
  408: 	$color{"purple"}="#FFFFFF";
  409:     } else {
  410: 	$color{"gb"}="#DDFFFF";
  411: 	$color{"red"}="#FFDDDD";
  412: 	$color{"yellow"}="#EEFFCC";
  413: 	$color{"green"}="#DDFFDD";
  414: 	$color{"purple"}="#FFDDFF";
  415:     }
  416: 
  417:     return \%color;
  418: }
  419: 
  420: sub ProblemStatisticsButtons {
  421:     my ($displayFormat, $displayLegend, $sortProblems)=@_;
  422: 
  423:     my $Ptr = '<tr><td></td><td align="left">';
  424:     $Ptr .= '<input type="submit" name="DoDiffGraph" ';
  425:     $Ptr .= 'value="Degree of Difficulty" />'."\n";
  426:     $Ptr .= '</td><td align="left">';
  427:     $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
  428:     $Ptr .= 'value="Percent Wrong" />'."\n";
  429:     $Ptr .= '</td></tr><tr><td></td><td>'."\n";
  430:     $Ptr .= '<input type="submit" name="SortProblems" ';
  431:     if($sortProblems eq 'Sort All Problems') {
  432:         $Ptr .= 'value="Sort Within Sequence" />'."\n";
  433:     } else {
  434:         $Ptr .= 'value="Sort All Problems" />'."\n";
  435:     }
  436:     $Ptr .= '</td><td align="left">';
  437:     $Ptr .= '<input type="submit" name="DisplayLegend" ';
  438:     if($displayLegend eq 'Show Legend') {
  439:         $Ptr .= 'value="Hide Legend" />'."\n";
  440:     } else {
  441:         $Ptr .= 'value="Show Legend" />'."\n";
  442:     }
  443:     $Ptr .= '</td><td align="left">';
  444:     $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
  445:     if($displayFormat eq 'Display CSV Format') {
  446:         $Ptr .= 'value="Display Table Format" />'."\n";
  447:     } else {
  448:         $Ptr .= 'value="Display CSV Format" />'."\n";
  449:     }
  450:     $Ptr .= '</td></tr>';
  451: 
  452:     return $Ptr;
  453: }
  454: 
  455: sub ProblemStatisticsLegend {
  456:     my $Ptr = '';
  457:     $Ptr = '<table border="0">';
  458:     $Ptr .= '<tr><td>';
  459:     $Ptr .= '<b>#Stdnts</b></td>';
  460:     $Ptr .= '<td>Total number of students attempted the problem.';
  461:     $Ptr .= '</td></tr><tr><td>';
  462:     $Ptr .= '<b>Tries</b></td>';
  463:     $Ptr .= '<td>Total number of tries for solving the problem.';
  464:     $Ptr .= '</td></tr><tr><td>';
  465:     $Ptr .= '<b>Mod</b></td>';
  466:     $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
  467:     $Ptr .= '</td></tr><tr><td>';
  468:     $Ptr .= '<b>Mean</b></td>';
  469:     $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
  470:     $Ptr .= '</td></tr><tr><td>';
  471:     $Ptr .= '<b>#YES</b></td>';
  472:     $Ptr .= '<td>Number of students solved the problem correctly.';
  473:     $Ptr .= '</td></tr><tr><td>';
  474:     $Ptr .= '<b>#yes</b></td>';
  475:     $Ptr .= '<td>Number of students solved the problem by override.';
  476:     $Ptr .= '</td></tr><tr><td>';
  477:     $Ptr .= '<b>%Wrong</b></td>';
  478:     $Ptr .= '<td>Percentage of students who tried to solve the problem ';
  479:     $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
  480:     $Ptr .= '</td></tr><tr><td>';
  481:     $Ptr .= '<b>DoDiff</b></td>';
  482:     $Ptr .= '<td>Degree of Difficulty of the problem.  ';
  483:     $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
  484:     $Ptr .= '</td></tr><tr><td>';
  485:     $Ptr .= '<b>S.D.</b></td>';
  486:     $Ptr .= '<td>Standard Deviation of the tries.  ';
  487:     $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
  488:     $Ptr .= 'where Xi denotes every student\'s tries ]';
  489:     $Ptr .= '</td></tr><tr><td>';
  490:     $Ptr .= '<b>Skew.</b></td>';
  491:     $Ptr .= '<td>Skewness of the students tries.';
  492:     $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
  493:     $Ptr .= '</td></tr><tr><td>';
  494:     $Ptr .= '<b>Dis.F.</b></td>';
  495:     $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
  496:     $Ptr .= 'problem according to a Criterion<br>';
  497:     $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';
  498:     $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';
  499:     $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
  500:     $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
  501:     $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
  502:     $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
  503:     $Ptr .= '</td></tr>';
  504:     $Ptr .= '<tr><td><b>Disc.</b></td>';
  505:     $Ptr .= '<td>Number of Students had at least one discussion.';
  506:     $Ptr .= '</td></tr></table>';
  507: 
  508:     return $Ptr;
  509: }
  510: 
  511: sub ExtractStudentData {
  512:     my ($cache, $students)=@_;
  513: 
  514:     my @problemList=();
  515:     my %problemData;
  516:     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
  517:         foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
  518:             foreach my $part (split(/\:/,$cache->{$sequence.':'.
  519:                                                   $problemID.
  520:                                                   ':parts'})) {
  521:                 my $id = $sequence.':'.$problemID.':'.$part;
  522:                 push(@problemList, $id);
  523:                 my $totalTries = 0;
  524:                 my $totalAwarded = 0;
  525:                 my $correct = 0;
  526:                 my $correctByOverride = 0;
  527:                 my $studentCount = 0;
  528:                 my $maxTries = 0;
  529:                 my $totalFirst = 0;
  530:                 my @studentTries=();
  531:                 foreach(@$students) {
  532:                     my $code = $cache->{"$_:$problemID:$part:code"};
  533: 
  534:                     if(defined($cache->{$_.':error'}) || $code eq ' ' ||
  535:                        $cache->{"$_:$problemID:NoVersion"} eq 'true') {
  536:                         next;
  537:                     }
  538: 
  539:                     $studentCount++;
  540:                     my $tries =  $cache->{"$_:$problemID:$part:tries"};
  541:                     if($maxTries < $tries) {
  542:                         $maxTries = $tries;
  543:                     }
  544:                     $totalTries += $tries;
  545:                     push(@studentTries, $tries);
  546: 
  547:                     my $awarded = $cache->{"$_:$problemID:$part:awarded"};
  548:                     $totalAwarded += $awarded;
  549: 
  550:                     if($code eq '*') {
  551:                         $correct++;
  552:                         if($tries == 1) {
  553:                             $totalFirst++;
  554:                         }
  555:                     } elsif($code eq '+') {
  556:                         $correctByOverride++;
  557:                     }
  558:                 }
  559: 
  560:                 my $studentTriesJoined = join(':::', @studentTries);
  561:                 $problemData{$id.':sequenceTitle'} = 
  562:                     $cache->{$sequence.':title'};
  563:                 $problemData{$id.':studentCount'} = $studentCount;
  564:                 $problemData{$id.':totalTries'} = $totalTries;
  565:                 $problemData{$id.':studentTries'} = $studentTriesJoined;
  566:                 $problemData{$id.':totalAwarded'} = $totalAwarded;
  567:                 $problemData{$id.':correct'} = $correct;
  568:                 $problemData{$id.':correctByOverride'} = $correctByOverride;
  569:                 $problemData{$id.':wrong'} = $studentCount - 
  570:                                              ($correct + $correctByOverride);
  571:                 $problemData{$id.':maxTries'} = $maxTries;
  572:                 $problemData{$id.':totalFirst'} = $totalFirst;
  573:             }
  574:         }
  575:     }
  576: 
  577:     my @upperStudents1=();
  578:     my @lowerStudents1=();
  579:     my @upperStudents2=();
  580:     my @lowerStudents2=();
  581:     my $upperCount = int(0.27*scalar(@$students));
  582:     # Discriminant Factor criterion 1
  583:     my $sortedStudents = &SortDivideByTries($students,$cache,':totalAwarded');
  584: 
  585:     for(my $i=0; $i<$upperCount; $i++) {
  586:         push(@lowerStudents1, $sortedStudents->[$i]);
  587:         push(@upperStudents1, $sortedStudents->[(scalar(@$students)-$i-1)]);
  588:     }
  589: 
  590:     $problemData{'studentsUpperListCriterion1'}=join(':::', @upperStudents1);
  591:     $problemData{'studentsLowerListCriterion1'}=join(':::', @lowerStudents1);
  592: 
  593:     # Discriminant Factor criterion 2
  594:     $sortedStudents = &SortDivideByTries($students, $cache, ':totalSolved');
  595: 
  596:     for(my $i=0; $i<$upperCount; $i++) {
  597:         push(@lowerStudents2, $sortedStudents->[$i]);
  598:         push(@upperStudents2, $sortedStudents->[(scalar(@$students)-$i-1)]);
  599:     }
  600:     $problemData{'studentsUpperListCriterion2'}=join(':::', @upperStudents2);
  601:     $problemData{'studentsLowerListCriterion2'}=join(':::', @lowerStudents2);
  602: 
  603:     $problemData{'problemList'} = join(':::', @problemList);
  604: 
  605:     return \%problemData;
  606: }
  607: 
  608: sub SortDivideByTries {
  609:     my ($toSort, $data, $sortOn)=@_;
  610:     my @orderedData = sort { ($data->{$a.':totalTries'}) ? 
  611:                              ($data->{$a.$sortOn}/$data->{$a.':totalTries'}):0
  612:                              <=>
  613:                              ($data->{$b.':totalTries'}) ? 
  614:                              ($data->{$b.$sortOn}/$data->{$b.':totalTries'}):0
  615:                            } @$toSort;
  616: 
  617:     return \@orderedData;
  618: }
  619: 
  620: sub SortProblems {
  621:     my ($problemData,$sortBy,$sortProblems,$ascend)=@_;
  622: 
  623:     my @problems = split(':::', $problemData->{'problemList'});
  624:     if($sortBy eq "Homework Sets Order") {
  625:         return \@problems;
  626:     }
  627: 
  628:     my $data;
  629: 
  630:     if   ($sortBy eq "#Stdnts") { $data = ':studentCount'; }
  631:     elsif($sortBy eq "Tries")   { $data = ':totalTries'; }
  632:     elsif($sortBy eq "Mod")     { $data = ':maxTries'; }
  633:     elsif($sortBy eq "Mean")    { $data = ':mean'; }
  634:     elsif($sortBy eq "#YES")    { $data = ':correct'; }
  635:     elsif($sortBy eq "#yes")    { $data = ':correctByOverride'; }
  636:     elsif($sortBy eq "%Wrng")   { $data = ':percentWrong'; }
  637:     elsif($sortBy eq "DoDiff")  { $data = ':degreeOfDifficulty'; }
  638:     elsif($sortBy eq "S.D.")    { $data = ':standardDeviation'; }
  639:     elsif($sortBy eq "Skew.")   { $data = ':skewness'; }
  640:     elsif($sortBy eq "D.F.1st") { $data = ':discriminationFactor1'; }
  641:     elsif($sortBy eq "D.F.2nd") { $data = ':discriminationFactor2'; }
  642:     else                        { return \@problems; }
  643: 
  644:     my %temp;
  645:     my @sequenceList=();
  646:     foreach(@problems) {
  647:         my ($sequence) = split(':', $_);
  648: 
  649:         my @array=();
  650:         my $tempArray;
  651:         if(defined($temp{$sequence})) {
  652:             $tempArray = $temp{$sequence};
  653:         } else {
  654:             push(@sequenceList, $sequence);
  655:             $tempArray = \@array;
  656:             $temp{$sequence} = $tempArray;
  657:         }
  658: 
  659:         push(@$tempArray, $_);
  660:     }
  661: 
  662:     my @orderedProblems;
  663:     if($sortProblems eq "Sort Within Sequence") {
  664:         foreach(keys(%temp)) {
  665:             my $tempArray = $temp{$_};
  666:             my @tempOrder =
  667:                 sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
  668:             @$tempArray;
  669:             $temp{$_} = \@tempOrder;
  670:         }
  671:         foreach(@sequenceList) {
  672:             my $tempArray = $temp{$_};
  673:             @orderedProblems = (@orderedProblems, @$tempArray);
  674:         }
  675:     } else {
  676:         @orderedProblems = 
  677:             sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
  678:         @problems;
  679:     }
  680: 
  681:     if($ascend eq 'Descending') {
  682:         @orderedProblems = reverse(@orderedProblems);
  683:     }
  684: 
  685:     return \@orderedProblems;
  686: }
  687: 
  688: sub CalculateStatistics {
  689:     my ($data, $cache)=@_;
  690: 
  691:     my @problems = split(':::', $data->{'problemList'});
  692:     foreach(@problems) {
  693:         # Mean
  694:         my $mean = ($data->{$_.':studentCount'}) ? 
  695:             ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
  696:         $data->{$_.':mean'} = sprintf("%.2f", $mean);
  697: 
  698:         # %Wrong
  699:         my $pw = ($data->{$_.':studentCount'}) ?
  700:             (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) : 
  701:             100.0;
  702:         $data->{$_.':percentWrong'} = sprintf("%.1f", $pw);
  703: 
  704:         # Degree of Difficulty
  705:         my $dod = ($data->{$_.':totalTries'}) ?
  706:             (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
  707:                   $data->{$_.':totalTries'})) : 0;
  708: 
  709:         $data->{$_.':degreeOfDifficulty'} = sprintf("%.2f", $dod);
  710: 
  711:         # Factor in mean
  712:         my @studentTries = split(':::', $data->{$_.':studentTries'});
  713:         foreach(my $index=0; $index < scalar(@studentTries); $index++) {
  714:             $studentTries[$index] -= $mean;
  715:         }
  716:         my $sumSquared = 0;
  717:         my $sumCubed = 0;
  718:         foreach(@studentTries) {
  719:             my $squared = ($_ * $_);
  720:             my $cubed = ($squared * $_);
  721:             $sumSquared += $squared;
  722:             $sumCubed += $cubed;
  723:         }
  724: 
  725:         # Standard deviation
  726:         my $standardDeviation;
  727:         if($data->{$_.':studentCount'} - 1 > 0) {
  728:             $standardDeviation = (sqrt($sumSquared)) / 
  729:                                  ($data->{$_.':studentCount'} - 1);
  730:         } else {
  731:             $standardDeviation =  0.0;
  732:         }
  733:         $data->{$_.':standardDeviation'} = sprintf("%.1f", $standardDeviation);
  734: 
  735:         # Skewness
  736:         my $skew;
  737:         if($standardDeviation > 0.0999 && $data->{$_.':studentCount'} > 0) {
  738:             $skew = (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) / 
  739:                      ($standardDeviation * 
  740:                       $standardDeviation * 
  741:                       $standardDeviation));
  742:         } else {
  743:             $skew = 0.0;
  744:         }
  745: 
  746:         $data->{$_.':skewness'} = sprintf("%.1f", $skew);
  747: 
  748:         # Discrimination Factor 1
  749:         my ($sequence, $problem, $part) = split(':', $_);
  750: 
  751:         my @upper1 = split(':::', $data->{'studentsUpperListCriterion1'});
  752:         my @lower1 = split(':::', $data->{'studentsLowerListCriterion1'});
  753: 
  754:         my $upper1Sum=0;
  755:         foreach my $name (@upper1) {
  756:             $upper1Sum += $cache->{"$name:$problem:$part:awarded"};
  757:         }
  758:         $upper1Sum = (scalar(@upper1)) ? ($upper1Sum/(scalar(@upper1))) : 0;
  759: 
  760:         my $lower1Sum=0;
  761:         foreach my $name (@lower1) {
  762:             $lower1Sum += $cache->{"$name:$problem:$part:awarded"};
  763:         }
  764:         $lower1Sum = (scalar(@lower1)) ? ($lower1Sum/(scalar(@lower1))) : 0;
  765: 
  766:         my $df1 = $upper1Sum - $lower1Sum;
  767:         $data->{$_.':discriminationFactor1'} = sprintf("%.2f", $df1);
  768: 
  769:         # Discrimination Factor 2
  770:         my @upper2 = split(':::', $data->{'studentsUpperListCriterion2'});
  771:         my @lower2 = split(':::', $data->{'studentsLowerListCriterion2'});
  772: 
  773:         my $upper2Sum=0;
  774:         foreach my $name (@upper2) {
  775:             $upper2Sum += $cache->{"$name:$problem:$part:awarded"};
  776:         }
  777:         $upper2Sum = (scalar(@upper2)) ? ($upper2Sum/(scalar(@upper2))) : 0;
  778: 
  779:         my $lower2Sum=0;
  780:         foreach my $name (@lower2) {
  781:             $lower2Sum += $cache->{"$name:$problem:$part:awarded"};
  782:         }
  783:         $lower2Sum = (scalar(@lower2)) ? ($lower2Sum/(scalar(@lower2))) : 0;
  784: 
  785:         my $df2 = $upper2Sum - $lower2Sum;
  786:         $data->{$_.':discriminationFactor2'} = sprintf("%.2f", $df2);
  787:     }
  788: 
  789:     return;
  790: }
  791: 
  792: #---- END Problem Statistics Web Page ----------------------------------------
  793: 
  794: 1;
  795: __END__

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