Diff for /loncom/interface/statistics/lonproblemanalysis.pm between versions 1.53 and 1.54

version 1.53, 2004/01/08 19:20:12 version 1.54, 2004/01/16 15:33:40
Line 42  my $plotcolors = ['#33ff00', Line 42  my $plotcolors = ['#33ff00',
                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',                    '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   ];                     ]; 
   
 my @SubmitButtons = ({ name => 'ProblemAnalyis',  my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
                          text => 'Previous Problem' },
                        { name => 'ProblemAnalysis',
                        text => 'Analyze Problem Again' },                         text => 'Analyze Problem Again' },
                        { name => 'NextProblemAnalysis',
                          text => 'Next Problem' },
                        { name => 'break'},
                      { name => 'ClearCache',                       { name => 'ClearCache',
                        text => 'Clear Caches' },                         text => 'Clear Caches' },
                      { name => 'updatecaches',                       { name => 'updatecaches',
Line 112  sub BuildProblemAnalysisPage { Line 117  sub BuildProblemAnalysisPage {
     if (exists($ENV{'form.problemchoice'}) &&       if (exists($ENV{'form.problemchoice'}) && 
         ! exists($ENV{'form.SelectAnother'})) {          ! exists($ENV{'form.SelectAnother'})) {
         foreach my $button (@SubmitButtons) {          foreach my $button (@SubmitButtons) {
             $r->print('<input type="submit" name="'.$button->{'name'}.'" '.              if ($button->{'name'} eq 'break') {
                       'value="'.&mt($button->{'text'}).'" />');                  $r->print("<br />\n");
             $r->print('&nbsp;'x5);              } else {
                   $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
                             'value="'.&mt($button->{'text'}).'" />');
                   $r->print('&nbsp;'x5);
               }
         }          }
         $r->print('<input type="hidden" name="problemchoice" value="'.  
                   $ENV{'form.problemchoice'}.'" />');  
         #          #
         $r->print('<hr />');          $r->print('<hr />');
         #  
         my ($symb,$part,$resid,$resptype) = &get_problem_symb(  
                   &Apache::lonnet::unescape($ENV{'form.problemchoice'}));  
         $r->rflush();          $r->rflush();
         #          #
         my $resource = &get_resource_from_symb($symb);          # Determine which problem we are to analyze
         if (! defined($resource) || ! defined($resptype)) {          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('<input type="hidden" name="problemchoice" value="'.
                     $ENV{'form.problemchoice'}.'" />');
           #
           if (! defined($current_problem->{'resource'})) {
             $r->print('resource is undefined');              $r->print('resource is undefined');
         } else {          } else {
               my $resource = $current_problem->{'resource'};
             $r->print('<h1>'.$resource->{'title'}.'</h1>');              $r->print('<h1>'.$resource->{'title'}.'</h1>');
             $r->print('<h3>'.$resource->{'src'}.'</h3>');              $r->print('<h3>'.$resource->{'src'}.'</h3>');
             $r->print(&render_resource($resource));              $r->print(&render_resource($resource));
             $r->rflush();              $r->rflush();
             my %Data = &get_problem_data($resource->{'src'});              my %Data = &get_problem_data($resource->{'src'});
             my $ProblemData = $Data{$part.'.'.$resid};              my $ProblemData = $Data{$current_problem->{'part'}.
             if ($resptype eq 'option') {                                      '.'.
                 &OptionResponseAnalysis($r,$resource,$resid,$ProblemData,                                      $current_problem->{'respid'}};
               if ($current_problem->{'resptype'} eq 'option') {
                   &OptionResponseAnalysis($r,$resource,
                                           $current_problem->{'respid'},
                                           $ProblemData,
                                         \@Students);                                          \@Students);
             } elsif ($resptype eq 'radiobutton') {              } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
                 &RadioResponseAnalysis($r,$resource,$part,$resid,$ProblemData,                  &RadioResponseAnalysis($r,$resource,
                                          $current_problem->{'part'},
                                          $current_problem->{'respid'},
                                          $ProblemData,
                                        \@Students);                                         \@Students);
             } else {              } else {
                 $r->print('<h2>This analysis is not supported</h2>');                  $r->print('<h2>This analysis is not supported</h2>');
Line 355  sub get_Radio_problem_data { Line 383  sub get_Radio_problem_data {
 #########################################################  #########################################################
 #########################################################  #########################################################
 sub OptionResponseAnalysis {  sub OptionResponseAnalysis {
     my ($r,$resource,$resid,$ProblemData,$Students) = @_;      my ($r,$resource,$respid,$ProblemData,$Students) = @_;
     my $PerformanceData =       my $PerformanceData = 
         &Apache::loncoursedata::get_response_data          &Apache::loncoursedata::get_response_data
         ($Students,$resource->{'symb'},$resid);          ($Students,$resource->{'symb'},$respid);
     if (! defined($PerformanceData) ||       if (! defined($PerformanceData) || 
         ref($PerformanceData) ne 'ARRAY' ) {          ref($PerformanceData) ne 'ARRAY' ) {
         $r->print('<h2>'.          $r->print('<h2>'.
Line 1491  sub ProblemSelector { Line 1519  sub ProblemSelector {
                     my $resptype = $partdata->{'ResponseTypes'}->[$i];                      my $resptype = $partdata->{'ResponseTypes'}->[$i];
                     if ($resptype eq 'option' ){                      if ($resptype eq 'option' ){
 #                    if ($resptype eq 'option' || $resptype eq 'radiobutton') {  #                    if ($resptype eq 'option' || $resptype eq 'radiobutton') {
                         my $value =                           my $value = &make_target_id({symb=>$res->{'symb'},
                             &Apache::lonnet::escape($res->{'symb'}.':'.$part.                                                       part=>$part,
                                                     ':'.$respid.':'.$resptype);                                                       respid=>$respid,
                                                        resptype=>$resptype});
                         my $checked = '';                          my $checked = '';
                         if ($ENV{'form.problemchoice'} eq $value) {                          if ($ENV{'form.problemchoice'} eq $value) {
                             $checked = 'checked ';                              $checked = 'checked ';
Line 1533  sub ProblemSelector { Line 1562  sub ProblemSelector {
 #########################################################  #########################################################
 sub get_problem_symb {  sub get_problem_symb {
     my $problemstring = shift();      my $problemstring = shift();
     my ($symb,$partid,$resid,$resptype) =       &Apache::lonnet::logthis('problemstring = '.$problemstring);
         ($problemstring=~ /^(.*):([^:]*):([^:]*):([^:]*)$/);      my ($symb,$partid,$respid,$resptype) = split(':',$problemstring);
     return ($symb,$partid,$resid,$resptype);      &Apache::lonnet::logthis("\n".
                                join("   ---   \n",split(':',$problemstring)));
       return ({ symb   => $symb,
                 part   => $partid,
                 respid => $respid,
                 type   => $resptype } );
 }  }
   
 sub get_resource_from_symb {  sub get_resource_from_symb {
Line 1550  sub get_resource_from_symb { Line 1584  sub get_resource_from_symb {
     return undef;      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<scalar(@{$partdata->{'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)});
   }
   
 #########################################################  #########################################################
 #########################################################  #########################################################

Removed from v.1.53  
changed lines
  Added in v.1.54


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>