--- loncom/interface/statistics/lonstudentsubmissions.pm 2004/02/20 16:38:49 1.3 +++ loncom/interface/statistics/lonstudentsubmissions.pm 2004/09/01 21:13:04 1.15 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstudentsubmissions.pm,v 1.3 2004/02/20 16:38:49 matthew Exp $ +# $Id: lonstudentsubmissions.pm,v 1.15 2004/09/01 21:13:04 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,10 +43,6 @@ my @SubmitButtons = ({ name => 'PrevProb { name => 'NextProblem', text => 'Next Problem' }, { name => 'break'}, - { name => 'ClearCache', - text => 'Clear Caches' }, - { name => 'updatecaches', - text => 'Update Student Data' }, { name => 'SelectAnother', text => 'Choose a different Problem' }, { name => 'Generate', @@ -75,18 +71,8 @@ sub BuildStudentSubmissionsPage { $r->print('

There are no students in the sections selected

'); } # - &Apache::loncoursedata::clear_internal_caches(); - if (exists($ENV{'form.ClearCache'}) || - exists($ENV{'form.updatecaches'}) || - (exists($ENV{'form.firstanalysis'}) && - $ENV{'form.firstanalysis'} ne 'no')) { - &Apache::lonstatistics::Gather_Full_Student_Data($r); - } - if (! exists($ENV{'form.firstanalysis'})) { - $r->print(''); - } else { - $r->print(''); - } + my @CacheButtonHTML = + &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status'); $r->rflush(); # if (exists($ENV{'form.problemchoice'}) && @@ -100,6 +86,9 @@ sub BuildStudentSubmissionsPage { $r->print(' 'x5); } } + foreach my $html (@CacheButtonHTML) { + $r->print($html.(' 'x5)); + } # $r->print('
'); $r->rflush(); @@ -133,15 +122,19 @@ sub BuildStudentSubmissionsPage { my $resource = $current_problem->{'resource'}; $r->print('

'.$resource->{'title'}.'

'); $r->print('

'.$resource->{'src'}.'

'); - $r->print(&Apache::lonstathelpers::render_resource($resource)); + if ($ENV{'form.renderprob'} eq 'true') { + $r->print(&Apache::lonstathelpers::render_resource($resource)); + } $r->rflush(); my %Data = &Apache::lonstathelpers::get_problem_data ($resource->{'src'}); my $ProblemData = $Data{$current_problem->{'part'}. '.'. $current_problem->{'respid'}}; - &prepare_excel_output($r,$current_problem, + &prepare_html_output($r,$current_problem, $ProblemData,\@Students); +# &prepare_excel_output($r,$current_problem, +# $ProblemData,\@Students); } $r->print('
'); } else { @@ -153,30 +146,308 @@ sub BuildStudentSubmissionsPage { } } - ######################################################### ######################################################### ## -## Excel output of student answers and correct answers +## prepare_html_output ## ######################################################### ######################################################### -sub prepare_excel_output { +sub prepare_html_output { my ($r,$problem,$ProblemData,$Students) = @_; + my $c = $r->connection(); my ($resource,$respid,$partid) = ($problem->{'resource'}, $problem->{'respid'}, $problem->{'part'}); - $r->print('

'. - &mt('Preparing Excel spreadsheet of student responses'). - '

'); + $r->print('

'.&mt('Student Responses').'

'); + # + if ($ENV{'form.correctans'} eq 'true') { + &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students, + 'Statistics', + 'stats_status'); + } + # + $r->rflush(); + my $response_type; + for (my $i=0; + $i{'partdata'}->{$partid}->{'ResponseIds'}}); + $i++) { + if($resource->{'partdata'}->{$partid}->{'ResponseIds'}->[$i] eq $respid){ + $response_type = + $resource->{'partdata'}->{$partid}->{'ResponseTypes'}->[$i]; + last; + } + } + if (! defined($response_type)) { + $r->print('

'.&mt('Unable to determine response type').'

'); + } else { + my $count = 0; + my $header; + if ($response_type eq 'essay') { + $header = &html_essay_header(); + } elsif ($response_type eq 'radiobutton') { + $header = &html_radiobutton_header(); + } elsif ($response_type eq 'option') { + $header = &html_option_header(); + } else { + $header = &html_generic_header(); + } + $header = ''.$header.''; + # + $r->print($/.''.$/.$header.$/); + foreach my $student (@$Students) { + if ($count >= 50) { + $r->print('
'.$/.''.$/.$header.$/); + $count = 0; + } + last if ($c->aborted()); + my $results = &Apache::loncoursedata::get_response_data_by_student + ($student,$resource->{'symb'},$respid); + next if (! defined($results) || ref($results) ne 'ARRAY'); + for (my $i=0;$i[$i]; + if ($ENV{'form.last_sub_only'} eq 'true' && + $i < (scalar(@$results)-1)) { + next; + } + my $data; + $data->{'sname'} = $student->{'username'}.'@'. + $student->{'domain'}; + $data->{'time'} = &Apache::lonlocal::locallocaltime + ($response->[&Apache::loncoursedata::RDs_timestamp()]); + $data->{'attempt'} = + $response->[&Apache::loncoursedata::RDs_tries()]; + $data->{'submission'} = + $response->[&Apache::loncoursedata::RDs_submission()]; + $data->{'correct'} = $student->{'answer'}; + my $row; + if ($response_type eq 'essay') { + $row = &html_essay($data); + } elsif ($response_type eq 'radiobutton') { + $row = &html_radiobutton($data); + } elsif ($response_type eq 'option') { + $row = &html_option($data); + } else { + $row = &html_generic($data); + } + $r->print($row.$/); + $count++; + } + } + $r->print('
'.$/); + } + return; +} + +##################################################### +## +## HTML helper routines +## +##################################################### +my @FullHeaders = ( + {name=>'sname', + display=>'Student'}, + {name => 'id', + display => 'Id'}, + {name => 'time', + display =>'Time'}, + {name => 'attempt', + display =>'Attempt'}, + {name => 'grading', + display =>'Grading'}, + ); + +sub html_essay_header { + my $header; + if ($ENV{'form.subdata'} eq 'true') { + foreach (@FullHeaders) { + $header .= ''.&mt($_->{'display'}).''; + } + } else { + $header = ''.&mt('Username and Submission').''; + } + return $header; +} + +sub html_essay { + my ($data)=@_; # - &GetStudentAnswers($r,$problem,$Students); + $data->{'submission'} =~ s|\\r\\n|$/|g; + $data->{'submission'} = + &HTML::Entities::encode($data->{'submission'},'<>&"'); + $data->{'submission'} =~ s|$/\s*$/|$/

$/|g; + $data->{'submission'} =~ s|\\||g; + $data->{'submission'} = '

'.$data->{'submission'}.'

'; + # + my $Str = ''; + if ($ENV{'form.subdata'} eq 'true') { + $Str .= + ''.$data->{'sname'}.''. + ''.$data->{'time'}.''. + ''.$data->{'attempt'}.''; + $Str .= ''; + $Str .= ''. + $data->{'submission'}.''; + } else { + $Str .= ''.$data->{'sname'}.''. + $data->{'submission'}.''; + } + if ($ENV{'form.correctans'} eq 'true') { + $Str .= ''; + if (defined($data->{'correct'}) && $data->{'correct'} !~ /^\s*$/) { + $Str .= ''. + ''.&mt('Correct Answer:').''.$data->{'correct'}.''; + } + } + $Str .= ''; + # + return $Str; +} + +sub html_radiobutton_header { + my $header; + if ($ENV{'form.subdata'} eq 'true') { + foreach (@FullHeaders) { + $header .= ''.&mt($_->{'display'}).''; + } + } else { + $header = + ''.&mt('Username').''; + } + $header .=''.&mt('Submission').''; + if ($ENV{'form.correctans'} eq 'true') { + $header .= ''.&mt('Correct').''; + } + return $header; +} + +sub html_radiobutton { + my ($data)=@_; + # + $data->{'submission'} =~ s/=([^=])$//; + # + my $Str = ''; + if ($ENV{'form.subdata'} eq 'true') { + $Str .= + ''.''.$data->{'sname'}.''. + ''.$data->{'time'}.''. + ''.$data->{'attempt'}.''; + $Str .= ''.$data->{'submission'}.''; + if ($ENV{'form.correctans'} eq 'true') { + $Str .= ''.$data->{'correct'}.''; + } + } else { + $Str .= ''.$data->{'sname'}.''; + $Str .= ''.$data->{'submission'}.''; + if ($ENV{'form.correctans'} eq 'true') { + $Str .= ''.$data->{'correct'}.''; + } + } + $Str .= ''; # - my @Columns = ( 'username','domain','attempt','time', - 'submission','correct', 'grading','awarded','weight', - 'score'); - my $awarded_col = 7; - my $weight_col = 8; + return $Str; +} + +sub html_generic_header { + my $header; + if ($ENV{'form.subdata'} eq 'true') { + foreach (@FullHeaders) { + $header .= ''.&mt($_->{'display'}).''; + } + } else { + $header = + ''.&mt('Username').''; + } + $header .= ''.&mt('Submission').''; + if ($ENV{'form.correctans'} eq 'true') { + $header .= ''.&mt('Correct').''; + } + return $header; +} + +sub html_generic { + my ($data)=@_; + $data->{'submission'} = &Apache::lonnet::unescape($data->{'submission'}); + my $Str = ''; + if ($ENV{'form.subdata'} eq 'true') { + $Str .= + ''.$data->{'sname'}.''. + ''.$data->{'time'}.''. + ''.$data->{'attempt'}.''; + } else { + $Str .= ''.$data->{'sname'}.''; + } + $Str .= ''.$data->{'submission'}.''; + if ($ENV{'form.correctans'} eq 'true') { + $Str .= ''.$data->{'correct'}.''; + } + $Str .= ''; + return $Str; +} + +sub html_option_header { + my $header; + if ($ENV{'form.subdata'} eq 'true') { + foreach (@FullHeaders) { + $header .= ''.&mt($_->{'display'}).''; + } + } else { + $header = + ''.&mt('Username').''; + } + $header .= ''.&mt('Submission').''; + if ($ENV{'form.correctans'} eq 'true') { + $header .= ''.&mt('Correct').''; + } + return $header; +} + +sub html_option { + my ($data)=@_; + $data->{'submission'} = '