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

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

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