version 1.32, 2005/02/02 23:05:26
|
version 1.36, 2005/03/10 17:28:59
|
Line 118 sub BuildStudentSubmissionsPage {
|
Line 118 sub BuildStudentSubmissionsPage {
|
$r->print('<h1>'.$resource->title.'</h1>'); |
$r->print('<h1>'.$resource->title.'</h1>'); |
$r->print('<h3>'.$resource->src.'</h3>'); |
$r->print('<h3>'.$resource->src.'</h3>'); |
if ($ENV{'form.renderprob'} eq 'true') { |
if ($ENV{'form.renderprob'} eq 'true') { |
$r->print( |
$r->print(&Apache::lonstathelpers::render_resource($resource)); |
&Apache::lonstathelpers::render_resource({src => $resource->src}) |
|
); |
|
$r->rflush(); |
$r->rflush(); |
} |
} |
} |
} |
Line 267 sub prepare_html_output {
|
Line 265 sub prepare_html_output {
|
if ($partid =~/^\d+$/) { |
if ($partid =~/^\d+$/) { |
$tmpname = $prob->part_display($partid); |
$tmpname = $prob->part_display($partid); |
} |
} |
|
if ($tmpname !~ /^part/) { |
|
$tmpname = 'Part '.$tmpname; |
|
} |
$headers{'part'} .= qq{<th colspan="$part_span">$tmpname</th>}; |
$headers{'part'} .= qq{<th colspan="$part_span">$tmpname</th>}; |
$nonempty_part_headers = 1; |
$nonempty_part_headers = 1; |
} else { |
} else { |
Line 622 sub prepare_excel_output {
|
Line 623 sub prepare_excel_output {
|
$r->rflush(); |
$r->rflush(); |
# |
# |
# Create the excel spreadsheet |
# Create the excel spreadsheet |
my $filename = '/prtspool/'. |
my ($workbook,$filename,$format) = |
$ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. |
&Apache::loncommon::create_workbook($r); |
time.'_'.rand(1000000000).'.xls'; |
return if (! defined($workbook)); |
my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename); |
|
if (! defined($workbook)) { |
|
$r->log_error("Error creating excel spreadsheet $filename: $!"); |
|
$r->print('<p>'.&mt("Unable to create new Excel file. ". |
|
"This error has been logged. ". |
|
"Please alert your LON-CAPA administrator"). |
|
'</p>'); |
|
return undef; |
|
} |
|
# |
|
$workbook->set_tempdir('/home/httpd/perl/tmp'); |
|
# |
|
my $format = &Apache::loncommon::define_excel_formats($workbook); |
|
my $worksheet = $workbook->addworksheet('Student Submission Data'); |
my $worksheet = $workbook->addworksheet('Student Submission Data'); |
# |
# |
# Add headers to the worksheet |
# Add headers to the worksheet |
Line 741 sub prepare_excel_output {
|
Line 729 sub prepare_excel_output {
|
$partid, |
$partid, |
$respid); |
$respid); |
my @response_data = |
my @response_data = |
&excel_response_data(\@headers,$prob,$partid, |
&compile_response_data(\@headers,$response, |
$respid,$response,$resptype); |
$prob,$partid,$respid, |
|
$resptype, |
|
\&excel_format_item); |
$worksheet->write_row($rows_output++,$cols_output, |
$worksheet->write_row($rows_output++,$cols_output, |
\@response_data); |
\@response_data); |
$cols_output+=scalar(@response_data); |
$cols_output+=scalar(@response_data); |
Line 754 sub prepare_excel_output {
|
Line 744 sub prepare_excel_output {
|
} |
} |
} |
} |
# Fill in the remaining rows with the students data |
# 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; |
my $cols = 0; |
foreach my $field (@StudentColumns) { |
foreach my $field (@StudentColumns) { |
$worksheet->write($row,$cols++, |
$worksheet->write($row,$cols++, |
$student->{$field}); |
$student->{$field}); |
} |
} |
} |
} |
$rows_output++; |
|
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, |
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, |
'last student'); |
'last student'); |
} |
} |
Line 782 sub prepare_excel_output {
|
Line 771 sub prepare_excel_output {
|
return; |
return; |
} |
} |
|
|
sub excel_response_data { |
sub compile_response_data { |
my ($headers,$prob,$partid,$respid,$response,$resptype) = @_; |
my ($headers,$response,$prob,$partid,$respid,$resptype,$format) = @_; |
if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) { |
if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) { |
return (); |
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 ''); |
return () if (! defined($submission) || $submission eq ''); |
$submission =~ s/\\\"/\"/g; |
$submission =~ s/\\\"/\"/g; |
$submission =~ s/\\\'/\'/g; |
$submission =~ s/\\\'/\'/g; |
Line 825 sub excel_response_data {
|
Line 819 sub excel_response_data {
|
} elsif (exists($submission{$header})) { |
} elsif (exists($submission{$header})) { |
$option = $submission{$header}; |
$option = $submission{$header}; |
} |
} |
push(@values,&excel_format_item($option,$header)); |
push(@values,&{$format}($option,$header)); |
} else { |
} else { |
# A normal column |
# A normal column |
push(@values, |
push(@values,&{$format}($response->{$original_header}, |
&excel_format_item($response->{$original_header}, |
|
$original_header)); |
$original_header)); |
} |
} |
} |
} |
} else { |
} else { |
@values = map { &excel_format_item($response->{$_},$_); } @$headers; |
@values = map { &{$format}($response->{$_},$_); } @$headers; |
} |
} |
return @values; |
return @values; |
} |
} |
Line 842 sub excel_response_data {
|
Line 835 sub excel_response_data {
|
sub excel_format_item { |
sub excel_format_item { |
my ($item,$type) = @_; |
my ($item,$type) = @_; |
if ($type eq 'Time') { |
if ($type eq 'Time') { |
&Apache::lonstathelpers::calc_serial($item); |
$item = &Apache::lonstathelpers::calc_serial($item); |
} else { |
} else { |
if ($item =~ m/^=/) { |
if ($item =~ m/^=/) { |
$item = ' '.$item; |
$item = ' '.$item; |
Line 941 sub prepare_csv_output {
|
Line 934 sub prepare_csv_output {
|
} |
} |
# |
# |
# Main loop |
# Main loop |
my $mycount = 10; |
|
foreach my $student (@$students) { |
foreach my $student (@$students) { |
last if ($mycount-- <0); |
|
last if ($c->aborted()); |
last if ($c->aborted()); |
my @rows; |
my @rows; |
foreach my $prob (@$problems) { |
foreach my $prob (@$problems) { |
Line 973 sub prepare_csv_output {
|
Line 964 sub prepare_csv_output {
|
$partid,$respid); |
$partid,$respid); |
my @data = &compile_response_data(\@headers,$response, |
my @data = &compile_response_data(\@headers,$response, |
$prob,$partid, |
$prob,$partid, |
$respid,$resptype); |
$respid,$resptype, |
|
\&csv_format_item); |
my $resp_start_idx = |
my $resp_start_idx = |
$start_col{$prob->symb}->{$partid}->{$respid}; |
$start_col{$prob->symb}->{$partid}->{$respid}; |
for (my $k=0;$k<=$#data;$k++) { |
for (my $k=0;$k<=$#data;$k++) { |
Line 1010 sub prepare_csv_output {
|
Line 1002 sub prepare_csv_output {
|
return; |
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 { |
sub csv_format_item { |
my ($item,$type) = @_; |
my ($item,$type) = @_; |
if ($type eq 'Time') { |
if ($type eq 'Time') { |
$item = localtime($item); |
$item = localtime($item); |
} |
} |
$item =&Apache::loncommon::csv_translate($item); |
$item =&Apache::loncommon::csv_translate($item); |
return $item; |
return $item; |
} |
} |