--- loncom/interface/statistics/lonstudentsubmissions.pm 2004/09/23 14:35:54 1.23 +++ loncom/interface/statistics/lonstudentsubmissions.pm 2010/03/26 13:25:17 1.57 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentsubmissions.pm,v 1.23 2004/09/23 14:35:54 matthew Exp $ +# $Id: lonstudentsubmissions.pm,v 1.57 2010/03/26 13:25:17 onken Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,7 +27,7 @@ package Apache::lonstudentsubmissions; use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::loncoursedata(); @@ -37,6 +37,9 @@ use Apache::lonstathelpers; use HTML::Entities(); use Time::Local(); use Spreadsheet::WriteExcel(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + my @SubmitButtons = ({ name => 'SelectAnother', text => 'Choose a different Problem' }, @@ -63,16 +66,18 @@ sub BuildStudentSubmissionsPage { my @Students = @Apache::lonstatistics::Students; # if (@Students < 1) { - $r->print('
'. - &mt('please select problems and use the Prepare Report button to continue.'). + &mt('Please select problems and use the [_1]Prepare Report[_2] button to continue.','',''). '
'); $r->print(&Apache::lonstathelpers::MultipleProblemSelector (undef,'problemchoice','Statistics')); } } +## +## get_extra_response_headers +## +sub get_extra_response_headers { + my @extra_resp_headers; + if ($env{'form.correctans'} eq 'true') { + push(@extra_resp_headers,'Correct'); + } + if ($env{'form.prob_status'} eq 'true') { + push(@extra_resp_headers,'Award Detail'); + push(@extra_resp_headers,'Time'); + push(@extra_resp_headers,'Attempt'); + push(@extra_resp_headers,'Awarded'); + } + return @extra_resp_headers; +} + +## +## get_headers: +## return the proper headers for the given response +sub get_headers { + my ($prob,$partid,$respid,$resptype,$analysis,$output,$purpose, + @basic_headers) = @_; + my @headers; + if ($resptype eq 'essay' && $purpose eq 'display' && + ($output eq 'html')) {# || scalar(@{$prob->parts})!=1)) { + @headers = (); + } elsif ($resptype =~ /^(option|match|rank)$/) { + my $prefix = '_'; + if ($purpose eq 'display') { + $prefix = ''; + } + my @foils = + map { + $prefix.$_; + } sort(keys(%{$analysis->{$partid.'.'.$respid}->{'_Foils'}})); + if (scalar(@basic_headers) && $basic_headers[0] eq 'Correct') { + @foils = map { ($_ , $_.' Correct') } @foils; + shift(@basic_headers); # Get rid of 'Correct' + } + @headers = (@foils,@basic_headers); + } elsif (lc($resptype) eq 'task') { + @headers = ('Grader','Status',@basic_headers,'Submission'); + } else { + @headers = ('Submission',@basic_headers); + } + return @headers; +} + ######################################################### ######################################################### ## @@ -167,20 +222,15 @@ sub prepare_html_output { } # # Compute the number of columns per response - my @response_headers = ('Submission'); - if ($ENV{'form.correctans'} eq 'true') { - push(@response_headers,'Correct'); - } - if ($ENV{'form.prob_status'} eq 'true') { - push(@response_headers,'Award Detail'); - push(@response_headers,'Time'); - push(@response_headers,'Attempt'); - push(@response_headers,'Awarded'); - } - my $response_multiplier = scalar(@response_headers); + my @extra_resp_headers = &get_extra_response_headers(); # # Create the table header - my @student_columns = ('username','domain','id'); + my @student_columns = @Apache::lonstatistics::SelectedStudentData; + foreach (@student_columns) { + if($_ eq 'all') { + @student_columns = ('fullname','username','domain','id','section','status','groups','comments'); + } + } # my %headers; my $student_column_count = scalar(@student_columns); @@ -192,7 +242,12 @@ sub prepare_html_output { # we put the headers into the %headers hash my $total_col = scalar(@student_columns); my $nonempty_part_headers = 0; + # + my %problem_analysis; foreach my $prob (@$problems) { + my %analysis = &Apache::lonstathelpers::get_problem_data($prob->src); + $problem_analysis{$prob->src}=\%analysis; + # my $prob_span = 0; my $single_part = 0; if (scalar(@{$prob->parts}) == 1) { @@ -203,28 +258,39 @@ sub prepare_html_output { my $responses = [$prob->responseIds($partid)]; my $resptypes = [$prob->responseType($partid)]; for (my $i=0;$i$/|g; + $submission =~ s|\\||g; + $submission = '
'.$submission.'
'; + return $submission; +} + +sub html_task_results { + my ($headers,$prob,$partid,$respid,$response,$resptype) = @_; + if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) { + return ''; } - return $Str; + + my @values; + @values = map { $response->{$_}; } @$headers; + + my $td = '$/|g; - $submission =~ s|\\||g; - $submission = '
'.$submission.'
'; - } elsif ($resptype eq 'radiobutton') { $submission =~ s/=([^=])$//; - } elsif ($resptype =~ /^(option|match|rank)$/) { - $submission = - ''.&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 my $rows_output = 0; $worksheet->write($rows_output++,0, - $ENV{'course.'.$ENV{'request.course.id'}.'.description'}, + $env{'course.'.$env{'request.course.id'}.'.description'}, $format->{'h1'}); $rows_output++; my $cols_output = 0; @@ -558,35 +708,38 @@ sub prepare_excel_output { $worksheet->write($partid_row,0,'Part ID',$format->{'bold'}); $worksheet->write($respid_row,0,'Response ID',$format->{'bold'}); # Student headers - my @StudentColumns = ('username','domain','id'); + my @StudentColumns = ('username','domain','id','section'); foreach (@StudentColumns) { $worksheet->write($header_row,$cols_output++,ucfirst($_), $format->{'bold'}); } # Problem headers + my %start_col; foreach my $prob (@$Problems) { my $title = $prob->compTitle; $worksheet->write($title_row,$cols_output, $title,$format->{'h3'}); foreach my $partid (@{$prob->parts}) { - $worksheet->write($partid_row,$cols_output,$partid); + $worksheet->write($partid_row,$cols_output, + $prob->part_display($partid)); my $responses = [$prob->responseIds($partid)]; my $resptypes = [$prob->responseType($partid)]; for (my $i=0;$i' + .&mt('Problems occurred in writing the CSV file.') + .' '.&mt('This error has been logged.') + .' '.&mt('Please alert your LON-CAPA administrator.') + .'
' + ); $outputfile = undef; } # # Compute the number of columns per response - my @response_headers = ('Submission'); - if ($ENV{'form.correctans'} eq 'true') { - push(@response_headers,'Correct'); - } - if ($ENV{'form.prob_status'} eq 'true') { - push(@response_headers,'Award Detail'); - push(@response_headers,'Time'); - push(@response_headers,'Attempt'); - push(@response_headers,'Awarded'); - } - my $response_multiplier = scalar(@response_headers); + my @extra_resp_headers = &get_extra_response_headers(); # # Create the table header - my @student_columns = ('username','domain','id'); + my @student_columns = ('username','domain','id','section'); # my %headers; push(@{$headers{'student'}},@student_columns); # Pad for the student data foreach my $row ('problem','part','response') { - foreach (@student_columns) { - push(@{$headers{$row}},''); - } + $headers{$row}=[map {''} @student_columns]; } # # we put the headers into the %headers hash - my $prob_start_idx = 0; + my %problem_analysis; + my %start_col; + my $max_column = scalar(@student_columns); foreach my $prob (@$problems) { - $headers{'problem'}->[$prob_start_idx] = $prob->compTitle; - my $part_start_idx = $prob_start_idx; + my %analysis = &Apache::lonstathelpers::get_problem_data($prob->src); + $problem_analysis{$prob->src}=\%analysis; + $headers{'problem'}->[$max_column] = $prob->compTitle; foreach my $partid (@{$prob->parts}) { - $headers{'part'}->[$part_start_idx] = &mt('Part [_1]',$partid); + $headers{'part'}->[$max_column] = $prob->part_display($partid); my $responses = [$prob->responseIds($partid)]; + my $resptypes = [$prob->responseType($partid)]; for (my $i=0;$i