Diff for /loncom/debugging_tools/activity_to_accesscount.pl between versions 1.1 and 1.4

version 1.1, 2003/11/14 18:24:40 version 1.4, 2006/06/27 15:01:14
Line 1 Line 1
 #!/usr/bin/perl -w  #!/usr/bin/perl -w
 #  #
 use strict;  use strict;
   use GDBM_File;
 sub unescape {  use lib '/home/httpd/lib/perl/';
     my $str=shift;  use LONCAPA;
     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;  
     return $str;  
 }  
   
 my %resourceaccess;  my %resourceaccess;
   
 sub main {  sub main {
     my $file=$ARGV[0];      my $file=$ARGV[0];
     print STDERR "Using $file\n";      my $target = $ARGV[1];
       my ($owner) = ($target =~ m:.*/(.*)/nohist_accesscount.db:);
       print STDERR "source: $file\ntarget: $target\nowner: $owner\n";
       my $accesstime = 0;
       my $starttime = time;
       if (-e $target) {
    my $accessDB = &LONCAPA::locking_hash_tie($target,&GDBM_READER());
    if (! $accessDB) {
               warn "Unable to tie to $target";
               return;
           }
           #
           if (exists($accessDB->{'tabulated '.$file})) {
               $accesstime = $accessDB->{'tabulated '.$file};
           }
    &LONCAPA::locking_hash_untie($accessDB);
       }
       #
     my $line;      my $line;
     open FILEID,'<'.$file;      open FILEID,'<'.$file;
     my @allaccess;      my @allaccess;
     print STDERR "Access by resource\n\n";      print STDERR "Access by resource after $accesstime\n\n";
     my $numlines = 0;      my $numlines = 0;
     while ($line=<FILEID>) {      while ($line=<FILEID>) {
         $numlines++;          $numlines++;
Line 38  sub main { Line 52  sub main {
         shift(@accesses);          shift(@accesses);
  while (@accesses) {   while (@accesses) {
             my $date = shift(@accesses);              my $date = shift(@accesses);
               next if ($date =~ /\D/ || $date < $accesstime);
             my $access = shift(@accesses);              my $access = shift(@accesses);
             next if (! defined($access) || $access eq '' ||               next if (! defined($access) || $access eq '' || 
                      ! defined($date)   || $date   eq '');                       ! defined($date)   || $date   eq '');
             $access =~ s/(\&$|^:)//g;              $access =~ s/(\&$|^:)//g;
             my ($resource,$who,$domain,$post,@posts)=split(':',$access);              my ($resource,$who,$domain,$post,@posts)=split(':',$access);
     if (!$resource) {      if (!$resource || $resource eq '') {
                 next;                   next; 
             }              }
             $resource = &unescape($resource);              $resource = &unescape($resource);
             if ($resource !~ m:/: || $resource =~ m:/prtspool/:) {              if ($resource !~ m:/$owner/:) {
                 next;                  next;
             }              }
             if ($resource =~ /___\d+___/) {              if ($resource =~ /___\d+___/) {
                 (undef,$resource) = split(/___\d+___/,$resource);                  (undef,$resource) = split(/___\d+___/,$resource);
             }              }
             next if ($resource =~ m:^/(res/adm|adm)/:);              next if ($resource =~ m:^/(res/adm|adm)/:);
             $resource =~ s:^/?res/?::;              $resource =~ s:^/?res/::;
             $resourceaccess{$resource}++;                          $resourceaccess{$resource}++;            
  }   }
     }      }
     print STDERR 'done.'.$/;      print STDERR 'done.  Updating '.$target.$/;
   
       my $accessDB = &LONCAPA::locking_hash_tie($target,&GDBM_WRCREAT());
       if (! $accessDB) {
           warn "Unable to open $target to store data".$/;
           return;
       }
       #
     while (my ($resource,$count) = each(%resourceaccess)) {      while (my ($resource,$count) = each(%resourceaccess)) {
           $resource = &escape($resource);
           if (exists($accessDB->{$resource})) {
               $accessDB->{$resource}+=$count;
           } else {
               $accessDB->{$resource} = $count;
           }
         print sprintf("%10.0f",$count).':'.$resource."\n";          print sprintf("%10.0f",$count).':'.$resource."\n";
     }      }
       $accessDB->{'tabulated '.$file} = $starttime;
       &LONCAPA::locking_hash_untie($accessDB);
 }  }
   
 main;  main;

Removed from v.1.1  
changed lines
  Added in v.1.4


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