File:  [LON-CAPA] / loncom / interface / statistics / lonstudentassessment.pm
Revision 1.49: download - view: text, annotated - select for diffs
Thu May 29 21:38:32 2003 UTC (21 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: HEAD
Bug 1470 - reimplement single student view in chart.
lonstatistics.pm:
  Changed handling of $curr_student, $prev_student, and $next_student.  Now
  assumed to be undef when they are not appropriate.
  Renamed 'StudentAssessmentStudent' form parameter to 'SelectedStudent'.
lonstudentassessment.pm:
  Added package variable $single_student_mode to flag the single student mode.
  Added hidden form parameter 'sort', to maintain sort key.
  Added &next_and_previous_buttons to present the user with 3 buttons:
	"previous student", "all students", and "next student"
  Added &SingleStudentTotal to output an html table with some statistics about
        the students performance.
  Modified &html_finish to call &SingleStudentTotal instead of
	&StudentAverageTotal if in $single_student_mode

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lonstudentassessment.pm,v 1.49 2003/05/29 21:38:32 matthew Exp $
    4: #
    5: # Copyright Michigan State University Board of Trustees
    6: #
    7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: # (Navigate problems for statistical reports
   27: #
   28: #######################################################
   29: #######################################################
   30: 
   31: =pod
   32: 
   33: =head1 NAME
   34: 
   35: lonstudentassessment
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: Presents assessment data about a student or a group of students.
   40: 
   41: =head1 Subroutines
   42: 
   43: =over 4 
   44: 
   45: =cut
   46: 
   47: #######################################################
   48: #######################################################
   49: 
   50: package Apache::lonstudentassessment;
   51: 
   52: use strict;
   53: use Apache::lonstatistics;
   54: use Apache::lonhtmlcommon;
   55: use Apache::loncoursedata;
   56: use Apache::lonnet; # for logging porpoises
   57: use Spreadsheet::WriteExcel;
   58: 
   59: #######################################################
   60: #######################################################
   61: =pod
   62: 
   63: =item Package Variables
   64: 
   65: =over 4
   66: 
   67: =item $Statistics Hash ref to store student data.  Indexed by symb,
   68:       contains hashes with keys 'score' and 'max'.
   69: 
   70: =cut
   71: 
   72: #######################################################
   73: #######################################################
   74: 
   75: my $Statistics;
   76: 
   77: #######################################################
   78: #######################################################
   79: 
   80: =pod
   81: 
   82: =item $show_links 'yes' or 'no' for linking to student performance data
   83: 
   84: =item $output_mode 'html', 'excel', or 'csv' for output mode
   85: 
   86: =item $show 'all', 'totals', or 'scores' determines how much data is output
   87: 
   88: =item $single_student_mode evaluates to true if we are showing only one
   89: student.
   90: 
   91: =cut
   92: 
   93: #######################################################
   94: #######################################################
   95: my $show_links;
   96: my $output_mode;
   97: my $show;
   98: my $single_student_mode;
   99: 
  100: #######################################################
  101: #######################################################
  102: # End of package variable declarations
  103: 
  104: =pod
  105: 
  106: =back
  107: 
  108: =cut
  109: 
  110: #######################################################
  111: #######################################################
  112: 
  113: =pod
  114: 
  115: =item &BuildStudentAssessmentPage()
  116: 
  117: Inputs: 
  118: 
  119: =over 4
  120: 
  121: =item $r Apache Request
  122: 
  123: =item $c Apache Connection 
  124: 
  125: =back
  126: 
  127: =cut
  128: 
  129: #######################################################
  130: #######################################################
  131: sub BuildStudentAssessmentPage {
  132:     my ($r,$c)=@_;
  133:     undef($Statistics);
  134:     $single_student_mode = 1 if ($ENV{'form.SelectedStudent'});
  135:     #
  136:     # Print out the HTML headers for the interface
  137:     #    This also parses the output mode selector
  138:     #    This step must always be done.
  139:     $r->print(&CreateInterface());
  140:     $r->print('<input type="hidden" name="notfirstrun" value="true" />');
  141:     $r->print('<input type="hidden" name="sort" value="'.
  142:               $ENV{'form.sort'}.'" />');
  143:     $r->rflush();
  144:     if (! exists($ENV{'form.notfirstrun'}) && ! $single_student_mode) {
  145:         $r->print(<<ENDMSG);
  146: <p>
  147: <font size="+2">
  148: Please make your selections in the boxes above and hit 
  149: the button marked &quot;Update&nbsp;Display&quot;.
  150: </font>
  151: </p>
  152: ENDMSG
  153: #        $r->print(&OutputDescriptions());
  154:         return;
  155:     }
  156:     #
  157:     #
  158:     my $initialize     = \&html_initialize;
  159:     my $output_student = \&html_outputstudent;
  160:     my $finish         = \&html_finish;
  161:     #
  162:     if ($output_mode eq 'excel') {
  163:         $initialize     = \&excel_initialize;
  164:         $output_student = \&excel_outputstudent;
  165:         $finish         = \&excel_finish;
  166: #    } elsif ($output_mode eq 'multi-sheet excel') {
  167: #        $initialize     = \&multi_sheet_excel_initialize;
  168: #        $output_student = \&multi_sheet_excel_outputstudent;
  169: #        $finish         = \&multi_sheet_excel_finish;
  170:     } elsif ($output_mode eq 'csv') {
  171:         $initialize     = \&csv_initialize;
  172:         $output_student = \&csv_outputstudent;
  173:         $finish         = \&csv_finish;
  174:     }
  175:     #
  176:     if($c->aborted()) {  return ; }
  177:     #
  178:     # Determine which students we want to look at
  179:     my @Students;
  180:     if ($single_student_mode) {
  181:         @Students = (&Apache::lonstatistics::current_student());
  182:         $r->print(&next_and_previous_buttons());
  183:         $r->rflush();
  184:     } else {
  185:         @Students = @Apache::lonstatistics::Students;
  186:     }
  187:     #
  188:     # Call the initialize routine selected above
  189:     $initialize->($r);
  190:     foreach my $student (@Students) {
  191:         if($c->aborted()) { 
  192:             $finish->($r);
  193:             return ; 
  194:         }
  195:         # Call the output_student routine selected above
  196:         $output_student->($r,$student);
  197:     }
  198:     # Call the "finish" routine selected above
  199:     $finish->($r);
  200:     #
  201:     return;
  202: }
  203: 
  204: #######################################################
  205: #######################################################
  206: sub next_and_previous_buttons {
  207:     my $Str = '';
  208:     $Str .= '<input type="hidden" name="SelectedStudent" value="'.
  209:         $ENV{'form.SelectedStudent'}.'" />';
  210:     #
  211:     # Build the previous student link
  212:     my $previous = &Apache::lonstatistics::previous_student();
  213:     my $previousbutton = '';
  214:     if (defined($previous)) {
  215:         my $sname = $previous->{'username'}.':'.$previous->{'domain'};
  216:         $previousbutton .= '<input type="button" value="'.
  217:             'Previous Student ('.
  218:             $previous->{'username'}.'@'.$previous->{'domain'}.')'.
  219:             '" onclick="document.Statistics.SelectedStudent.value='.
  220:             "'".$sname."'".';'.
  221:             'document.Statistics.submit();" />';
  222:     } else {
  223:         $previousbutton .= '<input type="button" value="'.
  224:             'Previous student (none)'.'" />';
  225:     }
  226:     #
  227:     # Build the next student link
  228:     my $next = &Apache::lonstatistics::next_student();
  229:     my $nextbutton = '';
  230:     if (defined($next)) {
  231:         my $sname = $next->{'username'}.':'.$next->{'domain'};
  232:         $nextbutton .= '<input type="button" value="'.
  233:             'Next Student ('.
  234:             $next->{'username'}.'@'.$next->{'domain'}.')'.
  235:             '" onclick="document.Statistics.SelectedStudent.value='.
  236:             "'".$sname."'".';'.
  237:             'document.Statistics.submit();" />';
  238:     } else {
  239:         $nextbutton .= '<input type="button" value="'.
  240:             'Next student (none)'.'" />';
  241:     }
  242:     #
  243:     # Build the 'all students' button
  244:     my $all = '';
  245:     $all .= '<input type="button" value="All Students" '.
  246:             '" onclick="document.Statistics.SelectedStudent.value='.
  247:             "''".';'.'document.Statistics.submit();" />';
  248:     $Str .= $previousbutton.('&nbsp;'x5).$all.('&nbsp;'x5).$nextbutton;
  249:     return $Str;
  250: }
  251: 
  252: #######################################################
  253: #######################################################
  254: 
  255: sub get_student_fields_to_show {
  256:     my @to_show = @Apache::lonstatistics::SelectedStudentData;
  257:     foreach (@to_show) {
  258:         if ($_ eq 'all') {
  259:             @to_show = @Apache::lonstatistics::StudentDataOrder;
  260:             last;
  261:         }
  262:     }
  263:     return @to_show;
  264: }
  265: 
  266: #######################################################
  267: #######################################################
  268: 
  269: =pod
  270: 
  271: =item &CreateInterface()
  272: 
  273: Called by &BuildStudentAssessmentPage to create the top part of the
  274: page which displays the chart.
  275: 
  276: Inputs: None
  277: 
  278: Returns:  A string containing the HTML for the headers and top table for 
  279: the chart page.
  280: 
  281: =cut
  282: 
  283: #######################################################
  284: #######################################################
  285: sub CreateInterface {
  286:     my $Str = '';
  287: #    $Str .= &CreateLegend();
  288:     $Str .= '<table cellspacing="5">'."\n";
  289:     $Str .= '<tr>';
  290:     $Str .= '<td align="center"><b>Sections</b></td>';
  291:     $Str .= '<td align="center"><b>Student Data</b></td>';
  292:     $Str .= '<td align="center"><b>Enrollment Status</b></td>';
  293:     $Str .= '<td align="center"><b>Sequences and Folders</b></td>';
  294:     $Str .= '<td align="center"><b>Output Format</b></td>';
  295:     $Str .= '</tr>'."\n";
  296:     #
  297:     $Str .= '<tr><td align="center">'."\n";
  298:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  299:     $Str .= '</td><td align="center">';
  300:     my $only_seq_with_assessments = sub { 
  301:         my $s=shift;
  302:         if ($s->{'num_assess'} < 1) { 
  303:             return 0;
  304:         } else { 
  305:             return 1;
  306:         }
  307:     };
  308:     $Str .= &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',
  309:                                                       5,undef);
  310:     $Str .= '</td><td>'."\n";
  311:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  312:     $Str .= '</td><td>'."\n";
  313:     $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
  314:                                               $only_seq_with_assessments);
  315:     $Str .= '</td><td>'."\n";
  316:     $Str .= &CreateAndParseOutputSelector();
  317:     $Str .= '</td></tr>'."\n";
  318:     $Str .= '</table>'."\n";
  319:     return $Str;
  320: }
  321: 
  322: #######################################################
  323: #######################################################
  324: 
  325: =pod
  326: 
  327: =item &CreateAndParseOutputSelector()
  328: 
  329: =cut
  330: 
  331: #######################################################
  332: #######################################################
  333: my @OutputOptions = 
  334:     ({ name  => 'HTML, with links',
  335:        value => 'html, with links',
  336:        description => 'Output HTML with each symbol linked to the problem '.
  337: 	   'which generated it.',
  338:        mode => 'html',
  339:        show => 'all',
  340:        show_links => 'yes',
  341:        },
  342:      { name  => 'HTML, with all links',
  343:        value => 'html, with all links',
  344:        description => 'Output HTML with each symbol linked to the problem '.
  345: 	   'which generated it.  '.
  346:            'This includes links for unattempted problems.',
  347:        mode => 'html',
  348:        show => 'all',
  349:        show_links => 'all',
  350:        },
  351:      { name  => 'HTML, without links',
  352:        value => 'html, without links',
  353:        description => 'Output HTML.  By not including links, the size of the'.
  354: 	   ' web page is greatly reduced.  If your browser crashes on the '.
  355: 	   'full display, try this.',
  356:        mode => 'html',
  357:        show => 'all',
  358:        show_links => 'no',
  359:            },
  360:      { name  => 'HTML, scores only',
  361:        value => 'html, scores only',
  362:        description => 'Output HTML, only showing the total number of correct'.
  363: 	   ' problems (or problem parts) and not the maximum possible for '.
  364: 	   'each student',
  365:        mode => 'html',
  366:        show => 'scores',
  367:        show_links => 'no',
  368:            },
  369:      { name  => 'HTML, totals',
  370:        value => 'html, totals',
  371:        description => 'Output HTML, but only the summary statistics for each'.
  372: 	   ' sequence selected for each student.',
  373:        mode => 'html',
  374:        show => 'totals',
  375:        show_links => 'no',
  376:        },
  377:      { name  => 'HTML, summary table only',
  378:        value => 'html summary table only',
  379:        description => 'Output HTML, but only the final summary table for '.
  380:            'all students across all sequences.',
  381:        mode => 'html',
  382:        show => 'final table',
  383:        show_links => 'no',
  384:        },
  385:      { name  => 'Excel, scores only',
  386:        value => 'excel, scores only',
  387:        description => 'Output an Excel file (compatable with Excel 95), '.
  388: 	   'with a single column for each sequence showing the students '.
  389: 	   'score.',
  390:        mode => 'excel',
  391:        show => 'scores',
  392:        show_links => 'no',
  393:            },
  394:      { name  => 'Excel, totals',
  395:        value => 'excel, totals',
  396:        description => 'Output an Excel file (compatable with Excel 95), '.
  397: 	   'with two columns for each sequence, the students score on the '.
  398: 	   'sequence and the students maximum possible on the sequence',
  399:        mode => 'excel',
  400:        show => 'totals',
  401:        show_links => 'no',
  402:            },
  403: #     { name  => 'multi-sheet Excel',
  404: #       value => 'multi-sheet excel',
  405: #       description => 'Output an Excel file (compatable with Excel 95), '.
  406: #	   'with a seperate worksheet for each sequence you have selected '.
  407: #           'the data for each problem part '.
  408: #           '(number of tries, status, points awarded) will be listed.',
  409: #       mode => 'multi-sheet excel',
  410: #       show => 'totals',
  411: #       show_links => 'no',
  412: #           },
  413: #     { name  => 'multi-sheet Excel, by section',
  414: #       value => 'multi-sheet excel, by section',
  415: #       description => 'Output an Excel file (compatable with Excel 95), '.
  416: #	   'with a seperate worksheet for each sequence you have selected '.
  417: #           'the data for each problem part '.
  418: #           '(number of tries, status, points awarded) will be listed.  '.
  419: #           'There will be one Excel workbook for each section selected.',
  420: #       mode => 'multi-sheet excel',
  421: #       show => 'by section',
  422: #       show_links => 'no',
  423: #           },
  424:      { name  => 'CSV, everything',
  425:        value => 'csv, everything',
  426:        description => '',
  427:        mode => 'csv',
  428:        show => 'all',
  429:        show_links => 'no',
  430:            },
  431:      { name  => 'CSV, scores only',
  432:        value => 'csv, scores only',
  433:        description => '',
  434:        mode => 'csv',
  435:        show => 'scores',
  436:        show_links => 'no',
  437:            },
  438:      { name  => 'CSV, totals',
  439:        value => 'csv, totals',
  440:        description => '',
  441:        mode => 'csv',
  442:        show => 'totals',
  443:        show_links => 'no',
  444:            },
  445:      );
  446: 
  447: sub OutputDescriptions {
  448:     my $Str = '';
  449:     $Str .= "<h2>Output Modes</h2>\n";
  450:     $Str .= "<dl>\n";
  451:     foreach my $outputmode (@OutputOptions) {
  452: 	$Str .="    <dt>".$outputmode->{'name'}."</dt>\n";
  453: 	$Str .="        <dd>".$outputmode->{'description'}."</dd>\n";
  454:     }
  455:     $Str .= "</dl>\n";
  456:     return $Str;
  457: }
  458: 
  459: sub CreateAndParseOutputSelector {
  460:     my $Str = '';
  461:     my $elementname = 'chartoutputmode';
  462:     #
  463:     # Format for output options is 'mode, restrictions';
  464:     my $selected = 'html, with links';
  465:     if (exists($ENV{'form.'.$elementname})) {
  466:         if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
  467:             $selected = $ENV{'form.'.$elementname}->[0];
  468:         } else {
  469:             $selected = $ENV{'form.'.$elementname};
  470:         }
  471:     }
  472:     #
  473:     # Set package variables describing output mode
  474:     $show_links  = 'no';
  475:     $output_mode = 'html';
  476:     $show        = 'all';
  477:     foreach my $option (@OutputOptions) {
  478:         next if ($option->{'value'} ne $selected);
  479:         $output_mode = $option->{'mode'};
  480:         $show        = $option->{'show'};
  481:         $show_links  = $option->{'show_links'};
  482:     }
  483: 
  484:     #
  485:     # Build the form element
  486:     $Str = qq/<select size="5" name="$elementname">/;
  487:     foreach my $option (@OutputOptions) {
  488:         $Str .= "\n".'    <option value="'.$option->{'value'}.'"';
  489:         $Str .= " selected " if ($option->{'value'} eq $selected);
  490:         $Str .= ">".$option->{'name'}."<\/option>";
  491:     }
  492:     $Str .= "\n</select>";
  493:     return $Str;
  494: }
  495: 
  496: #######################################################
  497: #######################################################
  498: 
  499: =pod
  500: 
  501: =head2 HTML output routines
  502: 
  503: =item &html_initialize($r)
  504: 
  505: Create labels for the columns of student data to show.
  506: 
  507: =item &html_outputstudent($r,$student)
  508: 
  509: Return a line of the chart for a student.
  510: 
  511: =item &html_finish($r)
  512: 
  513: =cut
  514: 
  515: #######################################################
  516: #######################################################
  517: {
  518:     my $padding;
  519:     my $count;
  520: 
  521:     my $nodata_count; # The number of students for which there is no data
  522:     my %prog_state;   # progress state used by loncommon PrgWin routines
  523: 
  524: sub html_initialize {
  525:     my ($r) = @_;
  526:     #
  527:     $padding = ' 'x3;
  528:     $count = 0;
  529:     $nodata_count = 0;
  530:     #
  531:     $r->print("<h3>".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
  532:               "&nbsp;&nbsp;".localtime(time)."</h3>");
  533: 
  534:     #
  535:     # Set up progress window for 'final table' display only
  536:     if ($show eq 'final table') {
  537:         my $studentcount = scalar(@Apache::lonstatistics::Students); 
  538:         %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
  539:             ($r,'Summary Table Status',
  540:              'Summary Table Compilation Progress', $studentcount);
  541:     }
  542:     my $Str = "<pre>\n";
  543:     # First, the @StudentData fields need to be listed
  544:     my @to_show = &get_student_fields_to_show();
  545:     foreach my $field (@to_show) {
  546:         my $title=$Apache::lonstatistics::StudentData{$field}->{'title'};
  547:         my $base =$Apache::lonstatistics::StudentData{$field}->{'base_width'};
  548:         my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
  549:         $Str .= $title.' 'x($width-$base).$padding;
  550:     }
  551:     # Now the selected sequences need to be listed
  552:     foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()){
  553:         my $title = $sequence->{'title'};
  554:         my $base  = $sequence->{'base_width'};
  555:         my $width = $sequence->{'width'};
  556:         $Str .= $title.' 'x($width-$base).$padding;
  557:     }
  558:     $Str .= "total (of shown problems)</pre>\n";
  559:     $Str .= "<pre>";
  560:     #
  561:     # Check for suppression of output
  562:     if ($show eq 'final table') {
  563:         $Str = '';
  564:     }
  565:     $r->print($Str);
  566:     $r->rflush();
  567:     return;
  568: }
  569: 
  570: sub html_outputstudent {
  571:     my ($r,$student) = @_;
  572:     my $Str = '';
  573:     #
  574:     if($count++ % 5 == 0 && $count > 0) {
  575:         $r->print("</pre><pre>");
  576:     }
  577:     # First, the @StudentData fields need to be listed
  578:     my @to_show = &get_student_fields_to_show();
  579:     foreach my $field (@to_show) {
  580:         my $title=$student->{$field};
  581:         my $base = length($title);
  582:         my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
  583:         $Str .= $title.' 'x($width-$base).$padding;
  584:     }
  585:     # Get ALL the students data
  586:     my %StudentsData;
  587:     my @tmp = &Apache::loncoursedata::get_current_state
  588:         ($student->{'username'},$student->{'domain'},undef,
  589:          $ENV{'request.course.id'});
  590:     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
  591:         %StudentsData = @tmp;
  592:     }
  593:     if (scalar(@tmp) < 1) {
  594:         $nodata_count++;
  595:         return if ($show eq 'final table');
  596:         $Str .= '<font color="blue">No Course Data</font>'."\n";
  597:         $r->print($Str);
  598:         $r->rflush();
  599:         return;
  600:     }
  601:     #
  602:     # By sequence build up the data
  603:     my $studentstats;
  604:     my $PerformanceStr = '';
  605:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  606:         my ($performance,$score,$seq_max) =
  607:             &StudentPerformanceOnSequence($student,\%StudentsData,
  608:                                           $seq,$show_links);
  609:         my $ratio = $score.'/'.$seq_max;
  610:         #
  611:         if ($show eq 'totals') {
  612:             $performance = ' 'x(length($seq_max)-length($score)).$ratio;
  613:             $performance .= ' 'x($seq->{'width'}-length($performance));
  614:         } elsif ($show eq 'scores') {
  615:             $performance = $score;
  616:             $performance .= ' 'x($seq->{'width'}-length($performance));
  617:         } else {
  618:             # Pad with extra spaces
  619:             $performance .= ' 'x($seq->{'width'}-$seq_max-
  620:                                  length($ratio)
  621:                                  ).$ratio;
  622:         }
  623:         #
  624:         $Str .= $performance.$padding;
  625:         #
  626:         $studentstats->{$seq->{'symb'}}->{'score'}= $score;
  627:         $studentstats->{$seq->{'symb'}}->{'max'}  = $seq_max;
  628:     }
  629:     #
  630:     # Total it up and store the statistics info.
  631:     my ($score,$max) = (0,0);
  632:     while (my ($symb,$seq_stats) = each (%{$studentstats})) {
  633:         $Statistics->{$symb}->{'score'} += $seq_stats->{'score'};
  634:         $Statistics->{$symb}->{'max'}   += $seq_stats->{'max'};
  635:         $score += $seq_stats->{'score'};
  636:         $max   += $seq_stats->{'max'};
  637:     }
  638:     $Str .= ' '.' 'x(length($max)-length($score)).$score.'/'.$max;
  639:     $Str .= " \n";
  640:     #
  641:     # Check for suppressed output and update the progress window if so...
  642:     if ($show eq 'final table') {
  643:         $Str = '';
  644:         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
  645:                                                  'last student');
  646:     }
  647:     #
  648:     $r->print($Str);
  649:     #
  650:     $r->rflush();
  651:     return;
  652: }    
  653: 
  654: sub html_finish {
  655:     my ($r) = @_;
  656:     #
  657:     # Check for suppressed output and close the progress window if so
  658:     if ($show eq 'final table') {
  659:         &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  660:     } else {
  661:         $r->print("</pre>\n"); 
  662:     }
  663:     if ($single_student_mode) {
  664:         $r->print(&SingleStudentTotal());
  665:     } else {
  666:         $r->print(&StudentAverageTotal());
  667:     }
  668:     $r->rflush();
  669:     return;
  670: }
  671: 
  672: sub StudentAverageTotal {
  673:     my $Str = "<h3>Summary Tables</h3>\n";
  674:     my $num_students = scalar(@Apache::lonstatistics::Students);
  675:     my $total_ave = 0;
  676:     my $total_max = 0;
  677:     $Str .= '<table border=2 cellspacing="1">'."\n";
  678:     $Str .= "<tr><th>Title</th><th>Average</th><th>Maximum</th></tr>\n";
  679:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  680:         my $ave;
  681:         if ($num_students > $nodata_count) {
  682:             $ave = int(100*($Statistics->{$seq->{'symb'}}->{'score'}/
  683:                             ($num_students-$nodata_count)))/100;
  684:         } else {
  685:             $ave = 0;
  686:         }
  687:         $total_ave += $ave;
  688:         my $max = $seq->{'num_assess_parts'};
  689:         $total_max += $max;
  690:         if ($ave == 0) {
  691:             $ave = "0.00";
  692:         }
  693:         $ave .= '&nbsp;';
  694:         $max .= '&nbsp;&nbsp;&nbsp;';
  695:         $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
  696:             '<td align="right">'.$ave.'</td>'.
  697:                 '<td align="right">'.$max.'</td></tr>'."\n";
  698:     }
  699:     $total_ave = int(100*$total_ave)/100; # only two digit
  700:     $Str .= "</table>\n";
  701:     $Str .= '<table border=2 cellspacing="1">'."\n";
  702:     $Str .= '<tr><th>Number of Students</th><th>Average</th>'.
  703:         "<th>Maximum</th></tr>\n";
  704:     $Str .= '<tr><td>'.($num_students-$nodata_count).'</td>'.
  705:         '<td>'.$total_ave.'</td><td>'.$total_max.'</td>';
  706:     $Str .= "</table>\n";
  707:     return $Str;
  708: }
  709: 
  710: sub SingleStudentTotal {
  711:     my $student = &Apache::lonstatistics::current_student();
  712:     my $Str = "<h3>Summary Table For ".$student->{'username'}.'@'.
  713:         $student->{'domain'}."</h3>\n";
  714:     $Str .= '<table border=2 cellspacing="1">'."\n";
  715:     $Str .= 
  716:         "<tr><th>Sequence or Folder</th><th>Score</th><th>Maximum</th></tr>\n";
  717:     my $total = 0;
  718:     my $total_max = 0;
  719:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  720:         my $value = $Statistics->{$seq->{'symb'}}->{'score'};
  721:         my $max = $Statistics->{$seq->{'symb'}}->{'max'};
  722:         $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
  723:             '<td align="right">'.$value.'</td>'.
  724:                 '<td align="right">'.$max.'</td></tr>'."\n";
  725:         $total += $value;
  726:         $total_max +=$max;
  727:     }
  728:     $Str .= '<tr><td><b>Total</b></td>'.
  729:         '<td align="right">'.$total.'</td>'.
  730:         '<td align="right">'.$total_max."</td></tr>\n";
  731:     $Str .= "</table>\n";
  732:     return $Str;
  733: }
  734: 
  735: }
  736: 
  737: #######################################################
  738: #######################################################
  739: 
  740: =pod
  741: 
  742: =head2 Multi-Sheet EXCEL subroutines
  743: 
  744: =item &multi_sheet_excel_initialize($r)
  745: 
  746: =item &multi_sheet_excel_outputstudent($r,$student)
  747: 
  748: =item &multi_sheet_excel_finish($r)
  749: 
  750: =cut
  751: 
  752: #######################################################
  753: #######################################################
  754: {
  755: 
  756: sub multi_sheet_excel_initialize {
  757:     my ($r)=@_;
  758:     $r->print("<h1>Not yet implemented</h1>");
  759:     # 
  760:     # Estimate the size of the file.  We would like to have < 5 megs of data.
  761:     my $max_size = 5000000;
  762:     my $num_students  = scalar(@Apache::lonstatistics::Students);
  763:     my $num_sequences = 0;
  764:     my $num_data_per_part  = 2; # 'status' and 'numtries'
  765:     my $fields_per_student = scalar(&get_student_fields_to_show());
  766:     my $bytes_per_field    = 20; # Back of the envelope calculation
  767:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  768:         $num_sequences++ if ($seq->{'num_assess'} > 0);
  769:         $fields_per_student += $num_data_per_part * $seq->{'num_assess_parts'};
  770:     }
  771:     my $size_estimate = $fields_per_student*$num_students*$bytes_per_field;
  772:     #
  773:     # Compute number of workbooks
  774:     my $num_workbooks = 1;
  775:     if ($size_estimate > $max_size) { # try to stay under 5 megs
  776:         $num_workbooks += int($size_estimate / $max_size);
  777:     }
  778:     if ($show eq 'by section') {
  779:         if (@Apache::lonstatistics::SelectedSections > 1 && 
  780:             $Apache::lonstatistics::SelectedSections[0] ne 'all') {
  781:             $num_workbooks = scalar(@Apache::lonstatistics::SelectedSections);
  782:         } else {
  783:             # @Apache::lonstatistics::Sections contains 'all' as well.
  784:             $num_workbooks = scalar(@Apache::lonstatistics::Sections) - 1;
  785:         }
  786:     }
  787:     
  788:     $r->print("Maximum allowed size: ".$max_size." bytes<br />");
  789:     $r->print("Number of students: ".$num_students."<br />");
  790:     $r->print("Number of fields per student: ".$fields_per_student."<br />");
  791:     $r->print("Total number of fields: ".($fields_per_student*$num_students).
  792:               "<br />");
  793:     $r->print("Bytes per field: ".$bytes_per_field." (estimated)"."<br />");
  794:     $r->print("Estimated size: ".$size_estimate." bytes<br />");
  795:     $r->print("Number of workbooks: ".$num_workbooks."<br />");
  796:     $r->rflush();
  797:     return;
  798: }
  799: 
  800: sub multi_sheet_excel_outputstudent {
  801:     my ($r,$student) = @_;
  802: }
  803: 
  804: sub multi_sheet_excel_finish {
  805:     my ($r) = @_;
  806: }
  807: 
  808: }
  809: #######################################################
  810: #######################################################
  811: 
  812: =pod
  813: 
  814: =head2 EXCEL subroutines
  815: 
  816: =item &excel_initialize($r)
  817: 
  818: =item &excel_outputstudent($r,$student)
  819: 
  820: =item &excel_finish($r)
  821: 
  822: =cut
  823: 
  824: #######################################################
  825: #######################################################
  826: {
  827: 
  828: my $excel_sheet;
  829: my $excel_workbook;
  830: 
  831: my $filename;
  832: my $rows_output;
  833: my $cols_output;
  834: 
  835: my %prog_state; # progress window state
  836: 
  837: sub excel_initialize {
  838:     my ($r) = @_;
  839:     #
  840:     $filename = '/prtspool/'.
  841:         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
  842:             time.'_'.rand(1000000000).'.xls';
  843:     #
  844:     $excel_workbook = undef;
  845:     $excel_sheet = undef;
  846:     #
  847:     $rows_output = 0;
  848:     $cols_output = 0;
  849:     #
  850:     # Create sheet
  851:     $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
  852:     #
  853:     # Check for errors
  854:     if (! defined($excel_workbook)) {
  855:         $r->log_error("Error creating excel spreadsheet $filename: $!");
  856:         $r->print("Problems creating new Excel file.  ".
  857:                   "This error has been logged.  ".
  858:                   "Please alert your LON-CAPA administrator");
  859:         return ;
  860:     }
  861:     #
  862:     # The excel spreadsheet stores temporary data in files, then put them
  863:     # together.  If needed we should be able to disable this (memory only).
  864:     # The temporary directory must be specified before calling 'addworksheet'.
  865:     # File::Temp is used to determine the temporary directory.
  866:     $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
  867:     #
  868:     # Add a worksheet
  869:     my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
  870:     if (length($sheetname) > 31) {
  871:         $sheetname = substr($sheetname,0,31);
  872:     }
  873:     $excel_sheet = $excel_workbook->addworksheet($sheetname);
  874:     #
  875:     # Put the course description in the header
  876:     $excel_sheet->write($rows_output,$cols_output++,
  877:                    $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
  878:     $cols_output += 3;
  879:     #
  880:     # Put a description of the sections listed
  881:     my $sectionstring = '';
  882:     my @Sections = @Apache::lonstatistics::SelectedSections;
  883:     if (scalar(@Sections) > 1) {
  884:         if (scalar(@Sections) > 2) {
  885:             my $last = pop(@Sections);
  886:             $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
  887:         } else {
  888:             $sectionstring = "Sections ".join(' and ',@Sections);
  889:         }
  890:     } else {
  891:         if ($Sections[0] eq 'all') {
  892:             $sectionstring = "All sections";
  893:         } else {
  894:             $sectionstring = "Section ".$Sections[0];
  895:         }
  896:     }
  897:     $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
  898:     $cols_output += scalar(@Sections);
  899:     #
  900:     # Put the date in there too
  901:     $excel_sheet->write($rows_output,$cols_output++,
  902:                         'Compiled on '.localtime(time));
  903:     #
  904:     $rows_output++;
  905:     #
  906:     # Add the student headers
  907:     $cols_output = 0;
  908:     foreach my $field (&get_student_fields_to_show()) {
  909:         $excel_sheet->write($rows_output,$cols_output++,$field);
  910:     }
  911:     #
  912:     # Add the Sequence Headers
  913:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  914:         $excel_sheet->write($rows_output,$cols_output,$seq->{'title'});
  915:         if ($show eq 'totals') {
  916:             $excel_sheet->write($rows_output+1,$cols_output,'score');
  917:             $excel_sheet->write($rows_output+1,$cols_output+1,'maximum');
  918:             $cols_output += 2;
  919:         } else {
  920:             $cols_output++;
  921:         }
  922:     }
  923:     #
  924:     # Bookkeeping
  925:     if ($show eq 'totals') {
  926:         $rows_output += 2;
  927:     } else {
  928:         $rows_output += 1;
  929:     }
  930:     #
  931:     # Output a row for MAX
  932:     if ($show ne 'totals') {
  933:         $cols_output = 0;
  934:         foreach my $field (&get_student_fields_to_show()) {
  935:             if ($field eq 'username' || $field eq 'fullname' || 
  936:                 $field eq 'id') {
  937:                 $excel_sheet->write($rows_output,$cols_output++,'Maximum');
  938:             } else {
  939:                 $excel_sheet->write($rows_output,$cols_output++,'');
  940:             }
  941:         }
  942:         #
  943:         # Add the Sequence Headers
  944:         foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  945:             $excel_sheet->write($rows_output,$cols_output++,
  946:                                 $seq->{'num_assess_parts'});
  947:         }
  948:         $rows_output++;
  949:     }
  950:     #
  951:     # Let the user know what we are doing
  952:     my $studentcount = scalar(@Apache::lonstatistics::Students); 
  953:     $r->print("<h1>Compiling Excel spreadsheet for ".
  954:               $studentcount.' student');
  955:     $r->print('s') if ($studentcount > 1);
  956:     $r->print("</h1>\n");
  957:     $r->rflush();
  958:     #
  959:     # Initialize progress window
  960:     %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
  961:         ($r,'Excel File Compilation Status',
  962:          'Excel File Compilation Progress', $studentcount);
  963:     #
  964:     return;
  965: }
  966: 
  967: sub excel_outputstudent {
  968:     my ($r,$student) = @_;
  969:     return if (! defined($excel_sheet));
  970:     $cols_output=0;
  971:     #
  972:     # Write out student data
  973:     my @to_show = &get_student_fields_to_show();
  974:     foreach my $field (@to_show) {
  975:         $excel_sheet->write($rows_output,$cols_output++,$student->{$field});
  976:     }
  977:     #
  978:     # Get student assessment data
  979:     my %StudentsData;
  980:     my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
  981:                                                         $student->{'domain'},
  982:                                                         undef,
  983:                                                    $ENV{'request.course.id'});
  984:     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
  985:         %StudentsData = @tmp;
  986:     }
  987:     #
  988:     # Write out sequence scores and totals data
  989:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  990:         my ($performance,$score,$seq_max) =
  991:             &StudentPerformanceOnSequence($student,\%StudentsData,
  992:                                           $seq,'no');
  993:         if ($show eq 'totals' || $show eq 'scores') {
  994:             $excel_sheet->write($rows_output,$cols_output++,$score);
  995:         }
  996:         if ($show eq 'totals') {
  997:             $excel_sheet->write($rows_output,$cols_output++,$seq_max);
  998:         }
  999:     }
 1000:     #
 1001:     # Bookkeeping
 1002:     $rows_output++; 
 1003:     $cols_output=0;
 1004:     #
 1005:     # Update the progress window
 1006:     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
 1007:     return;
 1008: }
 1009: 
 1010: sub excel_finish {
 1011:     my ($r) = @_;
 1012:     return if (! defined($excel_sheet));
 1013:     #
 1014:     # Write the excel file
 1015:     $excel_workbook->close();
 1016:     my $c = $r->connection();
 1017:     #
 1018:     return if($c->aborted());
 1019:     #
 1020:     # Close the progress window
 1021:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
 1022:     #
 1023:     # Tell the user where to get their excel file
 1024:     $r->print('<br />'.
 1025:               '<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n");
 1026:     $r->rflush();
 1027:     return;
 1028: }
 1029: 
 1030: }
 1031: #######################################################
 1032: #######################################################
 1033: 
 1034: =pod
 1035: 
 1036: =head2 CSV output routines
 1037: 
 1038: =item &csv_initialize($r)
 1039: 
 1040: =item &csv_outputstudent($r,$student)
 1041: 
 1042: =item &csv_finish($r)
 1043: 
 1044: =cut
 1045: 
 1046: #######################################################
 1047: #######################################################
 1048: {
 1049: 
 1050: my $outputfile;
 1051: my $filename;
 1052: 
 1053: my %prog_state; # progress window state
 1054: 
 1055: sub csv_initialize{
 1056:     my ($r) = @_;
 1057:     # 
 1058:     # Clean up
 1059:     $filename = undef;
 1060:     $outputfile = undef;
 1061:     undef(%prog_state);
 1062:     #
 1063:     # Open a file
 1064:     $filename = '/prtspool/'.
 1065:         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
 1066:             time.'_'.rand(1000000000).'.csv';
 1067:     unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) {
 1068:         $r->log_error("Couldn't open $filename for output $!");
 1069:         $r->print("Problems occured in writing the csv file.  ".
 1070:                   "This error has been logged.  ".
 1071:                   "Please alert your LON-CAPA administrator.");
 1072:         $outputfile = undef;
 1073:     }
 1074:     #
 1075:     # Datestamp
 1076:     my $description = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
 1077:     print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
 1078:         '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
 1079:             "\n";
 1080: 
 1081:     #
 1082:     # Print out the headings
 1083:     my $Str = '';
 1084:     my $Str2 = undef;
 1085:     foreach my $field (&get_student_fields_to_show()) {
 1086:         if ($show eq 'scores') {
 1087:             $Str .= '"'.&Apache::loncommon::csv_translate($field).'",';
 1088:         } elsif ($show eq 'totals') {
 1089:             $Str .= '"",'; # first row empty on the student fields
 1090:             $Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",';
 1091:         } elsif ($show eq 'all') {
 1092:             $Str .= '"'.&Apache::loncommon::csv_translate($field).'",';
 1093:         }
 1094:     }
 1095:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1096:         if ($show eq 'scores') {
 1097:             $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
 1098:                 '",';
 1099:         } elsif ($show eq 'totals') {
 1100:             $Str  .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
 1101:                 '","",';
 1102:             $Str2 .= '"score","total possible",';
 1103:         } elsif ($show eq 'all') {
 1104:             $Str  .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
 1105:                 '",';
 1106:             $Str .= '"",'x($seq->{'num_assess_parts'}-1);
 1107:             $Str .= '"score","total possible",';
 1108:         }
 1109:     }
 1110:     chop($Str);
 1111:     $Str .= "\n";
 1112:     print $outputfile $Str;
 1113:     if (defined($Str2)) {
 1114:         chop($Str2);
 1115:         $Str2 .= "\n";
 1116:         print $outputfile $Str2;
 1117:     }
 1118:     #
 1119:     # Initialize progress window
 1120:     my $studentcount = scalar(@Apache::lonstatistics::Students);
 1121:     %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
 1122:         ($r,'CSV File Compilation Status',
 1123:          'CSV File Compilation Progress', $studentcount);
 1124:     return;
 1125: }
 1126: 
 1127: sub csv_outputstudent {
 1128:     my ($r,$student) = @_;
 1129:     return if (! defined($outputfile));
 1130:     my $Str = '';
 1131:     #
 1132:     # Output student fields
 1133:     my @to_show = &get_student_fields_to_show();
 1134:     foreach my $field (@to_show) {
 1135:         $Str .= '"'.&Apache::loncommon::csv_translate($student->{$field}).'",';
 1136:     }
 1137:     #
 1138:     # Get student assessment data
 1139:     my %StudentsData;
 1140:     my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
 1141:                                                         $student->{'domain'},
 1142:                                                         undef,
 1143:                                                    $ENV{'request.course.id'});
 1144:     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
 1145:         %StudentsData = @tmp;
 1146:     }
 1147:     #
 1148:     # Output performance data
 1149:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1150:         my ($performance,$score,$seq_max) =
 1151:             &StudentPerformanceOnSequence($student,\%StudentsData,
 1152:                                           $seq,'no');
 1153:         if ($show eq 'scores') {
 1154:             $Str .= '"'.$score.'",';
 1155:         } elsif ($show eq 'totals') {
 1156:             $Str  .= '"'.$score.'","'.$seq_max.'",';
 1157:         } elsif ($show eq 'all') {
 1158:             $Str .= '"'.join('","',(split(//,$performance),$score,$seq_max)).
 1159:                 '",';
 1160:         }
 1161:     }
 1162:     chop($Str);
 1163:     $Str .= "\n";
 1164:     print $outputfile $Str;
 1165:     #
 1166:     # Update the progress window
 1167:     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
 1168:     return;
 1169: }
 1170: 
 1171: sub csv_finish {
 1172:     my ($r) = @_;
 1173:     return if (! defined($outputfile));
 1174:     close($outputfile);
 1175:     #
 1176:     my $c = $r->connection();
 1177:     return if ($c->aborted());
 1178:     #
 1179:     # Close the progress window
 1180:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
 1181:     #
 1182:     # Tell the user where to get their csv file
 1183:     $r->print('<br />'.
 1184:               '<a href="'.$filename.'">Your csv file.</a>'."\n");
 1185:     $r->rflush();
 1186:     return;
 1187:     
 1188: }
 1189: 
 1190: }
 1191: 
 1192: #######################################################
 1193: #######################################################
 1194: 
 1195: =pod
 1196: 
 1197: =item &StudentPerformanceOnSequence()
 1198: 
 1199: Inputs:
 1200: 
 1201: =over 4
 1202: 
 1203: =item $student
 1204: 
 1205: =item $studentdata Hash ref to all student data
 1206: 
 1207: =item $seq Hash ref, the sequence we are working on
 1208: 
 1209: =item $links if defined we will output links to each resource.
 1210: 
 1211: =back
 1212: 
 1213: =cut
 1214: 
 1215: #######################################################
 1216: #######################################################
 1217: sub StudentPerformanceOnSequence {
 1218:     my ($student,$studentdata,$seq,$links) = @_;
 1219:     $links = 'no' if (! defined($links));
 1220:     my $Str = '';
 1221:     my ($sum,$max) = (0,0);
 1222:     foreach my $resource (@{$seq->{'contents'}}) {
 1223:         next if ($resource->{'type'} ne 'assessment');
 1224:         my $resource_data = $studentdata->{$resource->{'symb'}};
 1225:         my $value = '';
 1226:         foreach my $partnum (@{$resource->{'parts'}}) {
 1227:             $max++;
 1228:             my $symbol = ' '; # default to space
 1229:             #
 1230:             if (exists($resource_data->{'resource.'.$partnum.'.solved'})) {
 1231:                 my $status = $resource_data->{'resource.'.$partnum.'.solved'};
 1232:                 if ($status eq 'correct_by_override') {
 1233:                     $symbol = '+';
 1234:                     $sum++;
 1235:                 } elsif ($status eq 'incorrect_by_override') {
 1236:                     $symbol = '-';
 1237:                 } elsif ($status eq 'ungraded_attempted') {
 1238:                     $symbol = '#';
 1239:                 } elsif ($status eq 'incorrect_attempted')  {
 1240:                     $symbol = '.';
 1241:                 } elsif ($status eq 'excused') {
 1242:                     $symbol = 'x';
 1243:                     $max--;
 1244:                 } elsif ($status eq 'correct_by_student' &&
 1245:                     exists($resource_data->{'resource.'.$partnum.'.tries'})){
 1246:                     my $num = $resource_data->{'resource.'.$partnum.'.tries'};
 1247:                     if ($num > 9) {
 1248:                         $symbol = '*';
 1249:                     } elsif ($num > 0) {
 1250:                         $symbol = $num;
 1251:                     } else {
 1252:                         $symbol = ' ';
 1253:                     }
 1254:                     $sum++;
 1255:                 } elsif (exists($resource_data->{'resource.'.
 1256:                                                      $partnum.'.tries'})){
 1257:                     $symbol = '.';
 1258:                 } else {
 1259:                     $symbol = ' ';
 1260:                 }
 1261:             } else {
 1262:                 # Unsolved.  Did they try?
 1263:                 if (exists($resource_data->{'resource.'.$partnum.'.tries'})){
 1264:                     $symbol = '.';
 1265:                 } else {
 1266:                     $symbol = ' ';
 1267:                 }
 1268:             }
 1269:             #
 1270:             if ( ($links eq 'yes' && $symbol ne ' ') ||
 1271:                  ($links eq 'all')) {
 1272:                 if (length($symbol) > 1) {
 1273:                     &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
 1274:                 }
 1275:                 $symbol = '<a href="/adm/grades'.
 1276:                     '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
 1277:                         '&student='.$student->{'username'}.
 1278:                             '&domain='.$student->{'domain'}.
 1279:                                 '&command=submission">'.$symbol.'</a>';
 1280:             }
 1281:             $value .= $symbol;
 1282:         }
 1283:         $Str .= $value;
 1284:     }
 1285:     return ($Str,$sum,$max);
 1286: }
 1287: 
 1288: #######################################################
 1289: #######################################################
 1290: 
 1291: =pod
 1292: 
 1293: =item &CreateLegend()
 1294: 
 1295: This function returns a formatted string containing the legend for the
 1296: chart.  The legend describes the symbols used to represent grades for
 1297: problems.
 1298: 
 1299: =cut
 1300: 
 1301: #######################################################
 1302: #######################################################
 1303: sub CreateLegend {
 1304:     my $Str = "<p><pre>".
 1305:               "   1  correct by student in 1 try\n".
 1306:               "   7  correct by student in 7 tries\n".
 1307:               "   *  correct by student in more than 9 tries\n".
 1308: 	      "   +  correct by hand grading or override\n".
 1309:               "   -  incorrect by override\n".
 1310: 	      "   .  incorrect attempted\n".
 1311: 	      "   #  ungraded attempted\n".
 1312:               "      not attempted (blank field)\n".
 1313: 	      "   x  excused".
 1314:               "</pre><p>";
 1315:     return $Str;
 1316: }
 1317: 
 1318: #######################################################
 1319: #######################################################
 1320: 
 1321: =pod 
 1322: 
 1323: =back
 1324: 
 1325: =cut
 1326: 
 1327: #######################################################
 1328: #######################################################
 1329: 
 1330: 1;
 1331: 
 1332: __END__

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