version 1.144, 2005/03/03 18:57:36
|
version 1.146, 2005/04/07 06:56:23
|
Line 50 package Apache::loncoursedata;
|
Line 50 package Apache::loncoursedata;
|
|
|
use strict; |
use strict; |
use Apache::Constants qw(:common :http); |
use Apache::Constants qw(:common :http); |
use Apache::lonnet(); |
use Apache::lonnet; |
use Apache::lonhtmlcommon; |
use Apache::lonhtmlcommon; |
use Time::HiRes; |
use Time::HiRes; |
use Apache::lonmysql; |
use Apache::lonmysql; |
Line 71 sub LoadDiscussion {
|
Line 71 sub LoadDiscussion {
|
my %Discuss=(); |
my %Discuss=(); |
my %contrib=&Apache::lonnet::dump( |
my %contrib=&Apache::lonnet::dump( |
$courseID, |
$courseID, |
$ENV{'course.'.$courseID.'.domain'}, |
$env{'course.'.$courseID.'.domain'}, |
$ENV{'course.'.$courseID.'.num'}); |
$env{'course.'.$courseID.'.num'}); |
|
|
#my %contrib=&DownloadCourseInformation($name, $courseID, 0); |
#my %contrib=&DownloadCourseInformation($name, $courseID, 0); |
|
|
Line 645 Returns: nothing
|
Line 645 Returns: nothing
|
################################################ |
################################################ |
sub delete_caches { |
sub delete_caches { |
my $courseid = shift; |
my $courseid = shift; |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
# |
# |
Line 861 sub get_student {
|
Line 861 sub get_student {
|
sub populate_student_table { |
sub populate_student_table { |
my ($courseid) = @_; |
my ($courseid) = @_; |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $env{'request.course.id'}; |
} |
} |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
Line 1351 Returns nothing on success and 'error' o
|
Line 1351 Returns nothing on success and 'error' o
|
###################################### |
###################################### |
sub ensure_tables_are_set_up { |
sub ensure_tables_are_set_up { |
my ($courseid) = @_; |
my ($courseid) = @_; |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
# |
# |
# Clean out package variables |
# Clean out package variables |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
Line 1408 sub ensure_current_data {
|
Line 1408 sub ensure_current_data {
|
my ($sname,$sdom,$courseid) = @_; |
my ($sname,$sdom,$courseid) = @_; |
my $status = 'okay'; # return value |
my $status = 'okay'; # return value |
# |
# |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
&ensure_tables_are_set_up($courseid); |
&ensure_tables_are_set_up($courseid); |
# |
# |
# Get the update time for the user |
# Get the update time for the user |
Line 1457 sub ensure_current_full_data {
|
Line 1457 sub ensure_current_full_data {
|
my ($sname,$sdom,$courseid) = @_; |
my ($sname,$sdom,$courseid) = @_; |
my $status = 'okay'; # return value |
my $status = 'okay'; # return value |
# |
# |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
&ensure_tables_are_set_up($courseid); |
&ensure_tables_are_set_up($courseid); |
# |
# |
# Get the update time for the user |
# Get the update time for the user |
Line 1633 an empty list is returned.
|
Line 1633 an empty list is returned.
|
sub get_current_state { |
sub get_current_state { |
my ($sname,$sdom,$symb,$courseid,$forcedownload)=@_; |
my ($sname,$sdom,$symb,$courseid,$forcedownload)=@_; |
# |
# |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
# |
# |
return () if (! defined($sname) || ! defined($sdom)); |
return () if (! defined($sname) || ! defined($sdom)); |
# |
# |
Line 1736 able to answer it correctly.
|
Line 1736 able to answer it correctly.
|
sub get_problem_statistics { |
sub get_problem_statistics { |
my ($Sections,$status,$symb,$part,$courseid,$starttime,$endtime) = @_; |
my ($Sections,$status,$symb,$part,$courseid,$starttime,$endtime) = @_; |
return if (! defined($symb) || ! defined($part)); |
return if (! defined($symb) || ! defined($part)); |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
my $symb_id = &get_symb_id($symb); |
my $symb_id = &get_symb_id($symb); |
Line 1885 sub execute_SQL_request {
|
Line 1885 sub execute_SQL_request {
|
sub populate_weight_table { |
sub populate_weight_table { |
my ($courseid) = @_; |
my ($courseid) = @_; |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $env{'request.course.id'}; |
} |
} |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
Line 2035 sub rank_students_by_scores_on_resources
|
Line 2035 sub rank_students_by_scores_on_resources
|
my ($resources,$Sections,$enrollment,$courseid,$starttime,$endtime) = @_; |
my ($resources,$Sections,$enrollment,$courseid,$starttime,$endtime) = @_; |
return if (! defined($resources) || ! ref($resources) eq 'ARRAY'); |
return if (! defined($resources) || ! ref($resources) eq 'ARRAY'); |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $env{'request.course.id'}; |
} |
} |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
Line 2095 Returns: the sum of the score on the pro
|
Line 2095 Returns: the sum of the score on the pro
|
sub get_sum_of_scores { |
sub get_sum_of_scores { |
my ($symb,$part,$students,$courseid,$starttime,$endtime) = @_; |
my ($symb,$part,$students,$courseid,$starttime,$endtime) = @_; |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $env{'request.course.id'}; |
} |
} |
if (defined($students) && |
if (defined($students) && |
((@$students == 0) || |
((@$students == 0) || |
Line 2159 Returns: minimum, maximum, mean, s.d., n
|
Line 2159 Returns: minimum, maximum, mean, s.d., n
|
sub score_stats { |
sub score_stats { |
my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_; |
my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_; |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $env{'request.course.id'}; |
} |
} |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
Line 2233 Returns: minimum, maximum, mean, s.d., a
|
Line 2233 Returns: minimum, maximum, mean, s.d., a
|
sub count_stats { |
sub count_stats { |
my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_; |
my ($Sections,$enrollment,$symbs,$starttime,$endtime,$courseid)=@_; |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $env{'request.course.id'}; |
} |
} |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
Line 2290 sub count_stats {
|
Line 2290 sub count_stats {
|
###################################################### |
###################################################### |
sub get_student_data { |
sub get_student_data { |
my ($students,$courseid) = @_; |
my ($students,$courseid) = @_; |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
my $dbh = &Apache::lonmysql::get_dbh(); |
my $dbh = &Apache::lonmysql::get_dbh(); |
return undef if (! defined($dbh)); |
return undef if (! defined($dbh)); |
Line 2331 sub get_response_data {
|
Line 2331 sub get_response_data {
|
my ($Sections,$enrollment,$symb,$response,$courseid) = @_; |
my ($Sections,$enrollment,$symb,$response,$courseid) = @_; |
return undef if (! defined($symb) || |
return undef if (! defined($symb) || |
! defined($response)); |
! defined($response)); |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
my $symb_id = &get_symb_id($symb); |
my $symb_id = &get_symb_id($symb); |
Line 2404 sub get_response_data_by_student {
|
Line 2404 sub get_response_data_by_student {
|
my ($student,$symb,$response,$courseid) = @_; |
my ($student,$symb,$response,$courseid) = @_; |
return undef if (! defined($symb) || |
return undef if (! defined($symb) || |
! defined($response)); |
! defined($response)); |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
my $symb_id = &get_symb_id($symb); |
my $symb_id = &get_symb_id($symb); |
Line 2460 sub get_response_time_data {
|
Line 2460 sub get_response_time_data {
|
my ($sections,$enrollment,$symb,$part,$courseid) = @_; |
my ($sections,$enrollment,$symb,$part,$courseid) = @_; |
return undef if (! defined($symb) || |
return undef if (! defined($symb) || |
! defined($part)); |
! defined($part)); |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
# |
# |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
my $symb_id = &get_symb_id($symb); |
my $symb_id = &get_symb_id($symb); |
Line 2526 sub get_response_time_data {
|
Line 2526 sub get_response_time_data {
|
################################################ |
################################################ |
################################################ |
################################################ |
sub get_student_scores { |
sub get_student_scores { |
my ($Sections,$Symbs,$enrollment,$courseid,$starttime,$endtime) = @_; |
my ($sections,$Symbs,$enrollment,$courseid,$starttime,$endtime) = @_; |
$courseid = $ENV{'request.course.id'} if (! defined($courseid)); |
$courseid = $env{'request.course.id'} if (! defined($courseid)); |
&setup_table_names($courseid); |
&setup_table_names($courseid); |
my $dbh = &Apache::lonmysql::get_dbh(); |
my $dbh = &Apache::lonmysql::get_dbh(); |
return (undef) if (! defined($dbh)); |
return (undef) if (! defined($dbh)); |
my $tmptable = $courseid.'_temp_'.time; |
my $tmptable = $courseid.'_temp_'.time; |
|
my $request = 'DROP TABLE IF EXISTS '.$tmptable; |
|
# &Apache::lonnet::logthis('request = '.$/.$request); |
|
$dbh->do($request); |
# |
# |
my $symb_requirements; |
my $symb_requirements; |
if (defined($Symbs) && @$Symbs) { |
if (defined($Symbs) && @$Symbs) { |
Line 2542 sub get_student_scores {
|
Line 2545 sub get_student_scores {
|
} @$Symbs).')'; |
} @$Symbs).')'; |
} |
} |
# |
# |
my $student_requirements; |
my ($student_requirements,$enrollment_requirements) = |
if ( (defined($Sections) && $Sections->[0] ne 'all')) { |
&limit_by_section_and_status($sections,$enrollment,'b'); |
$student_requirements = '('. |
|
join(' OR ', map { "b.section='".$_."'" } @$Sections |
|
).')'; |
|
} |
|
# |
|
my $enrollment_requirements=undef; |
|
if (defined($enrollment) && $enrollment ne 'Any') { |
|
$enrollment_requirements = "b.status='".$enrollment."'"; |
|
} |
|
# |
# |
my $time_requirements = undef; |
my $time_requirements = &limit_by_start_end_time($starttime,$endtime,'a'); |
if (defined($starttime)) { |
|
$time_requirements .= "a.timestamp>='".$starttime."'"; |
|
if (defined($endtime)) { |
|
$time_requirements .= " AND a.timestamp<='".$endtime."'"; |
|
} |
|
} elsif (defined($endtime)) { |
|
$time_requirements .= "a.timestamp<='".$endtime."'"; |
|
} |
|
## |
|
## |
## |
my $request = 'CREATE TEMPORARY TABLE IF NOT EXISTS '.$tmptable. |
$request = 'CREATE TEMPORARY TABLE IF NOT EXISTS '.$tmptable. |
' SELECT a.student_id,SUM(a.awarded) AS score FROM '. |
' SELECT a.student_id,SUM(a.awarded*c.weight) AS score FROM '. |
$performance_table.' AS a '; |
$performance_table.' AS a '; |
|
$request .= "LEFT JOIN ".$weight_table.' AS c ON a.symb_id=c.symb_id AND a.part_id=c.part_id '; |
if (defined($student_requirements) || defined($enrollment_requirements)) { |
if (defined($student_requirements) || defined($enrollment_requirements)) { |
$request .= ' NATURAL LEFT JOIN '.$student_table.' AS b '; |
$request .= ' LEFT JOIN '.$student_table.' AS b ON a.student_id=b.student_id'; |
} |
} |
if (defined($symb_requirements) || |
if (defined($symb_requirements) || |
defined($student_requirements) || |
defined($student_requirements) || |
Line 2631 Cleans up the package variables for loca
|
Line 2617 Cleans up the package variables for loca
|
sub setup_table_names { |
sub setup_table_names { |
my ($courseid) = @_; |
my ($courseid) = @_; |
if (! defined($courseid)) { |
if (! defined($courseid)) { |
$courseid = $ENV{'request.course.id'}; |
$courseid = $env{'request.course.id'}; |
} |
} |
# |
# |
if (! defined($current_course) || $current_course ne $courseid) { |
if (! defined($current_course) || $current_course ne $courseid) { |
Line 2706 from the students environment.
|
Line 2692 from the students environment.
|
|
|
Optional arguments are $cid, $cdom, and $cnum (course id, course domain, |
Optional arguments are $cid, $cdom, and $cnum (course id, course domain, |
and course number, respectively). Any omitted arguments will be taken |
and course number, respectively). Any omitted arguments will be taken |
from the current environment ($ENV{'request.course.id'}, |
from the current environment ($env{'request.course.id'}, |
$ENV{'course.'.$cid.'.domain'}, and $ENV{'course.'.$cid.'.num'}). |
$env{'course.'.$cid.'.domain'}, and $env{'course.'.$cid.'.num'}). |
|
|
Returns a reference to a hash which contains: |
Returns a reference to a hash which contains: |
keys '$sname:$sdom' |
keys '$sname:$sdom' |
Line 2735 sub CL_LOCKEDTYPE { return 9; }
|
Line 2721 sub CL_LOCKEDTYPE { return 9; }
|
|
|
sub get_classlist { |
sub get_classlist { |
my ($cid,$cdom,$cnum) = @_; |
my ($cid,$cdom,$cnum) = @_; |
$cid = $cid || $ENV{'request.course.id'}; |
$cid = $cid || $env{'request.course.id'}; |
$cdom = $cdom || $ENV{'course.'.$cid.'.domain'}; |
$cdom = $cdom || $env{'course.'.$cid.'.domain'}; |
$cnum = $cnum || $ENV{'course.'.$cid.'.num'}; |
$cnum = $cnum || $env{'course.'.$cid.'.num'}; |
my $now = time; |
my $now = time; |
# |
# |
my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum); |
my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum); |