[LON-CAPA-cvs] cvs: modules /albertel course_info.pl

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 26 Jun 2007 23:57:29 -0000


albertel		Tue Jun 26 19:57:29 2007 EDT

  Modified files:              
    /modules/albertel	course_info.pl 
  Log:
  - enable skip_tries option
  - add a since option to skip courses that are unaccessed recently
  
  
  
Index: modules/albertel/course_info.pl
diff -u modules/albertel/course_info.pl:1.9 modules/albertel/course_info.pl:1.10
--- modules/albertel/course_info.pl:1.9	Wed Dec 20 17:43:19 2006
+++ modules/albertel/course_info.pl	Tue Jun 26 19:57:25 2007
@@ -15,22 +15,27 @@
 use POSIX;
 
 my $year;
+my $since;
 my $domain = 'all';
+my $domain_skip = '';
 my $skip_tries = 0;
 my $help;
-my $result = GetOptions ("year=i"    => \$year,
-			 "domain=s"  => \$domain,
-			 "skiptries" => \$skip_tries,
-			 "help"      => \$help,);
+my $result = GetOptions ("year=i"        => \$year,
+                         "since=i"       => \$since,
+			 "domain=s"      => \$domain,
+			 "domainskip=s"  => \$domain_skip,
+			 "skiptries"     => \$skip_tries,
+			 "help"          => \$help,);
                                
 if ($help) {
     print <<END;
 course_info.pl - create a set of files documenting course activity
 Options:
    --help     Display this help.
-   --year=    Do only course create in the specified year
+   --year=    Do only course created in the specified year
+   --since=   Do only courses accessed at least X seconds ago
    --domain=  Do only courses in the specified domain
-              
+   --domainskip=  Do only courses not in the specified domain
 Examples:
     course_info.pl --year=2004 --domain=msu
 END
@@ -47,17 +52,24 @@
 sub main {
     my @domains = &Apache::lonnet::current_machine_domains();
     my @hostids = &Apache::lonnet::current_machine_ids();
-    my @domains_do = split(',',$domain);
+    my @domains_do   = split(',',$domain);
+    my @domains_skip = split(',',$domain_skip);
     &init_screen();
     foreach my $dom (sort(@domains)) {
 	if ($domain ne 'all') {
 	    if (!grep(/\Q$dom\E/,@domains_do)) { next; }
 	}
+	if ( grep(/\Q$dom\E/,@domains_skip)) { next; }
 	&logfile("output/$year/$year.$dom.info");
 	&log("\n\n$dom\n");
 	&increaselog();
+	if ($since <100) {
+            $since = time()-$since;
+	} else {
+	    $since = 1;
+	}
 	my %courses = 
-	    &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,\@hostids,'.',1);
+	    &Apache::lonnet::courseiddump($dom,'.',$since,'.','.','.',1,\@hostids,'.',1);
 	my $course_count=0;
 	foreach my $key (sort 
 			 { 
@@ -94,7 +106,9 @@
     &log('Created on: '.scalar(localtime(&creation_date($cdom,$cnum)))."\n");
     &log_adv_users($cdom,$cnum);
     &log_classlist($cdom,$cnum);
-    &log_course_info($cdom,$cnum);
+    if (!$skip_tries) {
+        &log_course_info($cdom,$cnum);
+    }
     &decreaselog();
 }
 
@@ -227,6 +241,8 @@
 	if ($section eq 'NONE') { $cl_section=''; }
 	my ($active_users,$total_logins) = (0,0);
 	foreach my $user (keys(%{ $classlist })) {
+	    &status(1," user $section ");
+	    &status(0," user $user ");
 	    if ($classlist->{$user}[$seccol] ne $cl_section) { next; }
 	    &status(1," user $section ");
 	    &status(0," user $user ");
@@ -274,7 +290,6 @@
     my ($logins,$accrole);
     my $userdir = &Apache::loncommon::propath($udom,$uname);
     open(ACTIVITY,"<$userdir/activity.log");
-#    &log("<$userdir/activity.log");
     while (my $line=<ACTIVITY>) {
 	chomp($line);
 	my ($date,$mahine,$action) = split(':',$line);
@@ -368,9 +383,10 @@
 
     sub status {
 	my ($line,$msg) = @_;
-	if (length($msg) > $max_width-2) {
-	    $msg=substr($msg,0,$max_width-2);
+	if (length($msg) > $max_width-3) {
+	    $msg=substr($msg,0,$max_width-3);
 	}
+	$msg =~ s/[\r\n]//g;
 	$lines[$line] = $msg;
 	&update_screen();
     }