version 1.145, 2005/03/07 20:12:08
|
version 1.150, 2005/10/04 18:27:32
|
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 869 sub populate_student_table {
|
Line 869 sub populate_student_table {
|
my $dbh = &Apache::lonmysql::get_dbh(); |
my $dbh = &Apache::lonmysql::get_dbh(); |
my $request = 'INSERT IGNORE INTO '.$student_table. |
my $request = 'INSERT IGNORE INTO '.$student_table. |
"(student,section,status) VALUES "; |
"(student,section,status) VALUES "; |
my $classlist = &get_classlist($courseid); |
my $cdom = $env{'course.'.$courseid.'.domain'}; |
|
my $cnum = $env{'course.'.$courseid.'.num'}; |
|
my $classlist = &get_classlist($cdom,$cnum); |
my $student_count=0; |
my $student_count=0; |
while (my ($student,$data) = each %$classlist) { |
while (my ($student,$data) = each %$classlist) { |
my ($section,$status) = ($data->[&CL_SECTION()], |
my ($section,$status) = ($data->[&CL_SECTION()], |
Line 1214 sub update_student_data {
|
Line 1216 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 1272 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 1308 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 1360 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 1417 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 1466 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 1642 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 1745 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 1894 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 2044 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 2104 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 2168 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 2242 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 2299 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 2340 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 2413 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 2469 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 2527 sub get_response_time_data {
|
Line 2536 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)); |
Line 2617 Cleans up the package variables for loca
|
Line 2626 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 2690 Retrieve the classist of a given class o
|
Line 2699 Retrieve the classist of a given class o
|
information is returned from the classlist.db file and, if needed, |
information is returned from the classlist.db file and, if needed, |
from the students environment. |
from the students environment. |
|
|
Optional arguments are $cid, $cdom, and $cnum (course id, course domain, |
Optional arguments are $cdom, and $cnum (course domain, |
and course number, respectively). Any omitted arguments will be taken |
and course number, respectively). If either is ommitted the course |
from the current environment ($ENV{'request.course.id'}, |
will be taken 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 2720 sub CL_TYPE { return 8; }
|
Line 2729 sub CL_TYPE { return 8; }
|
sub CL_LOCKEDTYPE { return 9; } |
sub CL_LOCKEDTYPE { return 9; } |
|
|
sub get_classlist { |
sub get_classlist { |
my ($cid,$cdom,$cnum) = @_; |
my ($cdom,$cnum) = @_; |
$cid = $cid || $ENV{'request.course.id'}; |
my $cid = $cdom.'_'.$cnum; |
$cdom = $cdom || $ENV{'course.'.$cid.'.domain'}; |
if (!defined($cdom) || !defined($cnum)) { |
$cnum = $cnum || $ENV{'course.'.$cid.'.num'}; |
$cid = $env{'request.course.id'}; |
|
$cdom = $env{'course.'.$cid.'.domain'}; |
|
$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); |