--- loncom/interface/statistics/lonproblemanalysis.pm 2004/01/08 19:20:12 1.53 +++ loncom/interface/statistics/lonproblemanalysis.pm 2004/01/16 15:33:40 1.54 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemanalysis.pm,v 1.53 2004/01/08 19:20:12 matthew Exp $ +# $Id: lonproblemanalysis.pm,v 1.54 2004/01/16 15:33:40 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,8 +42,13 @@ my $plotcolors = ['#33ff00', '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66', ]; -my @SubmitButtons = ({ name => 'ProblemAnalyis', +my @SubmitButtons = ({ name => 'PrevProblemAnalysis', + text => 'Previous Problem' }, + { name => 'ProblemAnalysis', text => 'Analyze Problem Again' }, + { name => 'NextProblemAnalysis', + text => 'Next Problem' }, + { name => 'break'}, { name => 'ClearCache', text => 'Clear Caches' }, { name => 'updatecaches', @@ -112,34 +117,57 @@ sub BuildProblemAnalysisPage { if (exists($ENV{'form.problemchoice'}) && ! exists($ENV{'form.SelectAnother'})) { foreach my $button (@SubmitButtons) { - $r->print(''); - $r->print(' 'x5); + if ($button->{'name'} eq 'break') { + $r->print("
\n"); + } else { + $r->print(''); + $r->print(' 'x5); + } } - $r->print(''); # $r->print('
'); - # - my ($symb,$part,$resid,$resptype) = &get_problem_symb( - &Apache::lonnet::unescape($ENV{'form.problemchoice'})); $r->rflush(); # - my $resource = &get_resource_from_symb($symb); - if (! defined($resource) || ! defined($resptype)) { + # Determine which problem we are to analyze + my $current_problem = &get_target_from_id($ENV{'form.problemchoice'}); + # + my ($prev,$curr,$next) = &get_prev_curr_next($current_problem); + if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) { + $current_problem = $prev; + } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) { + $current_problem = $next; + } else { + $current_problem = $curr; + } + # + # Store the current problem choice and send it out in the form + $ENV{'form.problemchoice'} = &make_target_id($current_problem); + $r->print(''); + # + if (! defined($current_problem->{'resource'})) { $r->print('resource is undefined'); } else { + my $resource = $current_problem->{'resource'}; $r->print('

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

'); $r->print('

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

'); $r->print(&render_resource($resource)); $r->rflush(); my %Data = &get_problem_data($resource->{'src'}); - my $ProblemData = $Data{$part.'.'.$resid}; - if ($resptype eq 'option') { - &OptionResponseAnalysis($r,$resource,$resid,$ProblemData, + my $ProblemData = $Data{$current_problem->{'part'}. + '.'. + $current_problem->{'respid'}}; + if ($current_problem->{'resptype'} eq 'option') { + &OptionResponseAnalysis($r,$resource, + $current_problem->{'respid'}, + $ProblemData, \@Students); - } elsif ($resptype eq 'radiobutton') { - &RadioResponseAnalysis($r,$resource,$part,$resid,$ProblemData, + } elsif ($current_problem->{'resptype'} eq 'radiobutton') { + &RadioResponseAnalysis($r,$resource, + $current_problem->{'part'}, + $current_problem->{'respid'}, + $ProblemData, \@Students); } else { $r->print('

This analysis is not supported

'); @@ -355,10 +383,10 @@ sub get_Radio_problem_data { ######################################################### ######################################################### sub OptionResponseAnalysis { - my ($r,$resource,$resid,$ProblemData,$Students) = @_; + my ($r,$resource,$respid,$ProblemData,$Students) = @_; my $PerformanceData = &Apache::loncoursedata::get_response_data - ($Students,$resource->{'symb'},$resid); + ($Students,$resource->{'symb'},$respid); if (! defined($PerformanceData) || ref($PerformanceData) ne 'ARRAY' ) { $r->print('

'. @@ -1491,9 +1519,10 @@ sub ProblemSelector { my $resptype = $partdata->{'ResponseTypes'}->[$i]; if ($resptype eq 'option' ){ # if ($resptype eq 'option' || $resptype eq 'radiobutton') { - my $value = - &Apache::lonnet::escape($res->{'symb'}.':'.$part. - ':'.$respid.':'.$resptype); + my $value = &make_target_id({symb=>$res->{'symb'}, + part=>$part, + respid=>$respid, + resptype=>$resptype}); my $checked = ''; if ($ENV{'form.problemchoice'} eq $value) { $checked = 'checked '; @@ -1533,9 +1562,14 @@ sub ProblemSelector { ######################################################### sub get_problem_symb { my $problemstring = shift(); - my ($symb,$partid,$resid,$resptype) = - ($problemstring=~ /^(.*):([^:]*):([^:]*):([^:]*)$/); - return ($symb,$partid,$resid,$resptype); + &Apache::lonnet::logthis('problemstring = '.$problemstring); + my ($symb,$partid,$respid,$resptype) = split(':',$problemstring); + &Apache::lonnet::logthis("\n". + join(" --- \n",split(':',$problemstring))); + return ({ symb => $symb, + part => $partid, + respid => $respid, + type => $resptype } ); } sub get_resource_from_symb { @@ -1550,6 +1584,100 @@ sub get_resource_from_symb { return undef; } +sub get_prev_curr_next { + my ($target) = @_; + while(my($k,$v) = each(%$target)) { + &Apache::lonnet::logthis($k.' = '.$v); + } + # + # Build an array with the data we need to search through + my @Resource; + foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) { + foreach my $res (@{$seq->{'contents'}}) { + next if ($res->{'type'} ne 'assessment'); + foreach my $part (@{$res->{'parts'}}) { + my $partdata = $res->{'partdata'}->{$part}; + for (my $i=0;$i{'ResponseTypes'}});$i++){ + my $respid = $partdata->{'ResponseIds'}->[$i]; + my $resptype = $partdata->{'ResponseTypes'}->[$i]; + next if ($resptype ne 'option'); + push (@Resource, + { symb => $res->{symb}, + part => $part, + respid => $partdata->{'ResponseIds'}->[$i], + resource => $res, + resptype => $resptype + } ); + } + } + } + } + # + &Apache::lonnet::logthis('size of @Resource = '.scalar(@Resource)); + # + # Get the index of the current situation + my $curr_idx; + for ($curr_idx=0;$curr_idx<$#Resource;$curr_idx++) { + my $curr_item = $Resource[$curr_idx]; + &Apache::lonnet::logthis('-----------------------------------'); + while(my($k,$v) = each(%$curr_item)) { + &Apache::lonnet::logthis($k.' = '.$v); + } + last if ($curr_item->{'symb'} eq $target->{'symb'} && + $curr_item->{'part'} eq $target->{'part'} && + $curr_item->{'respid'} eq $target->{'respid'} && + $curr_item->{'resptype'} eq $target->{'resptype'}); + } + my $curr_item = $Resource[$curr_idx]; + if ($curr_item->{'symb'} ne $target->{'symb'} || + $curr_item->{'part'} ne $target->{'part'} || + $curr_item->{'respid'} ne $target->{'respid'} || + $curr_item->{'resptype'} ne $target->{'resptype'}){ + # bogus symb - return nothing + &Apache::lonnet::logthis('bailing out'); + return (undef,undef,undef); + } + # + # Now just pick up the data we need + my ($prev,$curr,$next); + if ($curr_idx == 0) { + $prev = undef; + $curr = $Resource[$curr_idx ]; + $next = $Resource[$curr_idx+1]; + } elsif ($curr_idx == $#Resource) { + $prev = $Resource[$curr_idx-1]; + $curr = $Resource[$curr_idx ]; + $next = undef; + } else { + $prev = $Resource[$curr_idx-1]; + $curr = $Resource[$curr_idx ]; + $next = $Resource[$curr_idx+1]; + } + return ($prev,$curr,$next); +} + +sub make_target_id { + my ($target) = @_; + my $id = &Apache::lonnet::escape($target->{'symb'}).':'. + &Apache::lonnet::escape($target->{'part'}).':'. + &Apache::lonnet::escape($target->{'respid'}).':'. + &Apache::lonnet::escape($target->{'resptype'}); + return $id; +} + +sub get_target_from_id { + my ($id) = @_; + &Apache::lonnet::logthis('id = '.$id); + my ($symb,$part,$respid,$resptype) = split(':',$id); + &Apache::lonnet::logthis('get_target_from_id:symb='.$symb); + &Apache::lonnet::logthis('get_target_from_id:symb='.$part); + &Apache::lonnet::logthis('get_target_from_id:symb='.$respid); + &Apache::lonnet::logthis('get_target_from_id:symb='.$resptype); + return ({ symb =>&Apache::lonnet::unescape($symb), + part =>&Apache::lonnet::unescape($part), + respid =>&Apache::lonnet::unescape($respid), + resptype =>&Apache::lonnet::unescape($resptype)}); +} ######################################################### #########################################################