File:  [LON-CAPA] / loncom / interface / statistics / lonstudentassessment.pm
Revision 1.95: download - view: text, annotated - select for diffs
Mon Mar 1 16:39:19 2004 UTC (20 years, 4 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
No longer translate before calling lonhtmlcommon::breadcrumbs
and lonhtmlcommong::add_breadcrumb.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lonstudentassessment.pm,v 1.95 2004/03/01 16:39:19 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::loncommon();
   56: use Apache::loncoursedata;
   57: use Apache::lonnet; # for logging porpoises
   58: use Apache::lonlocal;
   59: use Spreadsheet::WriteExcel;
   60: use Spreadsheet::WriteExcel::Utility();
   61: 
   62: #######################################################
   63: #######################################################
   64: =pod
   65: 
   66: =item Package Variables
   67: 
   68: =over 4
   69: 
   70: =item $Statistics Hash ref to store student data.  Indexed by symb,
   71:       contains hashes with keys 'score' and 'max'.
   72: 
   73: =cut
   74: 
   75: #######################################################
   76: #######################################################
   77: 
   78: my $Statistics;
   79: 
   80: #######################################################
   81: #######################################################
   82: 
   83: =pod
   84: 
   85: =item $show_links 'yes' or 'no' for linking to student performance data
   86: 
   87: =item $output_mode 'html', 'excel', or 'csv' for output mode
   88: 
   89: =item $show 'all', 'totals', or 'scores' determines how much data is output
   90: 
   91: =item $single_student_mode evaluates to true if we are showing only one
   92: student.
   93: 
   94: =cut
   95: 
   96: #######################################################
   97: #######################################################
   98: my $show_links;
   99: my $output_mode;
  100: my $chosen_output;
  101: my $single_student_mode;
  102: 
  103: #######################################################
  104: #######################################################
  105: # End of package variable declarations
  106: 
  107: =pod
  108: 
  109: =back
  110: 
  111: =cut
  112: 
  113: #######################################################
  114: #######################################################
  115: 
  116: =pod
  117: 
  118: =item &BuildStudentAssessmentPage()
  119: 
  120: Inputs: 
  121: 
  122: =over 4
  123: 
  124: =item $r Apache Request
  125: 
  126: =item $c Apache Connection 
  127: 
  128: =back
  129: 
  130: =cut
  131: 
  132: #######################################################
  133: #######################################################
  134: sub BuildStudentAssessmentPage {
  135:     my ($r,$c)=@_;
  136:     #
  137:     undef($Statistics);
  138:     undef($show_links);
  139:     undef($output_mode);
  140:     undef($chosen_output);
  141:     undef($single_student_mode);
  142:     #
  143:     my %Saveable_Parameters = ('Status' => 'scalar',
  144:                                'chartoutputmode' => 'scalar',
  145:                                'chartoutputdata' => 'scalar',
  146:                                'Section' => 'array',
  147:                                'StudentData' => 'array',
  148:                                'Maps' => 'array');
  149:     &Apache::loncommon::store_course_settings('chart',\%Saveable_Parameters);
  150:     &Apache::loncommon::restore_course_settings('chart',\%Saveable_Parameters);
  151:     #
  152:     &Apache::lonstatistics::PrepareClasslist();
  153:     #
  154:     $single_student_mode = 0;
  155:     $single_student_mode = 1 if ($ENV{'form.SelectedStudent'});
  156:     if ($ENV{'form.selectstudent'}) {
  157:         &Apache::lonstatistics::DisplayClasslist($r);
  158:         return;
  159:     }
  160:     #
  161:     # Print out the HTML headers for the interface
  162:     #    This also parses the output mode selector
  163:     #    This step must *always* be done.
  164:     $r->print(&CreateInterface());
  165:     $r->print('<input type="hidden" name="notfirstrun" value="true" />');
  166:     $r->print('<input type="hidden" name="sort" value="'.
  167:               $ENV{'form.sort'}.'" />');
  168:     $r->rflush();
  169:     #
  170:     if (! exists($ENV{'form.notfirstrun'}) && ! $single_student_mode) {
  171:         return;
  172:     }
  173:     #
  174:     my $initialize     = \&html_initialize;
  175:     my $output_student = \&html_outputstudent;
  176:     my $finish         = \&html_finish;
  177:     #
  178:     if ($output_mode eq 'excel') {
  179:         $initialize     = \&excel_initialize;
  180:         $output_student = \&excel_outputstudent;
  181:         $finish         = \&excel_finish;
  182:     } elsif ($output_mode eq 'csv') {
  183:         $initialize     = \&csv_initialize;
  184:         $output_student = \&csv_outputstudent;
  185:         $finish         = \&csv_finish;
  186:     }
  187:     #
  188:     if($c->aborted()) {  return ; }
  189:     #
  190:     # Determine which students we want to look at
  191:     my @Students;
  192:     if ($single_student_mode) {
  193:         @Students = (&Apache::lonstatistics::current_student());
  194:         $r->print(&next_and_previous_buttons());
  195:         $r->rflush();
  196:     } else {
  197:         @Students = @Apache::lonstatistics::Students;
  198:     }
  199:     #
  200:     # Perform generic initialization tasks
  201:     #       Since we use lonnet::EXT to retrieve problem weights,
  202:     #       to ensure current data we must clear the caches out.
  203:     #       This makes sure that parameter changes at the student level
  204:     #       are immediately reflected in the chart.
  205:     &Apache::lonnet::clear_EXT_cache_status();
  206:     #
  207:     # Clean out loncoursedata's package data, just to be safe.
  208:     &Apache::loncoursedata::clear_internal_caches();
  209:     #
  210:     # Call the initialize routine selected above
  211:     $initialize->($r);
  212:     foreach my $student (@Students) {
  213:         if($c->aborted()) { 
  214:             $finish->($r);
  215:             return ; 
  216:         }
  217:         # Call the output_student routine selected above
  218:         $output_student->($r,$student);
  219:     }
  220:     # Call the "finish" routine selected above
  221:     $finish->($r);
  222:     #
  223:     return;
  224: }
  225: 
  226: #######################################################
  227: #######################################################
  228: sub next_and_previous_buttons {
  229:     my $Str = '';
  230:     $Str .= '<input type="hidden" name="SelectedStudent" value="'.
  231:         $ENV{'form.SelectedStudent'}.'" />';
  232:     #
  233:     # Build the previous student link
  234:     my $previous = &Apache::lonstatistics::previous_student();
  235:     my $previousbutton = '';
  236:     if (defined($previous)) {
  237:         my $sname = $previous->{'username'}.':'.$previous->{'domain'};
  238:         $previousbutton .= '<input type="button" value="'.
  239:             'Previous Student ('.
  240:             $previous->{'username'}.'@'.$previous->{'domain'}.')'.
  241:             '" onclick="document.Statistics.SelectedStudent.value='.
  242:             "'".$sname."'".';'.
  243:             'document.Statistics.submit();" />';
  244:     } else {
  245:         $previousbutton .= '<input type="button" value="'.
  246:             'Previous student (none)'.'" />';
  247:     }
  248:     #
  249:     # Build the next student link
  250:     my $next = &Apache::lonstatistics::next_student();
  251:     my $nextbutton = '';
  252:     if (defined($next)) {
  253:         my $sname = $next->{'username'}.':'.$next->{'domain'};
  254:         $nextbutton .= '<input type="button" value="'.
  255:             'Next Student ('.
  256:             $next->{'username'}.'@'.$next->{'domain'}.')'.
  257:             '" onclick="document.Statistics.SelectedStudent.value='.
  258:             "'".$sname."'".';'.
  259:             'document.Statistics.submit();" />';
  260:     } else {
  261:         $nextbutton .= '<input type="button" value="'.
  262:             'Next student (none)'.'" />';
  263:     }
  264:     #
  265:     # Build the 'all students' button
  266:     my $all = '';
  267:     $all .= '<input type="button" value="All Students" '.
  268:             '" onclick="document.Statistics.SelectedStudent.value='.
  269:             "''".';'.'document.Statistics.submit();" />';
  270:     $Str .= $previousbutton.('&nbsp;'x5).$all.('&nbsp;'x5).$nextbutton;
  271:     return $Str;
  272: }
  273: 
  274: #######################################################
  275: #######################################################
  276: 
  277: sub get_student_fields_to_show {
  278:     my @to_show = @Apache::lonstatistics::SelectedStudentData;
  279:     foreach (@to_show) {
  280:         if ($_ eq 'all') {
  281:             @to_show = @Apache::lonstatistics::StudentDataOrder;
  282:             last;
  283:         }
  284:     }
  285:     return @to_show;
  286: }
  287: 
  288: #######################################################
  289: #######################################################
  290: 
  291: =pod
  292: 
  293: =item &CreateInterface()
  294: 
  295: Called by &BuildStudentAssessmentPage to create the top part of the
  296: page which displays the chart.
  297: 
  298: Inputs: None
  299: 
  300: Returns:  A string containing the HTML for the headers and top table for 
  301: the chart page.
  302: 
  303: =cut
  304: 
  305: #######################################################
  306: #######################################################
  307: sub CreateInterface {
  308:     my $Str = '';
  309:     $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Chart');
  310: #    $Str .= &CreateLegend();
  311:     $Str .= '<table cellspacing="5">'."\n";
  312:     $Str .= '<tr>';
  313:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
  314:     $Str .= '<td align="center"><b>'.&mt('Student Data</b>').'</td>';
  315:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
  316:     $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
  317:     $Str .= '<td align="center"><b>'.&mt('Output Format').'</b>'.
  318:         &Apache::loncommon::help_open_topic("Chart_Output_Formats").
  319:         '</td>';
  320:     $Str .= '<td align="center"><b>'.&mt('Output Data').'</b>'.
  321:         &Apache::loncommon::help_open_topic("Chart_Output_Data").
  322:         '</td>';
  323:     $Str .= '</tr>'."\n";
  324:     #
  325:     $Str .= '<tr><td align="center">'."\n";
  326:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  327:     $Str .= '</td><td align="center">';
  328:     my $only_seq_with_assessments = sub { 
  329:         my $s=shift;
  330:         if ($s->{'num_assess'} < 1) { 
  331:             return 0;
  332:         } else { 
  333:             return 1;
  334:         }
  335:     };
  336:     $Str .= &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',
  337:                                                       5,undef);
  338:     $Str .= '</td><td>'."\n";
  339:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  340:     $Str .= '</td><td>'."\n";
  341:     $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
  342:                                               $only_seq_with_assessments);
  343:     $Str .= '</td><td>'."\n";
  344:     $Str .= &CreateAndParseOutputSelector();
  345:     $Str .= '</td><td>'."\n";
  346:     $Str .= &CreateAndParseOutputDataSelector();
  347:     $Str .= '</td></tr>'."\n";
  348:     $Str .= '</table>'."\n";
  349:     $Str .= '<input type="submit" name="Generate Chart" value="'.
  350:         &mt('Generate Chart').'" />';
  351:     $Str .= '&nbsp;'x5;
  352:     $Str .= '<input type="submit" name="selectstudent" value="'.
  353:         &mt('Select One Student').'" />';
  354:     $Str .= '&nbsp;'x5;
  355:     $Str .= '<input type="submit" name="ClearCache" value="'.
  356:         &mt('Clear Caches').'" />';
  357:     $Str .= '&nbsp;'x5;
  358:     $Str .= '<br />';
  359:     return $Str;
  360: }
  361: 
  362: #######################################################
  363: #######################################################
  364: 
  365: =pod
  366: 
  367: =item &CreateAndParseOutputSelector()
  368: 
  369: =cut
  370: 
  371: #######################################################
  372: #######################################################
  373: my @OutputOptions = 
  374:     ({ name  => 'HTML, with links',
  375:        value => 'html, with links',
  376:        description => 'Output HTML with each symbol linked to the problem '.
  377: 	   'which generated it.',
  378:        mode => 'html',
  379:        show_links => 'yes',
  380:        },
  381:      { name  => 'HTML, with all links',
  382:        value => 'html, with all links',
  383:        description => 'Output HTML with each symbol linked to the problem '.
  384: 	   'which generated it.  '.
  385:            'This includes links for unattempted problems.',
  386:        mode => 'html',
  387:        show_links => 'all',
  388:        },
  389:      { name  => 'HTML, without links',
  390:        value => 'html, without links',
  391:        description => 'Output HTML.  By not including links, the size of the'.
  392: 	   ' web page is greatly reduced.  If your browser crashes on the '.
  393: 	   'full display, try this.',
  394:        mode => 'html',
  395:        show_links => 'no',
  396:            },
  397:      { name  => 'Excel',
  398:        value => 'excel',
  399:        description => 'Output an Excel file (compatable with Excel 95).',
  400:        mode => 'excel',
  401:        show_links => 'no',
  402:    },
  403:      { name  => 'CSV',
  404:        value => 'csv',
  405:        description => 'Output a comma seperated values file suitable for '.
  406:            'import into a spreadsheet program.  Using this method as opposed '.
  407:            'to Excel output allows you to organize your data before importing'.
  408:            ' it into a spreadsheet program.',
  409:        mode => 'csv',
  410:        show_links => 'no',
  411:            },
  412:      );
  413: 
  414: sub OutputDescriptions {
  415:     my $Str = '';
  416:     $Str .= "<h2>Output Formats</h2>\n";
  417:     $Str .= "<dl>\n";
  418:     foreach my $outputmode (@OutputOptions) {
  419: 	$Str .="    <dt>".$outputmode->{'name'}."</dt>\n";
  420: 	$Str .="        <dd>".$outputmode->{'description'}."</dd>\n";
  421:     }
  422:     $Str .= "</dl>\n";
  423:     return $Str;
  424: }
  425: 
  426: sub CreateAndParseOutputSelector {
  427:     my $Str = '';
  428:     my $elementname = 'chartoutputmode';
  429:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  430:                                             [$elementname]);
  431:     #
  432:     # Format for output options is 'mode, restrictions';
  433:     my $selected = 'html, without links';
  434:     if (exists($ENV{'form.'.$elementname})) {
  435:         if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
  436:             $selected = $ENV{'form.'.$elementname}->[0];
  437:         } else {
  438:             $selected = $ENV{'form.'.$elementname};
  439:         }
  440:     }
  441:     #
  442:     # Set package variables describing output mode
  443:     $show_links  = 'no';
  444:     $output_mode = 'html';
  445:     foreach my $option (@OutputOptions) {
  446:         next if ($option->{'value'} ne $selected);
  447:         $output_mode = $option->{'mode'};
  448:         $show_links  = $option->{'show_links'};
  449:     }
  450: 
  451:     #
  452:     # Build the form element
  453:     $Str = qq/<select size="5" name="$elementname">/;
  454:     foreach my $option (@OutputOptions) {
  455:         $Str .= "\n".'    <option value="'.$option->{'value'}.'"';
  456:         $Str .= " selected " if ($option->{'value'} eq $selected);
  457:         $Str .= ">".&mt($option->{'name'})."<\/option>";
  458:     }
  459:     $Str .= "\n</select>";
  460:     return $Str;
  461: }
  462: 
  463: ##
  464: ## Data selector stuff
  465: ##
  466: my @OutputDataOptions =
  467:     (
  468:      { name  => 'Scores Summary',
  469:        base  => 'scores',
  470:        value => 'sum and total',
  471:        scores => 1,
  472:        tries  => 0,
  473:        every_problem => 0,
  474:        sequence_sum => 1,
  475:        sequence_max => 1,
  476:        grand_total => 1,
  477:        summary_table => 1,
  478:        maximum_row => 1,
  479:        shortdesc => 'Total Score and Maximum Possible for each '.
  480:            'Sequence or Folder',
  481:        longdesc => 'The score of each student as well as the '.
  482:            ' maximum possible on each Sequence or Folder.',
  483:        },
  484:      { name  => 'Scores Per Problem',
  485:        base  => 'scores',
  486:        value => 'scores',
  487:        scores => 1,
  488:        tries  => 0,
  489:        correct => 0,
  490:        every_problem => 1,
  491:        sequence_sum => 1,
  492:        sequence_max => 1,
  493:        grand_total => 1,
  494:        summary_table => 1,
  495:        maximum_row => 1,
  496:        shortdesc => 'Score on each Problem Part',
  497:        longdesc =>'The students score on each problem part, computed as'.
  498:            'the part weight * part awarded',
  499:        },
  500:      { name  =>'Tries',
  501:        base  =>'tries',
  502:        value => 'tries',
  503:        scores => 0,
  504:        tries  => 1,
  505:        correct => 0,
  506:        every_problem => 1,
  507:        sequence_sum => 0,
  508:        sequence_max => 0,
  509:        grand_total => 0,
  510:        summary_table => 0,
  511:        maximum_row => 0,
  512:        shortdesc => 'Number of Tries before success on each Problem Part',
  513:        longdesc =>'The number of tries before success on each problem part.',
  514:        },
  515:      { name  =>'Parts Correct',
  516:        base  =>'tries',
  517:        value => 'parts correct total',
  518:        scores => 0,
  519:        tries  => 0,
  520:        correct => 1,
  521:        every_problem => 1,
  522:        sequence_sum => 1,
  523:        sequence_max => 1,
  524:        grand_total => 1,
  525:        summary_table => 1,
  526:        maximum_row => 0,
  527:        shortdesc => 'Number of Problem Parts completed successfully.',
  528:        longdesc => 'The Number of Problem Parts completed successfully and '.
  529:            'the maximum possible for each student',
  530:        },
  531:      );
  532: 
  533: sub HTMLifyOutputDataDescriptions {
  534:     my $Str = '';
  535:     $Str .= "<h2>Output Data</h2>\n";
  536:     $Str .= "<dl>\n";
  537:     foreach my $option (@OutputDataOptions) {
  538:         $Str .= '    <dt>'.$option->{'name'}.'</dt>';
  539:         $Str .= '<dd>'.$option->{'longdesc'}.'</dd>'."\n";
  540:     }
  541:     $Str .= "</dl>\n";
  542:     return $Str;
  543: }
  544: 
  545: sub CreateAndParseOutputDataSelector {
  546:     my $Str = '';
  547:     my $elementname = 'chartoutputdata';
  548:     #
  549:     my $selected = 'scores';
  550:     if (exists($ENV{'form.'.$elementname})) {
  551:         if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
  552:             $selected = $ENV{'form.'.$elementname}->[0];
  553:         } else {
  554:             $selected = $ENV{'form.'.$elementname};
  555:         }
  556:     }
  557:     #
  558:     $chosen_output = $OutputDataOptions[0];
  559:     foreach my $option (@OutputDataOptions) {
  560:         if ($option->{'value'} eq $selected) {
  561:             $chosen_output = $option;
  562:         }
  563:     }
  564:     #
  565:     # Build the form element
  566:     $Str = qq/<select size="5" name="$elementname">/;
  567:     foreach my $option (@OutputDataOptions) {
  568:         $Str .= "\n".'    <option value="'.$option->{'value'}.'"';
  569:         $Str .= " selected " if ($option->{'value'} eq $chosen_output->{'value'});
  570:         $Str .= ">".&mt($option->{'name'})."<\/option>";
  571:     }
  572:     $Str .= "\n</select>";
  573:     return $Str;
  574: 
  575: }
  576: 
  577: #######################################################
  578: #######################################################
  579: 
  580: =pod
  581: 
  582: =head2 HTML output routines
  583: 
  584: =item &html_initialize($r)
  585: 
  586: Create labels for the columns of student data to show.
  587: 
  588: =item &html_outputstudent($r,$student)
  589: 
  590: Return a line of the chart for a student.
  591: 
  592: =item &html_finish($r)
  593: 
  594: =cut
  595: 
  596: #######################################################
  597: #######################################################
  598: {
  599:     my $padding;
  600:     my $count;
  601: 
  602:     my $nodata_count; # The number of students for which there is no data
  603:     my %prog_state;   # progress state used by loncommon PrgWin routines
  604: 
  605: sub html_initialize {
  606:     my ($r) = @_;
  607:     #
  608:     $padding = ' 'x3;
  609:     $count = 0;
  610:     $nodata_count = 0;
  611:     undef(%prog_state);
  612:     #
  613:     $r->print("<h3>".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
  614:               "&nbsp;&nbsp;".localtime(time)."</h3>");
  615: 
  616:     if ($chosen_output->{'base'} !~ /^final table/) {
  617:         $r->print("<h3>".$chosen_output->{'shortdesc'}."</h3>");        
  618:     }
  619:     my $Str = "<pre>\n";
  620:     # First, the @StudentData fields need to be listed
  621:     my @to_show = &get_student_fields_to_show();
  622:     foreach my $field (@to_show) {
  623:         my $title=$Apache::lonstatistics::StudentData{$field}->{'title'};
  624:         my $base =$Apache::lonstatistics::StudentData{$field}->{'base_width'};
  625:         my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
  626:         $Str .= $title.' 'x($width-$base).$padding;
  627:     }
  628:     #
  629:     # Compute the column widths and output the sequence titles
  630:     foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()){
  631:         #
  632:         # Comptue column widths
  633:         $sequence->{'width_sum'} = 0;
  634:         if ($chosen_output->{'sequence_sum'}) {
  635:             # Use 3 digits for the sum
  636:             $sequence->{'width_sum'} = 3;
  637:         }
  638:         if ($chosen_output->{'sequence_max'}) {
  639:             if ($sequence->{'width_sum'}>0) {
  640:                 # One digit for the '/'
  641:                 $sequence->{'width_sum'} +=1;
  642:             }
  643:             # Use 3 digits for the total
  644:             $sequence->{'width_sum'}+=3;
  645:         }
  646: 	#
  647:         if ($chosen_output->{'every_problem'}) {
  648:             # one problem per digit
  649:             $sequence->{'width_problem'} = $sequence->{'num_assess_parts'};
  650:         } else {
  651:             $sequence->{'width_problem'} = 0;
  652:         }
  653:         $sequence->{'width_total'} = $sequence->{'width_problem'} + 
  654:                                      $sequence->{'width_sum'};
  655:         if ($sequence->{'width_total'} < length(&HTML::Entities::decode($sequence->{'title'}))) {
  656:             $sequence->{'width_total'} = length(&HTML::Entities::decode($sequence->{'title'}));
  657:         }
  658:         #
  659:         # Output the sequence titles
  660:         $Str .= 
  661:             $sequence->{'title'}.' 'x($sequence->{'width_total'}-
  662:                                       length($sequence->{'title'})
  663:                                       ).$padding;
  664:     }
  665:     $Str .= "total</pre>\n";
  666:     $Str .= "<pre>";
  667:     $r->print($Str);
  668:     $r->rflush();
  669:     return;
  670: }
  671: 
  672: sub html_outputstudent {
  673:     my ($r,$student) = @_;
  674:     my $Str = '';
  675:     #
  676:     if($count++ % 5 == 0 && $count > 0) {
  677:         $r->print("</pre><pre>");
  678:     }
  679:     # First, the @StudentData fields need to be listed
  680:     my @to_show = &get_student_fields_to_show();
  681:     foreach my $field (@to_show) {
  682:         my $title=$student->{$field};
  683:         my $base = length($title);
  684:         my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
  685:         $Str .= $title.' 'x($width-$base).$padding;
  686:     }
  687:     # Get ALL the students data
  688:     my %StudentsData;
  689:     my @tmp = &Apache::loncoursedata::get_current_state
  690:         ($student->{'username'},$student->{'domain'},undef,
  691:          $ENV{'request.course.id'});
  692:     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
  693:         %StudentsData = @tmp;
  694:     }
  695:     if (scalar(@tmp) < 1) {
  696:         $nodata_count++;
  697:         $Str .= '<font color="blue">No Course Data</font>'."\n";
  698:         $r->print($Str);
  699:         $r->rflush();
  700:         return;
  701:     }
  702:     #
  703:     # By sequence build up the data
  704:     my $studentstats;
  705:     my $PerformanceStr = '';
  706:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  707:         my ($performance,$performance_length,$score,$seq_max,$rawdata);
  708:         if ($chosen_output->{'tries'}) {
  709:             ($performance,$performance_length,$score,$seq_max,$rawdata) =
  710:                 &StudentTriesOnSequence($student,\%StudentsData,
  711:                                         $seq,$show_links);
  712:         } else {
  713:             ($performance,$performance_length,$score,$seq_max,$rawdata) =
  714:                 &StudentPerformanceOnSequence($student,\%StudentsData,
  715:                                               $seq,$show_links);
  716:         }
  717:         my $ratio='';
  718:         if ($chosen_output->{'sequence_sum'}) {
  719:             $ratio .= sprintf("%3d",$score);
  720:         }
  721:         if ($chosen_output->{'sequence_max'}) {
  722:             if ($chosen_output->{'sequence_sum'}) {
  723:                 $ratio .= '/';
  724:             }
  725:             $ratio .= sprintf("%3d",$seq_max);
  726:         }
  727:         #
  728:         if (! $chosen_output->{'every_problem'}) {
  729:             $performance = '';
  730: 	    $performance_length=0;
  731:         }
  732:         $performance .= ' 'x($seq->{'width_total'}-$performance_length-$seq->{'width_sum'}).
  733:             $ratio;
  734:         #
  735:         $Str .= $performance.$padding;
  736:         #
  737:         $studentstats->{$seq->{'symb'}}->{'score'}= $score;
  738:         $studentstats->{$seq->{'symb'}}->{'max'}  = $seq_max;
  739:     }
  740:     #
  741:     # Total it up and store the statistics info.
  742:     my ($score,$max) = (0,0);
  743:     while (my ($symb,$seq_stats) = each (%{$studentstats})) {
  744:         $Statistics->{$symb}->{'score'} += $seq_stats->{'score'};
  745:         if ($Statistics->{$symb}->{'max'} < $seq_stats->{'max'}) {
  746:             $Statistics->{$symb}->{'max'} = $seq_stats->{'max'};
  747:         }
  748:         $score += $seq_stats->{'score'};
  749:         $max   += $seq_stats->{'max'};
  750:     }
  751:     $Str .= ' '.' 'x(length($max)-length($score)).$score.'/'.$max;
  752:     $Str .= " \n";
  753:     #
  754:     $r->print($Str);
  755:     #
  756:     $r->rflush();
  757:     return;
  758: }    
  759: 
  760: sub html_finish {
  761:     my ($r) = @_;
  762:     #
  763:     # Check for suppressed output and close the progress window if so
  764:     $r->print("</pre>\n"); 
  765:     if ($chosen_output->{'summary_table'}) {
  766:         if ($single_student_mode) {
  767:             $r->print(&SingleStudentTotal());
  768:         } else {
  769:             $r->print(&StudentAverageTotal());
  770:         }
  771:     }
  772:     $r->rflush();
  773:     return;
  774: }
  775: 
  776: sub StudentAverageTotal {
  777:     my $Str = "<h3>Summary Tables</h3>\n";
  778:     my $num_students = scalar(@Apache::lonstatistics::Students);
  779:     my $total_ave = 0;
  780:     my $total_max = 0;
  781:     $Str .= '<table border=2 cellspacing="1">'."\n";
  782:     $Str .= "<tr><th>Title</th><th>Average</th><th>Maximum</th></tr>\n";
  783:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  784:         my $ave;
  785:         if ($num_students > $nodata_count) {
  786:             $ave = int(100*($Statistics->{$seq->{'symb'}}->{'score'}/
  787:                             ($num_students-$nodata_count)))/100;
  788:         } else {
  789:             $ave = 0;
  790:         }
  791:         $total_ave += $ave;
  792:         my $max = $Statistics->{$seq->{'symb'}}->{'max'};
  793:         $total_max += $max;
  794:         $ave = sprintf("%.2f",$ave);
  795:         $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
  796:             '<td align="right">'.$ave.'&nbsp;</td>'.
  797:             '<td align="right">'.$max.'&nbsp;'.'</td></tr>'."\n";
  798:     }
  799:     $total_ave = sprintf('%.2f',$total_ave); # only two digit
  800:     $Str .= "</table>\n";
  801:     $Str .= '<table border=2 cellspacing="1">'."\n";
  802:     $Str .= '<tr><th>Number of Students</th><th>Average</th>'.
  803:         "<th>Maximum</th></tr>\n";
  804:     $Str .= '<tr>'.
  805:         '<td align="right">'.($num_students-$nodata_count).'</td>'.
  806:         '<td align="right">'.$total_ave.'&nbsp;'.'</td>'.
  807:         '<td align="right">'.$total_max.'&nbsp;'.'</td>';
  808:     $Str .= "</table>\n";
  809:     return $Str;
  810: }
  811: 
  812: sub SingleStudentTotal {
  813:     my $student = &Apache::lonstatistics::current_student();
  814:     my $Str = "<h3>Summary table for ".$student->{'fullname'}." ".
  815:         $student->{'username'}.'@'.$student->{'domain'}."</h3>\n";
  816:     $Str .= '<table border=2 cellspacing="1">'."\n";
  817:     $Str .= 
  818:         "<tr><th>Sequence or Folder</th><th>Score</th><th>Maximum</th></tr>\n";
  819:     my $total = 0;
  820:     my $total_max = 0;
  821:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  822:         my $value = $Statistics->{$seq->{'symb'}}->{'score'};
  823:         my $max = $Statistics->{$seq->{'symb'}}->{'max'};
  824:         $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.
  825:             '<td align="right">'.$value.'</td>'.
  826:                 '<td align="right">'.$max.'</td></tr>'."\n";
  827:         $total += $value;
  828:         $total_max +=$max;
  829:     }
  830:     $Str .= '<tr><td><b>Total</b></td>'.
  831:         '<td align="right">'.$total.'</td>'.
  832:         '<td align="right">'.$total_max."</td></tr>\n";
  833:     $Str .= "</table>\n";
  834:     return $Str;
  835: }
  836: 
  837: }
  838: 
  839: #######################################################
  840: #######################################################
  841: 
  842: =pod
  843: 
  844: =head2 EXCEL subroutines
  845: 
  846: =item &excel_initialize($r)
  847: 
  848: =item &excel_outputstudent($r,$student)
  849: 
  850: =item &excel_finish($r)
  851: 
  852: =cut
  853: 
  854: #######################################################
  855: #######################################################
  856: {
  857: 
  858: my $excel_sheet;
  859: my $excel_workbook;
  860: 
  861: my $filename;
  862: my $rows_output;
  863: my $cols_output;
  864: 
  865: my %prog_state; # progress window state
  866: my $request_aborted;
  867: 
  868: my $total_formula;
  869: 
  870: sub excel_initialize {
  871:     my ($r) = @_;
  872:     #
  873:     undef ($excel_sheet);
  874:     undef ($excel_workbook);
  875:     undef ($filename);
  876:     undef ($rows_output);
  877:     undef ($cols_output);
  878:     undef (%prog_state);
  879:     undef ($request_aborted);
  880:     undef ($total_formula);
  881:     #
  882:     my $total_columns = scalar(&get_student_fields_to_show());
  883:     my $num_students = scalar(@Apache::lonstatistics::Students);
  884:     #
  885:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  886:         if ($chosen_output->{'every_problem'}) {
  887:             $total_columns += $seq->{'num_assess_parts'};
  888:         }
  889:         # Add 2 because we need a 'sequence_sum' and 'total' column for each
  890:         $total_columns += 2;
  891:     }
  892:     if ($chosen_output->{'base'} eq 'tries' && $total_columns > 255) {
  893:         $r->print(<<END);
  894: <h2>Unable to Complete Request</h2>
  895: <p>
  896: LON-CAPA is unable to produce your Excel spreadsheet because your selections
  897: will result in more than 255 columns.  Excel allows only 255 columns in a
  898: spreadsheet.
  899: </p><p>
  900: You may consider reducing the number of <b>Sequences or Folders</b> you
  901: have selected.  
  902: </p><p>
  903: LON-CAPA can produce <b>CSV</b> files of this data or Excel files of the
  904: summary data (<b>Parts Correct</b> or <b>Parts Correct & Totals</b>).
  905: </p>
  906: END
  907:        $request_aborted = 1;
  908:     }
  909:     if ($chosen_output->{'base'} eq 'scores' && $total_columns > 255) {
  910:         $r->print(<<END);
  911: <h2>Unable to Complete Request</h2>
  912: <p>
  913: LON-CAPA is unable to produce your Excel spreadsheet because your selections
  914: will result in more than 255 columns.  Excel allows only 255 columns in a
  915: spreadsheet.
  916: </p><p>
  917: You may consider reducing the number of <b>Sequences or Folders</b> you
  918: have selected.  
  919: </p><p>
  920: LON-CAPA can produce <b>CSV</b> files of this data or Excel files of the
  921: <b>Scores Summary</b> data.
  922: </p>
  923: END
  924:        $request_aborted = 1;
  925:     }
  926:     return if ($request_aborted);
  927:     #
  928:     $filename = '/prtspool/'.
  929:         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
  930:             time.'_'.rand(1000000000).'.xls';
  931:     #
  932:     $excel_workbook = undef;
  933:     $excel_sheet = undef;
  934:     #
  935:     $rows_output = 0;
  936:     $cols_output = 0;
  937:     #
  938:     # Determine rows 
  939:     my $header_row = $rows_output++;
  940:     my $description_row = $rows_output++;
  941:     $rows_output++;        # blank row
  942:     my $summary_header_row;
  943:     if ($chosen_output->{'summary_table'}) {
  944:         $summary_header_row = $rows_output++;
  945:         $rows_output+= scalar(&Apache::lonstatistics::Sequences_with_Assess());
  946:         $rows_output++;
  947:     }
  948:     my $sequence_name_row = $rows_output++;
  949:     my $resource_name_row = $rows_output++;
  950:     my $maximum_data_row = $rows_output++;
  951:     if (! $chosen_output->{'maximum_row'}) {
  952:         $rows_output--;
  953:     }
  954:     my $first_data_row = $rows_output++;
  955:     #
  956:     # Create sheet
  957:     $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
  958:     #
  959:     # Check for errors
  960:     if (! defined($excel_workbook)) {
  961:         $r->log_error("Error creating excel spreadsheet $filename: $!");
  962:         $r->print("Problems creating new Excel file.  ".
  963:                   "This error has been logged.  ".
  964:                   "Please alert your LON-CAPA administrator");
  965:         return ;
  966:     }
  967:     #
  968:     # The excel spreadsheet stores temporary data in files, then put them
  969:     # together.  If needed we should be able to disable this (memory only).
  970:     # The temporary directory must be specified before calling 'addworksheet'.
  971:     # File::Temp is used to determine the temporary directory.
  972:     $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
  973:     #
  974:     my $format = &Apache::loncommon::define_excel_formats($excel_workbook);
  975:     #
  976:     # Add a worksheet
  977:     my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
  978:     $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
  979:     $excel_sheet = $excel_workbook->addworksheet($sheetname);
  980:     #
  981:     # Put the course description in the header
  982:     $excel_sheet->write($header_row,$cols_output++,
  983:                    $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
  984:                         $format->{'h1'});
  985:     $cols_output += 3;
  986:     #
  987:     # Put a description of the sections listed
  988:     my $sectionstring = '';
  989:     my @Sections = @Apache::lonstatistics::SelectedSections;
  990:     if (scalar(@Sections) > 1) {
  991:         if (scalar(@Sections) > 2) {
  992:             my $last = pop(@Sections);
  993:             $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
  994:         } else {
  995:             $sectionstring = "Sections ".join(' and ',@Sections);
  996:         }
  997:     } else {
  998:         if ($Sections[0] eq 'all') {
  999:             $sectionstring = "All sections";
 1000:         } else {
 1001:             $sectionstring = "Section ".$Sections[0];
 1002:         }
 1003:     }
 1004:     $excel_sheet->write($header_row,$cols_output++,$sectionstring,
 1005:                         $format->{'h3'});
 1006:     $cols_output += scalar(@Sections);
 1007:     #
 1008:     # Put the date in there too
 1009:     $excel_sheet->write($header_row,$cols_output++,
 1010:                         'Compiled on '.localtime(time),$format->{'h3'});
 1011:     #
 1012:     $cols_output = 0;
 1013:     $excel_sheet->write($description_row,$cols_output++,
 1014:                         $chosen_output->{'shortdesc'},
 1015:                         $format->{'h3'});
 1016:     ##############################################
 1017:     # Output headings for the raw data
 1018:     ##############################################
 1019:     #
 1020:     # Add the student headers
 1021:     $cols_output = 0;
 1022:     foreach my $field (&get_student_fields_to_show()) {
 1023:         $excel_sheet->write($resource_name_row,$cols_output++,$field,
 1024:                             $format->{'bold'});
 1025:     }
 1026:     #
 1027:     # Add the remaining column headers
 1028:     my $total_formula_string = '=0';
 1029:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1030:         $excel_sheet->write($sequence_name_row,,
 1031:                             $cols_output,$seq->{'title'},$format->{'bold'});
 1032:         # Determine starting cell
 1033:         $seq->{'Excel:startcell'}=
 1034:             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1035:             ($first_data_row,$cols_output);
 1036:         $seq->{'Excel:startcol'}=$cols_output;
 1037:         my $count = 0;
 1038:         if ($chosen_output->{'every_problem'}) {
 1039:             # Put the names of the problems and parts into the sheet
 1040:             foreach my $res (@{$seq->{'contents'}}) {
 1041:                 if ($res->{'type'} ne 'assessment'  || 
 1042:                     ! exists($res->{'parts'})       ||
 1043:                     ref($res->{'parts'}) ne 'ARRAY' ||
 1044:                     scalar(@{$res->{'parts'}}) < 1) {
 1045:                     next;
 1046:                 }
 1047:                 if (scalar(@{$res->{'parts'}}) > 1) {
 1048:                     foreach my $part (@{$res->{'parts'}}) {
 1049:                         $excel_sheet->write($resource_name_row,
 1050:                                             $cols_output++,
 1051:                                             $res->{'title'}.' part '.$part,
 1052:                                             $format->{'bold'});
 1053:                     }
 1054:                 } else {
 1055:                     $excel_sheet->write($resource_name_row,
 1056:                                         $cols_output++,
 1057:                                         $res->{'title'},$format->{'bold'});
 1058:                 }
 1059:                 $count++;
 1060:             }
 1061:         }
 1062:         # Determine ending cell
 1063:         if ($count <= 1) {
 1064:             $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};
 1065:             $seq->{'Excel:endcol'}  = $seq->{'Excel:startcol'};
 1066:         } else {
 1067:             $seq->{'Excel:endcell'} = 
 1068:                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1069:                 ($first_data_row,$cols_output-1);
 1070:             $seq->{'Excel:endcol'} = $cols_output-1;
 1071:         }
 1072:         # Create the formula for summing up this sequence
 1073:         if (! exists($seq->{'Excel:endcell'}) ||
 1074:             ! defined($seq->{'Excel:endcell'})) {
 1075:             $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};
 1076:         }
 1077:         $seq->{'Excel:sum'}= $excel_sheet->store_formula
 1078:             ('=SUM('.$seq->{'Excel:startcell'}.
 1079:              ':'.$seq->{'Excel:endcell'}.')');
 1080:         # Determine cell the score is held in
 1081:         $seq->{'Excel:scorecell'} = 
 1082:             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1083:             ($first_data_row,$cols_output);
 1084:         $seq->{'Excel:scorecol'}=$cols_output;
 1085:         if ($chosen_output->{'base'} eq 'parts correct total') {
 1086:             $excel_sheet->write($resource_name_row,$cols_output++,
 1087:                                 'parts correct',
 1088:                                 $format->{'bold'});
 1089:         } elsif ($chosen_output->{'sequence_sum'}) {
 1090:             if ($chosen_output->{'correct'}) {
 1091:                 # Only reporting the number correct, so do not call it score
 1092:                 $excel_sheet->write($resource_name_row,$cols_output++,
 1093:                                     'sum',
 1094:                                     $format->{'bold'});
 1095:             } else {
 1096:                 $excel_sheet->write($resource_name_row,$cols_output++,
 1097:                                     'score',
 1098:                                     $format->{'bold'});
 1099:             }
 1100:         }
 1101:         #
 1102:         $total_formula_string.='+'.
 1103:             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1104:             ($first_data_row,$cols_output-1);
 1105:         if ($chosen_output->{'sequence_max'}) {
 1106:             $excel_sheet->write($resource_name_row,$cols_output++,
 1107:                                 'maximum',
 1108:                                 $format->{'bold'});
 1109:         }
 1110:     }
 1111:     if ($chosen_output->{'grand_total'}) {
 1112:         $excel_sheet->write($resource_name_row,$cols_output++,'Total',
 1113:                             $format->{'bold'});
 1114:     }
 1115:     $total_formula = $excel_sheet->store_formula($total_formula_string);
 1116:     ##############################################
 1117:     # Output a row for MAX, if appropriate
 1118:     ##############################################
 1119:     if ($chosen_output->{'maximum_row'}) {
 1120:         $cols_output = 0;
 1121:         foreach my $field (&get_student_fields_to_show()) {
 1122:             if ($field eq 'username' || $field eq 'fullname' || 
 1123:                 $field eq 'id') {
 1124:                 $excel_sheet->write($maximum_data_row,$cols_output++,'Maximum',
 1125:                                     $format->{'bold'});
 1126:             } else {
 1127:                 $excel_sheet->write($maximum_data_row,$cols_output++,'');
 1128:             }
 1129:         }
 1130:         #
 1131:         # Add the maximums for each sequence or assessment
 1132:         my %total_cell_translation;
 1133:         foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1134:             $cols_output=$seq->{'Excel:startcol'};
 1135:             $total_cell_translation{$seq->{'Excel:scorecell'}} = 
 1136:                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1137:                 ($maximum_data_row,$seq->{'Excel:scorecol'});
 1138:             my $weight;
 1139:             my $max = 0;
 1140:             foreach my $resource (@{$seq->{'contents'}}) {
 1141:                 next if ($resource->{'type'} ne 'assessment');
 1142:                 foreach my $part (@{$resource->{'parts'}}) {
 1143:                     $weight = 1;
 1144:                     if ($chosen_output->{'scores'}) {
 1145:                         $weight = &Apache::lonnet::EXT
 1146:                             ('resource.'.$part.'.weight',$resource->{'symb'},
 1147:                              undef,undef,undef);
 1148:                         if (!defined($weight) || ($weight eq '')) { 
 1149:                             $weight=1;
 1150:                         }
 1151:                     }
 1152:                     if ($chosen_output->{'scores'} &&
 1153:                         $chosen_output->{'every_problem'}) {
 1154:                         $excel_sheet->write($maximum_data_row,$cols_output++,
 1155:                                             $weight);
 1156:                     }
 1157:                     $max += $weight;
 1158:                 }
 1159:             } 
 1160:             #
 1161:             if ($chosen_output->{'sequence_sum'} && 
 1162:                 $chosen_output->{'every_problem'}) {
 1163:                 my %replaceCells;
 1164:                 $replaceCells{$seq->{'Excel:startcell'}} = 
 1165:                     &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1166:                     ($maximum_data_row,$seq->{'Excel:startcol'});
 1167:                 $replaceCells{$seq->{'Excel:endcell'}} = 
 1168:                     &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1169:                     ($maximum_data_row,$seq->{'Excel:endcol'});
 1170:                 $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
 1171:                                              $seq->{'Excel:sum'},undef,
 1172:                                              %replaceCells);
 1173:             } elsif ($chosen_output->{'sequence_sum'}) {
 1174:                 $excel_sheet->write($maximum_data_row,$cols_output++,$max);
 1175:             }
 1176:             if ($chosen_output->{'sequence_max'}) {
 1177:                 $excel_sheet->write($maximum_data_row,$cols_output++,$max);
 1178:             }
 1179:             #
 1180:         }
 1181:         if ($chosen_output->{'grand_total'}) {
 1182:             $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
 1183:                                          $total_formula,undef,
 1184:                                          %total_cell_translation);
 1185:         }
 1186:     } # End of MAXIMUM row output  if ($chosen_output->{'maximum_row'}) {
 1187:     $rows_output = $first_data_row;
 1188:     ##############################################
 1189:     # Output summary table, which actually is above the sequence name row.
 1190:     ##############################################
 1191:     if ($chosen_output->{'summary_table'}) {
 1192:         $cols_output = 0;
 1193:         $excel_sheet->write($summary_header_row,$cols_output++,
 1194:                             'Summary Table',$format->{'bold'});
 1195:         if ($chosen_output->{'maximum_row'}) {
 1196:             $excel_sheet->write($summary_header_row,$cols_output++,
 1197:                                 'Maximum',$format->{'bold'});
 1198:         }
 1199:         $excel_sheet->write($summary_header_row,$cols_output++,
 1200:                             'Average',$format->{'bold'});
 1201:         $excel_sheet->write($summary_header_row,$cols_output++,
 1202:                             'Median',$format->{'bold'});
 1203:         $excel_sheet->write($summary_header_row,$cols_output++,
 1204:                             'Std Dev',$format->{'bold'});
 1205:         my $row = $summary_header_row+1;
 1206:         foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1207:             $cols_output = 0;
 1208:             $excel_sheet->write($row,$cols_output++,
 1209:                                 $seq->{'title'},
 1210:                                 $format->{'bold'});
 1211:             if ($chosen_output->{'maximum_row'}) {
 1212:                 $excel_sheet->write
 1213:                     ($row,$cols_output++,
 1214:                      '='.
 1215:                      &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1216:                      ($maximum_data_row,$seq->{'Excel:scorecol'})
 1217:                      );
 1218:             }
 1219:             my $range = 
 1220:                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1221:                 ($first_data_row,$seq->{'Excel:scorecol'}).
 1222:                 ':'.
 1223:                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1224:                 ($first_data_row+$num_students-1,$seq->{'Excel:scorecol'});
 1225:             $excel_sheet->write($row,$cols_output++,
 1226:                                 '=AVERAGE('.$range.')');
 1227:             $excel_sheet->write($row,$cols_output++,
 1228:                                 '=MEDIAN('.$range.')');
 1229:             $excel_sheet->write($row,$cols_output++,
 1230:                                 '=STDEV('.$range.')');
 1231:             $row++;
 1232:         }
 1233:     }
 1234:     ##############################################
 1235:     #   Take care of non-excel initialization
 1236:     ##############################################
 1237:     #
 1238:     # Let the user know what we are doing
 1239:     my $studentcount = scalar(@Apache::lonstatistics::Students); 
 1240:     if ($ENV{'form.SelectedStudent'}) {
 1241:         $studentcount = '1';
 1242:     }
 1243:     if ($studentcount > 1) {
 1244:         $r->print('<h1>'.&mt('Compiling Excel spreadsheet for [_1] students',
 1245:                              $studentcount)."</h1>\n");
 1246:     } else {
 1247:         $r->print('<h1>'.
 1248:                   &mt('Compiling Excel spreadsheet for 1 student').
 1249:                   "</h1>\n");
 1250:     }
 1251:     $r->rflush();
 1252:     #
 1253:     # Initialize progress window
 1254:     %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
 1255:         ($r,'Excel File Compilation Status',
 1256:          'Excel File Compilation Progress', $studentcount);
 1257:     #
 1258:     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
 1259:                                           'Processing first student');
 1260:     return;
 1261: }
 1262: 
 1263: sub excel_outputstudent {
 1264:     my ($r,$student) = @_;
 1265:     return if ($request_aborted);
 1266:     return if (! defined($excel_sheet));
 1267:     $cols_output=0;
 1268:     #
 1269:     # Write out student data
 1270:     my @to_show = &get_student_fields_to_show();
 1271:     foreach my $field (@to_show) {
 1272:         $excel_sheet->write($rows_output,$cols_output++,$student->{$field});
 1273:     }
 1274:     #
 1275:     # Get student assessment data
 1276:     my %StudentsData;
 1277:     my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
 1278:                                                         $student->{'domain'},
 1279:                                                         undef,
 1280:                                                    $ENV{'request.course.id'});
 1281:     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
 1282:         %StudentsData = @tmp;
 1283:     }
 1284:     #
 1285:     # Write out sequence scores and totals data
 1286:     my %total_cell_translation;
 1287:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1288:         $cols_output = $seq->{'Excel:startcol'};
 1289:         # Keep track of cells to translate in total cell
 1290:         $total_cell_translation{$seq->{'Excel:scorecell'}} = 
 1291:             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1292:                         ($rows_output,$seq->{'Excel:scorecol'});
 1293:         #
 1294:         my ($performance,$performance_length,$score,$seq_max,$rawdata);
 1295:         if ($chosen_output->{'tries'} || $chosen_output->{'correct'}){
 1296:             ($performance,$performance_length,$score,$seq_max,$rawdata) =
 1297:                 &StudentTriesOnSequence($student,\%StudentsData,
 1298:                                         $seq,'no');
 1299:         } else {
 1300:             ($performance,$performance_length,$score,$seq_max,$rawdata) =
 1301:                 &StudentPerformanceOnSequence($student,\%StudentsData,
 1302:                                               $seq,'no');
 1303:         } 
 1304:         if ($chosen_output->{'every_problem'}) {
 1305:             if ($chosen_output->{'correct'}) {
 1306:                 # only indiciate if each item is correct or not
 1307:                 foreach my $value (@$rawdata) {
 1308:                     # nonzero means correct
 1309:                     $value = 1 if ($value > 0);
 1310:                     $excel_sheet->write($rows_output,$cols_output++,$value);
 1311:                 }
 1312:             } else {
 1313:                 foreach my $value (@$rawdata) {
 1314:                     $excel_sheet->write($rows_output,$cols_output++,$value);
 1315:                 }
 1316:             }
 1317:         }
 1318:         if ($chosen_output->{'sequence_sum'} && 
 1319:             $chosen_output->{'every_problem'}) {
 1320:             # Write a formula for the sum of this sequence
 1321:             my %replaceCells;
 1322:             $replaceCells{$seq->{'Excel:startcell'}} = 
 1323:                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1324:                             ($rows_output,$seq->{'Excel:startcol'});
 1325:             $replaceCells{$seq->{'Excel:endcell'}} = 
 1326:                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
 1327:                             ($rows_output,$seq->{'Excel:endcol'});
 1328:             # The undef is for the format
 1329:             if (scalar(keys(%replaceCells)) == 1) {
 1330:                 $excel_sheet->repeat_formula($rows_output,$cols_output++,
 1331:                                              $seq->{'Excel:sum'},undef,
 1332:                                              %replaceCells,%replaceCells);
 1333:             } else {
 1334:                 $excel_sheet->repeat_formula($rows_output,$cols_output++,
 1335:                                              $seq->{'Excel:sum'},undef,
 1336:                                              %replaceCells);
 1337:             }
 1338:         } elsif ($chosen_output->{'sequence_sum'}) {
 1339:             $excel_sheet->write($rows_output,$cols_output++,$score);
 1340:         }
 1341:         if ($chosen_output->{'sequence_max'}) {
 1342:             $excel_sheet->write($rows_output,$cols_output++,$seq_max);
 1343:         }
 1344:     }
 1345:     #
 1346:     if ($chosen_output->{'grand_total'}) {
 1347:         $excel_sheet->repeat_formula($rows_output,$cols_output++,
 1348:                                      $total_formula,undef,
 1349:                                      %total_cell_translation);
 1350:     }
 1351:     #
 1352:     # Bookkeeping
 1353:     $rows_output++; 
 1354:     $cols_output=0;
 1355:     #
 1356:     # Update the progress window
 1357:     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
 1358:     return;
 1359: }
 1360: 
 1361: sub excel_finish {
 1362:     my ($r) = @_;
 1363:     return if ($request_aborted);
 1364:     return if (! defined($excel_sheet));
 1365:     #
 1366:     # Write the excel file
 1367:     $excel_workbook->close();
 1368:     my $c = $r->connection();
 1369:     #
 1370:     return if($c->aborted());
 1371:     #
 1372:     # Close the progress window
 1373:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
 1374:     #
 1375:     # Tell the user where to get their excel file
 1376:     $r->print('<br />'.
 1377:               '<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n");
 1378:     $r->rflush();
 1379:     return;
 1380: }
 1381: 
 1382: }
 1383: #######################################################
 1384: #######################################################
 1385: 
 1386: =pod
 1387: 
 1388: =head2 CSV output routines
 1389: 
 1390: =item &csv_initialize($r)
 1391: 
 1392: =item &csv_outputstudent($r,$student)
 1393: 
 1394: =item &csv_finish($r)
 1395: 
 1396: =cut
 1397: 
 1398: #######################################################
 1399: #######################################################
 1400: {
 1401: 
 1402: my $outputfile;
 1403: my $filename;
 1404: my $request_aborted;
 1405: my %prog_state; # progress window state
 1406: 
 1407: sub csv_initialize{
 1408:     my ($r) = @_;
 1409:     # 
 1410:     # Clean up
 1411:     undef($outputfile);
 1412:     undef($filename);
 1413:     undef($request_aborted);
 1414:     undef(%prog_state);
 1415:     #
 1416:     # Deal with unimplemented requests
 1417:     $request_aborted = undef;
 1418:     if ($chosen_output->{'base'} =~ /final table/) {
 1419:         $r->print(<<END);
 1420: <h2>Unable to Complete Request</h2>
 1421: <p>
 1422: The <b>Summary Table (Scores)</b> option is not available for non-HTML output.
 1423: </p>
 1424: END
 1425:        $request_aborted = 1;
 1426:     }
 1427:     return if ($request_aborted);
 1428:     #
 1429:     # Initialize progress window
 1430:     my $studentcount = scalar(@Apache::lonstatistics::Students);
 1431:     %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
 1432:         ($r,'CSV File Compilation Status',
 1433:          'CSV File Compilation Progress', $studentcount);
 1434:     #
 1435:     # Open a file
 1436:     $filename = '/prtspool/'.
 1437:         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
 1438:             time.'_'.rand(1000000000).'.csv';
 1439:     unless ($outputfile = Apache::File->new('>/home/httpd'.$filename)) {
 1440:         $r->log_error("Couldn't open $filename for output $!");
 1441:         $r->print("Problems occured in writing the csv file.  ".
 1442:                   "This error has been logged.  ".
 1443:                   "Please alert your LON-CAPA administrator.");
 1444:         $outputfile = undef;
 1445:     }
 1446:     #
 1447:     # Datestamp
 1448:     my $description = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
 1449:     print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
 1450:         '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
 1451:             "\n";
 1452:     #
 1453:     # Print out the headings
 1454:     my $sequence_row = '';
 1455:     my $resource_row = undef;
 1456:     foreach my $field (&get_student_fields_to_show()) {
 1457:         $sequence_row .='"",';
 1458:         $resource_row .= '"'.&Apache::loncommon::csv_translate($field).'",';
 1459:     }
 1460:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1461:         $sequence_row .= '"'.
 1462:             &Apache::loncommon::csv_translate($seq->{'title'}).'",';
 1463:         my $count = 0;
 1464:         if ($chosen_output->{'every_problem'}) {
 1465:             foreach my $res (@{$seq->{'contents'}}) {
 1466:                 if ($res->{'type'} ne 'assessment'  || 
 1467:                     ! exists($res->{'parts'})       ||
 1468:                     ref($res->{'parts'}) ne 'ARRAY' ||
 1469:                     scalar(@{$res->{'parts'}}) < 1) {
 1470:                     next;
 1471:                 }
 1472:                 foreach my $part (@{$res->{'parts'}}) {
 1473:                     $resource_row .= '"'.
 1474:                         &Apache::loncommon::csv_translate($res->{'title'}.
 1475:                                                           ', Part '.$part
 1476:                                                           ).'",';
 1477:                     $count++;
 1478:                 }
 1479:             }
 1480:         }
 1481:         $sequence_row.='"",'x$count;
 1482:         if ($chosen_output->{'sequence_sum'}) {
 1483:             if($chosen_output->{'correct'}) {
 1484:                 $resource_row .= '"sum",';
 1485:             } else {
 1486:                 $resource_row .= '"score",';
 1487:             }
 1488:         }
 1489:         if ($chosen_output->{'sequence_max'}) {
 1490:             $sequence_row.= '"",';
 1491:             $resource_row .= '"maximum possible",';
 1492:         }
 1493:     }
 1494:     if ($chosen_output->{'grand_total'}) {
 1495:         $sequence_row.= '"",';
 1496:         $resource_row.= '"Total",';
 1497:     } 
 1498:     chomp($sequence_row);
 1499:     chomp($resource_row);
 1500:     print $outputfile $sequence_row."\n";
 1501:     print $outputfile $resource_row."\n";
 1502:     return;
 1503: }
 1504: 
 1505: sub csv_outputstudent {
 1506:     my ($r,$student) = @_;
 1507:     return if ($request_aborted);
 1508:     return if (! defined($outputfile));
 1509:     my $Str = '';
 1510:     #
 1511:     # Output student fields
 1512:     my @to_show = &get_student_fields_to_show();
 1513:     foreach my $field (@to_show) {
 1514:         $Str .= '"'.&Apache::loncommon::csv_translate($student->{$field}).'",';
 1515:     }
 1516:     #
 1517:     # Get student assessment data
 1518:     my %StudentsData;
 1519:     my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
 1520:                                                         $student->{'domain'},
 1521:                                                         undef,
 1522:                                                    $ENV{'request.course.id'});
 1523:     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
 1524:         %StudentsData = @tmp;
 1525:     }
 1526:     #
 1527:     # Output performance data
 1528:     my $total = 0;
 1529:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
 1530:         my ($performance,$performance_length,$score,$seq_max,$rawdata);
 1531:         if ($chosen_output->{'tries'}){
 1532:             ($performance,$performance_length,$score,$seq_max,$rawdata) =
 1533:                 &StudentTriesOnSequence($student,\%StudentsData,
 1534:                                         $seq,'no');
 1535:         } else {
 1536:             ($performance,$performance_length,$score,$seq_max,$rawdata) =
 1537:                 &StudentPerformanceOnSequence($student,\%StudentsData,
 1538:                                               $seq,'no');
 1539:         }
 1540:         if ($chosen_output->{'every_problem'}) {
 1541:             if ($chosen_output->{'correct'}) {
 1542:                 $score = 0;
 1543:                 # Deal with number of parts correct data
 1544:                 $Str .= '"'.join('","',( map { if ($_>0) { 
 1545:                                                    $score += 1;
 1546:                                                    1; 
 1547:                                                } else { 
 1548:                                                    0; 
 1549:                                                }
 1550:                                              } @$rawdata)).'",';
 1551:             } else {
 1552:                 $Str .= '"'.join('","',(@$rawdata)).'",';
 1553:             }
 1554:         }
 1555:         if ($chosen_output->{'sequence_sum'}) {
 1556:             $Str .= '"'.$score.'",';
 1557:         } 
 1558:         if ($chosen_output->{'sequence_max'}) {
 1559:             $Str .= '"'.$seq_max.'",';
 1560:         }
 1561:         $total+=$score;
 1562:     }
 1563:     if ($chosen_output->{'grand_total'}) {
 1564:         $Str .= '"'.$total.'",';
 1565:     }
 1566:     chop($Str);
 1567:     $Str .= "\n";
 1568:     print $outputfile $Str;
 1569:     #
 1570:     # Update the progress window
 1571:     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
 1572:     return;
 1573: }
 1574: 
 1575: sub csv_finish {
 1576:     my ($r) = @_;
 1577:     return if ($request_aborted);
 1578:     return if (! defined($outputfile));
 1579:     close($outputfile);
 1580:     #
 1581:     my $c = $r->connection();
 1582:     return if ($c->aborted());
 1583:     #
 1584:     # Close the progress window
 1585:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
 1586:     #
 1587:     # Tell the user where to get their csv file
 1588:     $r->print('<br />'.
 1589:               '<a href="'.$filename.'">'.&mt('Your csv file.').'</a>'."\n");
 1590:     $r->rflush();
 1591:     return;
 1592:     
 1593: }
 1594: 
 1595: }
 1596: 
 1597: #######################################################
 1598: #######################################################
 1599: 
 1600: =pod
 1601: 
 1602: =item &StudentTriesOnSequence()
 1603: 
 1604: Inputs:
 1605: 
 1606: =over 4
 1607: 
 1608: =item $student
 1609: 
 1610: =item $studentdata Hash ref to all student data
 1611: 
 1612: =item $seq Hash ref, the sequence we are working on
 1613: 
 1614: =item $links if defined we will output links to each resource.
 1615: 
 1616: =back
 1617: 
 1618: =cut
 1619: 
 1620: #######################################################
 1621: #######################################################
 1622: sub StudentTriesOnSequence {
 1623:     my ($student,$studentdata,$seq,$links) = @_;
 1624:     $links = 'no' if (! defined($links));
 1625:     my $Str = '';
 1626:     my ($sum,$max) = (0,0);
 1627:     my $performance_length = 0;
 1628:     my @TriesData = ();
 1629:     my $tries;
 1630:     foreach my $resource (@{$seq->{'contents'}}) {
 1631:         next if ($resource->{'type'} ne 'assessment');
 1632:         my $resource_data = $studentdata->{$resource->{'symb'}};
 1633:         my $value = '';
 1634:         foreach my $partnum (@{$resource->{'parts'}}) {
 1635:             $tries = undef;
 1636:             $max++;
 1637:             $performance_length++;
 1638:             my $symbol = ' '; # default to space
 1639:             #
 1640:             my $awarded = 0;
 1641:             if (exists($resource_data->{'resource.'.$partnum.'.awarded'})) {
 1642:                 $awarded = $resource_data->{'resource.'.$partnum.'.awarded'};
 1643:                 $awarded = 0 if (! $awarded);
 1644:             }
 1645:             #
 1646:             my $status = '';
 1647:             if (exists($resource_data->{'resource.'.$partnum.'.solved'})) {
 1648:                 $status = $resource_data->{'resource.'.$partnum.'.solved'};
 1649:             }
 1650:             #
 1651:             my $tries = 0;
 1652:             if(exists($resource_data->{'resource.'.$partnum.'.tries'})) {
 1653:                 $tries = $resource_data->{'resource.'.$partnum.'.tries'};
 1654:             }
 1655:             #
 1656:             if ($awarded > 0) {
 1657:                 # The student has gotten the problem correct to some degree
 1658:                 if ($status eq 'excused') {
 1659:                     $symbol = 'x';
 1660:                     $max--;
 1661:                 } elsif ($status eq 'correct_by_override') {
 1662:                     $symbol = '+';
 1663:                     $sum++;
 1664:                 } elsif ($tries > 0) {
 1665:                     if ($tries > 9) {
 1666:                         $symbol = '*';
 1667:                     } else {
 1668:                         $symbol = $tries;
 1669:                     }
 1670:                     $sum++;
 1671:                 } else {
 1672:                     $symbol = '+';
 1673:                     $sum++;
 1674:                 }
 1675:             } else {
 1676:                 # The student has the problem incorrect or it is ungraded
 1677:                 if ($status eq 'excused') {
 1678:                     $symbol = 'x';
 1679:                     $max--;
 1680:                 } elsif ($status eq 'incorrect_by_override') {
 1681:                     $symbol = '-';
 1682:                 } elsif ($status eq 'ungraded_attempted') {
 1683:                     $symbol = '#';
 1684:                 } elsif ($status eq 'incorrect_attempted' ||
 1685:                          $tries > 0)  {
 1686:                     $symbol = '.';
 1687:                 } else {
 1688:                     # Problem is wrong and has not been attempted.
 1689:                     $symbol=' ';
 1690:                 }
 1691:             }
 1692:             #
 1693:             if (! defined($tries)) {
 1694:                 $tries = $symbol;
 1695:             }
 1696:             push (@TriesData,$tries);
 1697:             #
 1698:             if ( ($links eq 'yes' && $symbol ne ' ') ||
 1699:                  ($links eq 'all')) {
 1700:                 if (length($symbol) > 1) {
 1701:                     &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
 1702:                 }
 1703:                 $symbol = '<a href="/adm/grades'.
 1704:                     '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
 1705:                         '&student='.$student->{'username'}.
 1706:                             '&userdom='.$student->{'domain'}.
 1707:                                 '&command=submission">'.$symbol.'</a>';
 1708:             }
 1709:             $value .= $symbol;
 1710:         }
 1711:         $Str .= $value;
 1712:     }
 1713:     if ($seq->{'randompick'}) {
 1714:         $max = $seq->{'randompick'};
 1715:     }
 1716:     return ($Str,$performance_length,$sum,$max,\@TriesData);
 1717: }
 1718: 
 1719: #######################################################
 1720: #######################################################
 1721: 
 1722: =pod
 1723: 
 1724: =item &StudentPerformanceOnSequence()
 1725: 
 1726: Inputs:
 1727: 
 1728: =over 4
 1729: 
 1730: =item $student
 1731: 
 1732: =item $studentdata Hash ref to all student data
 1733: 
 1734: =item $seq Hash ref, the sequence we are working on
 1735: 
 1736: =item $links if defined we will output links to each resource.
 1737: 
 1738: =back
 1739: 
 1740: =cut
 1741: 
 1742: #######################################################
 1743: #######################################################
 1744: sub StudentPerformanceOnSequence {
 1745:     my ($student,$studentdata,$seq,$links) = @_;
 1746:     $links = 'no' if (! defined($links));
 1747:     my $Str = ''; # final result string
 1748:     my ($score,$max) = (0,0);
 1749:     my $performance_length = 0;
 1750:     my $symbol;
 1751:     my @ScoreData = ();
 1752:     my $partscore;
 1753:     foreach my $resource (@{$seq->{'contents'}}) {
 1754:         next if ($resource->{'type'} ne 'assessment');
 1755:         my $resource_data = $studentdata->{$resource->{'symb'}};
 1756:         foreach my $part (@{$resource->{'parts'}}) {
 1757:             $partscore = undef;
 1758:             my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
 1759:                                               $resource->{'symb'},
 1760:                                               $student->{'domain'},
 1761:                                               $student->{'username'},
 1762:                                               $student->{'section'});
 1763:             if (!defined($weight) || ($weight eq '')) { 
 1764:                 $weight=1;
 1765:             }
 1766:             #
 1767:             $max += $weight; # see the 'excused' branch below...
 1768:             $performance_length++; # one character per part
 1769:             $symbol = ' '; # default to space
 1770:             #
 1771:             my $awarded = 0;
 1772:             if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
 1773:                 $awarded = $resource_data->{'resource.'.$part.'.awarded'};
 1774:                 $awarded = 0 if (! $awarded);
 1775:             }
 1776:             #
 1777:             $partscore = $weight*$awarded;
 1778:             $score += $partscore;
 1779:             $symbol = $partscore; 
 1780:             if (abs($symbol - sprintf("%.0f",$symbol)) < 0.001) {
 1781:                 $symbol = sprintf("%.0f",$symbol);
 1782:             }
 1783:             if (length($symbol) > 1) {
 1784:                 $symbol = '*';
 1785:             }
 1786:             if (exists($resource_data->{'resource.'.$part.'.solved'})) {
 1787:                 my $status = $resource_data->{'resource.'.$part.'.solved'};
 1788:                 if ($status eq 'excused') {
 1789:                     $symbol = 'x';
 1790:                     $max -= $weight; # Do not count 'excused' problems.
 1791:                 }
 1792:             } else {
 1793:                 # Unsolved.  Did they try?
 1794:                 if (exists($resource_data->{'resource.'.$part.'.tries'})){
 1795:                     $symbol = '.';
 1796:                 } else {
 1797:                     $symbol = ' ';
 1798:                 }
 1799:             }
 1800:             #
 1801:             if (! defined($partscore)) {
 1802:                 $partscore = $symbol;
 1803:             }
 1804:             push (@ScoreData,$partscore);
 1805:             #
 1806:             if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
 1807:                 $symbol = '<a href="/adm/grades'.
 1808:                     '?symb='.&Apache::lonnet::escape($resource->{'symb'}).
 1809:                     '&student='.$student->{'username'}.
 1810:                     '&userdom='.$student->{'domain'}.
 1811:                     '&command=submission">'.$symbol.'</a>';
 1812:             }
 1813:             $Str .= $symbol;
 1814:         }
 1815:     }
 1816:     return ($Str,$performance_length,$score,$max,\@ScoreData);
 1817: }
 1818: 
 1819: #######################################################
 1820: #######################################################
 1821: 
 1822: =pod
 1823: 
 1824: =item &CreateLegend()
 1825: 
 1826: This function returns a formatted string containing the legend for the
 1827: chart.  The legend describes the symbols used to represent grades for
 1828: problems.
 1829: 
 1830: =cut
 1831: 
 1832: #######################################################
 1833: #######################################################
 1834: sub CreateLegend {
 1835:     my $Str = "<p><pre>".
 1836:               "   1  correct by student in 1 try\n".
 1837:               "   7  correct by student in 7 tries\n".
 1838:               "   *  correct by student in more than 9 tries\n".
 1839: 	      "   +  correct by hand grading or override\n".
 1840:               "   -  incorrect by override\n".
 1841: 	      "   .  incorrect attempted\n".
 1842: 	      "   #  ungraded attempted\n".
 1843:               "      not attempted (blank field)\n".
 1844: 	      "   x  excused".
 1845:               "</pre><p>";
 1846:     return $Str;
 1847: }
 1848: 
 1849: #######################################################
 1850: #######################################################
 1851: 
 1852: =pod 
 1853: 
 1854: =back
 1855: 
 1856: =cut
 1857: 
 1858: #######################################################
 1859: #######################################################
 1860: 
 1861: 1;
 1862: 
 1863: __END__

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