--- loncom/interface/statistics/lonstudentsubmissions.pm 2005/02/02 23:05:26 1.32 +++ loncom/interface/statistics/lonstudentsubmissions.pm 2005/02/03 00:25:01 1.33 @@ -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.33 2005/02/03 00:25:01 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -741,8 +741,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); @@ -782,13 +784,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 +832,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 +848,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 +947,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 +977,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 +1015,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; }