Annotation of loncom/debugging_tools/login_count.pl, revision 1.2

1.2     ! albertel    1: use strict;
1.1       albertel    2: use File::Find;
                      3: use POSIX qw(strftime);
                      4: use lib '/home/httpd/lib/perl/';
                      5: use LONCAPA::Configuration;
                      6: use Date::Manip;
1.2     ! albertel    7: 
        !             8: my $start_time=&UnixDate("Aug 30th 00:00:00 2004","%s");
        !             9: my @counts=('1','10','100','1000','10000','100000','250000');
        !            10: 
        !            11: 
1.1       albertel   12: sub only_user_activitylog_files {
                     13:     print (join("\n",@_));
                     14:     return 1;
                     15: }
                     16: 
                     17: my %data;
                     18: my $numusers;
                     19: sub process_activitylog_file {
                     20:     if ($File::Find::dir=~m|/\d/\d/\d/|) { return; }
                     21:     if ($_ ne 'activity.log') {	return; }
                     22:     open(FILE,"<$File::Find::name");
                     23:     $numusers++;
                     24:     my $user=(split('/',$File::Find::dir))[-1];
                     25:     while (my $line=<FILE>) {
                     26: 	if ($line !~ /Login/) { next; }
                     27: 	my ($date)=split(':',$line,2);
                     28: 	if ($date > 1093838400) { push (@{$data{$date}},$user);	}
                     29:     }
                     30:     if ($numusers%100 == 0) {
                     31: 	print "\b\b\b\b\b\b\b\b\b\b\b\b\b\bDid $user";
                     32:     }
                     33: }
1.2     ! albertel   34: 
1.1       albertel   35: sub print_data {
                     36:     my $total_login=0;
                     37:     my %byday;
                     38:     print("\n");
                     39:     foreach my $key (sort(keys(%data))) {
                     40: 	#print(scalar(localtime($key))." ".scalar(@{$data{$key}})."\n");
                     41: 	$total_login+=scalar(@{$data{$key}});
                     42: 	my $day=strftime('%F',localtime($key));
                     43: 	$byday{$day}+=scalar(@{$data{$key}});
1.2     ! albertel   44: 	while ($total_login >= $counts[0]) {
        !            45: 	    print("The $counts[0] ($total_login) login was ".
        !            46: 		  join(', ',@{$data{$key}})."\n");
        !            47:             shift(@counts);
        !            48:         }
        !            49: 
1.1       albertel   50:     }
                     51:     foreach my $key (sort(keys(%byday))) {
                     52:     	print("$key -> $byday{$key}\n");
                     53:     }
                     54:     print("total -> $total_login\n");
                     55: }
                     56: 
1.2     ! albertel   57: $|=1;
        !            58: sub main {
        !            59:     my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
        !            60:     find(
        !            61:          {
        !            62: #          preprocess => \&only_user_activitylog_files,
        !            63: #          wanted     => \&print_filename,
        !            64: #          wanted     => \&log_metadata,
        !            65: 	     wanted     => \&process_activitylog_file,
        !            66: 	 }, 
        !            67:          $perlvar->{'lonUsersDir'}.'/'.$perlvar->{'lonDefDomain'});
        !            68:     &print_data();
        !            69: }
        !            70: &main();
        !            71: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>