--- loncom/interface/statistics/lonstudentsubmissions.pm 2004/09/16 21:54:22 1.19 +++ loncom/interface/statistics/lonstudentsubmissions.pm 2006/05/05 20:03:43 1.44 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentsubmissions.pm,v 1.19 2004/09/16 21:54:22 matthew Exp $ +# $Id: lonstudentsubmissions.pm,v 1.44 2006/05/05 20:03:43 raeburn 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(); @@ -71,8 +71,8 @@ sub BuildStudentSubmissionsPage { '
$/|g; + $submission =~ s|\\||g; + $submission = '
'.$submission.'
'; + return $submission; +} -sub new_excel_output { +sub html_task_results { + my ($headers,$prob,$partid,$respid,$response,$resptype) = @_; + if (! ref($headers) || ref($headers) ne 'ARRAY' || ! scalar(@$headers)) { + return ''; + } + + my @values; + @values = map { $response->{$_}; } @$headers; + + my $td = ''.&mt('LON-CAPA is unable to produce your Excel spreadsheet because your selections will result in more than 255 columns. Excel allows only 255 columns in a spreadsheet.').'
'.$/. - ''.&mt('Consider selecting fewer problems to generate reports on, or reducing the number of items per problem. Or use HTML or CSV output.').'
'.$/); + ''.&mt('Consider selecting fewer problems to generate reports on, or reducing the number of items per problem. Or use HTML or CSV output.').'
'.$/. + ''.&mt('The last problem that will fit in the current spreadsheet is [_1].',$lastprob->compTitle).'
'); $r->rflush(); return; } @@ -180,28 +669,15 @@ sub new_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 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; @@ -213,28 +689,38 @@ sub new_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 = &get_title($prob->title,$prob->src); + 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$/|g; - $submission =~ s|\\||g; - $submission = '
'.$submission.'
'; - # - my $Str = ''. - &mt('See the status bar above for student answer computation progress'). - '
'); - foreach my $problem (@$Problems) { - my ($resource,$respid,$partid) = ($problem->{'resource'}, - $problem->{'respid'}, - $problem->{'part'}); - # - &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students, - 'Statistics', - 'stats_status'); - } - $r->print(''); - } - # - $r->rflush(); - - - - - - - - - - - my @ColumnLabels; - my @Columns = @DefaultColumns; - my %seen; - foreach my $problem (@$Problems) { - my ($resource,$respid,$partid) = ($problem->{'resource'}, - $problem->{'respid'}, - $problem->{'part'}); - my $partkey = $resource->{'symb'}.':'.$partid; - if (! $seen{$partkey}) { - $ColumnLabels[$#Columns]=$resource->{'title'}; - push(@ColumnLabels,$partid); - push(@Columns,@PartColumns); - } - push(@Column - if ($ENV{'form.correctans'} eq 'true') { - push(@Columns,'Computers answer'); - } - $seen{$resource->{'symb'}.':'.$partid} .= ':'.$respid; - - } - -# my ($awarded_col,$weight_col); -# for (my $i=0;$i<=$#Columns;$i++) { -# if ($Columns[$i]->{'name'} eq 'weight' ) { $weight_col = $i; } -# if ($Columns[$i]->{'name'} eq 'awarded') { $awarded_col = $i; } -# } - - # - # Create excel worksheet - 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 $worksheet = $workbook->addworksheet('Student Submission Data'); - # - # Make sure we get new weight data instead of data on a 10 minute delay - &Apache::lonnet::clear_EXT_cache_status(); - # - # Put on the standard headers and whatnot - my $rows_output=0; - $worksheet->write($rows_output++,0,$resource->{'title'},$format->{'h1'}); - $worksheet->write($rows_output++,0,$resource->{'src'},$format->{'h3'}); - $rows_output++; - $worksheet->write_row($rows_output++,0, - [map {$_->{'display'}} @Columns], - $format->{'bold'}); - # - # Populate the worksheet with the student data - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin - ($r,'Excel File Compilation Status', - 'Excel File Compilation Progress', - scalar(@$Students),'inline',undef,'Statistics','stats_status'); - foreach my $student (@$Students) { - last if ($c->aborted()); - my $results = &Apache::loncoursedata::get_response_data_by_student - ($student,$resource->{'symb'},$respid); - my %row; - $row{'username'} = $student->{'username'}; - $row{'domain'} = $student->{'domain'}; - $row{'id'} = $student->{'id'}; - $row{'correct'} = $student->{'answer'}; - $row{'weight'} = &Apache::lonnet::EXT - ('resource.'.$partid.'.weight',$resource->{'symb'}, - undef,undef,undef); - if (! defined($results) || ref($results) ne 'ARRAY') { - $row{'score'} = '='. - &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell - ($rows_output,$awarded_col) - .'*'. - &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell - ($rows_output,$weight_col); - my $cols_output = 0; - foreach my $col (@Columns) { - if (! exists($row{$col->{'name'}})) { - $cols_output++; - next; - } - $worksheet->write($rows_output,$cols_output++, - $row{$col->{'name'}}); - } - $rows_output++; - } else { - for (my $i=0;$i