File:  [LON-CAPA] / loncom / interface / statistics / lonstudentassessment.pm
Revision 1.9: download - view: text, annotated - select for diffs
Sat Aug 31 18:31:15 2002 UTC (21 years, 10 months ago) by stredwic
Branches: MAIN
CVS tags: HEAD
Fixed the problem where lonstudentassessment would not update after the
data had been downloaded once, even though the student had done more
work.  Now it updates properly.  Simply set the value to false instead
of checking to see if it was defined, since I define it if it true.  I
noticed the columns getting off a little now, so I will look at it next

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

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