Diff for /loncom/interface/statistics/lonproblemstatistics.pm between versions 1.82 and 1.87

version 1.82, 2004/04/01 22:13:39 version 1.87, 2004/06/04 21:42:18
Line 55  use Apache::loncommon(); Line 55  use Apache::loncommon();
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
 use Apache::loncoursedata;  use Apache::loncoursedata;
 use Apache::lonstatistics;  use Apache::lonstatistics;
   use LONCAPA::lonmetadata();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Spreadsheet::WriteExcel;  use Spreadsheet::WriteExcel;
 use Apache::lonstathelpers();  use Apache::lonstathelpers();
Line 95  my %SeqStat;    # keys are symbs, values Line 96  my %SeqStat;    # keys are symbs, values
 ##                                      statistics display?  ##                                      statistics display?
 ## selected        yes     (yes|no)     Is the column selected by default?  ## selected        yes     (yes|no)     Is the column selected by default?
 ##  ##
   ## format          no      sprintf format string
   ##
   ## excel_format    no      excel format type 
   ##                               (see &Apache::loncommon::define_excel_formats
 my @Fields = (  my @Fields = (
            { name => 'problem_num',             { name => 'problem_num',
              title => 'P#',               title => 'P#',
Line 260  my @Fields = ( Line 265  my @Fields = (
              selectable => 'yes',               selectable => 'yes',
              defaultselected => 'no',               defaultselected => 'no',
            },             },
   ##   duedate included for research purposes.  Commented out most of the time.
   #           { name => 'duedate',
   #             title => 'Due Date',
   #             align => 'left',
   #             color => '#FFFFFF',
   #             sortable => 'yes',
   #             graphable => 'no',
   #             long_title => 'Due date of resource for instructor',
   #             selectable => 'no',
   #             defaultselected => 'yes',
   #            },
   ##   opendate included for research purposes.  Commented out most of the time.
   #           { name => 'opendate',
   #             title => 'Open Date',
   #             align => 'left',
   #             color => '#FFFFFF',
   #             sortable => 'yes',
   #             graphable => 'no',
   #             long_title => 'date resource became answerable',
   #             selectable => 'no',
   #             defaultselected => 'yes',
   #            },
   ##   symb included for research purposes.  Commented out most of the time.
   #           { name => 'symb',
   #             title => 'Symb',
   #             align => 'left',
   #             color => '#FFFFFF',
   #             sortable => 'yes',
   #             graphable => 'no',
   #             long_title => 'Unique LON-CAPA identifier for problem',
   #             selectable => 'no',
   #             defaultselected => 'yes',
   #            },
   ##   resptypes included for research purposes.  Commented out most of the time.
   #           { name => 'resptypes',
   #             title => 'Response Types',
   #             align => 'left',
   #             color => '#FFFFFF',
   #             sortable => 'no',
   #             graphable => 'no',
   #             long_title => 'Response Types used in this problem',
   #             selectable => 'no',
   #             defaultselected => 'yes',
   #            },
 );  );
   
 my @SeqFields = (  my @SeqFields = (
Line 498  select sections, maps, and output. Line 547  select sections, maps, and output.
 ###############################################  ###############################################
 ###############################################  ###############################################
 sub CreateInterface {  sub CreateInterface {
       my ($r) = @_;
     #      #
     &parse_field_selection();      &parse_field_selection();
     #      #
Line 533  sub CreateInterface { Line 583  sub CreateInterface {
     $Str .= '</td><td>'.&field_selection_input();      $Str .= '</td><td>'.&field_selection_input();
     $Str .= '</td></tr>'."\n";      $Str .= '</td></tr>'."\n";
     $Str .= '</table>'."\n";      $Str .= '</table>'."\n";
       #
       $Str .= '<p>'.&mt('Status: [_1]',
                            '<input type="text" '.
                            'name="stats_status" size="60" value="" />'
                            ).
                            '</nobr></p>';
       #
     $Str .= '<input type="submit" name="GenerateStatistics" value="'.      $Str .= '<input type="submit" name="GenerateStatistics" value="'.
         &mt('Generate Statistics').'" />';          &mt('Generate Statistics').'" />';
     $Str .= '&nbsp;'x5;      $Str .= '&nbsp;'x5;
     $Str .= 'Plot '.&plot_dropdown().('&nbsp;'x10);      $Str .= 'Plot '.&plot_dropdown().('&nbsp;'x10);
     $Str .= '<input type="submit" name="ClearCache" value="'.      #
         &mt('Clear Caches').'" />';  
     $Str .= '&nbsp;'x5;  
     $Str .= '<input type="submit" name="UpdateCache" value="'.  
         &mt('Update Student Data').'" />';  
     $Str .= '&nbsp;'x5;  
     $Str .= '<input type="submit" name="Excel" value="'.  
         &mt('Produce Excel Output').'" />';  
     $Str .= '&nbsp;'x5;  
     return $Str;      return $Str;
 }  }
   
Line 583  sub BuildProblemStatisticsPage { Line 632  sub BuildProblemStatisticsPage {
     undef(%SeqStat);      undef(%SeqStat);
     #      #
     # Finally let the user know we are here      # Finally let the user know we are here
     my $interface = &CreateInterface();      my $interface = &CreateInterface($r);
     $r->print($interface);      $r->print($interface);
     $r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}.      $r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}.
               '" />');                '" />');
     #      #
     if (! exists($ENV{'form.statsfirstcall'})) {      my @CacheButtonHTML = 
         $r->print('<input type="hidden" name="statsfirstcall" value="yes" />');          &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
       my $Str;
       foreach my $html (@CacheButtonHTML) {
           $Str.=$html.('&nbsp;'x5);
       }
       #
       $r->print($Str);
       if (! exists($ENV{'form.firstrun'})) {
         $r->print('<h3>'.          $r->print('<h3>'.
                   &mt('Press "Generate Statistics" when you are ready.').                    &mt('Press "Generate Statistics" when you are ready.').
                   '</h3><p>'.                    '</h3><p>'.
Line 598  sub BuildProblemStatisticsPage { Line 654  sub BuildProblemStatisticsPage {
                       ' will not have this delay.').                        ' will not have this delay.').
                   '</p>');                    '</p>');
         return;          return;
     } elsif ($ENV{'form.statsfirstcall'} eq 'yes' ||   
              exists($ENV{'form.UpdateCache'}) ||  
              exists($ENV{'form.ClearCache'}) ) {  
         $r->print('<input type="hidden" name="statsfirstcall" value="no" />');  
         &Apache::lonstatistics::Gather_Student_Data($r);  
     } else {  
         $r->print('<input type="hidden" name="statsfirstcall" value="no" />');  
     }      }
     $r->rflush();      $r->rflush();
     #      #
Line 614  sub BuildProblemStatisticsPage { Line 663  sub BuildProblemStatisticsPage {
     #      #
     if (exists($ENV{'form.Excel'})) {      if (exists($ENV{'form.Excel'})) {
         &Excel_output($r);          &Excel_output($r);
     } else {      } else { 
           $r->print('<input type="submit" name="Excel" value="'.
                     &mt('Produce Excel Output').'" />'.'&nbsp;'x5);
           $r->rflush();
         my $count = 0;          my $count = 0;
         foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {          foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
             $count += $seq->{'num_assess_parts'};              $count += $seq->{'num_assess_parts'};
Line 1240  sub Excel_output { Line 1292  sub Excel_output {
         $cols_output=0;          $cols_output=0;
         foreach my $field (@SeqFields) {          foreach my $field (@SeqFields) {
             next if ($field->{'selected'} ne 'yes');              next if ($field->{'selected'} ne 'yes');
               my $fieldformat = undef;
               if (exists($field->{'excel_format'})) {
                   $fieldformat = $format->{$field->{'excel_format'}};
               }
             $excel_sheet->write($rows_output,$cols_output++,              $excel_sheet->write($rows_output,$cols_output++,
                                 $data->{$field->{'name'}});                                  $data->{$field->{'name'}},$fieldformat);
         }          }
         $rows_output++;          $rows_output++;
         $cols_output=0;          $cols_output=0;
Line 1259  sub Excel_output { Line 1315  sub Excel_output {
         foreach my $field (@Fields) {          foreach my $field (@Fields) {
             next if ($field->{'selected'} ne 'yes');              next if ($field->{'selected'} ne 'yes');
             next if ($field->{'name'} eq 'problem_num');              next if ($field->{'name'} eq 'problem_num');
               my $fieldformat = undef;
               if (exists($field->{'excel_format'})) {
                   $fieldformat = $format->{$field->{'excel_format'}};
               }
             $excel_sheet->write($rows_output,$cols_output++,              $excel_sheet->write($rows_output,$cols_output++,
                                 $data->{$field->{'name'}});                                  $data->{$field->{'name'}},$fieldformat);
         }          }
         $rows_output++;          $rows_output++;
         $cols_output=0;          $cols_output=0;
Line 1440  sub get_statistics { Line 1500  sub get_statistics {
                         (\@Apache::lonstatistics::SelectedSections,                          (\@Apache::lonstatistics::SelectedSections,
                          $Apache::lonstatistics::enrollment_status,                           $Apache::lonstatistics::enrollment_status,
                          $symb,$part,$courseid,$starttime,$endtime);                           $symb,$part,$courseid,$starttime,$endtime);
       $data->{'symb'}        = $symb;
     $data->{'part'}        = $part;      $data->{'part'}        = $part;
     $data->{'problem_num'} = $problem_num;      $data->{'problem_num'} = $problem_num;
     $data->{'container'}   = $sequence->{'title'};      $data->{'container'}   = $sequence->{'title'};
Line 1451  sub get_statistics { Line 1512  sub get_statistics {
         $data->{'deg_of_disc'} =           $data->{'deg_of_disc'} = 
             &compute_discrimination_factor($resource,$part,$sequence);              &compute_discrimination_factor($resource,$part,$sequence);
     }      }
       #
       # Store in metadata if computations were done for all students
       if ($data->{'num_students'} > 1) {
           my @Sections = @Apache::lonstatistics::SelectedSections;
           my $sections = '"'.join(' ',@Sections).'"';
           $sections =~ s/&+/_/g;  # Ensure no special characters
           $data->{'sections'}=$sections;
           $data->{'course'} = $ENV{'request.course.id'};
           my $urlres=(&Apache::lonnet::decode_symb($resource->{'symb'}))[2];
           $data->{'urlres'}=$urlres;
           my %storestats = 
               &LONCAPA::lonmetadata::dynamic_metadata_storage($data);
           my ($dom,$user) = $urlres=~/^(\w+)\/(\w+)/; 
           &Apache::lonnet::put('nohist_resevaldata',\%storestats,$dom,$user);
       }
       #
       # Get the due date for research purposes (commented out most of the time)
   #    $data->{'duedate'} = 
   #        &Apache::lonnet::EXT('resource.'.$part.'.duedate',$symb);
   #    $data->{'opendate'} = 
   #        &Apache::lonnet::EXT('resource.'.$part.'.opendate',$symb);
   #    $data->{'resptypes'} = join(',',@{$resource->{'partdata'}->{$part}->{'ResponseTypes'}});
     return $data;      return $data;
 }  }
   
Line 1478  sub compute_discrimination_factor { Line 1561  sub compute_discrimination_factor {
     }      }
     #      #
     # rank      # rank
       my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
     my $ranking =       my $ranking = 
         &Apache::loncoursedata::rank_students_by_scores_on_resources          &Apache::loncoursedata::rank_students_by_scores_on_resources
         (\@Resources,          (\@Resources,
          \@Apache::lonstatistics::SelectedSections,           \@Apache::lonstatistics::SelectedSections,
          $Apache::lonstatistics::enrollment_status,undef);           $Apache::lonstatistics::enrollment_status,undef,
            $starttime,$endtime);
     #      #
     # compute their percent scores on the problems in the sequence,      # compute their percent scores on the problems in the sequence,
     my $number_to_grab = int(scalar(@{$ranking})/4);      my $number_to_grab = int(scalar(@{$ranking})/4);
Line 1494  sub compute_discrimination_factor { Line 1579  sub compute_discrimination_factor {
             $_->[&Apache::loncoursedata::RNK_student()];               $_->[&Apache::loncoursedata::RNK_student()]; 
           } @{$ranking}[($num_students-$number_to_grab)..($num_students-1)];            } @{$ranking}[($num_students-$number_to_grab)..($num_students-1)];
     my ($bottom_sum,$bottom_max) =       my ($bottom_sum,$bottom_max) = 
         &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@BottomSet);          &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@BottomSet,
                                                     undef,$starttime,$endtime);
     my ($top_sum,$top_max) =       my ($top_sum,$top_max) = 
         &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@TopSet);          &Apache::loncoursedata::get_sum_of_scores($resource,$part,\@TopSet,
                                                     undef,$starttime,$endtime);
     my $deg_of_disc;      my $deg_of_disc;
     if ($top_max == 0 || $bottom_max==0) {      if ($top_max == 0 || $bottom_max==0) {
         $deg_of_disc = 'nan';          $deg_of_disc = 'nan';

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


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