Diff for /loncom/interface/statistics/lonproblemanalysis.pm between versions 1.31 and 1.33

version 1.31, 2003/10/10 21:45:34 version 1.33, 2003/10/13 19:17:42
Line 1 Line 1
 # The LearningOnline Network with CAPA  # The LearningOnline Network with CAPA
 #  #
   
 # $Id$  # $Id$
 #  #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
Line 42  sub BuildProblemAnalysisPage { Line 43  sub BuildProblemAnalysisPage {
     #      #
     my @Students = @Apache::lonstatistics::Students;      my @Students = @Apache::lonstatistics::Students;
     #      #
     if (exists($ENV{'form.problemchoice'}) && !exists($ENV{'SelectAnother'})) {      if (exists($ENV{'form.updatecaches'}) ||
           (exists($ENV{'form.firstanalysis'}) &&
            $ENV{'form.firstanalysis'} ne 'no')) {
           &Apache::lonstatistics::Gather_Full_Student_Data($r);
       }
       if (! exists($ENV{'form.firstanalysis'})) {
           $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
       } else {
           $r->print('<input type="hidden" name="firstanalysis" value="no" />');
       }
       if (exists($ENV{'form.problemchoice'}) && 
           ! exists($ENV{'form.SelectAnother'})) {
         $r->print('<input type="submit" name="ProblemAnalysis" value="'.          $r->print('<input type="submit" name="ProblemAnalysis" value="'.
                   &mt('Analyze Problem Again').'" />');                    &mt('Analyze Problem Again').'" />');
         $r->print('&nbsp;'x5);          $r->print('&nbsp;'x5);
         $r->print('<input type="submit" name="ClearCache" value="'.          $r->print('<input type="submit" name="ClearCache" value="'.
                   &mt('Clear Caches').'" />');                    &mt('Clear Caches').'" />');
         $r->print('&nbsp;'x5);          $r->print('&nbsp;'x5);
           $r->print('<input type="submit" name="updatecaches" value="'.
                     &mt('Update Student Data').'" />');
           $r->print('&nbsp;'x5);
         $r->print('<input type="hidden" name="problemchoice" value="'.          $r->print('<input type="hidden" name="problemchoice" value="'.
                   $ENV{'form.problemchoice'}.'" />');                    $ENV{'form.problemchoice'}.'" />');
         $r->print('<input type="submit" name="SelectAnother" value="'.          $r->print('<input type="submit" name="SelectAnother" value="'.
Line 56  sub BuildProblemAnalysisPage { Line 71  sub BuildProblemAnalysisPage {
         $r->print('&nbsp;'x5);          $r->print('&nbsp;'x5);
         #          #
         $r->print('<hr />');          $r->print('<hr />');
         &Apache::lonstatistics::Gather_Full_Student_Data($r);  
         #          #
         my ($symb,$part,$resid) = &get_problem_symb(          my ($symb,$part,$resid) = &get_problem_symb(
                      &Apache::lonnet::unescape($ENV{'form.problemchoice'})                       &Apache::lonnet::unescape($ENV{'form.problemchoice'})
Line 87  sub BuildProblemAnalysisPage { Line 101  sub BuildProblemAnalysisPage {
             if (defined($PerformanceData) &&               if (defined($PerformanceData) && 
                 ref($PerformanceData) eq 'ARRAY') {                  ref($PerformanceData) eq 'ARRAY') {
                 if ($ENV{'form.AnalyzeBy'} eq 'Tries') {                  if ($ENV{'form.AnalyzeBy'} eq 'Tries') {
                     my $analysis_html = &DoTriesAnalysis($PerformanceData,                      my $analysis_html = &tries_analysis($PerformanceData,
                                                            $ORdata);
                       $r->print($analysis_html);
                   } elsif ($ENV{'form.AnalyzeBy'} eq 'Time') {
                       my $analysis_html = &time_analysis($PerformanceData,
                                                          $ORdata);                                                           $ORdata);
                 $r->print($analysis_html);                  $r->print($analysis_html);
 #                } elsif ($ENV{'form.AnalyzeBy'} eq 'Time') {  
 #                    my $analysis_html = &DoTimeAnalysis($PerformanceData,  
 #                                                         $ORdata);  
 #                $r->print($analysis_html);  
                 } else {                  } else {
                     $r->print('<h2>'.                      $r->print('<h2>'.
                               &mt('The analysis you have selected is '.                                &mt('The analysis you have selected is '.
Line 119  sub BuildProblemAnalysisPage { Line 133  sub BuildProblemAnalysisPage {
 }  }
   
   
 sub DoTriesAnalysis {  #########################################################
     my ($PerformanceData,$ORdata) = @_;  #########################################################
     my $mintries = 1;  ##
     my $maxtries = $ENV{'form.NumPlots'};  ##      Misc interface routines use by analysis code
     my %ResponseData = &analyze_option_data_by_tries($PerformanceData,  ##
                                                  $mintries,$maxtries);  #########################################################
     my @Foils = sort(keys(%ResponseData));  #########################################################
   sub build_foil_index {
       my ($ORdata) = @_;
       my @Foils = sort(keys(%{$ORdata->{'Foiltext'}}));
     my %Row_Label;      my %Row_Label;
     foreach my $foilid (@Foils) {      foreach my $foilid (@Foils) {
         my $value = $ORdata->{'Foiltext'}->{$foilid};          my $value = $ORdata->{'Foiltext'}->{$foilid};
Line 133  sub DoTriesAnalysis { Line 150  sub DoTriesAnalysis {
     }      }
     #      #
     # Build up the table of row labels.      # Build up the table of row labels.
     my @Rows;  
     $Rows[0]= [ '<th>'.&mt('Foil Number').'</th>',   
                 '<th>'.&mt('Foil Text').'</td>'];  
     my $table = '<table border="1" >'."\n";      my $table = '<table border="1" >'."\n";
       $table .= '<tr><th>'.&mt('Foil Number').'</th>'.
           '<th>'.&mt('Foil Text')."</th></tr>\n";
     my $index = 1;      my $index = 1;
     foreach my $foilid (@Foils) {      foreach my $foilid (@Foils) {
         $table .= '<tr><td>'.$index.'</td>'.          $table .= '<tr><td>'.$index.'</td>'.
Line 145  sub DoTriesAnalysis { Line 161  sub DoTriesAnalysis {
         $index++;          $index++;
     }      }
     $table .= "</table>\n";      $table .= "</table>\n";
       return ($table,@Foils);
   }
   
   #########################################################
   #########################################################
   ##
   ##         Tries Analysis
   ##
   #########################################################
   #########################################################
   sub tries_analysis {
       my ($PerformanceData,$ORdata) = @_;
       my $mintries = 1;
       my $maxtries = $ENV{'form.NumPlots'};
       my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
                                                    $mintries,$maxtries);
       my ($table,@Foils) = &build_foil_index($ORdata);
     #      #
     # Compute the data neccessary to make the plots      # Compute the data neccessary to make the plots
     my @PlotData;      my @PlotData;
Line 264  sub analyze_option_data_by_tries { Line 297  sub analyze_option_data_by_tries {
     return %Trydata;      return %Trydata;
 }  }
   
 sub get_problem_symb {  #########################################################
     my $problemstring = shift();  #########################################################
     my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);  ##
     return ($symb,$partid,$resid);  ##                 Time Analysis
   ##
   #########################################################
   #########################################################
   sub time_analysis {
       my ($PerformanceData,$ORdata) = @_;
       my $num_plots = $ENV{'form.NumPlots'};
       my ($table,@Foils) = &build_foil_index($ORdata);
       my ($begin_index,$end_index);
       my $num_data = scalar(@$PerformanceData)-1;
       my $percent = sprintf('%2f',100/$num_plots);
       for (my $i=0;$i<$num_plots;$i++) {
           $begin_index = $i*int($num_data/$num_plots);
           $end_index = ($i+1)*int($num_data/$num_plots);
           my $lownum  = sprintf('%2.1f',$i*$percent);
           $lownum =~ s/(\.0)$//;
           my $highnum = sprintf('%2.1f',($i+1)*$percent);
           $highnum =~ s/(\.0)$//;
           my ($plothtml,$starttime,$endtime,$data) = 
               &analyze_option_data_by_time($PerformanceData,
                                            $begin_index,$end_index,
               $lownum.'% to '.$highnum.'% of submissions',
                                            @Foils);
           $table.=$plothtml;
       }
       return $table;
 }  }
   
   sub analyze_option_data_by_time {
       my ($PerformanceData,$begin_index,$end_index,$description,@Foils) = @_;
       my %TimeData;
       #
       # Get the start and end times for this segment of the plot
       my $starttime = $PerformanceData->[$begin_index]->[2];
       my $endtime   = $PerformanceData->[$end_index  ]->[2];
       #
       # Compute the number getting the foils correct or incorrects
       for (my $i=$begin_index;$i<=$end_index;$i++) {
           my $row = $PerformanceData->[$i];
           next if (! defined($row));
           my ($grading,$submission,$time,$tries) = @$row;
           my @Foilgrades = split('&',$grading);
           my @Foilsubs   = split('&',$submission);
           foreach my $foilgrade (@Foilgrades) {
               my ($foilid,$correct) = split('=',$foilgrade);
               if ($correct) {
                   $TimeData{$foilid}->{'correct'}++;
               } else {
                   $TimeData{$foilid}->{'incorrect'}++;
               }
           }
       }
       #
       # Compute the total and percent correct
       my @Plotdata1;
       my @Plotdata2;
       foreach my $foilid (@Foils) {
           if (! exists($TimeData{$foilid}->{'correct'})) {
               $TimeData{$foilid}->{'correct'} = 0;
           }
           if (! exists($TimeData{$foilid}->{'incorrect'})) {
               $TimeData{$foilid}->{'incorrect'} = 0;
           }
           $TimeData{$foilid}->{'total'} = $TimeData{$foilid}->{'correct'} +
                                   $TimeData{$foilid}->{'incorrect'};
           $TimeData{$foilid}->{'percent_corr'} = 100 *
               $TimeData{$foilid}->{'correct'} / 
               $TimeData{$foilid}->{'total'};
           push (@Plotdata1,    $TimeData{$foilid}->{'percent_corr'});
           push (@Plotdata2,100-$TimeData{$foilid}->{'percent_corr'});
       }
       #
       # Create the plot
       my $graphlink = &Apache::loncommon::DrawGraph
           ($description,#'Time Interval Analysis',
            'Foil Number',
            'Percent Correct / Incorrect',
            100,
            \@Plotdata1,\@Plotdata2);
       $graphlink .= "<br />\n".
           "<b>Start Time</b>: ".localtime($starttime)."<br />\n".
           "<b>End Time</b>: ".localtime($endtime)."<br />\n";
       #
       return ($graphlink,$starttime,$endtime,\%TimeData);
   }
   
   
   
   
   #########################################################
   #########################################################
   ##
   ##             Interface 
   ##
   #########################################################
   #########################################################
 sub CreateInterface {  sub CreateInterface {
     ##      ##
     ## Environment variable initialization      ## Environment variable initialization
Line 330  sub CreateInterface { Line 456  sub CreateInterface {
     if (! exists($ENV{'form.NumPlots'})       if (! exists($ENV{'form.NumPlots'}) 
         || $ENV{'form.NumPlots'} < 1           || $ENV{'form.NumPlots'} < 1 
         || $ENV{'form.NumPlots'} > 20) {          || $ENV{'form.NumPlots'} > 20) {
         $ENV{'form.NumPlots'} = 7;          $ENV{'form.NumPlots'} = 5;
     }      }
     foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {      foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
         $Str .= '<option value="'.$i.'" ';          $Str .= '<option value="'.$i.'" ';
Line 390  sub OptionResponseProblemSelector { Line 516  sub OptionResponseProblemSelector {
     return $Str;      return $Str;
 }  }
   
   #########################################################
   #########################################################
   ##
   ##              Misc functions
   ##
   #########################################################
   #########################################################
   sub get_problem_symb {
       my $problemstring = shift();
       my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);
       return ($symb,$partid,$resid);
   }
   
 sub get_resource_from_symb {  sub get_resource_from_symb {
     my ($symb) = @_;      my ($symb) = @_;
     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {      foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {

Removed from v.1.31  
changed lines
  Added in v.1.33


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