Diff for /loncom/interface/statistics/lonproblemanalysis.pm between versions 1.73 and 1.82

version 1.73, 2004/02/20 16:38:49 version 1.82, 2004/03/22 17:25:27
Line 160  sub BuildProblemAnalysisPage { Line 160  sub BuildProblemAnalysisPage {
                                        $ProblemData,                                         $ProblemData,
                                        \@Students);                                         \@Students);
             } elsif ($current_problem->{'resptype'} eq 'numerical') {              } elsif ($current_problem->{'resptype'} eq 'numerical') {
 #                if (exists($ENV{'form.ExcelOutput'})) {                  ## 
                     &Apache::lonstudentsubmissions::prepare_excel_output                  ## analyze all responses of a problem at once
                         ($r,$current_problem,$ProblemData,\@Students);                  my $res = $current_problem->{'resource'};
 #                } else {                  foreach my $partid (@{$res->{'parts'}}) {
 #                    &NumericalResponseAnalysis($r,$current_problem,                      $current_problem->{'part'} = $partid;
 #                                               $ProblemData,\@Students);                      foreach my $respid (@{$res->{'partdata'}->{$partid}->{'ResponseIds'}}) {
 #                }                          $current_problem->{'respid'}=$respid;
                           &NumericalResponseAnalysis($r,$current_problem,
                                                      $ProblemData,\@Students);
                       }
                   }
             } else {              } else {
                 $r->print('<h2>This analysis is not supported</h2>');                  $r->print('<h2>This analysis is not supported</h2>');
             }              }
Line 192  sub BuildProblemAnalysisPage { Line 196  sub BuildProblemAnalysisPage {
 #########################################################  #########################################################
 sub NumericalResponseAnalysis {  sub NumericalResponseAnalysis {
     my ($r,$problem,$ProblemData,$Students) = @_;      my ($r,$problem,$ProblemData,$Students) = @_;
     $r->print('<h2>This analysis is not yet supported</h2>');      my $c = $r->connection();
     my ($resource,$respid) = ($problem->{'resource'},      my ($resource,$partid,$respid) = ($problem->{'resource'},
                               $problem->{'respid'});                                        $problem->{'part'},
                                         $problem->{'respid'});
       #
       if (scalar(@{$resource->{'parts'}})>1) {
           if (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) {
               $r->print('<h3>'.
                         &mt('Part [_1], response [_2].',$partid,$respid).
                         '</h3>');
           } else { 
               $r->print('<h3>'.
                         &mt('Part [_1]',$partid,$respid).
                         '</h3>');
           }
       } elsif (@{$resource->{'partdata'}->{$partid}->{'ResponseIds'}}>1) {
           $r->print('<h3>'.&mt('Response [_1]',$respid).'</h3>');
       }
       #
     my $analysis_html;      my $analysis_html;
     my $PerformanceData =       my $PerformanceData = &Apache::loncoursedata::get_response_data
         &Apache::loncoursedata::get_response_data          (\@Apache::lonstatistics::SelectedSections,
         ($Students,$resource->{'symb'},$respid);           $Apache::lonstatistics::enrollment_status,
            $resource->{'symb'},$respid);
     if (! defined($PerformanceData) ||       if (! defined($PerformanceData) || 
         ref($PerformanceData) ne 'ARRAY' ) {          ref($PerformanceData) ne 'ARRAY' ) {
         $analysis_html = '<h2>'.          $analysis_html = '<h2>'.
Line 207  sub NumericalResponseAnalysis { Line 228  sub NumericalResponseAnalysis {
         $r->print($analysis_html);          $r->print($analysis_html);
         return;          return;
     }      }
     my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);      #
     $r->print('Maximum = '.$max.' Minimum = '.$min);      # This next call causes all the waiting around that people complain about
     my $max_students = 0;      my ($max,$min) = &Apache::lonstathelpers::GetStudentAnswers($r,$problem,
                                                                   $Students);
       return if ($c->aborted());
       #
       # Collate the data
     my %Data;      my %Data;
     foreach my $student (@$Students) {      foreach my $student (@$Students) {
         my $answer = $student->{'answer'};          my $answer = $student->{'answer'};
         $Data{$answer}++;          $Data{$answer}++;
         if ($max_students < $Data{$answer}) {  
             $max_students = $Data{$answer};  
         }  
     }  
     foreach (5,10,20,25,50,75,100,150,200,250,500,1000,1500,2000,2500,5000) {  
         if ($max_students < $_) {  
             $max_students = $_;  
             last;  
         }  
     }      }
     my @Labels = sort {$a <=> $b } keys(%Data);      my @Labels = sort {$a <=> $b } keys(%Data);
     $r->print('number of labels = '.scalar(@Labels));  
     my @PlotData = @Data{@Labels};      my @PlotData = @Data{@Labels};
     $r->print('number of PlotData = '.scalar(@PlotData));      #
     my $graph =       my $width  = 500; 
         &Apache::loncommon::DrawXYGraph('Correct Answer Distribution',      my $height = 100;
                                         'Correct Answer',      my $plot = &one_dimensional_plot($r,500,100,scalar(@$Students),
                                         'Number of students',                                       \@Labels,\@PlotData);
                                         $max_students,      $r->print($plot);
                                         undef,  
                                         \@Labels,  
                                         [\@PlotData],  
                                         (xskip=>10));  
     $r->print($graph);  
     return;      return;
 }  }
   
 sub GetStudentAnswers {  sub one_dimensional_plot {
     my ($r,$problem,$Students) = @_;      my ($r,$width,$height,$N,$Labels,$Data)=@_;
     my %Answers;      #
     my ($resource,$partid,$respid) = ($problem->{'resource'},      # Compute data -> image scaling factors
                                       $problem->{'part'},      my $min = $Labels->[0];
                                       $problem->{'respid'});      my $max = $Labels->[-1];
     # Open progress window      if ($max == $min) {
     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin          $max =$min+1;
         ($r,'Student Answer Compilation Status',      }
          'Student Answer Compilation Progress', scalar(@$Students));      my $h_scale = ($width-10)/($max-$min);
     $r->print("<table>\n");      #
     $r->rflush();      my $max_y = 0;
     foreach my $student (@$Students) {      foreach (@$Data) {
         my $sname = $student->{'username'};          $max_y = $_ if ($max_y < $_);
         my $sdom = $student->{'domain'};      }
         my $answer = &Apache::lonstathelpers::analyze_problem_as_student      my $ticscale = 5;
             ($resource,$sname,$sdom,$partid,$respid);      if ($max_y * $ticscale > $height/2) {
         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,          $ticscale = int($height/2/$max_y);
                                                  &mt('last student'));          $ticscale = 1 if ($ticscale < 1);
         $student->{'answer'} = $answer;      }
     }      #
     $r->print("</table>\n");      # Create the plot
     $r->rflush();      my $plot = 
     # close progress window          qq{<drawimage width="$width" height="$height" bgcolor="transparent" >};
     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);      for (my $idx=0;$idx<scalar(@$Labels);$idx++) {
     return;          my $xloc = 5+$h_scale*($Labels->[$idx] - $min);
           my $top    = $height/2-$Data->[$idx]*$ticscale;
           my $bottom = $height/2+$Data->[$idx]*$ticscale;
           $plot .= 
               &line($xloc,$top,$xloc,$bottom,'888888',1);
       }
       #
       # Put the scale on last to ensure it is on top of the data.
       if ($min < 0 && $max > 0) {
           my $circle_x = 5+$h_scale*abs($min);  # '0' in data coordinates
           my $r = 4;
           $plot .= &line(5,$height/2,$circle_x-$r,$height/2,'000000',1);
           $plot .= &circle($circle_x,$height/2,$r+1,'000000');
           $plot .= &line($circle_x+$r,$height/2,$width-5,$height/2,'000000',1);
       } else {
           $plot .= &line(5,$height/2,$width-5,$height/2,'000000',1);
       }
       $plot .= '</drawimage>';
       my $plotresult =  &Apache::lonxml::xmlparse($r,'web',$plot);
       
       my $title = 'Distribution of correct answers';
       my $result = '<table>'.
           '<tr><td colspan="3" align="center">'.
           '<font size="+2">'.$title.' (N='.$N.')'.
           '</font>'.
           '</td></tr>'.
           '<tr>'.
           '<td valign="center">'.$min.'</td>'.
           '<td>'.$plotresult.'</td>'.
           '<td valign="center">'.$max.'</td>'.
           '</tr>'.
           '<tr><td colspan="3" align="center">'.
           'Maximum Number of Coinciding Values: '.$max_y.
           '</td></tr>'.
           '</table>';
       return $result;
   }
   
   ##
   ## Helper subroutines for <drawimage>.  
   ## These should probably go somewhere more suitable soon.
   sub line {
       my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
       return qq{<line x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" />$/};
   }
   
   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 x="$x" y="$y" color="$color" font="$font" direction="$direction" >$text</text>};
   }
   
   sub rectangle {
       my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
       return qq{<rectangle x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" filled="$filled" />};
   }
   
   sub arc {
       my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_;
       return qq{<arc x="$x" y="$y" width="$width" height="$height" start="$start" end="$end" color="$color" thickness="$thickness" filled="$filled" />};
   }
   
   sub circle {
       my ($x,$y,$radius,$color,$thickness,$filled)=@_;
       return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
 }  }
   
 sub build_student_data_worksheet {  sub build_student_data_worksheet {
Line 308  sub RadioResponseAnalysis { Line 387  sub RadioResponseAnalysis {
     my ($resource,$respid) = ($problem->{'resource'},      my ($resource,$respid) = ($problem->{'resource'},
                               $problem->{'respid'});                                $problem->{'respid'});
     my $analysis_html;      my $analysis_html;
     my $PerformanceData =       my $PerformanceData = &Apache::loncoursedata::get_response_data
         &Apache::loncoursedata::get_response_data          (\@Apache::lonstatistics::SelectedSections,
         ($Students,$resource->{'symb'},$respid);           $Apache::lonstatistics::enrollment_status,
            $resource->{'symb'},$respid);
     if (! defined($PerformanceData) ||       if (! defined($PerformanceData) || 
         ref($PerformanceData) ne 'ARRAY' ) {          ref($PerformanceData) ne 'ARRAY' ) {
         $analysis_html = '<h2>'.          $analysis_html = '<h2>'.
Line 493  sub OptionResponseAnalysis { Line 573  sub OptionResponseAnalysis {
     my ($resource,$respid) = ($problem->{'resource'},      my ($resource,$respid) = ($problem->{'resource'},
                               $problem->{'respid'});                                $problem->{'respid'});
     # Note: part data is not needed.      # Note: part data is not needed.
     my $PerformanceData =       my $PerformanceData = &Apache::loncoursedata::get_response_data
         &Apache::loncoursedata::get_response_data          (\@Apache::lonstatistics::SelectedSections,
         ($Students,$resource->{'symb'},$respid);           $Apache::lonstatistics::enrollment_status,
            $resource->{'symb'},$respid);
     if (! defined($PerformanceData) ||       if (! defined($PerformanceData) || 
         ref($PerformanceData) ne 'ARRAY' ) {          ref($PerformanceData) ne 'ARRAY' ) {
         $r->print('<h2>'.          $r->print('<h2>'.
Line 541  sub OR_tries_analysis { Line 622  sub OR_tries_analysis {
     my $mintries = 1;      my $mintries = 1;
     my $maxtries = $ENV{'form.NumPlots'};      my $maxtries = $ENV{'form.NumPlots'};
     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);      my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
     if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {      if (! defined($Concepts) || 
           ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils'))) {
         $table = '<h3>'.          $table = '<h3>'.
             &mt('Not enough data for concept analysis.  '.              &mt('Not enough data for concept analysis.  '.
                 'Performing Foil Analysis').                  'Performing Foil Analysis').
Line 552  sub OR_tries_analysis { Line 634  sub OR_tries_analysis {
                                                      $mintries,$maxtries);                                                       $mintries,$maxtries);
     my $analysis = '';      my $analysis = '';
     if ($ENV{'form.AnalyzeAs'} eq 'Foils') {      if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
         $analysis = &OR_Tries_Foil_Analysis($mintries,$maxtries,$Foils,          $analysis = &OR_Tries_Foil_Analysis($mintries,$maxtries,$Concepts,
                                          \%ResponseData,$ORdata);                                           \%ResponseData,$ORdata);
     } else {      } else {
         $analysis = &OR_Tries_Concept_Analysis($mintries,$maxtries,          $analysis = &OR_Tries_Concept_Analysis($mintries,$maxtries,
Line 563  sub OR_tries_analysis { Line 645  sub OR_tries_analysis {
 }  }
   
 sub OR_Tries_Foil_Analysis {  sub OR_Tries_Foil_Analysis {
     my ($mintries,$maxtries,$Foils,$respdat,$ORdata) = @_;      my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
     my %ResponseData = %$respdat;      my %ResponseData = %$respdat;
     #      #
     # Compute the data neccessary to make the plots      # Compute the data neccessary to make the plots
     my @PlotData;       my @PlotData; 
     foreach my $foilid (@$Foils) {      foreach my $concept (@$Concepts) {
         for (my $i=$mintries;$i<=$maxtries;$i++) {          foreach my $foilid (@{$concept->{'foils'}}) {
             if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) {              for (my $try=$mintries;$try<=$maxtries;$try++) {
                 push(@{$PlotData[$i]->{'_correct'}},0);                  if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
             } else {                      push(@{$PlotData[$try]->{'_correct'}},0);
                 push(@{$PlotData[$i]->{'_correct'}},  
                      100*$ResponseData{$foilid}->[$i]->{'_correct'}/  
                      $ResponseData{$foilid}->[$i]->{'_total'});  
             }  
             foreach my $option (@{$ORdata->{'_Options'}}) {  
                 push(@{$PlotData[$i]->{'_total'}},  
                      $ResponseData{$foilid}->[$i]->{'_total'});  
                 if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) {  
                     push (@{$PlotData[$i]->{$option}},0);  
                 } else {                  } else {
                     if ($ResponseData{$foilid}->[$i]->{'_total'} ==                      push(@{$PlotData[$try]->{'_correct'}},
                         $ResponseData{$foilid}->[$i]->{'_correct'}) {                           100*$ResponseData{$foilid}->[$try]->{'_correct'}/
                         push(@{$PlotData[$i]->{$option}},0);                           $ResponseData{$foilid}->[$try]->{'_total'});
                   }
                   foreach my $option (@{$ORdata->{'_Options'}}) {
                       push(@{$PlotData[$try]->{'_total'}},
                            $ResponseData{$foilid}->[$try]->{'_total'});
                       if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
                           push (@{$PlotData[$try]->{$option}},0);
                     } else {                      } else {
                         push (@{$PlotData[$i]->{$option}},                          if ($ResponseData{$foilid}->[$try]->{'_total'} ==
                               100 * $ResponseData{$foilid}->[$i]->{$option} /                               $ResponseData{$foilid}->[$try]->{'_correct'}) {
                               ($ResponseData{$foilid}->[$i]->{'_total'} -                               push(@{$PlotData[$try]->{$option}},0);
                                $ResponseData{$foilid}->[$i]->{'_correct'}));                          } else {
                               push (@{$PlotData[$try]->{$option}},
                                     100 * 
                                     $ResponseData{$foilid}->[$try]->{$option} / 
                                     ($ResponseData{$foilid}->[$try]->{'_total'} 
                                      - 
                                      $ResponseData{$foilid}->[$try]->{'_correct'}
                                      ));
                           }
                     }                      }
                 }                  } # End of foreach my $option
             }              }
         }          } # End of foreach my $foilid
     }      } # End of foreach my $concept
     #       # 
     # Build a table for the plots      # Build a table for the plots
     my $analysis_html = "<table>\n";      my $analysis_html = "<table>\n";
     my $foilkey = &build_option_index($ORdata);      my $optionkey = &build_option_index($ORdata);
     for (my $i=$mintries;$i<=$maxtries;$i++) {      for (my $try=$mintries;$try<=$maxtries;$try++) {
         my $count = $ResponseData{'_total'}->[$i];          my $count = $ResponseData{'_total'}->[$try];
         if ($count == 0) {          my $title = 'Submission '.$try.' (N='.$count.')';
             $count = 'no submissions';  
         } elsif ($count == 1) {  
             $count = '1 submission';  
         } else {  
             $count = $count.' submissions';  
         }  
         my $title = 'Attempt '.$i.', '.$count;  
         my @Datasets;          my @Datasets;
         foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {          foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
             next if (! exists($PlotData[$i]->{$option}));              next if (! exists($PlotData[$try]->{$option}));
             push(@Datasets,$PlotData[$i]->{$option});              push(@Datasets,$PlotData[$try]->{$option});
         }          }
           #
           # Put a blank in the data set between concepts
           for (my $set =0;$set<=$#Datasets;$set++) {
               my @Data = @{$Datasets[$set]};
               my $idx = 0;
               foreach my $concept (@{$Concepts}) {
                   foreach my $foilid (@{$concept->{'foils'}}) {
                       $Datasets[$set]->[$idx++]=shift(@Data);
                   }
                   if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
                       $Datasets[$set]->[$idx++] = 0;
                   }
               }
           }
           #
           # Set up the labels needed for the bar graph
           my @Labels;
           my $idx = 1;
           foreach my $concept (@{$Concepts}) {
               foreach my $foilid (@{$concept->{'foils'}}) {
                   push(@Labels,$idx++);
               }
               push(@Labels,'');
           }
           #
         my $correctgraph = &Apache::loncommon::DrawBarGraph          my $correctgraph = &Apache::loncommon::DrawBarGraph
             ($title,'Foil Number','Percent Correct',              ($title,'Foil Number','Percent Correct',
              100,$plotcolors,undef,$Datasets[0]);               100,$plotcolors,\@Labels,$Datasets[0]);
         $analysis_html.= '<tr><td>'.$correctgraph.'</td>';          $analysis_html.= '<tr><td>'.$correctgraph.'</td>';
         ##          
         ##          #
           #
         next if (! defined($Datasets[0]));          next if (! defined($Datasets[0]));
         for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {          for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
             $Datasets[0]->[$i]=0;              $Datasets[0]->[$i]=0;
         }          }
         $count = $ResponseData{'_total'}->[$i]-$ResponseData{'_correct'}->[$i];          $count = $ResponseData{'_total'}->[$try] - 
         if ($count == 0) {                                             $ResponseData{'_correct'}->[$try];
             $count = 'no submissions';          $title = 'Submission '.$try.' (N='.$count.')';
         } elsif ($count == 1) {  
             $count = '1 submission';  
         } else {  
             $count = $count.' submissions';  
         }  
         $title = 'Attempt '.$i.', '.$count;  
         my $incorrectgraph = &Apache::loncommon::DrawBarGraph          my $incorrectgraph = &Apache::loncommon::DrawBarGraph
             ($title,'Foil Number','% Option Chosen Incorrectly',              ($title,'Foil Number','% Option Chosen Incorrectly',
              100,$plotcolors,undef,@Datasets);               100,$plotcolors,\@Labels,@Datasets);
         $analysis_html.= '<td>'.$incorrectgraph.'</td>';          $analysis_html.= '<td>'.$incorrectgraph.'</td>';
         $analysis_html.= '<td>'.$foilkey."<td></tr>\n";          $analysis_html.= '<td>'.$optionkey."<td></tr>\n";
     }      }
     $analysis_html .= "</table>\n";      $analysis_html .= "</table>\n";
     return $analysis_html;      return $analysis_html;
Line 1299  sub CreateInterface { Line 1399  sub CreateInterface {
     ## Build the menu      ## Build the menu
     my $Str = '';      my $Str = '';
     $Str .= &Apache::lonhtmlcommon::breadcrumbs      $Str .= &Apache::lonhtmlcommon::breadcrumbs
         (undef,&mt('Detailed Problem Analysis'));          (undef,'Detailed Problem Analysis');
     $Str .= '<table cellspacing="5">'."\n";      $Str .= '<table cellspacing="5">'."\n";
     $Str .= '<tr>';      $Str .= '<tr>';
     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';      $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';

Removed from v.1.73  
changed lines
  Added in v.1.82


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