Diff for /loncom/interface/statistics/lonstudentassessment.pm between versions 1.107 and 1.118

version 1.107, 2004/12/10 16:52:53 version 1.118, 2005/03/11 20:26:32
Line 56  use Apache::loncommon(); Line 56  use Apache::loncommon();
 use Apache::loncoursedata;  use Apache::loncoursedata;
 use Apache::lonnet; # for logging porpoises  use Apache::lonnet; # for logging porpoises
 use Apache::lonlocal;  use Apache::lonlocal;
   use Time::HiRes;
 use Spreadsheet::WriteExcel;  use Spreadsheet::WriteExcel;
 use Spreadsheet::WriteExcel::Utility();  use Spreadsheet::WriteExcel::Utility();
   
Line 327  sub CreateInterface { Line 328  sub CreateInterface {
     $Str .= '<tr><td align="center">'."\n";      $Str .= '<tr><td align="center">'."\n";
     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);      $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
     $Str .= '</td><td align="center">';      $Str .= '</td><td align="center">';
     my $only_seq_with_assessments = sub {   
         my $s=shift;  
         if ($s->{'num_assess'} < 1) {   
             return 0;  
         } else {   
             return 1;  
         }  
     };  
     $Str .= &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',      $Str .= &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',
                                                       5,undef);                                                        5,undef);
     $Str .= '</td><td>'."\n";      $Str .= '</td><td>'."\n";
     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);      $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
     $Str .= '</td><td>'."\n";      $Str .= '</td><td>'."\n";
     $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,      $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5);
                                               $only_seq_with_assessments);  
     $Str .= '</td><td>'."\n";      $Str .= '</td><td>'."\n";
     $Str .= &CreateAndParseOutputSelector();      $Str .= &CreateAndParseOutputSelector();
     $Str .= '</td><td>'."\n";      $Str .= '</td><td>'."\n";
Line 357  sub CreateInterface { Line 349  sub CreateInterface {
     $Str .= '<input type="submit" name="ClearCache" value="'.      $Str .= '<input type="submit" name="ClearCache" value="'.
         &mt('Clear Caches').'" />';          &mt('Clear Caches').'" />';
     $Str .= '&nbsp;'x5;      $Str .= '&nbsp;'x5;
       $Str .= 
           &mt('Status[_1]',
               '<input type="text" name="stats_status" size="60" value="" />');
     $Str .= '<br />';      $Str .= '<br />';
     return $Str;      return $Str;
 }  }
Line 516  my @OutputDataOptions = Line 511  my @OutputDataOptions =
        maximum_row => 0,         maximum_row => 0,
        shortdesc => 'Number of Tries before success on each Problem Part',         shortdesc => 'Number of Tries before success on each Problem Part',
        longdesc =>'The number of tries before success on each problem part.',         longdesc =>'The number of tries before success on each problem part.',
          non_html_notes => 'negative values indicate an incorrect problem',
        },         },
      { name  =>'Parts Correct',       { name  =>'Parts Correct',
        base  =>'tries',         base  =>'tries',
Line 582  sub CreateAndParseOutputDataSelector { Line 578  sub CreateAndParseOutputDataSelector {
   
 #######################################################  #######################################################
 #######################################################  #######################################################
   sub count_parts {
       my ($navmap,$sequence) = @_;
       my @resources = &get_resources($navmap,$sequence);
       my $count = 0;
       foreach my $res (@resources) {
           $count += scalar(@{$res->parts});
       }
       return $count;
   }
   
   sub get_resources {
       my ($navmap,$sequence) = @_;
       my @resources = $navmap->retrieveResources($sequence,
                                                  sub { shift->is_problem(); },
                                                  0,0,0);
       return @resources;
   }
   
   #######################################################
   #######################################################
   
 =pod  =pod
   
Line 609  Return a line of the chart for a student Line 625  Return a line of the chart for a student
     my %prog_state;   # progress state used by loncommon PrgWin routines      my %prog_state;   # progress state used by loncommon PrgWin routines
     my $total_sum_width;      my $total_sum_width;
   
       my %width; # Holds sequence width information
       my @sequences;
       my $navmap; # Have to keep this around since weakref is a bit zealous
   
 sub html_initialize {  sub html_initialize {
     my ($r) = @_;      my ($r) = @_;
     #      #
Line 616  sub html_initialize { Line 636  sub html_initialize {
     $count = 0;      $count = 0;
     $nodata_count = 0;      $nodata_count = 0;
     undef(%prog_state);      undef(%prog_state);
       undef(%width);
       #
       undef($navmap);
       undef(@sequences);
       ($navmap,@sequences) = 
           &Apache::lonstatistics::selected_sequences_with_assessments();
       if (! ref($navmap)) {
           # Unable to get data, so bail out
           $r->print("<h3>".
                     &mt('Unable to retrieve course information.').
                     '</h3>');
       }
     #      #
     $r->print("<h3>".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.      $r->print("<h3>".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
               "&nbsp;&nbsp;".localtime(time)."</h3>");                "&nbsp;&nbsp;".localtime(time)."</h3>");
       #
     if ($chosen_output->{'base'} !~ /^final table/) {      if ($chosen_output->{'base'} !~ /^final table/) {
         $r->print("<h3>".$chosen_output->{'shortdesc'}."</h3>");                  $r->print("<h3>".$chosen_output->{'shortdesc'}."</h3>");        
     }      }
Line 635  sub html_initialize { Line 667  sub html_initialize {
     #      #
     # Compute the column widths and output the sequence titles      # Compute the column widths and output the sequence titles
     my $total_count;      my $total_count;
     foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()){      #
         #      # Compute sequence widths
         # Comptue column widths      my $starttime = Time::HiRes::time;
         $sequence->{'width_sum'} = 0;      foreach my $seq (@sequences) {
           my $symb = $seq->symb;
           my $title = $seq->compTitle;
           $width{$symb}->{'width_sum'} = 0;
           # Compute width of sum
         if ($chosen_output->{'sequence_sum'}) {          if ($chosen_output->{'sequence_sum'}) {
             if ($chosen_output->{'every_problem'}) {              if ($chosen_output->{'every_problem'}) {
                 # Use 1 digit for a space                  # Use 1 digit for a space
                 $sequence->{'width_sum'} += 1;                              $width{$symb}->{'width_sum'} += 1;            
             }              }
     $total_count += $sequence->{'num_assess_parts'};      $total_count += &count_parts($navmap,$seq);
             # Use 3 digits for the sum              # Use 3 digits for the sum
             $sequence->{'width_sum'} += 3;              $width{$symb}->{'width_sum'} += 3;
         }          }
           # Compute width of maximum
         if ($chosen_output->{'sequence_max'}) {          if ($chosen_output->{'sequence_max'}) {
             if ($sequence->{'width_sum'}>0) {              if ($width{$symb}->{'width_sum'}>0) {
                 # One digit for the '/'                  # One digit for the '/'
                 $sequence->{'width_sum'} +=1;                  $width{$symb}->{'width_sum'} +=1;
             }              }
             # Use 3 digits for the total              # Use 3 digits for the total
             $sequence->{'width_sum'}+=3;              $width{$symb}->{'width_sum'}+=3;
         }          }
  #   #
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             # one problem per digit              # one problem per digit
             $sequence->{'width_problem'} = $sequence->{'num_assess_parts'};              $width{$symb}->{'width_parts'}= &count_parts($navmap,$seq);
               $width{$symb}->{'width_problem'} += $width{$symb}->{'width_parts'};
         } else {          } else {
             $sequence->{'width_problem'} = 0;              $width{$symb}->{'width_problem'} = 0;
         }          }
         $sequence->{'width_total'} = $sequence->{'width_problem'} +           $width{$symb}->{'width_total'} = $width{$symb}->{'width_problem'} + 
                                      $sequence->{'width_sum'};                                       $width{$symb}->{'width_sum'};
         if ($sequence->{'width_total'} < length(&HTML::Entities::decode($sequence->{'title'}))) {          if ($width{$symb}->{'width_total'} < length(&HTML::Entities::decode($title))) {
             $sequence->{'width_total'} = length(&HTML::Entities::decode($sequence->{'title'}));              $width{$symb}->{'width_total'} = length(&HTML::Entities::decode($title));
         }          }
         #          #
         # Output the sequence titles          # Output the sequence titles
         $Str .=           $Str .= $title.(' 'x($width{$symb}->{'width_total'}-
             $sequence->{'title'}.' 'x($sequence->{'width_total'}-                              length($title)
                                       length($sequence->{'title'})                              )).$padding;
                                       ).$padding;  
     }      }
     $total_sum_width = length($total_count)+1;      $total_sum_width = length($total_count)+1;
     $Str .= "    total</pre>\n";      $Str .= "    total</pre>\n";
Line 686  sub html_initialize { Line 723  sub html_initialize {
 sub html_outputstudent {  sub html_outputstudent {
     my ($r,$student) = @_;      my ($r,$student) = @_;
     my $Str = '';      my $Str = '';
       return if (! defined($navmap));
     #      #
     if($count++ % 5 == 0 && $count > 0) {      if($count++ % 5 == 0 && $count > 0) {
         $r->print("</pre><pre>");          $r->print("</pre><pre>");
Line 721  sub html_outputstudent { Line 759  sub html_outputstudent {
     # By sequence build up the data      # By sequence build up the data
     my $studentstats;      my $studentstats;
     my $PerformanceStr = '';      my $PerformanceStr = '';
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
           my $symb = $seq->symb;
         my ($performance,$performance_length,$score,$seq_max,$rawdata);          my ($performance,$performance_length,$score,$seq_max,$rawdata);
         if ($chosen_output->{'tries'}) {          if ($chosen_output->{'tries'}) {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &StudentTriesOnSequence($student,\%StudentsData,                  &student_tries_on_sequence($student,\%StudentsData,
                                         $seq,$show_links);                                             $navmap,$seq,$show_links);
         } else {          } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &StudentPerformanceOnSequence($student,\%StudentsData,                  &student_performance_on_sequence($student,\%StudentsData,
                                               $seq,$show_links);                                                   $navmap,$seq,$show_links);
         }          }
         my $ratio='';          my $ratio='';
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'} && 
               $chosen_output->{'sequence_sum'}) {
             $ratio .= ' ';              $ratio .= ' ';
         }          }
         if ($chosen_output->{'sequence_sum'} && $score ne ' ') {          if ($chosen_output->{'sequence_sum'} && $score ne ' ') {
             $ratio .= sprintf("%3.0f",$score);              my $score .= sprintf("%3.0f",$score);
               $ratio .= (' 'x(3-length($score))).$score;
         } elsif($chosen_output->{'sequence_sum'}) {          } elsif($chosen_output->{'sequence_sum'}) {
             $ratio .= ' 'x3;              $ratio .= ' 'x3;
         }          }
Line 752  sub html_outputstudent { Line 793  sub html_outputstudent {
             $performance = '';              $performance = '';
     $performance_length=0;      $performance_length=0;
         }          }
         $performance .= ' 'x($seq->{'width_total'}-$performance_length-$seq->{'width_sum'}).          $performance .= ' 'x($width{$symb}->{'width_total'} -
                                $performance_length -
                                $width{$symb}->{'width_sum'}).
             $ratio;              $ratio;
         #          #
         $Str .= $performance.$padding;          $Str .= $performance.$padding;
         #          #
         $studentstats->{$seq->{'symb'}}->{'score'}= $score;          $studentstats->{$symb}->{'score'}= $score;
         $studentstats->{$seq->{'symb'}}->{'max'}  = $seq_max;          $studentstats->{$symb}->{'max'}  = $seq_max;
     }      }
     #      #
     # Total it up and store the statistics info.      # Total it up and store the statistics info.
Line 778  sub html_outputstudent { Line 821  sub html_outputstudent {
         $score = ' ' x $total_sum_width;          $score = ' ' x $total_sum_width;
     } else {      } else {
         $score = sprintf("%.0f",$score);          $score = sprintf("%.0f",$score);
           $score = (' 'x(3-length($score))).$score;
     }      }
     $Str .= ' '.' 'x($total_sum_width-length($score)).$score.' / '.$max;      $Str .= ' '.' 'x($total_sum_width-length($score)).$score.' / '.$max;
     $Str .= " \n";      $Str .= " \n";
Line 790  sub html_outputstudent { Line 834  sub html_outputstudent {
   
 sub html_finish {  sub html_finish {
     my ($r) = @_;      my ($r) = @_;
       return if (! defined($navmap));
     #      #
     # Check for suppressed output and close the progress window if so      # Check for suppressed output and close the progress window if so
     $r->print("</pre>\n");       $r->print("</pre>\n"); 
Line 801  sub html_finish { Line 846  sub html_finish {
         }          }
     }      }
     $r->rflush();      $r->rflush();
       undef($navmap);
     return;      return;
 }  }
   
Line 812  sub StudentAverageTotal { Line 858  sub StudentAverageTotal {
         '<th>'.&mt('Average').'</th>'.          '<th>'.&mt('Average').'</th>'.
         '<th>'.&mt('Maximum').'</th>'.          '<th>'.&mt('Maximum').'</th>'.
         '</tr>'.$/;          '</tr>'.$/;
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
           my $symb = $seq->symb;
         my $ave;          my $ave;
         my $num_students = $Statistics->{$seq->{'symb'}}->{'num_students'};          my $num_students = $Statistics->{$symb}->{'num_students'};
         if ($num_students > 0) {          if ($num_students > 0) {
             $ave = int(100*              $ave = int(100*
                        ($Statistics->{$seq->{'symb'}}->{'score'}/$num_students)                         ($Statistics->{$symb}->{'score'}/$num_students)
                        )/100;                         )/100;
         } else {          } else {
             $ave = 0;              $ave = 0;
         }          }
         my $max = $Statistics->{$seq->{'symb'}}->{'max'};          my $max = $Statistics->{$symb}->{'max'};
         $ave = sprintf("%.2f",$ave);          $ave = sprintf("%.2f",$ave);
         $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.          $Str .= '<tr><td>'.$seq->compTitle.'</td>'.
             '<td align="right">'.$ave.'&nbsp;</td>'.              '<td align="right">'.$ave.'&nbsp;</td>'.
             '<td align="right">'.$max.'&nbsp;'.'</td></tr>'."\n";              '<td align="right">'.$max.'&nbsp;'.'</td></tr>'."\n";
     }      }
Line 833  sub StudentAverageTotal { Line 880  sub StudentAverageTotal {
 }  }
   
 sub SingleStudentTotal {  sub SingleStudentTotal {
       return if (! defined($navmap));
     my $student = &Apache::lonstatistics::current_student();      my $student = &Apache::lonstatistics::current_student();
     my $Str = '<h3>'.&mt('Summary table for [_1] ([_2]@[_3])',      my $Str = '<h3>'.&mt('Summary table for [_1] ([_2]@[_3])',
                          $student->{'fullname'},                           $student->{'fullname'},
Line 850  sub SingleStudentTotal { Line 898  sub SingleStudentTotal {
     $Str .= '<th>'.&mt('Maximum').'</th>'."</tr>\n";      $Str .= '<th>'.&mt('Maximum').'</th>'."</tr>\n";
     my $total = 0;      my $total = 0;
     my $total_max = 0;      my $total_max = 0;
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
         my $value = $Statistics->{$seq->{'symb'}}->{'score'};          my $value = $Statistics->{$seq->symb}->{'score'};
         my $max = $Statistics->{$seq->{'symb'}}->{'max'};          my $max = $Statistics->{$seq->symb}->{'max'};
         $Str .= '<tr><td>'.$seq->{'title'}.'</td>'.          $Str .= '<tr><td>'.&HTML::Entities::encode($seq->compTitle).'</td>'.
             '<td align="right">'.$value.'</td>'.              '<td align="right">'.$value.'</td>'.
                 '<td align="right">'.$max.'</td></tr>'."\n";                  '<td align="right">'.$max.'</td></tr>'."\n";
         $total += $value;          $total += $value;
Line 889  sub SingleStudentTotal { Line 937  sub SingleStudentTotal {
   
 my $excel_sheet;  my $excel_sheet;
 my $excel_workbook;  my $excel_workbook;
   my $format;
   
 my $filename;  my $filename;
 my $rows_output;  my $rows_output;
Line 899  my $request_aborted; Line 948  my $request_aborted;
   
 my $total_formula;  my $total_formula;
 my $maximum_formula;  my $maximum_formula;
   my %formula_data;
   
   my $navmap;
   my @sequences;
   
 sub excel_initialize {  sub excel_initialize {
     my ($r) = @_;      my ($r) = @_;
Line 913  sub excel_initialize { Line 966  sub excel_initialize {
     undef ($total_formula);      undef ($total_formula);
     undef ($maximum_formula);      undef ($maximum_formula);
     #      #
       undef(%formula_data);
       #
       undef($navmap);
       undef(@sequences);
       ($navmap,@sequences) = 
           &Apache::lonstatistics::selected_sequences_with_assessments();
       if (! ref($navmap)) {
           # Unable to get data, so bail out
           $r->print("<h3>".
                     &mt('Unable to retrieve course information.').
                     '</h3>');
       }
       #
     my $total_columns = scalar(&get_student_fields_to_show());      my $total_columns = scalar(&get_student_fields_to_show());
     my $num_students = scalar(@Apache::lonstatistics::Students);      my $num_students = scalar(@Apache::lonstatistics::Students);
     #      #
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             $total_columns += $seq->{'num_assess_parts'};              $total_columns+=&count_parts($navmap,$seq);
         }          }
         # Add 2 because we need a 'sequence_sum' and 'total' column for each          # Add 2 because we need a 'sequence_sum' and 'total' column for each
         $total_columns += 2;          $total_columns += 2;
Line 938  sub excel_initialize { Line 1004  sub excel_initialize {
     }      }
     return if ($request_aborted);      return if ($request_aborted);
     #      #
     $filename = '/prtspool/'.  
         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.  
             time.'_'.rand(1000000000).'.xls';  
     #      #
     $excel_workbook = undef;      $excel_workbook = undef;
     $excel_sheet = undef;      $excel_sheet = undef;
Line 951  sub excel_initialize { Line 1014  sub excel_initialize {
     # Determine rows       # Determine rows 
     my $header_row = $rows_output++;      my $header_row = $rows_output++;
     my $description_row = $rows_output++;      my $description_row = $rows_output++;
       my $notes_row = $rows_output++;
     $rows_output++;        # blank row      $rows_output++;        # blank row
     my $summary_header_row;      my $summary_header_row;
     if ($chosen_output->{'summary_table'}) {      if ($chosen_output->{'summary_table'}) {
         $summary_header_row = $rows_output++;          $summary_header_row = $rows_output++;
         $rows_output+= scalar(&Apache::lonstatistics::Sequences_with_Assess());          $rows_output+= scalar(@sequences);
         $rows_output++;          $rows_output++;
     }      }
     my $sequence_name_row = $rows_output++;      my $sequence_name_row = $rows_output++;
Line 967  sub excel_initialize { Line 1031  sub excel_initialize {
     my $first_data_row = $rows_output++;      my $first_data_row = $rows_output++;
     #      #
     # Create sheet      # Create sheet
     $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);      ($excel_workbook,$filename,$format)=
     #          &Apache::loncommon::create_workbook($r);
     # Check for errors      return if (! defined($excel_workbook));
     if (! defined($excel_workbook)) {  
         $r->log_error("Error creating excel spreadsheet $filename: $!");  
         $r->print("Problems creating new Excel file.  ".  
                   "This error has been logged.  ".  
                   "Please alert your LON-CAPA administrator");  
         return ;  
     }  
     #  
     # The excel spreadsheet stores temporary data in files, then put them  
     # together.  If needed we should be able to disable this (memory only).  
     # The temporary directory must be specified before calling 'addworksheet'.  
     # File::Temp is used to determine the temporary directory.  
     $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);  
     #  
     my $format = &Apache::loncommon::define_excel_formats($excel_workbook);  
     #      #
     # Add a worksheet      # Add a worksheet
     my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};      my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
Line 1025  sub excel_initialize { Line 1074  sub excel_initialize {
     $cols_output = 0;      $cols_output = 0;
     $excel_sheet->write($description_row,$cols_output++,      $excel_sheet->write($description_row,$cols_output++,
                         $chosen_output->{'shortdesc'},                          $chosen_output->{'shortdesc'},
                         $format->{'h3'});                          $format->{'b'});
       #
       $cols_output = 0;
       $excel_sheet->write($notes_row,$cols_output++,
                           $chosen_output->{'non_html_notes'},
                           $format->{'i'});
       
     ##############################################      ##############################################
     # Output headings for the raw data      # Output headings for the raw data
     ##############################################      ##############################################
Line 1040  sub excel_initialize { Line 1095  sub excel_initialize {
     # Add the remaining column headers      # Add the remaining column headers
     my $total_formula_string = '=0';      my $total_formula_string = '=0';
     my $maximum_formula_string = '=0';      my $maximum_formula_string = '=0';
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
           my $symb = $seq->symb;
         $excel_sheet->write($sequence_name_row,,          $excel_sheet->write($sequence_name_row,,
                             $cols_output,$seq->{'title'},$format->{'bold'});                              $cols_output,$seq->compTitle,$format->{'bold'});
         # Determine starting cell          # Determine starting cell
         $seq->{'Excel:startcell'}=          $formula_data{$symb}->{'Excel:startcell'}=
             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell              &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
             ($first_data_row,$cols_output);              ($first_data_row,$cols_output);
         $seq->{'Excel:startcol'}=$cols_output;          $formula_data{$symb}->{'Excel:startcol'}=$cols_output;
         my $count = 0;          my $count = 0;
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             # Put the names of the problems and parts into the sheet              # Put the names of the problems and parts into the sheet
             foreach my $res (@{$seq->{'contents'}}) {              foreach my $res (&get_resources($navmap,$seq)) {
                 if ($res->{'type'} ne 'assessment'  ||                   if (scalar(@{$res->parts}) > 1) {
                     ! exists($res->{'parts'})       ||                      foreach my $part (@{$res->parts}) {
                     ref($res->{'parts'}) ne 'ARRAY' ||  
                     scalar(@{$res->{'parts'}}) < 1) {  
                     next;  
                 }  
                 if (scalar(@{$res->{'parts'}}) > 1) {  
                     foreach my $part (@{$res->{'parts'}}) {  
                         $excel_sheet->write($resource_name_row,                          $excel_sheet->write($resource_name_row,
                                             $cols_output++,                                              $cols_output++,
                                             $res->{'title'}.' part '.$part,                                              $res->compTitle.' part '.$res->part_display($part),
                                             $format->{'bold'});                                              $format->{'bold'});
                         $count++;                          $count++;
                     }                      }
                 } else {                  } else {
                     $excel_sheet->write($resource_name_row,                      $excel_sheet->write($resource_name_row,
                                         $cols_output++,                                          $cols_output++,
                                         $res->{'title'},$format->{'bold'});                                          $res->compTitle,$format->{'bold'});
                     $count++;                      $count++;
                 }                  }
             }              }
         }          }
         # Determine ending cell          # Determine ending cell
         if ($count <= 1) {          if ($count <= 1) {
             $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};              $formula_data{$symb}->{'Excel:endcell'} = $formula_data{$symb}->{'Excel:startcell'};
             $seq->{'Excel:endcol'}  = $seq->{'Excel:startcol'};              $formula_data{$symb}->{'Excel:endcol'}  = $formula_data{$symb}->{'Excel:startcol'};
         } else {          } else {
             $seq->{'Excel:endcell'} =               $formula_data{$symb}->{'Excel:endcell'} = 
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                  &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                 ($first_data_row,$cols_output-1);                  ($first_data_row,$cols_output-1);
             $seq->{'Excel:endcol'} = $cols_output-1;              $formula_data{$symb}->{'Excel:endcol'} = $cols_output-1;
         }          }
         # Create the formula for summing up this sequence          # Create the formula for summing up this sequence
         if (! exists($seq->{'Excel:endcell'}) ||          if (! exists($formula_data{$symb}->{'Excel:endcell'}) ||
             ! defined($seq->{'Excel:endcell'})) {              ! defined($formula_data{$symb}->{'Excel:endcell'})) {
             $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};              $formula_data{$symb}->{'Excel:endcell'} = $formula_data{$symb}->{'Excel:startcell'};
         }          }
         $seq->{'Excel:sum'}= $excel_sheet->store_formula          $formula_data{$symb}->{'Excel:sum'}= $excel_sheet->store_formula
             ('=SUM('.$seq->{'Excel:startcell'}.              ('=SUM('.$formula_data{$symb}->{'Excel:startcell'}.
              ':'.$seq->{'Excel:endcell'}.')');               ':'.$formula_data{$symb}->{'Excel:endcell'}.')');
         # Determine cell the score is held in          # Determine cell the score is held in
         $seq->{'Excel:scorecell'} =           $formula_data{$symb}->{'Excel:scorecell'} = 
             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell              &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
             ($first_data_row,$cols_output);              ($first_data_row,$cols_output);
         $seq->{'Excel:scorecol'}=$cols_output;          $formula_data{$symb}->{'Excel:scorecol'}=$cols_output;
         if ($chosen_output->{'base'} eq 'parts correct total') {          if ($chosen_output->{'base'} eq 'parts correct total') {
             $excel_sheet->write($resource_name_row,$cols_output++,              $excel_sheet->write($resource_name_row,$cols_output++,
                                 'parts correct',                                  'parts correct',
Line 1121  sub excel_initialize { Line 1171  sub excel_initialize {
             $excel_sheet->write($resource_name_row,$cols_output,              $excel_sheet->write($resource_name_row,$cols_output,
                                 'maximum',                                  'maximum',
                                 $format->{'bold'});                                  $format->{'bold'});
             $seq->{'Excel:maxcell'} =               $formula_data{$symb}->{'Excel:maxcell'} = 
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                  &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                 ($first_data_row,$cols_output);                  ($first_data_row,$cols_output);
             $seq->{'Excel:maxcol'}=$cols_output;              $formula_data{$symb}->{'Excel:maxcol'}=$cols_output;
             $maximum_formula_string.='+'.              $maximum_formula_string.='+'.
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                  &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                 ($first_data_row,$cols_output);                  ($first_data_row,$cols_output);
Line 1160  sub excel_initialize { Line 1210  sub excel_initialize {
         # Add the maximums for each sequence or assessment          # Add the maximums for each sequence or assessment
         my %total_cell_translation;          my %total_cell_translation;
         my %maximum_cell_translation;          my %maximum_cell_translation;
         foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {          foreach my $seq (@sequences) {
             $cols_output=$seq->{'Excel:startcol'};              my $symb = $seq->symb;
             $total_cell_translation{$seq->{'Excel:scorecell'}} =               $cols_output=$formula_data{$symb}->{'Excel:startcol'};
               $total_cell_translation{$formula_data{$symb}->{'Excel:scorecell'}}=
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                  &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                 ($maximum_data_row,$seq->{'Excel:scorecol'});                  ($maximum_data_row,$formula_data{$symb}->{'Excel:scorecol'});
             $maximum_cell_translation{$seq->{'Excel:maxcell'}} =               $maximum_cell_translation{$formula_data{$symb}->{'Excel:maxcell'}}=
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                  &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                 ($maximum_data_row,$seq->{'Excel:maxcol'});                  ($maximum_data_row,$formula_data{$symb}->{'Excel:maxcol'});
             my $weight;              my $weight;
             my $max = 0;              my $max = 0;
             foreach my $resource (@{$seq->{'contents'}}) {              foreach my $resource (&get_resources($navmap,$seq)) {
                 next if ($resource->{'type'} ne 'assessment');                  foreach my $part (@{$resource->parts}){
                 foreach my $part (@{$resource->{'parts'}}) {  
                     $weight = 1;                      $weight = 1;
                     if ($chosen_output->{'scores'}) {                      if ($chosen_output->{'scores'}) {
                         $weight = &Apache::lonnet::EXT                          $weight = &Apache::lonnet::EXT
Line 1193  sub excel_initialize { Line 1243  sub excel_initialize {
             #              #
             if ($chosen_output->{'sequence_sum'} &&               if ($chosen_output->{'sequence_sum'} && 
                 $chosen_output->{'every_problem'}) {                  $chosen_output->{'every_problem'}) {
                 my %replaceCells;   my %replaceCells=
                 $replaceCells{$seq->{'Excel:startcell'}} =       ('^'.$formula_data{$symb}->{'Excel:startcell'}.':'.
                     &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell           $formula_data{$symb}->{'Excel:endcell'}.'$' =>
                     ($maximum_data_row,$seq->{'Excel:startcol'});       &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($maximum_data_row,$formula_data{$symb}->{'Excel:startcol'}).':'.
                 $replaceCells{$seq->{'Excel:endcell'}} =        &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($maximum_data_row,$formula_data{$symb}->{'Excel:endcol'}));
                     &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell  
                     ($maximum_data_row,$seq->{'Excel:endcol'});  
                 $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,                  $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
                                              $seq->{'Excel:sum'},undef,                                               $formula_data{$symb}->{'Excel:sum'},undef,
                                              %replaceCells);       %replaceCells);
   
             } elsif ($chosen_output->{'sequence_sum'}) {              } elsif ($chosen_output->{'sequence_sum'}) {
                 $excel_sheet->write($maximum_data_row,$cols_output++,$max);                  $excel_sheet->write($maximum_data_row,$cols_output++,$max);
             }              }
Line 1241  sub excel_initialize { Line 1290  sub excel_initialize {
         $excel_sheet->write($summary_header_row,$cols_output++,          $excel_sheet->write($summary_header_row,$cols_output++,
                             'Std Dev',$format->{'bold'});                              'Std Dev',$format->{'bold'});
         my $row = $summary_header_row+1;          my $row = $summary_header_row+1;
         foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {          foreach my $seq (@sequences) {
               my $symb = $seq->symb;
             $cols_output = 0;              $cols_output = 0;
             $excel_sheet->write($row,$cols_output++,              $excel_sheet->write($row,$cols_output++,
                                 $seq->{'title'},                                  $seq->compTitle,
                                 $format->{'bold'});                                  $format->{'bold'});
             if ($chosen_output->{'maximum_row'}) {              if ($chosen_output->{'maximum_row'}) {
                 $excel_sheet->write                  $excel_sheet->write
                     ($row,$cols_output++,                      ($row,$cols_output++,
                      '='.                       '='.
                      &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                       &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                      ($maximum_data_row,$seq->{'Excel:scorecol'})                       ($maximum_data_row,$formula_data{$symb}->{'Excel:scorecol'})
                      );                       );
             }              }
             my $range =               my $range = 
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                  &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                 ($first_data_row,$seq->{'Excel:scorecol'}).                  ($first_data_row,$formula_data{$symb}->{'Excel:scorecol'}).
                 ':'.                  ':'.
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell                  &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                 ($first_data_row+$num_students-1,$seq->{'Excel:scorecol'});                  ($first_data_row+$num_students-1,$formula_data{$symb}->{'Excel:scorecol'});
             $excel_sheet->write($row,$cols_output++,              $excel_sheet->write($row,$cols_output++,
                                 '=AVERAGE('.$range.')');                                  '=AVERAGE('.$range.')');
             $excel_sheet->write($row,$cols_output++,              $excel_sheet->write($row,$cols_output++,
Line 1291  sub excel_initialize { Line 1341  sub excel_initialize {
     # Initialize progress window      # Initialize progress window
     %prog_state=&Apache::lonhtmlcommon::Create_PrgWin      %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
         ($r,'Excel File Compilation Status',          ($r,'Excel File Compilation Status',
          'Excel File Compilation Progress', $studentcount);           'Excel File Compilation Progress', $studentcount,
            'inline',undef,'Statistics','stats_status');
     #      #
     &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,      &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
                                           'Processing first student');                                            'Processing first student');
Line 1300  sub excel_initialize { Line 1351  sub excel_initialize {
   
 sub excel_outputstudent {  sub excel_outputstudent {
     my ($r,$student) = @_;      my ($r,$student) = @_;
     return if ($request_aborted);      if ($request_aborted || ! defined($navmap) || ! defined($excel_sheet)) {
     return if (! defined($excel_sheet));          return;
       }
     $cols_output=0;      $cols_output=0;
     #      #
     # Write out student data      # Write out student data
Line 1328  sub excel_outputstudent { Line 1380  sub excel_outputstudent {
     # Write out sequence scores and totals data      # Write out sequence scores and totals data
     my %total_cell_translation;      my %total_cell_translation;
     my %maximum_cell_translation;      my %maximum_cell_translation;
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
         $cols_output = $seq->{'Excel:startcol'};          my $symb = $seq->symb;
           $cols_output = $formula_data{$symb}->{'Excel:startcol'};
         # Keep track of cells to translate in total cell          # Keep track of cells to translate in total cell
         $total_cell_translation{$seq->{'Excel:scorecell'}} =           $total_cell_translation{$formula_data{$symb}->{'Excel:scorecell'}} = 
             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell              &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
                         ($rows_output,$seq->{'Excel:scorecol'});                          ($rows_output,$formula_data{$symb}->{'Excel:scorecol'});
         # and maximum cell          # and maximum cell
         $maximum_cell_translation{$seq->{'Excel:maxcell'}} =           $maximum_cell_translation{$formula_data{$symb}->{'Excel:maxcell'}} = 
             &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell              &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
             ($rows_output,$seq->{'Excel:maxcol'});              ($rows_output,$formula_data{$symb}->{'Excel:maxcol'});
         #          #
         my ($performance,$performance_length,$score,$seq_max,$rawdata);          my ($performance,$performance_length,$score,$seq_max,$rawdata);
         if ($chosen_output->{'tries'} || $chosen_output->{'correct'}){          if ($chosen_output->{'tries'} || $chosen_output->{'correct'}){
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &StudentTriesOnSequence($student,\%StudentsData,                  &student_tries_on_sequence($student,\%StudentsData,
                                         $seq,'no');                                             $navmap,$seq,'no');
         } else {          } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &StudentPerformanceOnSequence($student,\%StudentsData,                  &student_performance_on_sequence($student,\%StudentsData,
                                               $seq,'no');                                                   $navmap,$seq,'no');
         }           } 
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             if ($chosen_output->{'correct'}) {              if ($chosen_output->{'correct'}) {
Line 1371  sub excel_outputstudent { Line 1424  sub excel_outputstudent {
         if ($chosen_output->{'sequence_sum'} &&           if ($chosen_output->{'sequence_sum'} && 
             $chosen_output->{'every_problem'}) {              $chosen_output->{'every_problem'}) {
             # Write a formula for the sum of this sequence              # Write a formula for the sum of this sequence
             my %replaceCells;              my %replaceCells=
             $replaceCells{$seq->{'Excel:startcell'}} =    ('^'.$formula_data{$symb}->{'Excel:startcell'}.':'.$formula_data{$symb}->{'Excel:endcell'}.'$'
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell   => 
                             ($rows_output,$seq->{'Excel:startcol'});   &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($rows_output,$formula_data{$symb}->{'Excel:startcol'}).':'.
             $replaceCells{$seq->{'Excel:endcell'}} =    &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($rows_output,$formula_data{$symb}->{'Excel:endcol'})
                 &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell   );
                             ($rows_output,$seq->{'Excel:endcol'});              # The undef is for the format    
             # The undef is for the format      $excel_sheet->repeat_formula($rows_output,$cols_output++,
             if (scalar(keys(%replaceCells)) == 1) {   $formula_data{$symb}->{'Excel:sum'},undef,
                 $excel_sheet->repeat_formula($rows_output,$cols_output++,   %replaceCells);
                                              $seq->{'Excel:sum'},undef,  
                                              %replaceCells,%replaceCells);  
             } else {  
                 $excel_sheet->repeat_formula($rows_output,$cols_output++,  
                                              $seq->{'Excel:sum'},undef,  
                                              %replaceCells);  
             }  
         } elsif ($chosen_output->{'sequence_sum'}) {          } elsif ($chosen_output->{'sequence_sum'}) {
             if ($score eq ' ') {              if ($score eq ' ') {
                 $cols_output++;                  $cols_output++;
Line 1422  sub excel_outputstudent { Line 1468  sub excel_outputstudent {
   
 sub excel_finish {  sub excel_finish {
     my ($r) = @_;      my ($r) = @_;
     return if ($request_aborted);      if ($request_aborted || ! defined($navmap) || ! defined($excel_sheet)) {
     return if (! defined($excel_sheet));          return;
       }
     #      #
     # Write the excel file      # Write the excel file
     $excel_workbook->close();      $excel_workbook->close();
Line 1465  my $outputfile; Line 1512  my $outputfile;
 my $filename;  my $filename;
 my $request_aborted;  my $request_aborted;
 my %prog_state; # progress window state  my %prog_state; # progress window state
   my $navmap;
   my @sequences;
   
 sub csv_initialize{  sub csv_initialize{
     my ($r) = @_;      my ($r) = @_;
Line 1475  sub csv_initialize{ Line 1524  sub csv_initialize{
     undef($request_aborted);      undef($request_aborted);
     undef(%prog_state);      undef(%prog_state);
     #      #
       undef($navmap);
       undef(@sequences);
       ($navmap,@sequences) = 
           &Apache::lonstatistics::selected_sequences_with_assessments();
       if (! ref($navmap)) {
           # Unable to get data, so bail out
           $r->print("<h3>".
                     &mt('Unable to retrieve course information.').
                     '</h3>');
       }
       #
     # Deal with unimplemented requests      # Deal with unimplemented requests
     $request_aborted = undef;      $request_aborted = undef;
     if ($chosen_output->{'base'} =~ /final table/) {      if ($chosen_output->{'base'} =~ /final table/) {
Line 1492  END Line 1552  END
     my $studentcount = scalar(@Apache::lonstatistics::Students);      my $studentcount = scalar(@Apache::lonstatistics::Students);
     %prog_state=&Apache::lonhtmlcommon::Create_PrgWin      %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
         ($r,'CSV File Compilation Status',          ($r,'CSV File Compilation Status',
          'CSV File Compilation Progress', $studentcount);           'CSV File Compilation Progress', $studentcount,
            'inline',undef,'Statistics','stats_status');
     #      #
     # Open a file      # Open a file
     $filename = '/prtspool/'.      $filename = '/prtspool/'.
Line 1511  END Line 1572  END
     print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.      print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
         '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.          '"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
             "\n";              "\n";
       foreach my $item ('shortdesc','non_html_notes') {
           next if (! exists($chosen_output->{$item}));
           print $outputfile 
               '"'.&Apache::loncommon::csv_translate($chosen_output->{$item}).'"'.
               "\n";
       }
     #      #
     # Print out the headings      # Print out the headings
     my $sequence_row = '';      my $sequence_row = '';
Line 1519  END Line 1586  END
         $sequence_row .='"",';          $sequence_row .='"",';
         $resource_row .= '"'.&Apache::loncommon::csv_translate($field).'",';          $resource_row .= '"'.&Apache::loncommon::csv_translate($field).'",';
     }      }
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
         $sequence_row .= '"'.          $sequence_row .= '"'.
             &Apache::loncommon::csv_translate($seq->{'title'}).'",';              &Apache::loncommon::csv_translate($seq->compTitle).'",';
         my $count = 0;          my $count = 0;
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             foreach my $res (@{$seq->{'contents'}}) {              foreach my $res (&get_resources($navmap,$seq)) {
                 if ($res->{'type'} ne 'assessment'  ||                   if (scalar(@{$res->parts}) < 1) {
                     ! exists($res->{'parts'})       ||  
                     ref($res->{'parts'}) ne 'ARRAY' ||  
                     scalar(@{$res->{'parts'}}) < 1) {  
                     next;                      next;
                 }                  }
                 foreach my $part (@{$res->{'parts'}}) {                  foreach my $part (@{$res->parts}) {
                     $resource_row .= '"'.                      $resource_row .= '"'.
                         &Apache::loncommon::csv_translate($res->{'title'}.                          &Apache::loncommon::csv_translate
                                                           ', Part '.$part                          ($res->compTitle.', Part '.$res->part_display($part)).'",';
                                                           ).'",';  
                     $count++;                      $count++;
                 }                  }
             }              }
Line 1570  END Line 1633  END
   
 sub csv_outputstudent {  sub csv_outputstudent {
     my ($r,$student) = @_;      my ($r,$student) = @_;
     return if ($request_aborted);      if ($request_aborted || ! defined($navmap) || ! defined($outputfile)) {
     return if (! defined($outputfile));          return;
       }
     my $Str = '';      my $Str = '';
     #      #
     # Output student fields      # Output student fields
Line 1598  sub csv_outputstudent { Line 1662  sub csv_outputstudent {
     # Output performance data      # Output performance data
     my $total = 0;      my $total = 0;
     my $maximum = 0;      my $maximum = 0;
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (@sequences) {
         my ($performance,$performance_length,$score,$seq_max,$rawdata);          my ($performance,$performance_length,$score,$seq_max,$rawdata);
         if ($chosen_output->{'tries'}){          if ($chosen_output->{'tries'}){
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &StudentTriesOnSequence($student,\%StudentsData,                  &student_tries_on_sequence($student,\%StudentsData,
                                         $seq,'no');                                             $navmap,$seq,'no');
         } else {          } else {
             ($performance,$performance_length,$score,$seq_max,$rawdata) =              ($performance,$performance_length,$score,$seq_max,$rawdata) =
                 &StudentPerformanceOnSequence($student,\%StudentsData,                  &student_performance_on_sequence($student,\%StudentsData,
                                               $seq,'no');                                                   $navmap,$seq,'no');
         }          }
         if ($chosen_output->{'every_problem'}) {          if ($chosen_output->{'every_problem'}) {
             if ($chosen_output->{'correct'}) {              if ($chosen_output->{'correct'}) {
Line 1650  sub csv_outputstudent { Line 1714  sub csv_outputstudent {
   
 sub csv_finish {  sub csv_finish {
     my ($r) = @_;      my ($r) = @_;
     return if ($request_aborted);      if ($request_aborted || ! defined($navmap) || ! defined($outputfile)) {
     return if (! defined($outputfile));          return;
       }
     close($outputfile);      close($outputfile);
     #      #
     my $c = $r->connection();      my $c = $r->connection();
Line 1695  Inputs: Line 1760  Inputs:
   
 #######################################################  #######################################################
 #######################################################  #######################################################
 sub StudentTriesOnSequence {  sub student_tries_on_sequence {
     my ($student,$studentdata,$seq,$links) = @_;      my ($student,$studentdata,$navmap,$seq,$links) = @_;
     $links = 'no' if (! defined($links));      $links = 'no' if (! defined($links));
     my $Str = '';      my $Str = '';
     my ($sum,$max) = (0,0);      my ($sum,$max) = (0,0);
Line 1704  sub StudentTriesOnSequence { Line 1769  sub StudentTriesOnSequence {
     my @TriesData = ();      my @TriesData = ();
     my $tries;      my $tries;
     my $hasdata = 0; # flag - true if the student has any data on the sequence      my $hasdata = 0; # flag - true if the student has any data on the sequence
     foreach my $resource (@{$seq->{'contents'}}) {      foreach my $resource (&get_resources($navmap,$seq)) {
         next if ($resource->{'type'} ne 'assessment');          my $resource_data = $studentdata->{$resource->symb};
         my $resource_data = $studentdata->{$resource->{'symb'}};  
         my $value = '';          my $value = '';
         foreach my $partnum (@{$resource->{'parts'}}) {          foreach my $partnum (@{$resource->parts()}) {
             $tries = undef;              $tries = undef;
             $max++;              $max++;
             $performance_length++;              $performance_length++;
Line 1768  sub StudentTriesOnSequence { Line 1832  sub StudentTriesOnSequence {
                 }                  }
             }              }
             #              #
             if (! defined($tries) || $symbol eq '.') {              if (! defined($tries)) {
                 $tries = $symbol;                  $tries = 0;
               }
               if ($status =~ /^(incorrect|ungraded)/) {
                   # Bug 3390: show '-' for tries on incorrect problems 
                   # (csv & excel only)
                   push(@TriesData,-$tries);
               } else {
                   push (@TriesData,$tries);
             }              }
             push (@TriesData,$tries);  
             #              #
             if ( ($links eq 'yes' && $symbol ne ' ') ||              if ( ($links eq 'yes' && $symbol ne ' ') ||
                  ($links eq 'all')) {                   ($links eq 'all')) {
Line 1779  sub StudentTriesOnSequence { Line 1849  sub StudentTriesOnSequence {
                     &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');                      &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
                 }                  }
                 $symbol = '<a href="/adm/grades'.                  $symbol = '<a href="/adm/grades'.
                     '?symb='.&Apache::lonnet::escape($resource->{'symb'}).                      '?symb='.&Apache::lonnet::escape($resource->symb).
                         '&student='.$student->{'username'}.                          '&student='.$student->{'username'}.
                             '&userdom='.$student->{'domain'}.                              '&userdom='.$student->{'domain'}.
                                 '&command=submission">'.$symbol.'</a>';                                  '&command=submission">'.$symbol.'</a>';
Line 1788  sub StudentTriesOnSequence { Line 1858  sub StudentTriesOnSequence {
         }          }
         $Str .= $value;          $Str .= $value;
     }      }
     if ($seq->{'randompick'}) {      if ($seq->randompick()) {
         $max = $seq->{'randompick'};          $max = $seq->randompick();
     }      }
     if (! $hasdata && $sum == 0) {      if (! $hasdata && $sum == 0) {
         $sum = ' ';          $sum = ' ';
Line 1802  sub StudentTriesOnSequence { Line 1872  sub StudentTriesOnSequence {
   
 =pod  =pod
   
 =item &StudentPerformanceOnSequence()  =item &student_performance_on_sequence
   
 Inputs:  Inputs:
   
Line 1822  Inputs: Line 1892  Inputs:
   
 #######################################################  #######################################################
 #######################################################  #######################################################
 sub StudentPerformanceOnSequence {  sub student_performance_on_sequence {
     my ($student,$studentdata,$seq,$links) = @_;      my ($student,$studentdata,$navmap,$seq,$links) = @_;
     $links = 'no' if (! defined($links));      $links = 'no' if (! defined($links));
     my $Str = ''; # final result string      my $Str = ''; # final result string
     my ($score,$max) = (0,0);      my ($score,$max) = (0,0);
Line 1832  sub StudentPerformanceOnSequence { Line 1902  sub StudentPerformanceOnSequence {
     my @ScoreData = ();      my @ScoreData = ();
     my $partscore;      my $partscore;
     my $hasdata = 0; # flag, 0 if there were no submissions on the sequence      my $hasdata = 0; # flag, 0 if there were no submissions on the sequence
     foreach my $resource (@{$seq->{'contents'}}) {      foreach my $resource (&get_resources($navmap,$seq)) {
         next if ($resource->{'type'} ne 'assessment');          my $symb = $resource->symb;
         my $resource_data = $studentdata->{$resource->{'symb'}};          my $resource_data = $studentdata->{$symb};
         foreach my $part (@{$resource->{'parts'}}) {          foreach my $part (@{$resource->parts()}) {
             $partscore = undef;              $partscore = undef;
             my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',              my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
                                               $resource->{'symb'},                                                $symb,
                                               $student->{'domain'},                                                $student->{'domain'},
                                               $student->{'username'},                                                $student->{'username'},
                                               $student->{'section'});                                                $student->{'section'});
Line 1876  sub StudentPerformanceOnSequence { Line 1946  sub StudentPerformanceOnSequence {
                     $max -= $weight; # Do not count 'excused' problems.                      $max -= $weight; # Do not count 'excused' problems.
                 }                  }
                 $hasdata = 1;                  $hasdata = 1;
             } else {              } elsif (!exists($resource_data->{'resource.'.$part.'.awarded'})){
                 # Unsolved.  Did they try?                  # Unsolved.  Did they try?
                 if (exists($resource_data->{'resource.'.$part.'.tries'})){                  if (exists($resource_data->{'resource.'.$part.'.tries'})){
                     $symbol = '.';                      $symbol = '.';
Line 1893  sub StudentPerformanceOnSequence { Line 1963  sub StudentPerformanceOnSequence {
             #              #
             if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {              if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
                 $symbol = '<a href="/adm/grades'.                  $symbol = '<a href="/adm/grades'.
                     '?symb='.&Apache::lonnet::escape($resource->{'symb'}).                      '?symb='.&Apache::lonnet::escape($symb).
                     '&student='.$student->{'username'}.                      '&student='.$student->{'username'}.
                     '&userdom='.$student->{'domain'}.                      '&userdom='.$student->{'domain'}.
                     '&command=submission">'.$symbol.'</a>';                      '&command=submission">'.$symbol.'</a>';

Removed from v.1.107  
changed lines
  Added in v.1.118


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