--- loncom/interface/statistics/lonproblemanalysis.pm 2004/03/12 20:29:48 1.78 +++ loncom/interface/statistics/lonproblemanalysis.pm 2004/06/24 18:47:36 1.87 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemanalysis.pm,v 1.78 2004/03/12 20:29:48 matthew Exp $ +# $Id: lonproblemanalysis.pm,v 1.87 2004/06/24 18:47:36 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,10 +51,6 @@ my @SubmitButtons = ({ name => 'PrevProb { name => 'NextProblemAnalysis', text => 'Next Problem' }, { name => 'break'}, - { name => 'ClearCache', - text => 'Clear Caches' }, - { name => 'updatecaches', - text => 'Update Student Data' }, { name => 'SelectAnother', text => 'Choose a different Problem' }, { name => 'ExcelOutput', @@ -81,25 +77,18 @@ sub BuildProblemAnalysisPage { # my @Students = @Apache::lonstatistics::Students; # - if (@Students < 1) { + if (@Students < 1 && exists($ENV{'form.firstrun'})) { $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(); # - my $problem_types = '(option|radiobutton|numerical)'; + # Support for numerical and radio response isn't complete enough to + # include in 1.2 release. + # my $problem_types = '(option|radiobutton|numerical)'; + my $problem_types = '(option)'; if (exists($ENV{'form.problemchoice'}) && ! exists($ENV{'form.SelectAnother'})) { foreach my $button (@SubmitButtons) { @@ -111,6 +100,9 @@ sub BuildProblemAnalysisPage { $r->print(' 'x5); } } + foreach my $html (@CacheButtonHTML) { + $r->print($html.(' 'x5)); + } # $r->print('
'); $r->rflush(); @@ -160,13 +152,17 @@ sub BuildProblemAnalysisPage { $ProblemData, \@Students); } elsif ($current_problem->{'resptype'} eq 'numerical') { -# if (exists($ENV{'form.ExcelOutput'})) { -# &Apache::lonstudentsubmissions::prepare_excel_output -# ($r,$current_problem,$ProblemData,\@Students); -# } else { - &NumericalResponseAnalysis($r,$current_problem, - $ProblemData,\@Students); -# } + ## + ## analyze all responses of a problem at once + my $res = $current_problem->{'resource'}; + foreach my $partid (@{$res->{'parts'}}) { + $current_problem->{'part'} = $partid; + foreach my $respid (@{$res->{'partdata'}->{$partid}->{'ResponseIds'}}) { + $current_problem->{'respid'}=$respid; + &NumericalResponseAnalysis($r,$current_problem, + $ProblemData,\@Students); + } + } } else { $r->print('

This analysis is not supported

'); } @@ -192,12 +188,30 @@ sub BuildProblemAnalysisPage { ######################################################### sub NumericalResponseAnalysis { my ($r,$problem,$ProblemData,$Students) = @_; - my ($resource,$respid) = ($problem->{'resource'}, - $problem->{'respid'}); + my $c = $r->connection(); + my ($resource,$partid,$respid) = ($problem->{'resource'}, + $problem->{'part'}, + $problem->{'respid'}); + # + if (scalar(@{$resource->{'parts'}})>1) { + if (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) { + $r->print('

'. + &mt('Part [_1], response [_2].',$partid,$respid). + '

'); + } else { + $r->print('

'. + &mt('Part [_1]',$partid,$respid). + '

'); + } + } elsif (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) { + $r->print('

'.&mt('Response [_1]',$respid).'

'); + } + # my $analysis_html; - my $PerformanceData = - &Apache::loncoursedata::get_response_data - ($Students,$resource->{'symb'},$respid); + my $PerformanceData = &Apache::loncoursedata::get_response_data + (\@Apache::lonstatistics::SelectedSections, + $Apache::lonstatistics::enrollment_status, + $resource->{'symb'},$respid); if (! defined($PerformanceData) || ref($PerformanceData) ne 'ARRAY' ) { $analysis_html = '

'. @@ -208,7 +222,11 @@ sub NumericalResponseAnalysis { } # # This next call causes all the waiting around that people complain about - my ($max,$min) = &GetStudentAnswers($r,$problem,$Students); + my ($max,$min) = + &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students, + 'Statistics', + 'stats_status'); + return if ($c->aborted()); # # Collate the data my %Data; @@ -233,6 +251,9 @@ sub one_dimensional_plot { # Compute data -> image scaling factors my $min = $Labels->[0]; my $max = $Labels->[-1]; + if ($max == $min) { + $max =$min+1; + } my $h_scale = ($width-10)/($max-$min); # my $max_y = 0; @@ -295,6 +316,17 @@ sub line { return qq{$/}; } +sub text { + my ($x,$y,$color,$text,$font,$direction) = @_; + if (! defined($font) || $font !~ /^(tiny|small|medium|large|giant)$/) { + $font = 'medium'; + } + if (! defined($direction) || $direction ne 'vertical') { + $direction = ''; + } + return qq{$text}; +} + sub rectangle { my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_; return qq{}; @@ -310,34 +342,6 @@ sub circle { return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled); } -sub GetStudentAnswers { - my ($r,$problem,$Students) = @_; - my %Answers; - my ($resource,$partid,$respid) = ($problem->{'resource'}, - $problem->{'part'}, - $problem->{'respid'}); - # Open progress window - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin - ($r,'Student Answer Compilation Status', - 'Student Answer Compilation Progress', scalar(@$Students)); - $r->print("\n"); - $r->rflush(); - foreach my $student (@$Students) { - my $sname = $student->{'username'}; - my $sdom = $student->{'domain'}; - my $answer = &Apache::lonstathelpers::analyze_problem_as_student - ($resource,$sname,$sdom,$partid,$respid); - &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, - &mt('last student')); - $student->{'answer'} = $answer; - } - $r->print("
\n"); - $r->rflush(); - # close progress window - &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); - return; -} - sub build_student_data_worksheet { my ($workbook,$format) = @_; my $rows_output = 3; @@ -377,9 +381,10 @@ sub RadioResponseAnalysis { my ($resource,$respid) = ($problem->{'resource'}, $problem->{'respid'}); my $analysis_html; - my $PerformanceData = - &Apache::loncoursedata::get_response_data - ($Students,$resource->{'symb'},$respid); + my $PerformanceData = &Apache::loncoursedata::get_response_data + (\@Apache::lonstatistics::SelectedSections, + $Apache::lonstatistics::enrollment_status, + $resource->{'symb'},$respid); if (! defined($PerformanceData) || ref($PerformanceData) ne 'ARRAY' ) { $analysis_html = '

'. @@ -562,9 +567,10 @@ sub OptionResponseAnalysis { my ($resource,$respid) = ($problem->{'resource'}, $problem->{'respid'}); # Note: part data is not needed. - my $PerformanceData = - &Apache::loncoursedata::get_response_data - ($Students,$resource->{'symb'},$respid); + my $PerformanceData = &Apache::loncoursedata::get_response_data + (\@Apache::lonstatistics::SelectedSections, + $Apache::lonstatistics::enrollment_status, + $resource->{'symb'},$respid); if (! defined($PerformanceData) || ref($PerformanceData) ne 'ARRAY' ) { $r->print('

'. @@ -1308,18 +1314,18 @@ sub build_foil_index { if (@Concepts > 1) { $table .= ''. ''.$conceptindex.''. - ''.&HTML::Entities::encode($concept->{'name'}).''. + ''.&HTML::Entities::encode($concept->{'name'},'<>&"').''. ''.$foilindex++.''. - ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).''. + ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').''. ''.$Foildata{$firstfoil}->{'text'}.''. - ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).''. + ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').''. "\n"; } else { $table .= ''. ''.$foilindex++.''. - ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).''. + ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').''. ''.$Foildata{$firstfoil}->{'text'}.''. - ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).''. + ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').''. "\n"; } foreach my $foilid (@FoilsInConcept) { @@ -1328,16 +1334,16 @@ sub build_foil_index { ''. ''. ''.$foilindex.''. - ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).''. + ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').''. ''.$Foildata{$foilid}->{'text'}.''. - ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).''. + ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').''. "\n"; } else { $table .= ''. ''.$foilindex.''. - ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).''. + ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').''. ''.$Foildata{$foilid}->{'text'}.''. - ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).''. + ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').''. "\n"; } } continue { @@ -1362,7 +1368,7 @@ sub build_option_index { ''. ''. (' 'x4).''. - ''.&HTML::Entities::encode($option).''. + ''.&HTML::Entities::encode($option,'<>&"').''. "\n"); } shift(@Rows); # Throw away 'correct option chosen' color @@ -1456,7 +1462,7 @@ sub CreateInterface { $Str .= '
'; } { - $Str .= '
'.&mt('Number of Plots:'); + $Str .= ''.&mt('Number of Plots:'); $Str .= &Apache::loncommon::help_open_topic ('Analysis_num_plots'); $Str .= ''; + $Str .= '
'; + } + { + $Str .= ''.&mt('Status: [_1]', + '' + ). + '
'; } } $Str .= '';