version 1.21, 2004/09/22 15:38:49
|
version 1.22, 2004/09/23 13:50:45
|
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 723 sub excel_format_response {
|
Line 725 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 733 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 743 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 760 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] = |
|
&get_title($prob->title,$prob->src); |
|
my $part_start_idx = $prob_start_idx; |
|
foreach my $partid (@{$prob->parts}) { |
|
$headers{'part'}->[$part_start_idx] = &mt('Part [_1]',$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 879 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 910 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 '; |