Annotation of loncom/interface/statistics/lonstudentassessment.pm, revision 1.27

1.1       stredwic    1: # The LearningOnline Network with CAPA
                      2: # (Publication Handler
                      3: #
1.27    ! minaeibi    4: # $Id: lonstudentassessment.pm,v 1.26 2003/01/09 16:37:48 minaeibi Exp $
1.1       stredwic    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      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: # YEAR=2001
                     29: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
                     30: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
                     31: # YEAR=2002
                     32: # 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
1.23      minaeibi   33: # 5/12,5/14,5/15,5/19,5/26,7/16,12/24  Behrouz Minaei
1.27    ! minaeibi   34: # YEAR=2003  
        !            35: # 1/11  Behrouz Minaei
1.1       stredwic   36: ###
                     37: 
1.21      minaeibi   38: package Apache::lonstudentassessment;
1.1       stredwic   39: 
                     40: use strict;
                     41: use Apache::lonhtmlcommon;
                     42: use Apache::loncoursedata;
                     43: use GDBM_File;
                     44: 
1.4       stredwic   45: 
1.1       stredwic   46: sub BuildStudentAssessmentPage {
1.2       stredwic   47:     my ($cacheDB,$students,$courseID,$formName,$headings,$spacing,
                     48:         $studentInformation,$r,$c)=@_;
1.1       stredwic   49:     my %cache;
1.6       stredwic   50:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.11      stredwic   51:         $r->print('<html><body>Unable to tie database.</body></html>');
1.2       stredwic   52:         return;
1.1       stredwic   53:     }
1.3       stredwic   54: 
                     55:     # Remove students who don't have the proper section.
                     56:     my @sectionsSelected = split(':',$cache{'sectionsSelected'});
                     57:     for(my $studentIndex=((scalar @$students)-1); $studentIndex>=0;
                     58:         $studentIndex--) {
                     59:         my $value = $cache{$students->[$studentIndex].':section'};
                     60:         my $found = 0;
                     61:         foreach (@sectionsSelected) {
                     62:             if($_ eq 'none') {
                     63:                 if($value eq '' || !defined($value) || $value eq ' ') {
                     64:                     $found = 1;
                     65:                     last;
                     66:                 }
                     67:             } else {
                     68:                 if($value eq $_) {
                     69:                     $found = 1;
                     70:                     last;
                     71:                 }
                     72:             }
                     73:         }
                     74:         if($found == 0) {
                     75:             splice(@$students, $studentIndex, 1);
                     76:         }
                     77:     }
1.4       stredwic   78:     my ($infoHeadings, $infoKeys, $sequenceHeadings, $sequenceKeys,
1.21      minaeibi   79:         $doNotShow) =
1.4       stredwic   80:         &ShouldShowColumns(\%cache, $headings, $studentInformation);
1.3       stredwic   81: 
1.21      minaeibi   82:     my $selectedName = &FindSelectedStudent(\%cache,
1.2       stredwic   83:                                             $cache{'StudentAssessmentStudent'},
                     84:                                             $students);
1.4       stredwic   85:     $r->print(&CreateInterface(\%cache, $selectedName, $students, $formName,
                     86:                                $doNotShow));
1.7       stredwic   87:     $r->rflush();
1.1       stredwic   88: 
1.4       stredwic   89:     my $Str = '';
1.1       stredwic   90:     if($selectedName eq 'No Student Selected') {
1.4       stredwic   91: 	$Str .= '<h3><font color=blue>WARNING: ';
                     92:         $Str .= 'Please select a student</font></h3>';
                     93:         $r->print($Str);
1.2       stredwic   94:         return;
1.1       stredwic   95:     }
                     96: 
1.2       stredwic   97:     $r->print(&CreateTableHeadings(\%cache, $spacing, $infoKeys, $infoHeadings,
                     98:                                    $sequenceKeys, $sequenceHeadings));
                     99:     untie(%cache);
1.6       stredwic  100:     if($c->aborted()) {  return $Str; }
1.2       stredwic  101: 
1.1       stredwic  102:     my $selected=0;
1.24      minaeibi  103:     my $Count = 0;
1.2       stredwic  104:     $r->print('<pre>'."\n");
1.1       stredwic  105:     foreach (@$students) {
1.8       stredwic  106:         if($c->aborted()) { return $Str; }
1.17      minaeibi  107:         next if ($_ ne $selectedName &&
1.1       stredwic  108:                  $selectedName ne 'All Students');
                    109:         $selected = 1;
1.2       stredwic  110: 
1.8       stredwic  111:         my @who = ($_);
1.17      minaeibi  112:         next if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'true',
                    113:                                                              $cacheDB, 'true',
1.8       stredwic  114:                                                              'false', $courseID,
                    115:                                                              $r, $c) ne 'OK');
1.6       stredwic  116:         next if($c->aborted());
1.2       stredwic  117: 
1.6       stredwic  118:         if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.8       stredwic  119:             my @before=();
                    120:             my @after=();
                    121:             my @updateColumn=();
                    122:             my $foundUpdate = 0;
                    123:             foreach(@$infoKeys) {
                    124:                 if(/updateTime/) {
                    125:                     $foundUpdate=1;
                    126:                     push(@updateColumn, $_);
                    127:                     next;
                    128:                 }
                    129:                 if($foundUpdate) {
                    130:                     push(@after, $_);
                    131:                 } else {
                    132:                     push(@before, $_);
                    133:                 }
                    134:             }
1.24      minaeibi  135:             $Count++;
                    136: 	    my $out = '';
1.27    ! minaeibi  137: 	    $out .= sprintf("%3d) ", $Count);
1.24      minaeibi  138:             if($Count % 2) {
                    139:                 $out .= '<bgcolor="#FFFFFF">';
                    140:             } else {
1.27    ! minaeibi  141:                 $out .= '<bgcolor="#505050">';
1.24      minaeibi  142:             }
                    143: 	    my $displayString = $out.'DISPLAYDATA'.$spacing;
                    144: 	    $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
1.2       stredwic  145:                                                          \%cache, $_,
1.8       stredwic  146:                                                          \@before,
                    147:                                                          $displayString,
                    148:                                                          'preformatted'));
                    149: 
                    150:             if($foundUpdate) {
                    151:                 $displayString = '';
                    152:                 $displayString .= '<a href="/adm/statistics?reportSelected=';
                    153:                 $displayString .= &Apache::lonnet::escape('Student Assessment');
                    154:                 $displayString .= '&download='.$_.'">';
                    155:                 $displayString .= 'DISPLAYDATA</a>'.$spacing;
                    156:                 $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
                    157:                                                                    \%cache, $_,
                    158:                                                                    \@updateColumn,
                    159:                                                                    $displayString,
                    160:                                                                    'preformatted'));
                    161:             }
                    162: 
                    163:             $displayString = 'DISPLAYDATA'.$spacing;
                    164:             $r->print(&Apache::lonhtmlcommon::FormatStudentInformation(
                    165:                                                          \%cache, $_,
                    166:                                                          \@after,
1.2       stredwic  167:                                                          $displayString,
                    168:                                                          'preformatted'));
                    169:             $r->print(&StudentReport(\%cache, $_, $spacing, $sequenceKeys));
                    170:             $r->print("\n");
1.7       stredwic  171:             $r->rflush();
1.1       stredwic  172:             untie(%cache);
                    173:         }
                    174:     }
1.26      minaeibi  175:     $r->print('</pre>'."\n"); 
1.1       stredwic  176:     if($selected == 0) {
1.4       stredwic  177: 	$Str .= '<h3><font color=blue>WARNING: ';
1.26      minaeibi  178:         $Str .= 'No Students enrolled OR Please select a student</font></h3>';
1.4       stredwic  179:         $r->print($Str);
1.26      minaeibi  180:     } else {
                    181: 	if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
                    182: 	    $r->print(&StudentAverageTotal(\%cache, $students, $sequenceKeys));
                    183: 	    untie(%cache);
                    184: 	}
1.1       stredwic  185:     }
1.2       stredwic  186:     return;
                    187: }
                    188: 
1.21      minaeibi  189: 
1.2       stredwic  190: #---- Student Assessment Web Page --------------------------------------------
                    191: 
                    192: sub CreateInterface {
1.4       stredwic  193:     my($cache,$selectedName,$students,$formName,$doNotShow)=@_;
                    194: 
                    195:     my $Str = '';
                    196:     $Str .= &CreateLegend();
                    197:     $Str .= '<table><tr><td>'."\n";
                    198:     $Str .= '<input type="submit" name="PreviousStudent" ';
                    199:     $Str .= 'value="Previous Student" />'."\n";
                    200:     $Str .= '&nbsp&nbsp&nbsp'."\n";
1.17      minaeibi  201:     $Str .= &Apache::lonhtmlcommon::StudentOptions($cache, $students,
1.21      minaeibi  202:                                                    $selectedName,
                    203:                                                    'StudentAssessment',
1.2       stredwic  204:                                                    $formName);
1.4       stredwic  205:     $Str .= "\n".'&nbsp&nbsp&nbsp'."\n";
                    206:     $Str .= '<input type="submit" name="NextStudent" ';
                    207:     $Str .= 'value="Next Student" />'."\n";
                    208:     $Str .= '</td></tr></table>'."\n";
                    209:     $Str .= '<table cellspacing="5"><tr>'."\n";
                    210:     $Str .= '<td align="center"><b>Select Sections</b>'."\n";
                    211:     $Str .= '</td>'."\n";
                    212:     $Str .= '<td align="center"><b>Select column to view:</b></td>'."\n";
                    213:     $Str .= '<td></td></tr>'."\n";
1.3       stredwic  214: 
1.4       stredwic  215:     $Str .= '<tr><td align="center">'."\n";
1.3       stredwic  216:     my @sections = split(':',$cache->{'sectionList'});
                    217:     my @selectedSections = split(':',$cache->{'sectionsSelected'});
1.4       stredwic  218:     $Str .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
1.3       stredwic  219:                                                           \@selectedSections,
                    220:                                                           'Statistics');
1.4       stredwic  221:     $Str .= '</td><td align="center">';
                    222:     $Str .= &CreateColumnSelectionBox($doNotShow);
                    223:     $Str .= '</td><td>'."\n";
                    224:     $Str .= '<input type="submit" name="DefaultColumns" ';
                    225:     $Str .= 'value="Default Column Display" />'."\n";
1.18      matthew   226:     $Str .= '</td><td>'."\n";
                    227:     $Str .= '<input type="submit" name="displaymode" ';
                    228:     if (! exists($ENV{'form.displaymode'}) ||
                    229:         lc($ENV{'form.displaymode'}) eq 'display with links') {
                    230:         $Str .= 'value="Display without links" />';
                    231:         # Set the current value, in case it is undefined
1.21      minaeibi  232:         $ENV{'form.displaymode'} = 'Display with links';
1.18      matthew   233:     } else {
                    234:         $Str .= 'value="Display with links" />';
                    235:     }
                    236:     $Str .= "\n";
1.4       stredwic  237:     $Str .= '</td></tr></table>'."\n";
1.2       stredwic  238: 
1.4       stredwic  239:     return $Str;
1.1       stredwic  240: }
                    241: 
1.2       stredwic  242: sub CreateTableHeadings {
                    243:     my($cache,$spacing,$infoKeys,$infoHeadings,$sequenceKeys,
                    244:        $sequenceHeadings)=@_;
                    245: 
1.24      minaeibi  246: #    my $Str = '&nbsp&nbsp&nbsp&nbsp&nbsp';
1.2       stredwic  247:     my $Str = '';
1.4       stredwic  248:     $Str .= '<table border="0" cellpadding="0" cellspacing="0">'."\n";
                    249:     $Str .= '<tr>'."\n";
1.27    ! minaeibi  250:     $Str .= '<td><pre>     </pre></td>'."\n";
1.4       stredwic  251:     $Str .= &CreateColumnSelectors($infoHeadings, $sequenceHeadings,
                    252:                                    $sequenceKeys);
                    253:     $Str .= '<td></td></tr>'."\n";
1.2       stredwic  254: 
1.4       stredwic  255:     $Str .= '<tr>'."\n";
1.27    ! minaeibi  256:     my $displayString = '';
        !           257:     $displayString .= '<td><pre>     </pre></td>'."\n";
        !           258:     $displayString .= '<td align="left"><pre><a href="/adm/statistics?';
1.2       stredwic  259:     $displayString .= 'sort=LINKDATA">DISPLAYDATA</a>FORMATTING';
                    260:     $displayString .= $spacing.'</pre></td>'."\n";
1.17      minaeibi  261:     $Str .= &Apache::lonhtmlcommon::CreateHeadings($cache,
1.2       stredwic  262:                                                    $infoKeys,
                    263:                                                    $infoHeadings,
                    264:                                                    $displayString,
                    265:                                                    'preformatted');
                    266: 
1.8       stredwic  267:     $displayString  = '<td align="left"><pre>DISPLAYDATAFORMATTING'.$spacing;
1.2       stredwic  268:     $displayString .= '</pre></td>'."\n";
                    269:     $Str .= &Apache::lonhtmlcommon::CreateHeadings($cache,
                    270:                                                    $sequenceKeys,
                    271:                                                    $sequenceHeadings,
                    272:                                                    $displayString,
                    273:                                                    'preformatted');
                    274: 
                    275:     $Str .= '<td><pre>Total Solved/Total Problems</pre></td>';
                    276:     $Str .= '</tr></table>'."\n";
                    277: 
                    278:     return $Str;
                    279: }
                    280: 
                    281: =pod
                    282: 
                    283: =item &FormatStudentData()
                    284: 
                    285: First, FormatStudentInformation is called and prefixes the course information.
1.18      matthew   286: This function produces a formatted string of the student\'s course information.
1.2       stredwic  287: Each column of data represents all the problems for a given sequence.  For
                    288: valid grade data, a link is created for that problem to a submission record
                    289: for that problem.
                    290: 
                    291: =over 4
                    292: 
                    293: Input: $name, $studentInformation, $ChartDB
                    294: 
                    295: $name: The name and domain of the current student in name:domain format
                    296: 
                    297: $studentInformation: A pointer to an array holding the names used to 
                    298: remove data from the hash.  They represent 
                    299: the name of the data to be removed.
                    300: 
                    301: $ChartDB: The name of the cached data database which will be tied to that 
                    302: database.
                    303: 
                    304: Output: $Str
                    305: 
1.21      minaeibi  306: $Str: Formatted string that is an entire row of the chart.  It is a
1.2       stredwic  307: concatenation of student information and student course information.
                    308: 
                    309: =back
                    310: 
                    311: =cut
1.1       stredwic  312: 
                    313: sub StudentReport {
1.2       stredwic  314:     my ($cache,$name,$spacing,$showSequences)=@_;
                    315:     my ($username,$domain)=split(':',$name);
1.1       stredwic  316: 
                    317:     my $Str = '';
1.8       stredwic  318:     if(defined($cache->{$name.':error'})) {
1.10      stredwic  319:         return $Str;
1.8       stredwic  320:     }
1.1       stredwic  321:     if($cache->{$name.':error'} =~ /course/) {
                    322:         $Str .= '<b><font color="blue">No course data for student </font>';
                    323:         $Str .= '<font color="red">'.$username.'.</font></b><br>';
                    324:         return $Str;
                    325:     }
                    326: 
1.10      stredwic  327:     my $hasVersion = 'false';
                    328:     my $hasFinalData = 'false';
1.2       stredwic  329:     foreach my $sequence (@$showSequences) {
1.10      stredwic  330:         my $hasData = 'false';
1.2       stredwic  331:         my $characterCount=0;
1.1       stredwic  332:         foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
                    333:             my $problem = $cache->{$problemID.':problem'};
1.2       stredwic  334:             # All grades (except for versionless parts) are displayed as links
                    335:             # to their submission record.  Loop through all the parts for the
                    336:             # current problem in the correct order and prepare the output links
                    337:             foreach(split(/\:/,$cache->{$sequence.':'.$problemID.
                    338:                                         ':parts'})) {
1.9       stredwic  339:                 if($cache->{$name.':'.$problemID.':NoVersion'} eq 'true' ||
1.10      stredwic  340:                    $cache->{$name.':'.$problemID.':'.$_.':code'} eq ' ' ||
                    341:                    $cache->{$name.':'.$problemID.':'.$_.':code'} eq '') {
1.8       stredwic  342:                     $Str .= ' ';
1.10      stredwic  343:                     $characterCount++;
1.8       stredwic  344:                     next;
1.2       stredwic  345:                 }
1.10      stredwic  346:                 $hasVersion = 'true';
                    347:                 $hasData = 'true';
1.18      matthew   348:                 if (lc($ENV{'form.displaymode'}) ne 'display without links') {
                    349:                     $Str .= '<a href="/adm/grades?symb=';
                    350:                     $Str .= &Apache::lonnet::escape($problem);
                    351:                     $Str .= '&student='.$username.'&domain='.$domain;
1.21      minaeibi  352:                     $Str .= '&command=submission">';
1.18      matthew   353:                 }
1.8       stredwic  354:                 my $code = $cache->{$name.':'.$problemID.':'.$_.':code'};
                    355:                 my $tries = $cache->{$name.':'.$problemID.':'.$_.':tries'};
                    356:                 if($code eq '*' && $tries < 10 && $tries ne '') {
                    357:                     $code = $tries;
1.2       stredwic  358:                 }
1.8       stredwic  359:                 $Str .= $code;
1.18      matthew   360:                 if (lc($ENV{'form.displaymode'}) ne 'display without links') {
                    361:                     $Str .= '</a>';
                    362:                 }
1.10      stredwic  363:                 $characterCount++;
1.2       stredwic  364:             }
                    365:         }
                    366: 
                    367:         # Output the number of correct answers for the current sequence.
1.17      minaeibi  368:         # This part takes up 6 character slots, but is formated right
                    369:         # justified.
                    370:         my $spacesNeeded=$cache->{$sequence.':columnWidth'}-$characterCount;
                    371:         $spacesNeeded -= 3;
                    372:         $Str .= (' 'x$spacesNeeded);
                    373: 
                    374: #        my $outputProblemsCorrect = sprintf("%3d", $cache->{$name.':'.$sequence.
                    375: #							    ':problemsCorrect'});
                    376: 
                    377: 	my $outputProblemsCorrect = sprintf("%2d/%2d", $cache->{$name.':'.$sequence.
                    378:                                             ':problemsCorrect'},
                    379:                                             $characterCount);
                    380:         if($hasData eq 'true') {
                    381:             $Str .= '<font color="#007700">'.$outputProblemsCorrect.'</font>';
                    382:             $hasFinalData = 'true';
                    383:         } else {
                    384:             $Str .= '<font color="#007700">     </font>';
                    385:         }
                    386:         $Str .= $spacing;
                    387:     }
                    388: 
                    389:     # Output the total correct problems over the total number of problems.
                    390:     # I don't like this type of formatting, but it is a solution.  Need
                    391:     # a way to dynamically determine the space requirements.
                    392:     my $outputProblemsSolved = sprintf("%4d", $cache->{$name.':problemsSolved'});
                    393:     my $outputTotalProblems  = sprintf("%4d", $cache->{$name.':totalProblems'});
                    394:     if($hasFinalData eq 'true') {
                    395:         $Str .= '<font color="#000088">'.$outputProblemsSolved.
                    396: 	    ' / '.$outputTotalProblems.'</font>';
                    397:     } else {
                    398:         $Str .= '<font color="#000088">           </font>';
                    399:     }
                    400: 
                    401:     if($hasVersion eq 'false') {
                    402:         $Str = '<b><font color="blue">No course data.</font></b>';
                    403:     }
                    404: 
                    405:     return $Str;
                    406: }
                    407: 
                    408: 
                    409: sub StudentAverageTotal {
1.21      minaeibi  410:     my ($cache, $students, $sequenceKeys)=@_;
1.23      minaeibi  411:     my $Str = "\n<b>Summary Tables:</b>\n";
1.21      minaeibi  412:     my %Correct = ();
                    413:     my $ProblemsSolved = 0;
                    414:     my $TotalProblems = 0;
                    415:     my $StudentCount = 0;
                    416: 
                    417:     foreach my $name (@$students) {
                    418:         $StudentCount++;
                    419:         foreach my $sequence (@$sequenceKeys) {
1.23      minaeibi  420:             $Correct{$sequence} +=
                    421: 	       $cache->{$name.':'.$sequence.':problemsCorrect'};
1.17      minaeibi  422:         }
1.21      minaeibi  423: 	$ProblemsSolved += $cache->{$name.':problemsSolved'};
                    424:         $TotalProblems += $cache->{$name.':totalProblems'};
1.1       stredwic  425:     }
1.25      matthew   426:     if ($StudentCount) { 
1.27    ! minaeibi  427:         $ProblemsSolved = sprintf( "%.2f", 
        !           428:                              $ProblemsSolved/$StudentCount);
1.25      matthew   429:         $TotalProblems /= $StudentCount;
                    430:     } else {
                    431:         $ProblemsSolved = 0;
                    432:         $TotalProblems  = 0;
                    433:     }
1.27    ! minaeibi  434: 
1.24      minaeibi  435:     $Str .= '<table border=2 cellspacing="1">'."\n";
1.23      minaeibi  436:     $Str .= '<tr><td><b>Students Count</b></td><td><b>'.
                    437:             $StudentCount.'</b></td></tr>'."\n";
                    438:     $Str .= '<tr><td><b>Total Problems</b></td><td><b>'.
                    439:             $TotalProblems.'</b></td></tr>'."\n";
                    440:     $Str .= '<tr><td><b>Average Correct</b></td><td><b>'.
                    441:             $ProblemsSolved.'</b></td></tr>'."\n";
                    442:     $Str .= '</table>'."\n";
                    443: 
1.24      minaeibi  444:     $Str .= '<table border=2 cellspacing="1">'."\n";
1.23      minaeibi  445:     $Str .= '<tr><th>Title</th><th>Total Problems</th>'.
                    446:             '<th>Average Correct</th></tr>'."\n";
                    447:     foreach my $S(@$sequenceKeys) {
                    448:         my $title=$cache->{$S.':title'};
                    449: 	#$Str .= $cache->{$S.':problems'};
1.24      minaeibi  450: 	#my @problems=split(':', $cache->{$S.':problems'});
1.23      minaeibi  451: 	#my $pCount=scalar @problems;
                    452: 	my $pCount=MaxSeqPr($cache,@$students[0],$S);
1.25      matthew   453:         my $crr;
                    454: 	if ($StudentCount) {
                    455:             $crr=sprintf( "%.2f", $Correct{$S}/$StudentCount );
                    456:         } else {
                    457:             $crr="0.00";
                    458:         }
1.23      minaeibi  459:         $Str .= '<tr><td>'.$title.
                    460:                 '</td><td align=center>'.$pCount.
                    461:                 '</td><td align=center>'.$crr.
                    462:                 '</td></tr>'."\n";
1.10      stredwic  463:     }
1.1       stredwic  464: 
1.23      minaeibi  465:     $Str .= '</table>'."\n";
                    466: 
1.1       stredwic  467:     return $Str;
                    468: }
1.23      minaeibi  469: 
                    470: 
                    471: 
                    472: sub MaxSeqPr {
                    473:     my ($cache, $name, $sequence)=@_;
                    474:     my $prCount=0;
                    475:     foreach my $problemID (split(':', $cache->{$sequence.':problems'})) {
                    476:         my $problem = $cache->{$problemID.':problem'};
                    477:         foreach(split(/\:/,$cache->{$sequence.':'.$problemID.':parts'})) {
                    478:             if($cache->{$name.':'.$problemID.':NoVersion'} eq 'true' ||
                    479:                $cache->{$name.':'.$problemID.':'.$_.':code'} eq ' ' ||
                    480:                $cache->{$name.':'.$problemID.':'.$_.':code'} eq '') {
                    481:                  $prCount++;
                    482:                  next;
                    483:             }
                    484:             $prCount++;
                    485:         }
                    486:     }
                    487:     return $prCount;
                    488: }
                    489: 
                    490: 
1.1       stredwic  491: 
1.17      minaeibi  492: 
                    493: 
1.2       stredwic  494: =pod
                    495: 
                    496: =item &CreateLegend()
                    497: 
                    498: This function returns a formatted string containing the legend for the
                    499: chart.  The legend describes the symbols used to represent grades for
                    500: problems.
                    501: 
                    502: =cut
                    503: 
                    504: sub CreateLegend {
                    505:     my $Str = "<p><pre>".
1.13      minaeibi  506:               "   1  correct by student in 1 try\n".
                    507:               "   7  correct by student in 7 tries\n".
1.12      minaeibi  508:               "   *  correct by student in more than 9 tries\n".
1.20      minaeibi  509: 	      "   +  correct by hand grading or override\n".
1.12      minaeibi  510:               "   -  incorrect by override\n".
                    511: 	      "   .  incorrect attempted\n".
                    512: 	      "   #  ungraded attempted\n".
1.13      minaeibi  513:               "      not attempted (blank field)\n".
1.12      minaeibi  514: 	      "   x  excused".
1.17      minaeibi  515:               "</pre><p>";
1.2       stredwic  516:     return $Str;
                    517: }
                    518: 
                    519: =pod
                    520: 
                    521: =item &CreateColumnSelectionBox()
                    522: 
                    523: If there are columns not being displayed then this selection box is created
1.17      minaeibi  524: with a list of those columns.  When selections are made and the page
1.2       stredwic  525: refreshed, the columns will be removed from this box and the column is
                    526: put back in the chart.  If there is no columns to select, no row is added
                    527: to the interface table.
                    528: 
                    529: =over 4
                    530: Input: $CacheData, $headings
                    531: 
                    532: 
                    533: $CacheData: A pointer to a hash tied to the cached data
                    534: 
1.17      minaeibi  535: $headings:  An array of the names of the columns for the student information.
1.2       stredwic  536: They are used for displaying which columns are missing.
                    537: 
                    538: Output: $notThere
                    539: 
1.17      minaeibi  540: $notThere: The string contains one row of a table.  The first column has the
                    541: name of the selection box.  The second contains the selection box
1.2       stredwic  542: which has a size of four.
                    543: 
                    544: =back
                    545: 
                    546: =cut
                    547: 
                    548: sub CreateColumnSelectionBox {
1.4       stredwic  549:     my ($doNotShow)=@_;
1.2       stredwic  550: 
1.4       stredwic  551:     my $notThere = '';
                    552:     $notThere .= '<select name="ReselectColumns" size="4" ';
                    553:     $notThere .= 'multiple="true">'."\n";
                    554: 
                    555:     for(my $index=0; $index<$doNotShow->{'count'}; $index++) {
                    556:         my $name = $doNotShow->{$index.':name'};
                    557:         $notThere .= '<option value="';
                    558:         $notThere .= $doNotShow->{$index.':id'}.'">';
1.2       stredwic  559:         $notThere .= $name.'</option>'."\n";
                    560:     }
                    561: 
1.4       stredwic  562:     $notThere .= '</select>';
1.2       stredwic  563: 
1.4       stredwic  564:     return $notThere;
1.2       stredwic  565: }
                    566: 
                    567: =pod
                    568: 
                    569: =item &CreateColumnSelectors()
                    570: 
1.17      minaeibi  571: This function generates the checkboxes above the column headings.  The
1.2       stredwic  572: column will be removed if the checkbox is unchecked.
                    573: 
                    574: =over 4
                    575: 
                    576: Input: $CacheData, $headings
                    577: 
                    578: $CacheData: A pointer to a hash tied to the cached data
                    579: 
                    580: $headings:  An array of the names of the columns for the student 
                    581: information.  They are used to know what are the student information columns
                    582: 
                    583: Output: $present
                    584: 
                    585: $present: The string contains the first row of a table.  Each column contains
                    586: a checkbox which is left justified.  Currently left justification is used
                    587: for consistency of location over the column in which it presides.
                    588: 
                    589: =back
                    590: 
                    591: =cut
                    592: 
                    593: sub CreateColumnSelectors {
1.4       stredwic  594:     my ($infoHeadings, $sequenceHeadings, $sequenceKeys)=@_;
1.2       stredwic  595: 
1.4       stredwic  596:     my $present = '';
                    597:     for(my $index=0; $index<(scalar @$infoHeadings); $index++) {
1.2       stredwic  598:         $present .= '<td align="left">';
                    599:         $present .= '<input type="checkbox" checked="on" ';
1.4       stredwic  600:         $present .= 'name="HeadingColumn'.$infoHeadings->[$index].'" />';
                    601:         $present .= '</td>'."\n";
1.2       stredwic  602:     }
                    603: 
1.4       stredwic  604:     for(my $index=0; $index<(scalar @$sequenceHeadings); $index++) {
1.2       stredwic  605:         $present .= '<td align="left">';
                    606:         $present .= '<input type="checkbox" checked="on" ';
1.4       stredwic  607:         $present .= 'name="SequenceColumn'.$sequenceKeys->[$index].'" />';
                    608:         $present .= '</td>'."\n";
1.2       stredwic  609:     }
                    610: 
1.4       stredwic  611:     return $present;
1.2       stredwic  612: }
                    613: 
1.1       stredwic  614: #---- END Student Assessment Web Page ----------------------------------------
1.2       stredwic  615: 
                    616: #---- Student Assessment Worker Functions ------------------------------------
                    617: 
                    618: sub FindSelectedStudent {
                    619:     my($cache, $selectedName, $students)=@_;
1.3       stredwic  620: 
1.17      minaeibi  621:     if($selectedName eq 'All Students' ||
1.3       stredwic  622:        $selectedName eq 'No Student Selected') {
                    623:         return $selectedName;
                    624:     }
                    625: 
                    626:     for(my $index=0; $index<(scalar @$students); $index++) {
1.2       stredwic  627:         my $fullname = $cache->{$students->[$index].':fullname'};
                    628:         if($fullname eq $selectedName) {
                    629:             if($cache->{'StudentAssessmentMove'} eq 'next') {
                    630:                 if($index == ((scalar @$students) - 1)) {
                    631:                     $selectedName = $students->[0];
1.3       stredwic  632:                     return $selectedName;
1.2       stredwic  633:                 } else {
                    634:                     $selectedName = $students->[$index+1];
1.3       stredwic  635:                     return $selectedName;
1.2       stredwic  636:                 }
                    637:             } elsif($cache->{'StudentAssessmentMove'} eq 'previous') {
                    638:                 if($index == 0) {
                    639:                     $selectedName = $students->[-1];
1.3       stredwic  640:                     return $selectedName;
1.2       stredwic  641:                 } else {
                    642:                     $selectedName = $students->[$index-1];
1.3       stredwic  643:                     return $selectedName;
1.2       stredwic  644:                 }
                    645:             } else {
                    646:                 $selectedName = $students->[$index];
1.3       stredwic  647:                 return $selectedName;
1.2       stredwic  648:             }
                    649:             last;
                    650:         }
                    651:     }
                    652: 
1.3       stredwic  653:     return 'No Student Selected';
1.2       stredwic  654: }
                    655: 
                    656: =pod
                    657: 
                    658: =item &ShouldShowColumn()
                    659: 
                    660: Determine if a specified column should be shown on the chart.
                    661: 
                    662: =over 4
                    663: 
                    664: Input: $cache, $test
                    665: 
                    666: $cache: A pointer to the hash tied to the cached data
                    667: 
                    668: $test: The form name of the column (heading.$headingIndex) or 
                    669: (sequence.$sequenceIndex)
                    670: 
                    671: Output: 0 (false), 1 (true)
                    672: 
                    673: =back
                    674: 
                    675: =cut
                    676: 
                    677: sub ShouldShowColumns {
                    678:     my ($cache,$headings,$cacheKey)=@_;
                    679: 
                    680:     my @infoKeys=();
                    681:     my @infoHeadings=();
                    682: 
                    683:     my @sequenceKeys=();
                    684:     my @sequenceHeadings=();
                    685: 
1.4       stredwic  686:     my %doNotShow;
                    687: 
1.2       stredwic  688:     my $index;
1.4       stredwic  689:     my $count = 0;
                    690:     my $check = '';
1.2       stredwic  691:     for($index=0; $index < scalar @$headings; $index++) {
1.4       stredwic  692:         $check = 'HeadingColumn'.$headings->[$index];
                    693:         if($cache->{'HeadingsFound'} =~ /$check/) {
                    694:             push(@infoHeadings, $headings->[$index]);
                    695:             push(@infoKeys, $cacheKey->[$index]);
                    696:         } else {
                    697:             $doNotShow{$count.':name'} = $headings->[$index];
                    698:             $doNotShow{$count.':id'} = 'HeadingColumn'.$headings->[$index];
                    699:             $count++;
                    700:         }
1.2       stredwic  701:     }
                    702: 
                    703:     foreach my $sequence (split(/\:/,$cache->{'orderedSequences'})) {
1.4       stredwic  704:         $check = 'SequenceColumn'.$sequence;
1.21      minaeibi  705:         if($cache->{'SequencesFound'} eq 'All Sequences' ||
1.4       stredwic  706:            $cache->{'SequencesFound'} =~ /$check/) {
                    707:             push(@sequenceHeadings, $cache->{$sequence.':title'});
                    708:             push(@sequenceKeys, $sequence);
                    709:         } else {
                    710:             $doNotShow{$count.':name'} = $cache->{$sequence.':title'};
                    711:             $doNotShow{$count.':id'} = 'SequenceColumn'.$sequence;
                    712:             $count++;
                    713:         }
1.2       stredwic  714:     }
                    715: 
1.4       stredwic  716:     $doNotShow{'count'} = $count;
1.2       stredwic  717: 
1.21      minaeibi  718:     return (\@infoHeadings, \@infoKeys, \@sequenceHeadings,
1.4       stredwic  719:             \@sequenceKeys, \%doNotShow);
1.2       stredwic  720: }
                    721: 
                    722: #---- END Student Assessment Worker Functions --------------------------------
                    723: 
1.1       stredwic  724: 1;
                    725: __END__

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