Diff for /loncom/interface/loncoursedata.pm between versions 1.128 and 1.129

version 1.128, 2004/03/26 22:01:30 version 1.129, 2004/04/01 20:02:55
Line 2160  sub populate_weight_table { Line 2160  sub populate_weight_table {
   
 =pod  =pod
   
   =item &limit_by_start_end_times
   
   Build SQL WHERE condition which limits the data collected by the start
   and end times provided
   
   Inputs: $starttime, $endtime, $table
   
   Returns: $time_limits
   
   =cut
   
   ##########################################################
   ##########################################################
   sub limit_by_start_end_time {
       my ($starttime,$endtime,$table) = @_;
       my $time_requirements = undef;
       if (defined($starttime)) {
           $time_requirements .= $table.".timestamp>='".$starttime."'";
           if (defined($endtime)) {
               $time_requirements .= " AND ".$table.".timestamp<='".$endtime."'";
           }
       } elsif (defined($endtime)) {
           $time_requirements .= $table.".timestamp<='".$endtime."'";
       }
       return $time_requirements;
   }
   
   ##########################################################
   ##########################################################
   
   =pod
   
 =item &limit_by_section_and_status  =item &limit_by_section_and_status
   
 Build SQL WHERE condition which limits the data collected by section and  Build SQL WHERE condition which limits the data collected by section and
Line 2300  sub get_sum_of_scores { Line 2332  sub get_sum_of_scores {
     return ($rows->[0],$rows->[1]);      return ($rows->[0],$rows->[1]);
 }  }
   
   ########################################################
   ########################################################
   
   =pod
   
   =item &score_stats
   
   Inputs: $Sections, $enrollment, $symbs, $starttime,
           $endtime, $courseid
   
   $Sections, $enrollment, $starttime, $endtime, and $courseid are the same as 
   elsewhere in this module.  
   $symbs is an array ref of symbs
   
   Returns: minimum, maximum, mean, s.d., number of students, and maximum
     possible of student scores on the given resources
   
   =cut
   
   ########################################################
   ########################################################
   sub score_stats {
       my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_;
       if (! defined($courseid)) {
           $courseid = $ENV{'request.course.id'};
       }
       #
       &setup_table_names($courseid);
       my $dbh = &Apache::lonmysql::get_dbh();
       #
       my ($section_limits,$enrollment_limits)=
           &limit_by_section_and_status($Sections,$enrollment,'b');
       my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a');
       my @Symbids = map { &get_symb_id($_); } @{$symbs};
       #
       my $stats_table = $courseid.'_problem_stats';
       my $symb_restriction = join(' OR ',map {'a.symb_id='.$_;} @Symbids);
       my $request = 'DROP TABLE '.$stats_table;
       $dbh->do($request);
       $request = 
           'CREATE TEMPORARY TABLE '.$stats_table.' '.
           'SELECT a.student_id,'.
           'SUM(a.awarded*w.weight) AS score FROM '.
           $performance_table.' AS a '.
           'NATURAL LEFT JOIN '.$weight_table.' AS w '.
           'LEFT JOIN '.$student_table.' AS b ON a.student_id=b.student_id '.
           'WHERE ('.$symb_restriction.')';
       if ($time_limits) {
           $request .= ' AND '.$time_limits;
       }
       if ($section_limits) {
           $request .= ' AND '.$section_limits;
       }
       if ($enrollment_limits) {
           $request .= ' AND '.$enrollment_limits;
       }
       $request .= ' GROUP BY a.student_id';
   #    &Apache::lonnet::logthis('request = '.$/.$request);
       my $sth = $dbh->prepare($request);
       $sth->execute();
       $request = 
           'SELECT AVG(score),STD(score),MAX(score),MIN(score),COUNT(score) '.
           'FROM '.$stats_table;
       my ($ave,$std,$max,$min,$count) = &execute_SQL_request($dbh,$request);
   #    &Apache::lonnet::logthis('request = '.$/.$request);
       
       $request = 'SELECT SUM(weight) FROM '.$weight_table.
           ' WHERE ('.$symb_restriction.')';
       my ($max_possible) = &execute_SQL_request($dbh,$request);
       # &Apache::lonnet::logthis('request = '.$/.$request);
       return($min,$max,$ave,$std,$count,$max_possible);
   }
   
   
   ########################################################
   ########################################################
   
   =pod
   
   =item &count_stats
   
   Inputs: $Sections, $enrollment, $symbs, $starttime,
           $endtime, $courseid
   
   $Sections, $enrollment, $starttime, $endtime, and $courseid are the same as 
   elsewhere in this module.  
   $symbs is an array ref of symbs
   
   Returns: minimum, maximum, mean, s.d., and number of students
     of the number of items correct on the given resources
   
   =cut
   
   ########################################################
   ########################################################
   sub count_stats {
       my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_;
       if (! defined($courseid)) {
           $courseid = $ENV{'request.course.id'};
       }
       #
       &setup_table_names($courseid);
       my $dbh = &Apache::lonmysql::get_dbh();
       #
       my ($section_limits,$enrollment_limits)=
           &limit_by_section_and_status($Sections,$enrollment,'b');
       my $time_limits = &limit_by_start_end_time($starttime,$endtime,'a');
       my @Symbids = map { &get_symb_id($_); } @{$symbs};
       #
       my $stats_table = $courseid.'_problem_stats';
       my $symb_restriction = join(' OR ',map {'a.symb_id='.$_;} @Symbids);
       my $request = 'DROP TABLE '.$stats_table;
       $dbh->do($request);
       $request = 
           'CREATE TEMPORARY TABLE '.$stats_table.' '.
           'SELECT a.student_id,'.
           'COUNT(a.award) AS count FROM '.
           $performance_table.' AS a '.
           'LEFT JOIN '.$student_table.' AS b ON a.student_id=b.student_id '.
           'WHERE ('.$symb_restriction.')'.
           " AND a.award!='INCORRECT_ATTEMPTED'";
       if ($time_limits) {
           $request .= ' AND '.$time_limits;
       }
       if ($section_limits) {
           $request .= ' AND '.$section_limits;
       }
       if ($enrollment_limits) {
           $request .= ' AND '.$enrollment_limits;
       }
       $request .= ' GROUP BY a.student_id';
       &Apache::lonnet::logthis('request = '.$/.$request);
       my $sth = $dbh->prepare($request);
       $sth->execute();
       $request = 
           'SELECT AVG(count),STD(count),MAX(count),MIN(count),COUNT(count) '.
           'FROM '.$stats_table;
       my ($ave,$std,$max,$min,$count) = &execute_SQL_request($dbh,$request);
       &Apache::lonnet::logthis('request = '.$/.$request);
       return($min,$max,$ave,$std,$count);
   }
   
 ######################################################  ######################################################
 ######################################################  ######################################################

Removed from v.1.128  
changed lines
  Added in v.1.129


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