version 1.21, 2004/09/22 15:38:49
|
version 1.25, 2004/10/08 16:40:54
|
Line 109 sub BuildStudentSubmissionsPage {
|
Line 109 sub BuildStudentSubmissionsPage {
|
my $resource = $navmap->getBySymb($symb); |
my $resource = $navmap->getBySymb($symb); |
push(@Problems,$resource); |
push(@Problems,$resource); |
} |
} |
# |
# |
if (! scalar(@Problems) || ! defined($Problems[0])) { |
if (! scalar(@Problems) || ! defined($Problems[0])) { |
$r->print('resource is undefined'); |
$r->print('resource is undefined'); |
} else { |
} else { |
Line 126 sub BuildStudentSubmissionsPage {
|
Line 126 sub BuildStudentSubmissionsPage {
|
} |
} |
if ($ENV{'form.output'} eq 'excel') { |
if ($ENV{'form.output'} eq 'excel') { |
&prepare_excel_output($r,\@Problems,\@Students); |
&prepare_excel_output($r,\@Problems,\@Students); |
|
} elsif ($ENV{'form.output'} eq 'csv') { |
|
&prepare_csv_output($r,\@Problems,\@Students); |
} else { |
} else { |
&prepare_html_output($r,\@Problems,\@Students); |
&prepare_html_output($r,\@Problems,\@Students); |
} |
} |
Line 217 sub prepare_html_output {
|
Line 219 sub prepare_html_output {
|
if (! $single_part) { |
if (! $single_part) { |
my $tmpname = $partid; |
my $tmpname = $partid; |
if ($partid =~/^\d+$/) { |
if ($partid =~/^\d+$/) { |
$tmpname = &mt('Part [_1]',$partid); |
$tmpname = $prob->part_display($partid); |
} |
} |
$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; |
Line 226 sub prepare_html_output {
|
Line 228 sub prepare_html_output {
|
} |
} |
$prob_span += $part_span; |
$prob_span += $part_span; |
} |
} |
my $title = &get_title($prob->title,$prob->src); |
my $title = $prob->compTitle; |
if ($prob_span > 0) { |
if ($prob_span > 0) { |
$headers{'problem'}.= qq{<th colspan="$prob_span">$title</th>}; |
$headers{'problem'}.= qq{<th colspan="$prob_span">$title</th>}; |
} elsif ($single_response) { |
} elsif ($single_response) { |
Line 388 sub html_essay_results {
|
Line 390 sub html_essay_results {
|
} |
} |
my $Str; |
my $Str; |
if (! $single_response) { |
if (! $single_response) { |
my $id = &get_title($prob->title,$prob->src); |
my $id = $prob->compTitle; |
if (defined($partid) && $partid ne '0') { |
if (defined($partid) && $partid ne '0') { |
$id .= ' '.$partid; |
$id .= ' '.$prob->part_display($partid); |
} |
} |
if (defined($respid)) { |
if (defined($respid)) { |
$id .= ' '.$respid; |
$id .= ' '.$respid; |
Line 456 sub html_results {
|
Line 458 sub html_results {
|
sub html_format_sub { |
sub html_format_sub { |
my ($submission,$resptype) = @_; |
my ($submission,$resptype) = @_; |
return '' if (! defined($submission) || $submission eq ''); |
return '' if (! defined($submission) || $submission eq ''); |
|
$submission = &HTML::Entities::decode($submission); |
|
$submission =~ s/\\\"/\"/g; |
|
$submission =~ s/\\\'/\'/g; |
if ($resptype eq 'essay') { |
if ($resptype eq 'essay') { |
$submission =~ s|\\r\\n|$/|g; |
$submission =~ s|\\r\\n|$/|g; |
$submission = &HTML::Entities::encode($submission,'<>&"'); |
$submission = &HTML::Entities::encode($submission,'<>&"'); |
Line 463 sub html_format_sub {
|
Line 468 sub html_format_sub {
|
$submission =~ s|\\||g; |
$submission =~ s|\\||g; |
$submission = '<p>'.$submission.'</p>'; |
$submission = '<p>'.$submission.'</p>'; |
} elsif ($resptype eq 'radiobutton') { |
} elsif ($resptype eq 'radiobutton') { |
|
$submission = &HTML::Entities::encode($submission,'<>&"'); |
$submission =~ s/=([^=])$//; |
$submission =~ s/=([^=])$//; |
} elsif ($resptype =~ /^(option|match|rank)$/) { |
} elsif ($resptype =~ /^(option|match|rank)$/) { |
$submission = |
$submission = |
'<ul class="sub_studentans">'. |
'<ul class="sub_studentans">'. |
'<li>'.join('</li><li>', |
'<li>'.join('</li><li>', |
map { |
map { &HTML::Entities::encode($_,'<>&"'); |
&Apache::lonnet::unescape($_) ; |
} map { |
} sort split('&',$submission) |
&Apache::lonnet::unescape($_) ; |
|
} sort split('&',$submission) |
). |
). |
'</li><ul>'; |
'</li><ul>'; |
|
} else { |
|
$submission = &HTML::Entities::encode($submission,'<>&"'); |
} |
} |
return $submission; |
return $submission; |
} |
} |
Line 504 sub prepare_excel_output {
|
Line 513 sub prepare_excel_output {
|
$r->print('<h1>'.&mt('Unable to complete request').'</h1>'.$/. |
$r->print('<h1>'.&mt('Unable to complete request').'</h1>'.$/. |
'<p>'.&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.').'</p>'.$/. |
'<p>'.&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.').'</p>'.$/. |
'<p>'.&mt('Consider selecting fewer problems to generate reports on, or reducing the number of items per problem. Or use HTML or CSV output.').'</p>'.$/. |
'<p>'.&mt('Consider selecting fewer problems to generate reports on, or reducing the number of items per problem. Or use HTML or CSV output.').'</p>'.$/. |
'<p>'.&mt('The last problem that will fit in the current spreadsheet is [_1].',&get_title($lastprob->title,$lastprob->src)).'</p>'); |
'<p>'.&mt('The last problem that will fit in the current spreadsheet is [_1].',$lastprob->compTitle).'</p>'); |
$r->rflush(); |
$r->rflush(); |
return; |
return; |
} |
} |
Line 563 sub prepare_excel_output {
|
Line 572 sub prepare_excel_output {
|
} |
} |
# Problem headers |
# Problem headers |
foreach my $prob (@$Problems) { |
foreach my $prob (@$Problems) { |
my $title = &get_title($prob->title,$prob->src); |
my $title = $prob->compTitle; |
$worksheet->write($title_row,$cols_output, |
$worksheet->write($title_row,$cols_output, |
$title,$format->{'h3'}); |
$title,$format->{'h3'}); |
foreach my $partid (@{$prob->parts}) { |
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 $responses = [$prob->responseIds($partid)]; |
my $resptypes = [$prob->responseType($partid)]; |
my $resptypes = [$prob->responseType($partid)]; |
for (my $i=0;$i<scalar(@$responses);$i++) { |
for (my $i=0;$i<scalar(@$responses);$i++) { |
Line 696 sub write_excel_row {
|
Line 706 sub write_excel_row {
|
return $col; |
return $col; |
} |
} |
|
|
sub get_title { |
|
my ($title,$src) = @_; |
|
if ($title eq '') { |
|
($title) = ($src =~ m|/([^/]+)$|); |
|
} else { |
|
$title =~ s/\:/:/g; |
|
} |
|
return $title; |
|
} |
|
|
|
sub excel_format_response { |
sub excel_format_response { |
my ($answer,$responsetype) = @_; |
my ($answer,$responsetype) = @_; |
if ($responsetype eq 'radiobutton') { |
if ($responsetype eq 'radiobutton') { |
Line 716 sub excel_format_response {
|
Line 716 sub excel_format_response {
|
&Apache::lonnet::unescape($_) ; |
&Apache::lonnet::unescape($_) ; |
} sort split('&',$answer) |
} sort split('&',$answer) |
); |
); |
|
} elsif ($responsetype eq 'string') { |
|
$answer =~ s/\\(n|r)/\n/g; |
|
$answer =~ s/(\s*$|^\s*)//g; |
|
$answer =~ s/\\\'/\'/g; |
} |
} |
if ($answer =~ m/^=/) { |
if ($answer =~ m/^=/) { |
$answer = ' '.$answer; |
$answer = ' '.$answer; |
Line 723 sub excel_format_response {
|
Line 727 sub excel_format_response {
|
return $answer; |
return $answer; |
} |
} |
|
|
## |
|
## Currently not used |
|
sub get_problem_data { |
|
my ($r,$Problems) = @_; |
|
# |
|
# Analyze |
|
my %Data; |
|
if (scalar(@$Problems) > 5) { |
|
# progress window |
|
my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin |
|
($r,'Problem Analysis Status', |
|
'Problem Analysis Progress', |
|
scalar(@$Problems), |
|
'inline',undef,'Statistics','stats_status'); |
|
foreach my $problem (@$Problems) { |
|
$Data{$problem->symb} = |
|
{&Apache::lonstathelpers::get_problem_data |
|
($problem->src)}; |
|
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, |
|
'last problem'); |
|
} |
|
&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); |
|
} else { |
|
foreach my $problem (@$Problems) { |
|
$Data{$problem->symb} = |
|
{&Apache::lonstathelpers::get_problem_data |
|
($problem->src)}; |
|
} |
|
} |
|
return \%Data; |
|
} |
|
|
|
|
|
=pod |
|
|
|
######################################################### |
######################################################### |
######################################################### |
######################################################### |
## |
## |
Line 766 sub get_problem_data {
|
Line 735 sub get_problem_data {
|
######################################################### |
######################################################### |
######################################################### |
######################################################### |
sub prepare_csv_output { |
sub prepare_csv_output { |
my ($r,$Problems,$Students) = @_; |
my ($r,$problems,$students) = @_; |
my $problem; |
|
# |
|
my $c = $r->connection(); |
my $c = $r->connection(); |
my ($resource,$respid,$partid) = ($problem->{'resource'}, |
|
$problem->{'respid'}, |
|
$problem->{'part'}); |
|
# |
|
if ($ENV{'form.correctans'} eq 'true') { |
|
$r->print('<h2>'.&mt('Generating Correct Answers').'</h2>'); |
|
&Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students, |
|
'Statistics', |
|
'stats_status'); |
|
} |
|
# |
# |
$r->print('<h2>'. |
$r->print('<h2>'. |
&mt('Generating CSV report of student responses').'</h2>'); |
&mt('Generating CSV report of student responses').'</h2>'); |
Line 788 sub prepare_csv_output {
|
Line 745 sub prepare_csv_output {
|
my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin |
my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin |
($r,'CSV File Compilation Status', |
($r,'CSV File Compilation Status', |
'CSV File Compilation Progress', |
'CSV File Compilation Progress', |
scalar(@$Students),'inline',undef,'Statistics','stats_status'); |
scalar(@$students),'inline',undef,'Statistics','stats_status'); |
|
|
$r->rflush(); |
$r->rflush(); |
# |
# |
# Open a file |
# Open a file |
Line 805 sub prepare_csv_output {
|
Line 762 sub prepare_csv_output {
|
$outputfile = undef; |
$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); |
|
# |
|
# Create the table header |
|
my @student_columns = ('username','domain','id'); |
# |
# |
my @Columns; |
my %headers; |
if (exists($ENV{'form.concise'}) && $ENV{'form.concise'} eq 'true') { |
push(@{$headers{'student'}},@student_columns); |
foreach (@DefaultColumns) { |
# Pad for the student data |
if ($_->{'name'} =~ /^(username|domain|id)$/){ |
foreach my $row ('problem','part','response') { |
push(@Columns,$_); |
foreach (@student_columns) { |
} |
push(@{$headers{$row}},''); |
} |
} |
} else { |
|
@Columns = @DefaultColumns; |
|
} |
} |
# |
# |
my $response_type = &get_response_type($resource,$partid,$respid); |
# we put the headers into the %headers hash |
if (! defined($response_type) || $response_type eq '') { |
my $prob_start_idx = 0; |
$r->print('<h2>'.&mt('Unable to determine response type').'</h2>'); |
foreach my $prob (@$problems) { |
return; |
$headers{'problem'}->[$prob_start_idx] = $prob->compTitle; |
|
my $part_start_idx = $prob_start_idx; |
|
foreach my $partid (@{$prob->parts}) { |
|
$headers{'part'}->[$part_start_idx] = $prob->part_display($partid); |
|
my $responses = [$prob->responseIds($partid)]; |
|
for (my $i=0;$i<scalar(@$responses);$i++) { |
|
my $resp_idx = $prob_start_idx + $response_multiplier * $i; |
|
$headers{'response'}->[$resp_idx]= |
|
&mt('Response [_1]',$responses->[$i]); |
|
for (my $j=0;$j<=$#response_headers;$j++) { |
|
$headers{'student'}->[$resp_idx+$j]=$response_headers[$j]; |
|
} |
|
} |
|
$part_start_idx += scalar(@$responses)*$response_multiplier; |
|
} |
|
$prob_start_idx += $prob->countResponses * $response_multiplier; |
|
} |
|
foreach my $row ('problem','part','response','student') { |
|
print $outputfile '"'.join('","',map { ''; } @student_columns).'","'. |
|
join('","', |
|
map { |
|
&Apache::loncommon::csv_translate($_); |
|
} @{$headers{$row}}).'"'.$/; |
} |
} |
# |
# |
my $header = &csv_headers(\@Columns).','.&csv_generic_headers(); |
# Main loop |
print $outputfile $header.$/; |
foreach my $student (@$students) { |
# |
my @rows; |
foreach my $student (@$Students) { |
my $prob_start_idx = 0; |
last if ($c->aborted()); |
foreach my $prob (@$problems) { |
my $results = &Apache::loncoursedata::get_response_data_by_student |
my $part_start_idx = 0; |
($student,$resource->{'symb'},$respid); |
foreach my $partid (@{$prob->parts}) { |
next if (! defined($results) || ref($results) ne 'ARRAY'); |
my @responses = $prob->responseIds($partid); |
for (my $i=0;$i<scalar(@$results);$i++) { |
my @response_type = $prob->responseType($partid); |
my $response = $results->[$i]; |
for (my $i=0;$i<=$#responses;$i++) { |
if ($ENV{'form.last_sub_only'} eq 'true' && |
my $resp_start_idx = $response_multiplier * $i; |
$i < (scalar(@$results)-1)) { |
my $respid = $responses[$i]; |
next; |
my $results = |
} |
&Apache::loncoursedata::get_response_data_by_student |
my $data; |
($student,$prob->symb(),$respid); |
$data->{'username'} = $student->{'username'}; |
if (! defined($results)) { |
$data->{'domain'} = $student->{'domain'}; |
$results = []; |
$data->{'id'} = $student->{'id'}; |
} |
$data->{'fullname'} = $student->{'fullanem'}; |
for (my $j=0; $j<scalar(@$results);$j++) { |
$data->{'status'} = $student->{'status'}; |
if ($ENV{'form.all_sub'} ne 'true') { |
$data->{'time'} = &Apache::lonlocal::locallocaltime |
next if ($j != 0); |
($response->[&Apache::loncoursedata::RDs_timestamp()]); |
} |
$data->{'attempt'} = |
my $idx = scalar(@$results) - $j - 1; |
$response->[&Apache::loncoursedata::RDs_tries()]; |
my $response = $results->[$idx]; |
$data->{'awarded'} = |
my @data = &compile_response_data($response,$student, |
$response->[&Apache::loncoursedata::RDs_awarded()]; |
$prob,$partid, |
$data->{'awarddetail'} = |
$respid); |
$response->[&Apache::loncoursedata::RDs_awarddetail()]; |
for (my $k=0;$k<=$#data;$k++) { |
$data->{'weight'} = &Apache::lonnet::EXT |
$rows[$j]->[$prob_start_idx + $part_start_idx + |
('resource.'.$partid.'.weight',$resource->{'symb'}, |
$resp_start_idx + $k] = $data[$k]; |
undef,undef,undef); |
} |
$data->{'score'} = $data->{'weight'} * $data->{'awarded'}; |
} |
my $rowextra = ''; |
} |
my $row; |
$part_start_idx += scalar(@responses)*$response_multiplier; |
foreach my $col (@Columns) { |
} |
$row .= '"'. |
$prob_start_idx += $prob->countResponses * $response_multiplier; |
&Apache::loncommon::csv_translate($data->{$col->{'name'}}).'",'; |
} |
} |
foreach my $row (@rows) { |
if ($response_type eq 'option') { |
print $outputfile '"'.join('","', |
$row .= &csv_option_results |
map { $student->{$_}; } |
($response->[&Apache::loncoursedata::RDs_submission()], |
@student_columns).'"'; |
$student->{'answer'}, |
|
scalar(@Columns),$rowextra); |
for (my $i=0;$i<$prob_start_idx;$i++) { |
} elsif ($response_type eq 'radiobutton') { |
my $value = &Apache::loncommon::csv_translate($row->[$i]); |
$row .= &csv_radiobutton_results |
$value ||=''; |
($response->[&Apache::loncoursedata::RDs_submission()], |
print $outputfile ',"'.$value.'"'; |
$student->{'answer'}, |
|
scalar(@Columns),$rowextra); |
|
} else { |
|
$row .= &csv_generic_results |
|
($response->[&Apache::loncoursedata::RDs_submission()], |
|
$student->{'answer'}, |
|
scalar(@Columns),$rowextra); |
|
} |
} |
print $outputfile $row.$/; |
print $outputfile $/; |
} |
} |
|
undef(@rows); |
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, |
&Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, |
'last student'); |
'last student'); |
} |
} |
Line 894 sub prepare_csv_output {
|
Line 880 sub prepare_csv_output {
|
return; |
return; |
} |
} |
|
|
sub csv_headers { |
sub compile_response_data { |
my ($Columns) = @_; |
my ($response,$student,$prob,$partid,$respid) = @_; |
my $Str; |
my @rowdata; |
foreach my $column (@$Columns) { |
push(@rowdata,$response->[&Apache::loncoursedata::RDs_submission()]); |
$Str .= |
|
'"'.&Apache::loncommon::csv_translate($column->{'display'}).'",'; |
|
} |
|
chop($Str); |
|
return $Str; |
|
} |
|
|
|
sub csv_generic_headers { |
|
my ($title) = @_; |
|
if (! defined($title)) { |
|
$title = &mt('Submission'); |
|
} |
|
my $header = '"'.&Apache::loncommon::csv_translate($title).'"'; |
|
if ($ENV{'form.correctans'} eq 'true') { |
if ($ENV{'form.correctans'} eq 'true') { |
$header .= ',"'.&Apache::loncommon::csv_translate(&mt('Correct')).'"'; |
my $correct = &Apache::lonstathelpers::analyze_problem_as_student |
} |
($prob,$student->{'username'},$student->{'domain'}, |
return $header; |
$partid,$respid); |
} |
push(@rowdata,$correct); |
|
|
#------------------------------------------ |
|
sub csv_essay_results { |
|
my ($submission,$correct,$tablewidth,$rowextra)=@_; |
|
# |
|
$submission =~ s|\\r|\\\\r|g; |
|
$submission =~ s|\\n|\\\\n|g; |
|
# |
|
return &csv_generic_results($submission,$correct,$tablewidth); |
|
} |
|
|
|
#------------------------------------------ |
|
sub csv_radiobutton_results { |
|
my ($submission,$correct,$tablewidth,$rowclass)=@_; |
|
$submission =~ s/=[^=]*$//; |
|
return &csv_generic_results($submission,$correct,$tablewidth,$rowclass); |
|
} |
|
|
|
#------------------------------------------ |
|
sub csv_option_results { |
|
my ($submission,$correct,$tablewidth,$rowclass)=@_; |
|
$submission = join(',', |
|
map { |
|
&Apache::lonnet::unescape($_) ; |
|
} sort split('&',$submission) |
|
); |
|
if (defined($correct) && $correct !~ /^\s*$/) { |
|
$correct =join(',', |
|
map { |
|
&Apache::lonnet::unescape($_) ; |
|
} sort split('&',$submission)); |
|
} |
} |
return &csv_generic_results($submission,$correct,$tablewidth,$rowclass); |
if ($ENV{'form.prob_status'}) { |
} |
push(@rowdata,$response->[&Apache::loncoursedata::RDs_awarddetail()]); |
|
push(@rowdata,&Apache::lonlocal::locallocaltime |
#------------------------------------------ |
($response->[&Apache::loncoursedata::RDs_timestamp()])); |
sub csv_generic_results { |
push(@rowdata,$response->[&Apache::loncoursedata::RDs_tries()]); |
my ($submission,$correct,$tablewidth,$rowclass)=@_; |
push(@rowdata,$response->[&Apache::loncoursedata::RDs_awarded()]); |
my $Str .= |
|
'"'.&Apache::loncommon::csv_translate($submission).'"'; |
|
if ($ENV{'form.correctans'} eq 'true') { |
|
$Str .= ',"'.&Apache::loncommon::csv_translate($correct).'"'; |
|
} |
} |
return $Str; |
return @rowdata; |
} |
} |
|
|
=cut |
|
|
|
######################################################### |
######################################################### |
######################################################### |
######################################################### |
## |
## |
Line 975 sub CreateInterface {
|
Line 911 sub CreateInterface {
|
## |
## |
## Output Selection |
## Output Selection |
my $output_selector = $/.'<select name="output">'.$/; |
my $output_selector = $/.'<select name="output">'.$/; |
# foreach ('HTML','Excel','CSV') { |
foreach ('HTML','Excel','CSV') { |
foreach ('HTML','Excel') { |
|
$output_selector .= ' <option value="'.lc($_).'"'; |
$output_selector .= ' <option value="'.lc($_).'"'; |
if ($ENV{'form.output'} eq lc($_)) { |
if ($ENV{'form.output'} eq lc($_)) { |
$output_selector .= ' selected '; |
$output_selector .= ' selected '; |