--- loncom/interface/statistics/lonproblemanalysis.pm 2003/10/21 21:31:35 1.45 +++ loncom/interface/statistics/lonproblemanalysis.pm 2003/10/24 13:38:06 1.46 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemanalysis.pm,v 1.45 2003/10/21 21:31:35 matthew Exp $ +# $Id: lonproblemanalysis.pm,v 1.46 2003/10/24 13:38:06 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,6 +43,34 @@ my $plotcolors = ['#33ff00', '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66', ]; +my @SubmitButtons = ({ name => 'ProblemAnalyis', + text => 'Analyze Problem Again' }, + { name => 'ClearCache', + text => 'Clear Caches' }, + { name => 'updatecaches', + text => 'Update Student Data' }, + { name => 'SelectAnother', + text => 'Choose a different resource' }, + { name => 'ExcelOutput', + text => 'Produce Excel Output' }); + +sub render_resource { + my ($resource) = @_; + ## + ## Render the problem + my $base; + ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|); + $base = "http://".$ENV{'SERVER_NAME'}.$base; + my $rendered_problem = + &Apache::lonnet::ssi_body($resource->{'src'}); + $rendered_problem =~ s/<\s*form\s*/)|<\/nop>|g; + return '
'. + ''. + $rendered_problem. + '
'; +} + sub BuildProblemAnalysisPage { my ($r,$c)=@_; $r->print('

'.&mt('Option Response Problem Analysis').'

'); @@ -50,6 +78,11 @@ sub BuildProblemAnalysisPage { # my @Students = @Apache::lonstatistics::Students; # + if (@Students < 1) { + $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'}) && @@ -62,94 +95,34 @@ sub BuildProblemAnalysisPage { $r->print(''); } $r->rflush(); + # if (exists($ENV{'form.problemchoice'}) && ! exists($ENV{'form.SelectAnother'})) { - $r->print(''); - $r->print(' 'x5); - $r->print(''); - $r->print(' 'x5); - $r->print(''); - $r->print(' 'x5); + foreach my $button (@SubmitButtons) { + $r->print(''); + $r->print(' 'x5); + } $r->print(''); - $r->print(''); - $r->print(' 'x5); - $r->print(''); - $r->print(' 'x5); # $r->print('
'); # my ($symb,$part,$resid) = &get_problem_symb( - &Apache::lonnet::unescape($ENV{'form.problemchoice'}) - ); + &Apache::lonnet::unescape($ENV{'form.problemchoice'})); $r->rflush(); # my $resource = &get_resource_from_symb($symb); - if (defined($resource)) { + if (! defined($resource)) { + $r->print('resource is undefined'); + } else { $r->print('

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

'); $r->print('

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

'); $r->rflush(); my %Data = &get_problem_data($resource->{'src'}); - my $PerformanceData = - &Apache::loncoursedata::get_optionresponse_data - (\@Students,$symb,$resid); - my $ORdata = $Data{$part.'.'.$resid}; - if (exists($ENV{'form.ExcelOutput'}) && - defined($PerformanceData)) { - my $result = &prepare_excel_sheet($r,$resource, - $PerformanceData,$ORdata); - $r->print($result); - $r->rflush(); - } - ## - ## Render the problem - my $base; - ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|); - $base = "http://".$ENV{'SERVER_NAME'}.$base; - my $rendered_problem = - &Apache::lonnet::ssi_body($resource->{'src'}); - $rendered_problem =~ s/<\s*form\s*/)|<\/nop>|g; - $r->print('
'. - ''. - $rendered_problem. - '
'); - $r->rflush(); - if (! exists($ENV{'form.ExcelOutput'})) { - ## - ## Analyze the problem - if (defined($PerformanceData) && - ref($PerformanceData) eq 'ARRAY') { - if ($ENV{'form.AnalyzeOver'} eq 'Tries') { - my $analysis_html = &tries_analysis($r, - $PerformanceData, - $ORdata); - $r->print($analysis_html); - $r->rflush(); - } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') { - my $analysis_html = &time_analysis($PerformanceData, - $ORdata); - $r->print($analysis_html); - $r->rflush(); - } else { - $r->print('

'. - &mt('The analysis you have selected is '. - 'not supported at this time'). - '

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

'. - &mt('There is no student data for this problem.'). - '

'); - } - } - } else { - $r->print('resource is undefined'); + my $ProblemData = $Data{$part.'.'.$resid}; + &OptionResponseAnalysis($r,$resource,$resid,$ProblemData, + \@Students); } $r->print('
'); } else { @@ -157,154 +130,63 @@ sub BuildProblemAnalysisPage { &mt('Analyze Problem').'" />'); $r->print(' 'x5); $r->print('

'.&mt('Please select a problem to analyze').'

'); - $r->print(&OptionResponseProblemSelector()); + $r->print(&ProblemSelector()); } } ######################################################### ######################################################### ## -## Misc interface routines use by analysis code +## Option Response Routines ## ######################################################### ######################################################### -sub build_foil_index { - my ($ORdata) = @_; - return if (! exists($ORdata->{'Foils'})); - my %Foildata = %{$ORdata->{'Foils'}}; - my @Foils = sort(keys(%Foildata)); - my %Concepts; - foreach my $foilid (@Foils) { - push(@{$Concepts{$Foildata{$foilid}->{'Concept'}}}, - $foilid); - } - undef(@Foils); - # Having gathered the concept information in a hash, we now translate it - # into an array because we need to be consistent about order. - # Also put the foils in order, too. - my $sortfunction = sub { - my %Numbers = (one => 1, - two => 2, - three => 3, - four => 4, - five => 5, - six => 6, - seven => 7, - eight => 8, - nine => 9, - ten => 10,); - my $a1 = lc($a); - my $b1 = lc($b); - if (exists($Numbers{$a})) { - $a1 = $Numbers{$a}; - } - if (exists($Numbers{$b})) { - $b1 = $Numbers{$b}; - } - $a1 cmp $b1; - }; - my @Concepts; - foreach my $concept (sort $sortfunction (keys(%Concepts))) { - push(@Concepts,{ name => $concept, - foils => [@{$Concepts{$concept}}]}); - push(@Foils,(@{$Concepts{$concept}})); - } - # - # Build up the table of row labels. - my $table = ''."\n"; - if (@Concepts > 1) { - $table .= ''. - ''. - ''. - ''. - ''. - ''. - ''. - "\n"; - } else { - $table .= ''. - ''. - ''. - ''. - ''. - "\n"; - } - my $conceptindex = 1; - my $foilindex = 1; - foreach my $concept (@Concepts) { - my @FoilsInConcept = @{$concept->{'foils'}}; - my $firstfoil = shift(@FoilsInConcept); - if (@Concepts > 1) { - $table .= ''. - ''. - ''. - ''. - ''. - ''. - ''. - "\n"; +sub OptionResponseAnalysis { + my ($r,$resource,$resid,$ProblemData,$Students) = @_; + &Apache::lonnet::logthis('resid = '.$resid); + my $PerformanceData = + &Apache::loncoursedata::get_optionresponse_data + ($Students,$resource->{'symb'},$resid); + if (! defined($PerformanceData) || + ref($PerformanceData) ne 'ARRAY' ) { + $r->print('

'. + &mt('There is no student data for this problem.'). + '

'); + } else { + $r->print(&render_resource($resource)); + $r->rflush(); + if (exists($ENV{'form.ExcelOutput'})) { + my $result = &prepare_optionresponse_excel_sheet($r,$resource, + $PerformanceData, + $ProblemData); + $r->print($result); + $r->rflush(); } else { - $table .= ''. - ''. - ''. - ''. - ''. - "\n"; - } - foreach my $foilid (@FoilsInConcept) { - if (@Concepts > 1) { - $table .= ''. - ''. - ''. - ''. - ''. - ''. - ''. - "\n"; + if ($ENV{'form.AnalyzeOver'} eq 'Tries') { + my $analysis_html = &tries_analysis($r, + $PerformanceData, + $ProblemData); + $r->print($analysis_html); + $r->rflush(); + } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') { + my $analysis_html = &time_analysis($PerformanceData, + $ProblemData); + $r->print($analysis_html); + $r->rflush(); } else { - $table .= ''. - ''. - ''. - ''. - ''. - "\n"; - } - } continue { - $foilindex++; + $r->print('

'. + &mt('The analysis you have selected is '. + 'not supported at this time'). + '

'); + } } - } continue { - $conceptindex++; - } - $table .= "
'.&mt('Concept Number').''.&mt('Concept').''.&mt('Foil Number').''.&mt('Foil Name').''.&mt('Foil Text').''.&mt('Correct Value').'
'.&mt('Foil Number').''.&mt('Foil Name').''.&mt('Foil Text').''.&mt('Correct Value').'
'.$conceptindex.''.$concept->{'name'}.''.$foilindex++.''.$Foildata{$firstfoil}->{'name'}.''.$Foildata{$firstfoil}->{'text'}.''.$Foildata{$firstfoil}->{'value'}.'
'.$foilindex++.''.$Foildata{$firstfoil}->{'name'}.''.$Foildata{$firstfoil}->{'text'}.''.$Foildata{$firstfoil}->{'value'}.'
'.$foilindex.''.$Foildata{$foilid}->{'name'}.''.$Foildata{$foilid}->{'text'}.''.$Foildata{$foilid}->{'value'}.'
'.$foilindex.''.$Foildata{$foilid}->{'name'}.''.$Foildata{$foilid}->{'text'}.''.$Foildata{$foilid}->{'value'}.'
\n"; - # - # Build option index with color stuff - return ($table,\@Foils,\@Concepts); -} - -sub build_option_index { - my ($ORdata)= @_; - my $table = "\n"; - my $optionindex = 0; - my @Rows; - foreach my $option (&mt('correct option chosen'),@{$ORdata->{'Options'}}) { - push (@Rows, - ''. - ''. - ''. - "\n"); } - shift(@Rows); # Throw away 'correct option chosen' color - $table .= join('',reverse(@Rows)); - $table .= "
'. - (' 'x4).''.$option.'
\n"; } ######################################################### -######################################################### -## -## Tries Analysis -## -######################################################### +# +# Option Response: Tries Analysis +# ######################################################### sub tries_analysis { my ($r,$PerformanceData,$ORdata) = @_; @@ -385,7 +267,7 @@ sub Tries_Foil_Analysis { next if (! exists($PlotData[$i]->{$option})); push(@Datasets,$PlotData[$i]->{$option}); } - my $correctgraph = &Apache::loncommon::DrawGraph + my $correctgraph = &Apache::loncommon::DrawBarGraph ($title,'Foil Number','Percent Correct', 100,$plotcolors,$Datasets[0]); $analysis_html.= ''.$correctgraph.''; @@ -403,7 +285,7 @@ sub Tries_Foil_Analysis { $count = $count.' submissions'; } $title = 'Attempt '.$i.', '.$count; - my $incorrectgraph = &Apache::loncommon::DrawGraph + my $incorrectgraph = &Apache::loncommon::DrawBarGraph ($title,'Foil Number','% Option Chosen Incorrectly', 100,$plotcolors,@Datasets); $analysis_html.= ''.$incorrectgraph.''; @@ -470,7 +352,7 @@ sub Tries_Concept_Analysis { $count = $count.' submissions'; } $title = 'Attempt '.$i.', '.$count; - my $graphlink = &Apache::loncommon::DrawGraph + my $graphlink = &Apache::loncommon::DrawBarGraph ($title,'Concept Number','Percent Correct', 100,$plotcolors,$PlotData[$i]->{'_correct'}); $analysis_html.= ''.$graphlink."\n"; @@ -486,8 +368,8 @@ sub analyze_option_data_by_tries { $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries); foreach my $row (@$PerformanceData) { next if (! defined($row)); - my $tries = &get_tries_from_row($row); - my %Row = &Process_Row($row); + my $tries = &get_tries_from_OR_row($row); + my %Row = &Process_OR_Row($row); next if (! %Row); while (my ($foilid,$href) = each(%Row)) { if (! ref($href)) { @@ -503,11 +385,9 @@ sub analyze_option_data_by_tries { } ######################################################### -######################################################### -## -## Time Analysis -## -######################################################### +# +# Option Response: Time Analysis +# ######################################################### sub time_analysis { my ($PerformanceData,$ORdata) = @_; @@ -532,14 +412,14 @@ sub time_analysis { ('enddate_'.$i); if (! defined($starttime) || ! defined($endtime)) { my $sec_in_day = 86400; - my $last_sub_time = &get_time_from_row($PerformanceData->[-1]); + my $last_sub_time = &get_time_from_OR_row($PerformanceData->[-1]); my ($sday,$smon,$syear); (undef,undef,undef,$sday,$smon,$syear) = localtime($last_sub_time - $sec_in_day*$i); $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear); $endtime = $starttime + $sec_in_day; if ($i == ($num_plots -1 )) { - $starttime = &get_time_from_row($PerformanceData->[0]); + $starttime = &get_time_from_OR_row($PerformanceData->[0]); } } my $startdateform = &Apache::lonhtmlcommon::date_setter @@ -551,11 +431,12 @@ sub time_analysis { my $end_index; my $j; while (++$j < scalar(@$PerformanceData)) { - last if (&get_time_from_row($PerformanceData->[$j]) > $starttime); + last if (&get_time_from_OR_row($PerformanceData->[$j]) + > $starttime); } $begin_index = $j; while (++$j < scalar(@$PerformanceData)) { - last if (&get_time_from_row($PerformanceData->[$j]) > $endtime); + last if (&get_time_from_OR_row($PerformanceData->[$j]) > $endtime); } $end_index = $j; ## @@ -589,7 +470,7 @@ sub Foil_Time_Analysis { for (my $j=$begin_index;$j<=$end_index;$j++) { my $row = $PerformanceData->[$j]; next if (! defined($row)); - my %Row = &Process_Row($row); + my %Row = &Process_OR_Row($row); while (my ($foilid,$href) = each(%Row)) { if (! ref($href)) { $TimeData{$foilid} += $href; @@ -633,12 +514,12 @@ sub Foil_Time_Analysis { } else { $title = $count.' submissions'; } - my $correctplot = &Apache::loncommon::DrawGraph($title, - 'Foil Number', - 'Percent Correct', - 100, - $plotcolors, - $Plotdata[0]); + my $correctplot = &Apache::loncommon::DrawBarGraph($title, + 'Foil Number', + 'Percent Correct', + 100, + $plotcolors, + $Plotdata[0]); for (my $j=0; $j< scalar(@{$Plotdata[0]});$j++) { $Plotdata[0]->[$j]=0; } @@ -650,7 +531,7 @@ sub Foil_Time_Analysis { } else { $title = $count.' submissions'; } - my $incorrectplot = &Apache::loncommon::DrawGraph($title, + my $incorrectplot = &Apache::loncommon::DrawBarGraph($title, 'Foil Number', 'Incorrect Option Choice', 100, @@ -685,7 +566,7 @@ sub Concept_Time_Analysis { for (my $j=$begin_index;$j<=$end_index;$j++) { my $row = $PerformanceData->[$j]; next if (! defined($row)); - my %Row = &Process_Row($row); + my %Row = &Process_OR_Row($row); while (my ($foilid,$href) = each(%Row)) { if (! ref($href)) { $TimeData{$foilid} += $href; @@ -714,7 +595,7 @@ sub Concept_Time_Analysis { # # Create the plot my $title = ($end_index - $begin_index).' submissions'; - my $correctplot = &Apache::loncommon::DrawGraph($title, + my $correctplot = &Apache::loncommon::DrawBarGraph($title, 'Concept Number', 'Percent Correct', 100, @@ -740,7 +621,7 @@ sub Concept_Time_Analysis { ## ######################################################### ######################################################### -sub prepare_excel_sheet { +sub prepare_optionresponse_excel_sheet { my ($r,$resource,$PerformanceData,$ORdata) = @_; my $response = ''; my (undef,$Foils,$Concepts) = &build_foil_index($ORdata); @@ -1130,10 +1011,141 @@ sub _adjustment { return $adjust; } +sub build_foil_index { + my ($ORdata) = @_; + return if (! exists($ORdata->{'Foils'})); + my %Foildata = %{$ORdata->{'Foils'}}; + my @Foils = sort(keys(%Foildata)); + my %Concepts; + foreach my $foilid (@Foils) { + push(@{$Concepts{$Foildata{$foilid}->{'Concept'}}}, + $foilid); + } + undef(@Foils); + # Having gathered the concept information in a hash, we now translate it + # into an array because we need to be consistent about order. + # Also put the foils in order, too. + my $sortfunction = sub { + my %Numbers = (one => 1, + two => 2, + three => 3, + four => 4, + five => 5, + six => 6, + seven => 7, + eight => 8, + nine => 9, + ten => 10,); + my $a1 = lc($a); + my $b1 = lc($b); + if (exists($Numbers{$a})) { + $a1 = $Numbers{$a}; + } + if (exists($Numbers{$b})) { + $b1 = $Numbers{$b}; + } + $a1 cmp $b1; + }; + my @Concepts; + foreach my $concept (sort $sortfunction (keys(%Concepts))) { + push(@Concepts,{ name => $concept, + foils => [@{$Concepts{$concept}}]}); + push(@Foils,(@{$Concepts{$concept}})); + } + # + # Build up the table of row labels. + my $table = ''."\n"; + if (@Concepts > 1) { + $table .= ''. + ''. + ''. + ''. + ''. + ''. + ''. + "\n"; + } else { + $table .= ''. + ''. + ''. + ''. + ''. + "\n"; + } + my $conceptindex = 1; + my $foilindex = 1; + foreach my $concept (@Concepts) { + my @FoilsInConcept = @{$concept->{'foils'}}; + my $firstfoil = shift(@FoilsInConcept); + if (@Concepts > 1) { + $table .= ''. + ''. + ''. + ''. + ''. + ''. + ''. + "\n"; + } else { + $table .= ''. + ''. + ''. + ''. + ''. + "\n"; + } + foreach my $foilid (@FoilsInConcept) { + if (@Concepts > 1) { + $table .= ''. + ''. + ''. + ''. + ''. + ''. + ''. + "\n"; + } else { + $table .= ''. + ''. + ''. + ''. + ''. + "\n"; + } + } continue { + $foilindex++; + } + } continue { + $conceptindex++; + } + $table .= "
'.&mt('Concept Number').''.&mt('Concept').''.&mt('Foil Number').''.&mt('Foil Name').''.&mt('Foil Text').''.&mt('Correct Value').'
'.&mt('Foil Number').''.&mt('Foil Name').''.&mt('Foil Text').''.&mt('Correct Value').'
'.$conceptindex.''.$concept->{'name'}.''.$foilindex++.''.$Foildata{$firstfoil}->{'name'}.''.$Foildata{$firstfoil}->{'text'}.''.$Foildata{$firstfoil}->{'value'}.'
'.$foilindex++.''.$Foildata{$firstfoil}->{'name'}.''.$Foildata{$firstfoil}->{'text'}.''.$Foildata{$firstfoil}->{'value'}.'
'.$foilindex.''.$Foildata{$foilid}->{'name'}.''.$Foildata{$foilid}->{'text'}.''.$Foildata{$foilid}->{'value'}.'
'.$foilindex.''.$Foildata{$foilid}->{'name'}.''.$Foildata{$foilid}->{'text'}.''.$Foildata{$foilid}->{'value'}.'
\n"; + # + # Build option index with color stuff + return ($table,\@Foils,\@Concepts); +} + +sub build_option_index { + my ($ORdata)= @_; + my $table = "\n"; + my $optionindex = 0; + my @Rows; + foreach my $option (&mt('correct option chosen'),@{$ORdata->{'Options'}}) { + push (@Rows, + ''. + ''. + ''. + "\n"); + } + shift(@Rows); # Throw away 'correct option chosen' color + $table .= join('',reverse(@Rows)); + $table .= "
'. + (' 'x4).''.$option.'
\n"; +} + ######################################################### ######################################################### ## -## Interface +## Generic Interface Routines ## ######################################################### ######################################################### @@ -1232,7 +1244,7 @@ sub CreateInterface { return $Str; } -sub OptionResponseProblemSelector { +sub ProblemSelector { my $Str; $Str = "\n\n"; foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) { @@ -1301,7 +1313,7 @@ sub get_resource_from_symb { return undef; } -sub get_time_from_row { +sub get_time_from_OR_row { my ($row) = @_; if (ref($row)) { return $row->[4]; @@ -1309,7 +1321,7 @@ sub get_time_from_row { return undef; } -sub get_tries_from_row { +sub get_tries_from_OR_row { my ($row) = @_; if (ref($row)) { return $row->[5]; @@ -1317,7 +1329,7 @@ sub get_tries_from_row { return undef; } -sub Process_Row { +sub Process_OR_Row { my ($row) = @_; my %RowData; my ($student_id,$award,$grading,$submission,$time,$tries) = @$row;