[LON-CAPA-cvs] cvs: loncom /metadata_database parse_activity_log.pl

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 25 Aug 2004 15:55:17 -0000


matthew		Wed Aug 25 11:55:17 2004 EDT

  Modified files:              
    /loncom/metadata_database	parse_activity_log.pl 
  Log:
  Removed $action_table as MySQL really did not like doing joins with it.
  logfile now appears in the lonDaemons directory.  Added indicies to
  the activity table on the student_id and time columns.
  
  
Index: loncom/metadata_database/parse_activity_log.pl
diff -u loncom/metadata_database/parse_activity_log.pl:1.3 loncom/metadata_database/parse_activity_log.pl:1.4
--- loncom/metadata_database/parse_activity_log.pl:1.3	Thu Aug 19 17:08:46 2004
+++ loncom/metadata_database/parse_activity_log.pl	Wed Aug 25 11:55:17 2004
@@ -2,7 +2,7 @@
 #
 # The LearningOnline Network
 #
-# $Id: parse_activity_log.pl,v 1.3 2004/08/19 21:08:46 matthew Exp $
+# $Id: parse_activity_log.pl,v 1.4 2004/08/25 15:55:17 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -99,7 +99,7 @@
 ## Set up logging code
 my $logthis = \&nothing;
 if ($log) {
-    my $logfile = "/tmp/parse_activity_log.log.".time;
+    my $logfile = $perlvar{'lonDaemons'}.'/tmp/parse_activity_log.log.'.time;
     print STDERR "$0: logging to $logfile".$/;
     if (! open(LOGFILE,">$logfile")) {
         die "Unable to open $logfile for writing.  Run aborted.";
@@ -183,20 +183,20 @@
   'PRIMARY KEY' => ['res_id'],
 };
 
-my $action_table = $prefix.'actions';
-my $action_table_def =
-{ id => $action_table,
-  permanent => 'no',
-  columns => [{ name => 'action_id',
-                type => 'MEDIUMINT UNSIGNED',
-                restrictions => 'NOT NULL',
-                auto_inc     => 'yes', },
-              { name => 'action',
-                type => 'VARCHAR(100)',
-                restrictions => 'NOT NULL'},
-              ],
-  'PRIMARY KEY' => ['action_id',], 
-};
+#my $action_table = $prefix.'actions';
+#my $action_table_def =
+#{ id => $action_table,
+#  permanent => 'no',
+#  columns => [{ name => 'action_id',
+#                type => 'MEDIUMINT UNSIGNED',
+#                restrictions => 'NOT NULL',
+#                auto_inc     => 'yes', },
+#              { name => 'action',
+#                type => 'VARCHAR(100)',
+#                restrictions => 'NOT NULL'},
+#              ],
+#  'PRIMARY KEY' => ['action_id',], 
+#};
 
 my $machine_table = $prefix.'machine_table';
 my $machine_table_def =
@@ -227,8 +227,8 @@
               { name => 'student_id',
                 type => 'MEDIUMINT UNSIGNED',
                 restrictions => 'NOT NULL',},
-              { name => 'action_id',
-                type => 'MEDIUMINT UNSIGNED',
+              { name => 'action',
+                type => 'VARCHAR(10)',
                 restrictions => 'NOT NULL',},
               { name => 'idx',                # This is here in case a student
                 type => 'MEDIUMINT UNSIGNED', # has multiple submissions during
@@ -240,12 +240,17 @@
               { name => 'action_values',
                 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_Table = ($activity_table_def);
-my @ID_Tables = ($student_table_def,$res_table_def,
-                 $action_table_def,$machine_table_def);
-                       
+my @Activity_Table = ($activity_table_def); 
+
+#my @ID_Tables = ($student_table_def,$res_table_def,
+#                 $action_table_def,$machine_table_def);
+
+my @ID_Tables = ($student_table_def,$res_table_def,$machine_table_def);
+                      
 
 ##
 ## End of table definitions
@@ -443,7 +448,7 @@
             $time_this->('split_and_error_check');
             my $student_id = &get_id($student_table,'student',$student);
             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);
             #
             if (! defined($student_id) || $student_id eq '') { 
@@ -452,9 +457,9 @@
             if (! defined($res_id) || $res_id eq '') { 
                 $warningflag.='res_id'; 
             }
-            if (! defined($action_id) || $action_id eq '') { 
-                $warningflag.='action_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.$/;
@@ -470,7 +475,8 @@
             my $row = [$res_id,
                        qq{'$sql_time'},
                        $student_id,
-                       $action_id,
+                       "'".$action."'",
+#                       $action_id,
                        qq{''},        # idx
                        $machine_id,
                        $values];
@@ -619,9 +625,11 @@
 sub create_tables {
     foreach my $table (@ID_Tables,@Activity_Table) {
         my $table_id = &Apache::lonmysql::create_table($table);
+#        print STDERR "Unable to create table ".$table->{'id'}.$/;
+#        print STDERR join($/,&Apache::lonmysql::build_table_creation_request($table)).$/;
         if (! defined($table_id)) {
             warn "Unable to create table ".$table->{'id'}.$/;
-            warn &Apache::lonmysql::build_table_creation_request($table).$/;
+            warn join($/,&Apache::lonmysql::build_table_creation_request($table)).$/;
             return 0;
         }
     }