--- loncom/interface/statistics/lonstudentsubmissions.pm 2005/02/02 23:05:26 1.32 +++ loncom/interface/statistics/lonstudentsubmissions.pm 2005/03/14 20:28:22 1.37 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentsubmissions.pm,v 1.32 2005/02/02 23:05:26 matthew Exp $ +# $Id: lonstudentsubmissions.pm,v 1.37 2005/03/14 20:28:22 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -110,6 +110,9 @@ sub BuildStudentSubmissionsPage { push(@Problems,$resource); } # + $r->print('

'. + &Apache::lonstatistics::section_and_enrollment_description(). + '

'); if (! scalar(@Problems) || ! defined($Problems[0])) { $r->print('resource is undefined'); } else { @@ -118,9 +121,7 @@ sub BuildStudentSubmissionsPage { $r->print('

'.$resource->title.'

'); $r->print('

'.$resource->src.'

'); if ($ENV{'form.renderprob'} eq 'true') { - $r->print( - &Apache::lonstathelpers::render_resource({src => $resource->src}) - ); + $r->print(&Apache::lonstathelpers::render_resource($resource)); $r->rflush(); } } @@ -267,6 +268,9 @@ sub prepare_html_output { if ($partid =~/^\d+$/) { $tmpname = $prob->part_display($partid); } + if ($tmpname !~ /^part/) { + $tmpname = 'Part '.$tmpname; + } $headers{'part'} .= qq{$tmpname}; $nonempty_part_headers = 1; } else { @@ -622,22 +626,9 @@ sub prepare_excel_output { $r->rflush(); # # Create the excel spreadsheet - my $filename = '/prtspool/'. - $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. - time.'_'.rand(1000000000).'.xls'; - my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); - if (! defined($workbook)) { - $r->log_error("Error creating excel spreadsheet $filename: $!"); - $r->print('

'.&mt("Unable to create new Excel file. ". - "This error has been logged. ". - "Please alert your LON-CAPA administrator"). - '

'); - return undef; - } - # - $workbook->set_tempdir('/home/httpd/perl/tmp'); - # - my $format = &Apache::loncommon::define_excel_formats($workbook); + my ($workbook,$filename,$format) = + &Apache::loncommon::create_workbook($r); + return if (! defined($workbook)); my $worksheet = $workbook->addworksheet('Student Submission Data'); # # Add headers to the worksheet @@ -741,8 +732,10 @@ sub prepare_excel_output { $partid, $respid); my @response_data = - &excel_response_data(\@headers,$prob,$partid, - $respid,$response,$resptype); + &compile_response_data(\@headers,$response, + $prob,$partid,$respid, + $resptype, + \&excel_format_item); $worksheet->write_row($rows_output++,$cols_output, \@response_data); $cols_output+=scalar(@response_data); @@ -754,14 +747,13 @@ sub prepare_excel_output { } } # Fill in the remaining rows with the students data - for (my $row = $student_row+1;$row<=$max_row;$row++) { + for (my $row = $student_row+1;$row<$max_row;$row++) { my $cols = 0; foreach my $field (@StudentColumns) { $worksheet->write($row,$cols++, $student->{$field}); } } - $rows_output++; &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, 'last student'); } @@ -782,13 +774,18 @@ sub prepare_excel_output { return; } -sub excel_response_data { - my ($headers,$prob,$partid,$respid,$response,$resptype) = @_; +sub compile_response_data { + my ($headers,$response,$prob,$partid,$respid,$resptype,$format) = @_; if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) { return (); } + if (ref($format) ne 'CODE') { + $format = sub { return $_[0]; }; + } # - my $submission = &HTML::Entities::decode($response->{'Submission'}); + my $submission = + &HTML::Entities::decode + (&Apache::lonnet::unescape($response->{'Submission'})); return () if (! defined($submission) || $submission eq ''); $submission =~ s/\\\"/\"/g; $submission =~ s/\\\'/\'/g; @@ -825,16 +822,15 @@ sub excel_response_data { } elsif (exists($submission{$header})) { $option = $submission{$header}; } - push(@values,&excel_format_item($option,$header)); + push(@values,&{$format}($option,$header)); } else { # A normal column - push(@values, - &excel_format_item($response->{$original_header}, + push(@values,&{$format}($response->{$original_header}, $original_header)); } } } else { - @values = map { &excel_format_item($response->{$_},$_); } @$headers; + @values = map { &{$format}($response->{$_},$_); } @$headers; } return @values; } @@ -842,7 +838,7 @@ sub excel_response_data { sub excel_format_item { my ($item,$type) = @_; if ($type eq 'Time') { - &Apache::lonstathelpers::calc_serial($item); + $item = &Apache::lonstathelpers::calc_serial($item); } else { if ($item =~ m/^=/) { $item = ' '.$item; @@ -941,9 +937,7 @@ sub prepare_csv_output { } # # Main loop - my $mycount = 10; foreach my $student (@$students) { - last if ($mycount-- <0); last if ($c->aborted()); my @rows; foreach my $prob (@$problems) { @@ -973,7 +967,8 @@ sub prepare_csv_output { $partid,$respid); my @data = &compile_response_data(\@headers,$response, $prob,$partid, - $respid,$resptype); + $respid,$resptype, + \&csv_format_item); my $resp_start_idx = $start_col{$prob->symb}->{$partid}->{$respid}; for (my $k=0;$k<=$#data;$k++) { @@ -1010,64 +1005,11 @@ sub prepare_csv_output { return; } -sub compile_response_data { - my ($headers,$response,$prob,$partid,$respid,$resptype) = @_; - if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) { - return (); - } - # - my $submission = - &HTML::Entities::decode - (&Apache::lonnet::unescape($response->{'Submission'})); - return () if (! defined($submission) || $submission eq ''); - $response->{'Submission'} = $submission; - my @values; - if ($resptype =~ /^(option|match|rank)$/) { - my %submission = - map { - my ($foil,$value) = split('=',&Apache::lonnet::unescape($_)); - ($foil,$value); - } split('&',$response->{'Submission'}); - my %correct; - if (exists($response->{'Correct'})) { - %correct = - map { - my ($foil,$value)=split('=',&Apache::lonnet::unescape($_)); - ($foil,$value); - } split('&',$response->{'Correct'}); - } - # - foreach my $original_header (@$headers) { - if ($original_header =~ /^_/) { - # '_' denotes a foil column - my ($header) = ($original_header =~ m/^_(.*)$/); - my $option = ''; - if ( my ($foil) = ($header =~ /(.*) Correct$/)) { - if (exists($correct{$foil})) { - $option = $correct{$foil}; - } - } elsif (exists($submission{$header})) { - $option = $submission{$header}; - } - push(@values,&csv_format_item($option,$header)); - } else { - # A normal column - push(@values, - &csv_format_item($response->{$original_header}, - $original_header)); - } - } - } else { - @values = map { &csv_format_item($response->{$_},$_); } @$headers; - } - return @values; -} - sub csv_format_item { my ($item,$type) = @_; if ($type eq 'Time') { $item = localtime($item); - } + } $item =&Apache::loncommon::csv_translate($item); return $item; }