version 1.144, 2005/03/03 18:57:36
|
version 1.149, 2005/07/14 02:28:25
|
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 1214 sub update_student_data {
|
Line 1214 sub update_student_data {
|
# |
# |
# Set the students update time |
# Set the students update time |
if ($Results[0] eq 'okay') { |
if ($Results[0] eq 'okay') { |
&store_updatetime($student_id,$time_of_retrieval,$time_of_retrieval); |
&store_updatetime($student_id,$time_of_retrieval); |
} |
} |
# |
# |
return @Results; |
return @Results; |
Line 1270 sub store_student_data {
|
Line 1270 sub store_student_data {
|
# make sure the symb is set up properly |
# make sure the symb is set up properly |
my $symb_id = &get_symb_id($current_symb); |
my $symb_id = &get_symb_id($current_symb); |
# |
# |
# Load data into the tables |
# Parameters |
while (my ($parameter,$value) = each(%$param_hash)) { |
while (my ($parameter,$value) = each(%$param_hash)) { |
my $newstring; |
|
if ($parameter !~ /(timestamp|resource\.(.*)\.(solved|tries|awarded|award|awarddetail|previous))/) { |
if ($parameter !~ /(timestamp|resource\.(.*)\.(solved|tries|awarded|award|awarddetail|previous))/) { |
$newstring = "('".join("','", |
my $sql_parameter = "('".join("','", |
$symb_id,$student_id, |
$symb_id,$student_id, |
$parameter)."',". |
$parameter)."',". |
$dbh->quote($value)."),\n"; |
$dbh->quote($value)."),\n"; |
$num_parameters ++; |
$num_parameters ++; |
if ($newstring !~ /''/) { |
if ($sql_parameter !~ /''/) { |
$store_parameters_command .= $newstring; |
$store_parameters_command .= $sql_parameter; |
$rows_stored++; |
#$rows_stored++; |
} |
} |
} |
} |
next if ($parameter !~ /^resource\.(.*)\.solved$/); |
} |
# |
# Performance |
|
my %stored; |
|
while (my ($parameter,$value) = each(%$param_hash)) { |
|
next if ($parameter !~ /^resource\.(.*)\.(solved|awarded)$/); |
my $part = $1; |
my $part = $1; |
|
next if (exists($stored{$part})); |
|
$stored{$part}++; |
|
# |
my $part_id = &get_part_id($part); |
my $part_id = &get_part_id($part); |
next if (!defined($part_id)); |
next if (!defined($part_id)); |
my $solved = $value; |
my $solved = $value; |
Line 1301 sub store_student_data {
|
Line 1306 sub store_student_data {
|
$awarded = '' if (! defined($awarded)); |
$awarded = '' if (! defined($awarded)); |
$award = '' if (! defined($award)); |
$award = '' if (! defined($award)); |
$awarddetail = '' if (! defined($awarddetail)); |
$awarddetail = '' if (! defined($awarddetail)); |
$newstring = "('".join("','",$symb_id,$student_id,$part_id,$part, |
my $sql_performance = |
$solved,$tries,$awarded,$award, |
"('".join("','",$symb_id,$student_id,$part_id,$part, |
$awarddetail,$timestamp)."'),\n"; |
$solved,$tries,$awarded,$award, |
$store_performance_command .= $newstring; |
$awarddetail,$timestamp)."'),\n"; |
|
$store_performance_command .= $sql_performance; |
$rows_stored++; |
$rows_stored++; |
} |
} |
} |
} |
chop $store_parameters_command; |
if (! $rows_stored) { return ($returnstatus, undef); } |
chop $store_parameters_command; |
$store_parameters_command =~ s|,\n$||; |
chop $store_performance_command; |
$store_performance_command =~ s|,\n$||; |
chop $store_performance_command; |
|
my $start = Time::HiRes::time; |
my $start = Time::HiRes::time; |
$dbh->do($store_performance_command); |
$dbh->do($store_performance_command); |
if ($dbh->err()) { |
if ($dbh->err()) { |
&Apache::lonnet::logthis(' bigass insert error:'.$dbh->errstr()); |
&Apache::lonnet::logthis('performance bigass insert error:'. |
&Apache::lonnet::logthis('command = '.$store_performance_command); |
$dbh->errstr()); |
|
&Apache::lonnet::logthis('command = '.$/.$store_performance_command); |
$returnstatus = 'error: unable to insert performance into database'; |
$returnstatus = 'error: unable to insert performance into database'; |
return ($returnstatus,$student_data); |
return ($returnstatus,$student_data); |
} |
} |
$dbh->do($store_parameters_command) if ($num_parameters>0); |
$dbh->do($store_parameters_command) if ($num_parameters>0); |
if ($dbh->err()) { |
if ($dbh->err()) { |
&Apache::lonnet::logthis(' bigass insert error:'.$dbh->errstr()); |
&Apache::lonnet::logthis('parameters bigass insert error:'. |
&Apache::lonnet::logthis('command = '.$store_parameters_command); |
$dbh->errstr()); |
|
&Apache::lonnet::logthis('command = '.$/.$store_parameters_command); |
&Apache::lonnet::logthis('rows_stored = '.$rows_stored); |
&Apache::lonnet::logthis('rows_stored = '.$rows_stored); |
&Apache::lonnet::logthis('student_id = '.$student_id); |
&Apache::lonnet::logthis('student_id = '.$student_id); |
$returnstatus = 'error: unable to insert parameters into database'; |
$returnstatus = 'error: unable to insert parameters into database'; |
Line 1351 Returns nothing on success and 'error' o
|
Line 1358 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 1415 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 1464 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 1640 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 1743 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 1892 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 2042 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 2102 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 2166 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 2240 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 2297 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 2338 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 2411 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 2467 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 2533 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 2552 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 2624 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 2699 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 2728 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); |