Diff for /loncom/interface/statistics/lonproblemanalysis.pm between versions 1.75 and 1.78

version 1.75, 2004/03/11 19:34:10 version 1.78, 2004/03/12 20:29:48
Line 99  sub BuildProblemAnalysisPage { Line 99  sub BuildProblemAnalysisPage {
     }      }
     $r->rflush();      $r->rflush();
     #      #
     my $problem_types = '(option|radiobutton)';      my $problem_types = '(option|radiobutton|numerical)';
     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) {
Line 161  sub BuildProblemAnalysisPage { Line 161  sub BuildProblemAnalysisPage {
                                        \@Students);                                         \@Students);
             } elsif ($current_problem->{'resptype'} eq 'numerical') {              } elsif ($current_problem->{'resptype'} eq 'numerical') {
 #                if (exists($ENV{'form.ExcelOutput'})) {  #                if (exists($ENV{'form.ExcelOutput'})) {
                     &Apache::lonstudentsubmissions::prepare_excel_output  #                    &Apache::lonstudentsubmissions::prepare_excel_output
                         ($r,$current_problem,$ProblemData,\@Students);  #                        ($r,$current_problem,$ProblemData,\@Students);
 #                } else {  #                } else {
 #                    &NumericalResponseAnalysis($r,$current_problem,                      &NumericalResponseAnalysis($r,$current_problem,
 #                                               $ProblemData,\@Students);                                                 $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 192  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 ($resource,$respid) = ($problem->{'resource'},      my ($resource,$respid) = ($problem->{'resource'},
                               $problem->{'respid'});                                $problem->{'respid'});
     my $analysis_html;      my $analysis_html;
Line 207  sub NumericalResponseAnalysis { Line 206  sub NumericalResponseAnalysis {
         $r->print($analysis_html);          $r->print($analysis_html);
         return;          return;
     }      }
       #
       # This next call causes all the waiting around that people complain about
     my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);      my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);
     $r->print('Maximum = '.$max.' Minimum = '.$min);      #
     my $max_students = 0;      # 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 one_dimensional_plot {
       my ($r,$width,$height,$N,$Labels,$Data)=@_;
       #
       # Compute data -> image scaling factors
       my $min = $Labels->[0];
       my $max = $Labels->[-1];
       my $h_scale = ($width-10)/($max-$min);
       #
       my $max_y = 0;
       foreach (@$Data) {
           $max_y = $_ if ($max_y < $_);
       }
       my $ticscale = 5;
       if ($max_y * $ticscale > $height/2) {
           $ticscale = int($height/2/$max_y);
           $ticscale = 1 if ($ticscale < 1);
       }
       #
       # Create the plot
       my $plot = 
           qq{<drawimage width="$width" height="$height" bgcolor="transparent" >};
       for (my $idx=0;$idx<scalar(@$Labels);$idx++) {
           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 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 GetStudentAnswers {  sub GetStudentAnswers {
     my ($r,$problem,$Students) = @_;      my ($r,$problem,$Students) = @_;
     my %Answers;      my %Answers;
Line 541  sub OR_tries_analysis { Line 610  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 570  sub OR_Tries_Foil_Analysis { Line 640  sub OR_Tries_Foil_Analysis {
     my @PlotData;       my @PlotData; 
     foreach my $concept (@$Concepts) {      foreach my $concept (@$Concepts) {
         foreach my $foilid (@{$concept->{'foils'}}) {          foreach my $foilid (@{$concept->{'foils'}}) {
             for (my $i=$mintries;$i<=$maxtries;$i++) {              for (my $try=$mintries;$try<=$maxtries;$try++) {
                 if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) {                  if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
                     push(@{$PlotData[$i]->{'_correct'}},0);                      push(@{$PlotData[$try]->{'_correct'}},0);
                 } else {                  } else {
                     push(@{$PlotData[$i]->{'_correct'}},                      push(@{$PlotData[$try]->{'_correct'}},
                          100*$ResponseData{$foilid}->[$i]->{'_correct'}/                           100*$ResponseData{$foilid}->[$try]->{'_correct'}/
                          $ResponseData{$foilid}->[$i]->{'_total'});                           $ResponseData{$foilid}->[$try]->{'_total'});
                 }                  }
                 foreach my $option (@{$ORdata->{'_Options'}}) {                  foreach my $option (@{$ORdata->{'_Options'}}) {
                     push(@{$PlotData[$i]->{'_total'}},                      push(@{$PlotData[$try]->{'_total'}},
                          $ResponseData{$foilid}->[$i]->{'_total'});                           $ResponseData{$foilid}->[$try]->{'_total'});
                     if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) {                      if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
                         push (@{$PlotData[$i]->{$option}},0);                          push (@{$PlotData[$try]->{$option}},0);
                     } else {                      } else {
                         if ($ResponseData{$foilid}->[$i]->{'_total'} ==                          if ($ResponseData{$foilid}->[$try]->{'_total'} ==
                             $ResponseData{$foilid}->[$i]->{'_correct'}) {                              $ResponseData{$foilid}->[$try]->{'_correct'}) {
                             push(@{$PlotData[$i]->{$option}},0);                              push(@{$PlotData[$try]->{$option}},0);
                         } else {                          } else {
                             push (@{$PlotData[$i]->{$option}},                              push (@{$PlotData[$try]->{$option}},
                               100 * $ResponseData{$foilid}->[$i]->{$option} /                                     100 * 
                               ($ResponseData{$foilid}->[$i]->{'_total'} -                                     $ResponseData{$foilid}->[$try]->{$option} / 
                                $ResponseData{$foilid}->[$i]->{'_correct'}));                                    ($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 $optionkey = &build_option_index($ORdata);      my $optionkey = &build_option_index($ORdata);
     for (my $try=$mintries;$try<=$maxtries;$try++) {      for (my $try=$mintries;$try<=$maxtries;$try++) {
         my $count = $ResponseData{'_total'}->[$try];          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 '.$try.', '.$count;  
         my @Datasets;          my @Datasets;
         foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {          foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
             next if (! exists($PlotData[$try]->{$option}));              next if (! exists($PlotData[$try]->{$option}));
             push(@Datasets,$PlotData[$try]->{$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>';
                   
         #          #
Line 630  sub OR_Tries_Foil_Analysis { Line 721  sub OR_Tries_Foil_Analysis {
         }          }
         $count = $ResponseData{'_total'}->[$try] -           $count = $ResponseData{'_total'}->[$try] - 
                                            $ResponseData{'_correct'}->[$try];                                             $ResponseData{'_correct'}->[$try];
         if ($count == 0) {          $title = 'Submission '.$try.' (N='.$count.')';
             $count = 'no submissions';  
         } elsif ($count == 1) {  
             $count = '1 submission';  
         } else {  
             $count = $count.' submissions';  
         }  
         $title = 'Attempt '.$try.', '.$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>'.$optionkey."<td></tr>\n";          $analysis_html.= '<td>'.$optionkey."<td></tr>\n";
     }      }

Removed from v.1.75  
changed lines
  Added in v.1.78


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