version 1.1, 2004/08/11 18:37:23
|
version 1.13, 2005/02/09 21:54:15
|
Line 26
|
Line 26
|
# |
# |
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
############################################################################### |
#-------------------------------------------------------------------- |
# |
|
# Expects |
|
# |
|
# ../key/$class.key - key file $username:$keynumber |
|
# ../rawdata/$class.log - log file |
|
# ../rawdata/$class.seq - sequence file |
|
# ../data writable |
|
# ------------------------------------------------------------------ Course log |
|
|
|
# |
# |
# Exit codes |
# Exit codes |
# 0 Everything is okay |
# 0 Everything is okay |
Line 43
|
Line 34
|
# 2 Activity log does not exist |
# 2 Activity log does not exist |
# 3 Unable to connect to database |
# 3 Unable to connect to database |
# 4 Unable to create database tables |
# 4 Unable to create database tables |
# 5 Unspecified error? |
# 5 Unable to open log file |
|
# 6 Unable to get lock on activity log |
|
# |
|
|
|
# |
|
# Notes: |
|
# |
|
# Logging is done via the $logthis variable, which may be the result of |
|
# overcleverness. log via $logthis->('logtext'); Those are parentheses, |
|
# not curly braces. If the -log command line parameter is set, the $logthis |
|
# routine is set to a routine which writes to a file. If the command line |
|
# parameter is not set $logthis is set to ¬hing, which does what you |
|
# would expect. |
# |
# |
|
|
use strict; |
use strict; |
use DBI; |
use DBI; |
use lib '/home/httpd/lib/perl/Apache'; |
use lib '/home/httpd/lib/perl/Apache'; |
|
use lib '/home/httpd/lib/perl/'; |
|
use LONCAPA::Configuration(); |
|
use Apache::lonmysql(); |
use lonmysql(); |
use lonmysql(); |
use Time::HiRes(); |
use Time::HiRes(); |
use Getopt::Long(); |
use Getopt::Long(); |
|
use IO::File; |
|
use File::Copy; |
|
use Fcntl qw(:flock); |
|
|
# |
# |
# Determine parameters |
# Determine parameters |
my ($help,$course,$domain,$drop,$file,$time_run,$nocleanup); |
my ($help,$course,$domain,$drop_when_done,$srcfile,$logfile,$time_run,$nocleanup,$log,$backup); |
&Getopt::Long::GetOptions( "course=s" => \$course, |
&Getopt::Long::GetOptions( "course=s" => \$course, |
"domain=s" => \$domain, |
"domain=s" => \$domain, |
|
"backup" => \$backup, |
"help" => \$help, |
"help" => \$help, |
"logfile=s" => \$file, |
"logfile=s" => \$logfile, |
|
"srcfile=s" => \$srcfile, |
"timerun" => \$time_run, |
"timerun" => \$time_run, |
"nocleanup" => \$nocleanup, |
"nocleanup" => \$nocleanup, |
"drop" => \$drop); |
"dropwhendone" => \$drop_when_done, |
|
"log" => \$log); |
if (! defined($course) || $help) { |
if (! defined($course) || $help) { |
print<<USAGE; |
print<<USAGE; |
parse_activity_log.pl |
parse_activity_log.pl |
Line 70 parse_activity_log.pl
|
Line 82 parse_activity_log.pl
|
Process a lon-capa activity log into a database. |
Process a lon-capa activity log into a database. |
Parameters: |
Parameters: |
course Required |
course Required |
domain Optional |
domain optional |
drop optional if present, drop all course |
backup optional if present, backup the activity log file |
specific activity log tables. |
before processing it |
file optional Specify the file to parse, including path |
dropwhendone optional if present, drop all course |
|
specific activity log tables after processing. |
|
srcfile optional Specify the file to parse, including path |
time optional if present, print out timing data |
time optional if present, print out timing data |
nocleanup optional if present, do not remove old files |
nocleanup optional if present, do not remove old files |
|
log optional if present, prepare log file of activity |
|
logfile optional specifies the logfile to use |
Examples: |
Examples: |
$0 -course=123456abcdef -domain=msu |
$0 -course=123456abcdef -domain=msu |
$0 -course=123456abcdef -file=activity.log |
$0 -course=123456abcdef -srcfile=activity.log |
|
$0 -course-123456abcdef -log -logfile=/tmp/logfile -dropwhendone |
USAGE |
USAGE |
exit; |
exit; |
} |
} |
|
|
## |
## |
## Set up timing code |
## Set up timing code |
## |
|
my $time_this = \¬hing; |
my $time_this = \¬hing; |
if ($time_run) { |
if ($time_run) { |
$time_this = \&time_action; |
$time_this = \&time_action; |
Line 95 my $initial_time = Time::HiRes::time;
|
Line 111 my $initial_time = Time::HiRes::time;
|
## |
## |
## Read in configuration parameters |
## Read in configuration parameters |
## |
## |
my %perlvar; |
my %perlvar = %{&LONCAPA::Configuration::read_conf('loncapa.conf')}; |
&initialize_configuration(); |
|
if (! defined($domain) || $domain eq '') { |
if (! defined($domain) || $domain eq '') { |
$domain = $perlvar{'lonDefDomain'}; |
$domain = $perlvar{'lonDefDomain'}; |
} |
} |
&update_process_name($course.'@'.$domain); |
&update_process_name($course.'@'.$domain); |
|
|
## |
## |
|
## Set up logging code |
|
my $logthis = \¬hing; |
|
|
|
if ($log) { |
|
if (! $logfile) { |
|
$logfile = $perlvar{'lonDaemons'}.'/tmp/parse_activity_log.log.'.time; |
|
} |
|
print STDERR "$0: logging to $logfile".$/; |
|
if (! open(LOGFILE,">$logfile")) { |
|
warn("Unable to open $logfile for writing. Run aborted."); |
|
exit 5; |
|
} else { |
|
$logthis = \&log_to_file; |
|
} |
|
} |
|
|
|
|
|
## |
## Determine filenames |
## Determine filenames |
## |
## |
my $sourcefilename; # activity log data |
my $sourcefilename; # activity log data |
my $newfilename; # $sourcefilename will be renamed to this |
my $newfilename; # $sourcefilename will be renamed to this |
my $sql_filename; # the mysql backup data file name. |
my $gz_sql_filename; # the gzipped mysql backup data file name. |
if ($file) { |
my $error_filename; # Errors in parsing the activity log will be written here |
$sourcefilename = $file; |
if ($srcfile) { |
|
$sourcefilename = $srcfile; |
} else { |
} else { |
$sourcefilename = &get_filename($course,$domain); |
$sourcefilename = &get_filename($course,$domain); |
} |
} |
$sql_filename = $sourcefilename; |
my $sql_filename = $sourcefilename; |
$sql_filename =~ s|[^/]*$|activitylog.sql|; |
$sql_filename =~ s|[^/]*$|activity.log.sql|; |
|
$gz_sql_filename = $sql_filename.'.gz'; |
|
$error_filename = $sourcefilename; |
|
$error_filename =~ s|[^/]*$|activity.log.errors|; |
|
$logthis->('Beginning logging '.time); |
|
|
|
|
|
# |
|
# Wait for a lock on the lockfile to avoid collisions |
|
my $lockfilename = $sourcefilename.'.lock'; |
|
open(LOCKFILE,'>'.$lockfilename); |
|
if (!flock(LOCKFILE,LOCK_EX)) { |
|
warn("Unable to lock $lockfilename. Aborting".$/); |
|
exit 6; |
|
} |
|
|
## |
## |
## There will only be a $newfilename file if a copy of this program is already |
## There will only be a $newfilename file if a copy of this program is already |
Line 122 $sql_filename =~ s|[^/]*$|activitylog.sq
|
Line 171 $sql_filename =~ s|[^/]*$|activitylog.sq
|
my $newfilename = $sourcefilename.'.processing'; |
my $newfilename = $sourcefilename.'.processing'; |
if (-e $newfilename) { |
if (-e $newfilename) { |
warn "$newfilename exists"; |
warn "$newfilename exists"; |
|
$logthis->($newfilename.' exists, so I cannot work on it.'); |
exit 2; |
exit 2; |
} |
} |
|
|
if (-e $sourcefilename) { |
if (-e $sourcefilename) { |
|
$logthis->('renaming '.$sourcefilename.' to '.$newfilename); |
rename($sourcefilename,$newfilename); |
rename($sourcefilename,$newfilename); |
|
Copy($newfilename,$newfilename.'.'.time) if ($backup); |
|
$logthis->("renamed $sourcefilename to $newfilename"); |
|
} else { |
|
my $command = 'touch '.$newfilename; |
|
$logthis->($command); |
|
system($command); |
|
$logthis->('touch was completed'); |
} |
} |
|
|
|
close(LOCKFILE); |
|
|
## |
## |
## Table definitions |
## Table definitions |
## |
## |
my $prefix = $course.'_'.$domain.'_'; |
my $prefix = $course.'_'.$domain.'_'; |
my $student_table = $prefix.'students'; |
my $student_table = &Apache::lonmysql::fix_table_name($prefix.'students'); |
my $student_table_def = |
my $student_table_def = |
{ id => $student_table, |
{ id => $student_table, |
permanent => 'no', |
permanent => 'no', |
Line 149 my $student_table_def =
|
Line 209 my $student_table_def =
|
'PRIMARY KEY' => ['student_id',], |
'PRIMARY KEY' => ['student_id',], |
}; |
}; |
|
|
my $res_table = $prefix.'resource'; |
my $res_table = &Apache::lonmysql::fix_table_name($prefix.'resource'); |
my $res_table_def = |
my $res_table_def = |
{ id => $res_table, |
{ id => $res_table, |
permanent => 'no', |
permanent => 'no', |
Line 164 my $res_table_def =
|
Line 224 my $res_table_def =
|
'PRIMARY KEY' => ['res_id'], |
'PRIMARY KEY' => ['res_id'], |
}; |
}; |
|
|
my $action_table = $prefix.'actions'; |
#my $action_table = &Apache::lonmysql::fix_table_name($prefix.'actions'); |
my $action_table_def = |
#my $action_table_def = |
{ id => $action_table, |
#{ id => $action_table, |
permanent => 'no', |
# permanent => 'no', |
columns => [{ name => 'action_id', |
# columns => [{ name => 'action_id', |
type => 'MEDIUMINT UNSIGNED', |
# type => 'MEDIUMINT UNSIGNED', |
restrictions => 'NOT NULL', |
# restrictions => 'NOT NULL', |
auto_inc => 'yes', }, |
# auto_inc => 'yes', }, |
{ name => 'action', |
# { name => 'action', |
type => 'VARCHAR(100)', |
# type => 'VARCHAR(100)', |
restrictions => 'NOT NULL'}, |
# restrictions => 'NOT NULL'}, |
], |
# ], |
'PRIMARY KEY' => ['action_id',], |
# 'PRIMARY KEY' => ['action_id',], |
}; |
#}; |
|
|
my $machine_table = $prefix.'machine_table'; |
my $machine_table = &Apache::lonmysql::fix_table_name($prefix.'machine_table'); |
my $machine_table_def = |
my $machine_table_def = |
{ id => $machine_table, |
{ id => $machine_table, |
permanent => 'no', |
permanent => 'no', |
Line 194 my $machine_table_def =
|
Line 254 my $machine_table_def =
|
'PRIMARY KEY' => ['machine_id',], |
'PRIMARY KEY' => ['machine_id',], |
}; |
}; |
|
|
my $activity_table = $prefix.'activity'; |
my $activity_table = &Apache::lonmysql::fix_table_name($prefix.'activity'); |
my $activity_table_def = |
my $activity_table_def = |
{ id => $activity_table, |
{ id => $activity_table, |
permanent => 'no', |
permanent => 'no', |
Line 206 my $activity_table_def =
|
Line 266 my $activity_table_def =
|
type => 'DATETIME', |
type => 'DATETIME', |
restrictions => 'NOT NULL',}, |
restrictions => 'NOT NULL',}, |
{ name => 'student_id', |
{ name => 'student_id', |
type => 'VARCHAR(100) BINARY', |
type => 'MEDIUMINT UNSIGNED', |
restrictions => 'NOT NULL',}, |
restrictions => 'NOT NULL',}, |
{ name => 'action_id', |
{ name => 'action', |
type => 'VARCHAR(100) BINARY', |
type => 'VARCHAR(10)', |
restrictions => 'NOT NULL',}, |
restrictions => 'NOT NULL',}, |
{ name => 'idx', # This is here in case a student |
{ name => 'idx', # This is here in case a student |
type => 'MEDIUMINT UNSIGNED', # has multiple submissions during |
type => 'MEDIUMINT UNSIGNED', # has multiple submissions during |
restrictions => 'NOT NULL', # one second. It happens, trust |
restrictions => 'NOT NULL', # one second. It happens, trust |
auto_inc => 'yes', }, # me. |
auto_inc => 'yes', }, # me. |
{ name => 'machine_id', |
{ name => 'machine_id', |
type => 'VARCHAR(100) BINARY', |
type => 'MEDIUMINT UNSIGNED', |
restrictions => 'NOT NULL',}, |
restrictions => 'NOT NULL',}, |
{ name => 'action_values', |
{ name => 'action_values', |
type => 'MEDIUMTEXT', }, |
type => 'MEDIUMTEXT', }, |
], |
], |
'PRIMARY KEY' => ['res_id','time','student_id','action_id','idx'], |
'PRIMARY KEY' => ['time','student_id','res_id','idx'], |
|
'KEY' => [{columns => ['student_id']}, |
|
{columns => ['time']},], |
}; |
}; |
my @Activity_Tables = ($student_table_def,$res_table_def, |
|
$action_table_def,$machine_table_def, |
|
$activity_table_def); |
|
|
|
|
|
|
my @Activity_Table = ($activity_table_def); |
|
my @ID_Tables = ($student_table_def,$res_table_def,$machine_table_def); |
## |
## |
## End of table definitions |
## End of table definitions |
## |
## |
|
|
# |
$logthis->('Connectiong to mysql'); |
&Apache::lonmysql::set_mysql_user_and_password($perlvar{'lonSqlUser'}, |
&Apache::lonmysql::set_mysql_user_and_password('www', |
$perlvar{'lonSqlAccess'}); |
$perlvar{'lonSqlAccess'}); |
if (!&Apache::lonmysql::verify_sql_connection()) { |
if (!&Apache::lonmysql::verify_sql_connection()) { |
warn "Unable to connect to MySQL database."; |
warn "Unable to connect to MySQL database."; |
|
$logthis->("Unable to connect to MySQL database."); |
exit 3; |
exit 3; |
} |
} |
|
$logthis->('SQL connection is up'); |
|
|
if ($drop) { &drop_tables(); } |
if (-s $gz_sql_filename) { |
if (-e $sql_filename) { |
my $backup_modification_time = (stat($gz_sql_filename))[9]; |
# if ANY one of the tables does not exist, load the tables from the |
$logthis->($gz_sql_filename.' was last modified '. |
# backup. |
localtime($backup_modification_time). |
|
'('.$backup_modification_time.')'); |
|
# Check for missing tables |
my @Current_Tables = &Apache::lonmysql::tables_in_db(); |
my @Current_Tables = &Apache::lonmysql::tables_in_db(); |
|
$logthis->(join(',',@Current_Tables)); |
my %Found; |
my %Found; |
foreach my $tablename (@Current_Tables) { |
foreach my $tablename (@Current_Tables) { |
foreach my $table (@Activity_Tables) { |
foreach my $table (@Activity_Table,@ID_Tables) { |
if ($tablename eq $table->{'id'}) { |
if ($tablename eq $table->{'id'}) { |
$Found{$tablename}++; |
$Found{$tablename}++; |
} |
} |
} |
} |
} |
} |
foreach my $table (@Activity_Tables) { |
$logthis->('Found tables '.join(',',keys(%Found))); |
|
my $missing_a_table = 0; |
|
foreach my $table (@Activity_Table,@ID_Tables) { |
|
# Hmmm, should I dump the tables? |
if (! $Found{$table->{'id'}}) { |
if (! $Found{$table->{'id'}}) { |
$time_this->(); |
$logthis->('Missing table '.$table->{'id'}); |
&load_backup_tables($sql_filename); |
$missing_a_table = 1; |
$time_this->('load backup tables'); |
|
last; |
last; |
} |
} |
} |
} |
|
if ($missing_a_table) { |
|
my $table_modification_time = $backup_modification_time; |
|
# If the backup happened prior to the last table modification, |
|
foreach my $table (@Activity_Table,@ID_Tables) { |
|
my %tabledata = &Apache::lonmysql::table_information($table->{'id'}); |
|
next if (! scalar(keys(%tabledata))); # table does not exist |
|
if ($table_modification_time < $tabledata{'Update_time'}) { |
|
$table_modification_time = $tabledata{'Update_time'}; |
|
} |
|
} |
|
$logthis->("Table modification time = ".$table_modification_time); |
|
if ($table_modification_time > $backup_modification_time) { |
|
# Save the current tables in case we need them another time. |
|
my $backup_name = $gz_sql_filename.'.'.time; |
|
$logthis->('Backing existing tables up in '.$backup_name); |
|
&backup_tables($backup_name); |
|
} |
|
$time_this->(); |
|
&load_backup_tables($gz_sql_filename); |
|
$time_this->('load backup tables'); |
|
} |
} |
} |
|
|
|
## |
|
## Ensure the tables we need exist |
# create_tables does not complain if the tables already exist |
# create_tables does not complain if the tables already exist |
|
$logthis->('creating tables'); |
if (! &create_tables()) { |
if (! &create_tables()) { |
warn "Unable to create tables"; |
warn "Unable to create tables"; |
|
$logthis->('Unable to create tables'); |
exit 4; |
exit 4; |
} |
} |
|
|
|
## |
|
## Read the ids used for various tables |
|
$logthis->('reading id tables'); |
&read_id_tables(); |
&read_id_tables(); |
|
$logthis->('finished reading id tables'); |
|
|
## |
## |
## Do the main bit of work |
## Set up the errors file |
if (-e $newfilename) { |
my $error_fh = IO::File->new(">>$error_filename"); |
my $result = &process_courselog($newfilename); |
|
|
## |
|
## Parse the course log |
|
$logthis->('processing course log'); |
|
if (-s $newfilename) { |
|
my $result = &process_courselog($newfilename,$error_fh); |
if (! defined($result)) { |
if (! defined($result)) { |
# Something went wrong along the way... |
# Something went wrong along the way... |
|
$logthis->('process_courselog returned undef'); |
exit 5; |
exit 5; |
} elsif ($result > 0) { |
} elsif ($result > 0) { |
$time_this->(); |
$time_this->(); |
&backup_tables($sql_filename); |
$logthis->('process_courselog returned '.$result.' backing up tables'); |
|
&backup_tables($gz_sql_filename); |
$time_this->('write backup tables'); |
$time_this->('write backup tables'); |
} |
} |
|
if ($drop_when_done) { &drop_tables(); $logthis->('dropped tables'); } |
} |
} |
|
close($error_fh); |
|
|
## |
## |
## Clean up the filesystem |
## Clean up the filesystem |
## |
|
&Apache::lonmysql::disconnect_from_db(); |
&Apache::lonmysql::disconnect_from_db(); |
unlink($newfilename) if (! $nocleanup); |
unlink($newfilename) if (-e $newfilename && ! $nocleanup); |
|
|
|
## |
|
## Print timing data |
|
$logthis->('printing timing data'); |
if ($time_run) { |
if ($time_run) { |
print "Overall time: ".(Time::HiRes::time - $initial_time).$/; |
my $elapsed_time = Time::HiRes::time - $initial_time; |
|
print "Overall time: ".$elapsed_time.$/; |
print &outputtimes(); |
print &outputtimes(); |
|
$logthis->("Overall time: ".$elapsed_time); |
|
$logthis->(&outputtimes()); |
|
} |
|
|
|
if ($log) { |
|
close LOGFILE; |
|
} |
|
|
|
foreach my $file ($lockfilename, $error_filename,$logfile) { |
|
if (-z $file) { |
|
unlink($file); |
|
} |
} |
} |
|
|
|
|
exit 0; # Everything is okay, so end here before it gets worse. |
exit 0; # Everything is okay, so end here before it gets worse. |
|
|
######################################################## |
######################################################## |
Line 308 exit 0; # Everything is okay, so end h
|
Line 429 exit 0; # Everything is okay, so end h
|
# |
# |
# Returns the number of lines in the activity.log file that were processed. |
# Returns the number of lines in the activity.log file that were processed. |
sub process_courselog { |
sub process_courselog { |
my ($inputfile) = @_; |
my ($inputfile,$error_fh) = @_; |
if (! open(IN,$inputfile)) { |
if (! open(IN,$inputfile)) { |
warn "Unable to open '$inputfile' for reading"; |
warn "Unable to open '$inputfile' for reading"; |
|
$logthis->("Unable to open '$inputfile' for reading"); |
return undef; |
return undef; |
} |
} |
my ($linecount,$insertcount); |
my ($linecount,$insertcount); |
Line 341 sub process_courselog {
|
Line 463 sub process_courselog {
|
$log = &unescape($log); |
$log = &unescape($log); |
$time_this->('translate_and_unescape'); |
$time_this->('translate_and_unescape'); |
# now go over all log entries |
# now go over all log entries |
|
if (! defined($host)) { $host = 'unknown'; } |
my $machine_id = &get_id($machine_table,'machine',$host); |
my $machine_id = &get_id($machine_table,'machine',$host); |
foreach (split(/\&\&\&/,$log)) { |
my $prevchunk = 'none'; |
|
foreach my $chunk (split(/\&\&\&/,$log)) { |
|
my $warningflag = ''; |
$time_this->(); |
$time_this->(); |
my ($time,$res,$uname,$udom,$action,@values)= split(/:/,$_); |
my ($time,$res,$uname,$udom,$action,@values)= split(/:/,$chunk); |
|
my $student = $uname.':'.$udom; |
if (! defined($res) || $res =~ /^\s*$/) { |
if (! defined($res) || $res =~ /^\s*$/) { |
$res = '/adm/roles'; |
$res = '/adm/roles'; |
$action = 'log in'; |
$action = 'LOGIN'; |
} |
} |
if ($res =~ m|^/prtspool/|) { |
if ($res =~ m|^/prtspool/|) { |
$res = '/prtspool/'; |
$res = '/prtspool/'; |
} |
} |
if (! defined($action) || $action eq '') { |
if (! defined($action) || $action eq '') { |
$action = 'view'; |
$action = 'VIEW'; |
} |
} |
my $student = $uname.':'.$udom; |
if ($action !~ /^(LOGIN|VIEW|POST|CSTORE|STORE)$/) { |
|
$warningflag .= 'action'; |
|
print $error_fh 'full log entry:'.$log.$/; |
|
print $error_fh 'error on chunk:'.$chunk.$/; |
|
$logthis->('(action) Unable to parse '.$/.$chunk.$/. |
|
'got '. |
|
'time = '.$time.$/. |
|
'res = '.$res.$/. |
|
'uname= '.$uname.$/. |
|
'udom = '.$udom.$/. |
|
'action='.$action.$/. |
|
'@values = '.join('&',@values)); |
|
next; #skip it if we cannot understand what is happening. |
|
} |
|
if (! defined($student) || $student eq ':') { |
|
$student = 'unknown'; |
|
$warningflag .= 'student'; |
|
} |
|
if (! defined($res) || $res =~ /^\s*$/) { |
|
$res = 'unknown'; |
|
$warningflag .= 'res'; |
|
} |
|
if (! defined($action) || $action =~ /^\s*$/) { |
|
$action = 'unknown'; |
|
$warningflag .= 'action'; |
|
} |
|
if (! defined($time) || $time !~ /^\d+$/) { |
|
$time = 0; |
|
$warningflag .= 'time'; |
|
} |
|
# |
$time_this->('split_and_error_check'); |
$time_this->('split_and_error_check'); |
my $student_id = &get_id($student_table,'student',$student); |
my $student_id = &get_id($student_table,'student',$student); |
my $res_id = &get_id($res_table,'resource',$res); |
my $res_id = &get_id($res_table,'resource',$res); |
my $action_id = &get_id($action_table,'action',$action); |
# my $action_id = &get_id($action_table,'action',$action); |
my $sql_time = &Apache::lonmysql::sqltime($time); |
my $sql_time = &Apache::lonmysql::sqltime($time); |
my $values = $dbh->quote(join('',@values)); |
# |
|
if (! defined($student_id) || $student_id eq '') { |
|
$warningflag.='student_id'; |
|
} |
|
if (! defined($res_id) || $res_id eq '') { |
|
$warningflag.='res_id'; |
|
} |
|
# if (! defined($action_id) || $action_id eq '') { |
|
# $warningflag.='action_id'; |
|
# } |
|
if ($warningflag ne '') { |
|
print $error_fh 'full log entry:'.$log.$/; |
|
print $error_fh 'error on chunk:'.$chunk.$/; |
|
$logthis->('warningflag ('.$warningflag.') on chunk '. |
|
$/.$chunk.$/.'prevchunk = '.$/.$prevchunk); |
|
$prevchunk .= $chunk; |
|
next; # skip this chunk |
|
} |
|
# |
|
my $store_values; |
|
if ($action eq 'POST') { |
|
$store_values = |
|
$dbh->quote(join('&',map { &escape($_); } @values)); |
|
} else { |
|
$store_values = $dbh->quote(join('&',@values)); |
|
} |
$time_this->('get_ids'); |
$time_this->('get_ids'); |
# |
# |
my $row = [$res_id, |
my $row = [$res_id, |
qq{'$sql_time'}, |
qq{'$sql_time'}, |
$student_id, |
$student_id, |
$action_id, |
"'".$action."'", |
|
# $action_id, |
qq{''}, # idx |
qq{''}, # idx |
$machine_id, |
$machine_id, |
$values]; |
$store_values]; |
push(@RowData,$row); |
push(@RowData,$row); |
$time_this->('push_row'); |
$time_this->('push_row'); |
|
$prevchunk = $chunk; |
# |
# |
} |
} |
$time_this->(); |
$time_this->(); |
if ($linecount % 100 == 0) { |
if ((scalar(@RowData) > 0) && ($linecount % 100 == 0)) { |
my $result = &Apache::lonmysql::bulk_store_rows($activity_table, |
my $result = &Apache::lonmysql::bulk_store_rows($activity_table, |
undef, |
undef, |
\@RowData); |
\@RowData); |
|
# $logthis->('result = '.$result); |
$time_this->('bulk_store_rows'); |
$time_this->('bulk_store_rows'); |
if (! defined($result)) { |
if (! defined($result)) { |
warn "Error occured during insert.". |
my $error = &Apache::lonmysql::get_error(); |
&Apache::lonmysql::get_error(); |
warn "Error occured during insert.".$error; |
|
$logthis->('error = '.$error); |
} |
} |
undef(@RowData); |
undef(@RowData); |
} |
} |
} |
} |
if (@RowData) { |
if (@RowData) { |
$time_this->(); |
$time_this->(); |
|
$logthis->('storing '.$linecount); |
my $result = &Apache::lonmysql::bulk_store_rows($activity_table, |
my $result = &Apache::lonmysql::bulk_store_rows($activity_table, |
undef, |
undef, |
\@RowData); |
\@RowData); |
|
$logthis->('result = '.$result); |
$time_this->('bulk_store_rows'); |
$time_this->('bulk_store_rows'); |
if (! defined($result)) { |
if (! defined($result)) { |
warn "Error occured during insert.". |
my $error = &Apache::lonmysql::get_error(); |
&Apache::lonmysql::get_error(); |
warn "Error occured during insert.".$error; |
|
$logthis->('error = '.$error); |
} |
} |
undef(@RowData); |
undef(@RowData); |
} |
} |
Line 406 sub process_courselog {
|
Line 594 sub process_courselog {
|
return $linecount; |
return $linecount; |
} |
} |
|
|
|
|
|
## |
|
## Somtimes, instead of doing something, doing nothing is appropriate. |
|
sub nothing { |
|
return; |
|
} |
|
|
|
## |
|
## Logging routine |
|
## |
|
sub log_to_file { |
|
my ($input)=@_; |
|
print LOGFILE $input.$/; |
|
} |
|
|
## |
## |
## Timing routines |
## Timing routines |
## |
## |
Line 413 sub process_courselog {
|
Line 616 sub process_courselog {
|
my %Timing; |
my %Timing; |
my $starttime; |
my $starttime; |
|
|
sub nothing { |
|
return; |
|
} |
|
|
|
sub time_action { |
sub time_action { |
my ($key) = @_; |
my ($key) = @_; |
if (defined($key)) { |
if (defined($key)) { |
Line 449 sub outputtimes {
|
Line 648 sub outputtimes {
|
## Use mysqldump to store backups of the tables |
## Use mysqldump to store backups of the tables |
## |
## |
sub backup_tables { |
sub backup_tables { |
my ($sql_filename) = @_; |
my ($gz_sql_filename) = @_; |
my $command = qq{mysqldump --opt loncapa }; |
my $command = qq{mysqldump --quote-names --opt loncapa }; |
|
foreach my $table (@ID_Tables,@Activity_Table) { |
foreach my $table (@Activity_Tables) { |
|
my $tablename = $table->{'id'}; |
my $tablename = $table->{'id'}; |
|
$tablename =~ s/\`//g; |
$command .= $tablename.' '; |
$command .= $tablename.' '; |
} |
} |
$command .= '>'.$sql_filename; |
$command .= '| gzip >'.$gz_sql_filename; |
warn $command.$/; |
$logthis->($command); |
system($command); |
system($command); |
} |
} |
|
|
Line 465 sub backup_tables {
|
Line 664 sub backup_tables {
|
## Load in mysqldumped files |
## Load in mysqldumped files |
## |
## |
sub load_backup_tables { |
sub load_backup_tables { |
my ($sql_filename) = @_; |
my ($gz_sql_filename) = @_; |
return undef if (! -e $sql_filename); |
if (-s $gz_sql_filename) { |
# Check for .my.cnf |
$logthis->('loading data from gzipped sql file'); |
my $command = 'mysql -e "SOURCE '.$sql_filename.'" loncapa'; |
my $command='gzip -dc '.$gz_sql_filename.' | mysql --database=loncapa'; |
warn $command.$/; |
system($command); |
system($command); |
$logthis->('finished loading gzipped data');; |
|
} else { |
|
return undef; |
|
} |
} |
} |
|
|
## |
## |
## |
## |
## |
## |
sub initialize_configuration { |
|
# Fake it for now: |
|
$perlvar{'lonSqlUser'} = 'www'; |
|
$perlvar{'lonSqlAccess'} = 'localhostkey'; |
|
$perlvar{'lonUsersDir'} = '/home/httpd/lonUsers'; |
|
$perlvar{'lonDefDomain'} = '103'; |
|
} |
|
|
|
sub update_process_name { |
sub update_process_name { |
my ($text) = @_; |
my ($text) = @_; |
$0 = 'parse_activity_log.pl: '.$text; |
$0 = 'parse_activity_log.pl: '.$text; |
Line 496 sub get_filename {
|
Line 690 sub get_filename {
|
} |
} |
|
|
sub create_tables { |
sub create_tables { |
foreach my $table (@Activity_Tables) { |
foreach my $table (@ID_Tables,@Activity_Table) { |
my $table_id = &Apache::lonmysql::create_table($table); |
my $table_id = &Apache::lonmysql::create_table($table); |
if (! defined($table_id)) { |
if (! defined($table_id)) { |
warn "Unable to create table ".$table->{'id'}.$/; |
warn "Unable to create table ".$table->{'id'}.$/; |
warn &Apache::lonmysql::build_table_creation_request($table).$/; |
$logthis->('Unable to create table '.$table->{'id'}); |
|
$logthis->(join($/,&Apache::lonmysql::build_table_creation_request($table))); |
return 0; |
return 0; |
} |
} |
} |
} |
Line 508 sub create_tables {
|
Line 703 sub create_tables {
|
} |
} |
|
|
sub drop_tables { |
sub drop_tables { |
foreach my $table (@Activity_Tables) { |
foreach my $table (@ID_Tables,@Activity_Table) { |
my $table_id = $table->{'id'}; |
my $table_id = $table->{'id'}; |
&Apache::lonmysql::drop_table($table_id); |
&Apache::lonmysql::drop_table($table_id); |
} |
} |
Line 525 sub drop_tables {
|
Line 720 sub drop_tables {
|
my %IDs; |
my %IDs; |
|
|
sub read_id_tables { |
sub read_id_tables { |
foreach my $table (@Activity_Tables) { |
foreach my $table (@ID_Tables) { |
my @Data = &Apache::lonmysql::get_rows($table->{'id'}); |
my @Data = &Apache::lonmysql::get_rows($table->{'id'}); |
|
my $count = 0; |
foreach my $row (@Data) { |
foreach my $row (@Data) { |
$IDs{$table->{'id'}}->{$row->[1]} = $row->[0]; |
$IDs{$table->{'id'}}->{$row->[1]} = $row->[0]; |
} |
} |
} |
} |
|
return; |
} |
} |
|
|
sub get_id { |
sub get_id { |
Line 551 sub get_id {
|
Line 748 sub get_id {
|
$IDs{$table}->{$value}=$Data[0]->[0]; |
$IDs{$table}->{$value}=$Data[0]->[0]; |
return $IDs{$table}->{$value}; |
return $IDs{$table}->{$value}; |
} else { |
} else { |
warn "Unable to retrieve id for $table $fieldname $value".$/; |
$logthis->("Unable to retrieve id for $table $fieldname $value"); |
return undef; |
return undef; |
} |
} |
} |
} |
Line 578 sub unescape {
|
Line 775 sub unescape {
|
$str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
$str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
return $str; |
return $str; |
} |
} |
|
|