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

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

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