Diff for /loncom/interface/statistics/lonproblemanalysis.pm between versions 1.49 and 1.55

version 1.49, 2003/11/11 22:14:28 version 1.55, 2004/01/16 15:35:04
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',
                        text => 'Update Student Data' },                         text => 'Update Student Data' },
                      { name => 'SelectAnother',                       { name => 'SelectAnother',
                        text => 'Choose a different resource' },                         text => 'Choose a different Problem' },
                      { name => 'ExcelOutput',                       { name => 'ExcelOutput',
                        text => 'Produce Excel Output' });                         text => 'Produce Excel Output' });
   
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 1403  sub CreateInterface { Line 1431  sub CreateInterface {
     { # These braces are here to organize the code, not scope it.      { # These braces are here to organize the code, not scope it.
         {          {
             $Str .= '<nobr>'.&mt('Analyze Over ');              $Str .= '<nobr>'.&mt('Analyze Over ');
               $Str .= &Apache::loncommon::help_open_topic
                                                     ('Analysis_Analyze_Over');
             $Str .='<select name="AnalyzeOver" >';              $Str .='<select name="AnalyzeOver" >';
             $Str .= '<option value="Tries" ';              $Str .= '<option value="Tries" ';
             if (! exists($ENV{'form.AnalyzeOver'}) ||               if (! exists($ENV{'form.AnalyzeOver'}) || 
Line 1414  sub CreateInterface { Line 1444  sub CreateInterface {
             $Str .= '<option value="Time" ';              $Str .= '<option value="Time" ';
             $Str .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');              $Str .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');
             $Str .= '>'.&mt('Time').'</option>';              $Str .= '>'.&mt('Time').'</option>';
             $Str .= '</select></nobr><br />';              $Str .= '</select>';
               $Str .= '</nobr><br />';
         }          }
         {          {
             $Str .= '<nobr>'.&mt('Analyze as ');              $Str .= '<nobr>'.&mt('Analyze as ');
               $Str .= &Apache::loncommon::help_open_topic
                                                     ('Analysis_Analyze_as');
             $Str .='<select name="AnalyzeAs" >';              $Str .='<select name="AnalyzeAs" >';
             $Str .= '<option value="Concepts" ';              $Str .= '<option value="Concepts" ';
             if (! exists($ENV{'form.AnalyzeAs'}) ||               if (! exists($ENV{'form.AnalyzeAs'}) || 
Line 1433  sub CreateInterface { Line 1466  sub CreateInterface {
         }          }
         {          {
             $Str .= '<br /><nobr>'.&mt('Number of Plots:');              $Str .= '<br /><nobr>'.&mt('Number of Plots:');
               $Str .= &Apache::loncommon::help_open_topic
                                                     ('Analysis_num_plots');
             $Str .= '<select name="NumPlots">';              $Str .= '<select name="NumPlots">';
             if (! exists($ENV{'form.NumPlots'})               if (! exists($ENV{'form.NumPlots'}) 
                 || $ENV{'form.NumPlots'} < 1                   || $ENV{'form.NumPlots'} < 1 
Line 1484  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 ';
                         }                          }
                           my $title = $res->{'title'};
                           if (! defined($title) || $title eq '') {
                               ($title) = ($res->{'src'} =~ m:/([^/]*)$:);
                           }
                         $seq_str .= '<tr><td>'.                          $seq_str .= '<tr><td>'.
   '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.    '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
   '</td><td>'.    '</td><td>'.
   '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a> ';    '<a href="'.$res->{'src'}.'">'.$title.'</a> ';
 #  '<a href="'.$res->{'src'}.'">'.$resptype.' '.$res->{'title'}.'</a> ';  #  '<a href="'.$res->{'src'}.'">'.$resptype.' '.$res->{'title'}.'</a> ';
                         if ($partdata->{'option'} > 1) {                          if ($partdata->{'option'} > 1) {
                             $seq_str .= &mt('response').' '.$respid;                              $seq_str .= &mt('response').' '.$respid;
Line 1522  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) =       my ($symb,$partid,$respid,$resptype) = split(':',$problemstring);
         ($problemstring=~ /^(.*):([^:]*):([^:]*):([^:]*)$/);      return ({ symb   => $symb,
     return ($symb,$partid,$resid,$resptype);                part   => $partid,
                 respid => $respid,
                 type   => $resptype } );
 }  }
   
 sub get_resource_from_symb {  sub get_resource_from_symb {
Line 1539  sub get_resource_from_symb { Line 1581  sub get_resource_from_symb {
     return undef;      return undef;
 }  }
   
   sub get_prev_curr_next {
       my ($target) = @_;
       #
       # 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
                               } );
                   }
               }
           }
       }
       #
       #
       # 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];
           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
           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) = @_;
       my ($symb,$part,$respid,$resptype) = split(':',$id);
       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.49  
changed lines
  Added in v.1.55


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