[LON-CAPA-cvs] cvs: modules /raeburn HS_usage.pl

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 21 Mar 2005 16:39:16 -0000


This is a MIME encoded message

--raeburn1111423156
Content-Type: text/plain

raeburn		Mon Mar 21 11:39:16 2005 EDT

  Modified files:              
    /modules/raeburn	HS_usage.pl 
  Log:
  Collect information about proportion of uploaded, imported or special documents in a course.
  
  
--raeburn1111423156
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20050321113916.txt"

Index: modules/raeburn/HS_usage.pl
diff -u modules/raeburn/HS_usage.pl:1.2 modules/raeburn/HS_usage.pl:1.3
--- modules/raeburn/HS_usage.pl:1.2	Thu Mar 17 16:12:13 2005
+++ modules/raeburn/HS_usage.pl	Mon Mar 21 11:39:16 2005
@@ -3,7 +3,10 @@
 use lib '/home/httpd/lib/perl';
 use Apache::lonnet;
 use Apache::loncommon;
+use Apache::lonuserstate;
+use Apache::lonnavmaps;
 use LONCAPA::Configuration;
+use GDBM_File;
                                                                               
 # Determine the library server's domain and hostID
 my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
@@ -13,19 +16,24 @@
 my @allowners = ();
 my %ownernames = ();
 my %owneremails = ();
+my %ownercourses = ();
 my %lastactivity = ();
 my %totals = ();
 my %sizes = ();
+my %publish = ();
+my %external = ();
+my %crscount = ();
+my %homegrown = ();
+my %uploaded = ();
+my %uploadtotal = ();
+my %folders = ();
+my %pages = ();
 
-                                                                              
 # Determine the present time;
 my $timenow = time();
 
-my @okdomains = ("webbervilleschools","brs","redford","portland","lakefenton","grandblanc","judson","leslie","novi"."ithaca","wmston","glps","haslett");
-                                                                              
 # For each domain ......
 foreach my $dom (@domains) {
-  if (grep/^$dom$/,@okdomains) {
     my %courses = &Apache::lonnet::courseiddump($dom,'.',1,'.','.',1,\@hostids);
     foreach my $key (sort keys %courses) {
         my ($cdom,$crs) = split/_/,$key;
@@ -35,7 +43,7 @@
         if ($crs =~ m/^(\w)(\w)(\w)/) {
             $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
         }
-        my $crsdir = $$perlvarref{'lonUsersDir'}.'/'.$dom.'/'.$longcrs;
+        my $crsdir = $$perlvarref{'lonUsersDir'}.'/'.$cdom.'/'.$longcrs;
         my $acfile = $crsdir.'/activity.log';
         my $classlist = $crsdir.'/classlist.db';
         if (-e $acfile) {
@@ -85,6 +93,24 @@
             unless (grep/^$owner:$ownerdom/,@allowners) {
                 push @allowners, $owner.':'.$ownerdom;
             }
+            unless (defined($ownercourses{$owner.':'.$ownerdom})) {
+                $ownercourses{$owner.':'.$ownerdom} = 0;
+            }
+            unless (defined($external{$owner.':'.$ownerdom})) {
+                $external{$owner.':'.$ownerdom} = 0;
+            }
+            unless (defined($homegrown{$owner.':'.$ownerdom})) {
+                $homegrown{$owner.':'.$ownerdom} = 0;
+            }
+            unless (defined($uploaded{$owner.':'.$ownerdom})) {
+                $uploaded{$owner.':'.$ownerdom} = 0;
+            }
+            unless (defined($uploadtotal{$owner.':'.$ownerdom})) {
+                $uploaded{$owner.':'.$ownerdom} = 0;
+            }
+            unless (defined($crscount{$owner.':'.$ownerdom})) {
+                %{$crscount{$owner.':'.$ownerdom}} = ();
+            }
             my %ownerhash =  &Apache::lonnet::dump('environment',$ownerdom,$owner);
             foreach my $key (sort keys %ownerhash) {
                 if ($key eq 'firstname') {
@@ -106,27 +132,103 @@
         }
 
         if ($stucount > 0 && $lastvisit > 0) {
+            my $crsitems = 0;
+            $ENV{'user.name'} = $owner;
+            $ENV{'user.home'} = &Apache::lonnet::homeserver($owner,$ownerdom);
+            $ENV{'user.domain'} = $ownerdom;
+
             print "$dom -- Found $key -- has value ".&Apache::lonnet::unescape($courses{$key})."\n";
             print "lastvisit ".localtime($lastvisit)." count is $stucount owner is $ownername, e-mail is $ownermail\n";
+            $ownercourses{$owner.':'.$ownerdom} ++;
+            my ($furl,$ferr) = &Apache::lonuserstate::readmap($cdom.'/'.$crs);
+            my $fn = $ENV{"request.course.fn"};
+            my %hash = ();
+            if (-e "$fn.db") {
+              if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
+                 foreach my $key (sort keys %hash) {
+                     if ($key =~ /^src_/) {
+                         $crsitems ++;
+                         my $src = $hash{$key};
+                         my $extension;
+                         $src =~ s#^/adm/wrapper##;
+                         if ($src =~ m-^/res/([^/]+)/([^/]+)/-) {
+                             if ($1 eq $ownerdom && $2 eq $owner) {
+                                 $homegrown{$owner.':'.$ownerdom} ++;
+                             } else {
+                                 if ($1 eq 'lib' && $2 eq 'templates') {
+                                     if ($src =~ m-/([^/]+)\.problem$-) {
+                                          $crscount{$owner.':'.$ownerdom}{$1} ++;
+                                     }
+                                 } else {
+                                     $external{$owner.':'.$ownerdom} ++;
+                                 }
+                             }
+                             ($extension) = ($src =~ m/\.([^\.]+)$/);
+                             $crscount{$owner.':'.$ownerdom}{$extension} ++;
+                         } elsif ($src =~ m-/adm/-) {
+                             $src =~ s/\?[^\?]*$//g;
+                             ($extension) = ($src =~ m-/([^/]+)$-);
+                             $crscount{$owner.':'.$ownerdom}{$extension} ++;
+                         } elsif ($src =~ m-/uploaded/-) {
+                             ($extension) = ($src =~ m-\.([^\.]+)$-);
+                             $crscount{$owner.':'.$ownerdom}{$extension} ++;
+                             if ($extension eq 'sequence') {
+                                 $folders{$owner.':'.$ownerdom} ++;
+                             } elsif ($extension eq 'page') {
+                                 $pages{$owner.':'.$ownerdom} ++;
+                             } else {
+                                 $uploaded{$owner.':'.$ownerdom} ++;
+                                 my $filepath = $src; 
+                                 $filepath =~ s#^/uploaded/$cdom/$crs#$crsdir/userfiles/#;
+                                 if (-e "$filepath") {
+                                     my @fileinfo = stat($filepath);
+                                     $uploadtotal{$owner.':'.$ownerdom} += $fileinfo[7];
+                                 }  
+                             }
+                         } elsif ($src =~ m-^/public/-) {
+                             $src =~ s/\?[^\?]*$//g;
+                             if ($src =~ m-syllabus$-) {
+                                 $crscount{$owner.':'.$ownerdom}{syllabus} ++;
+                             } else {
+                                 $crscount{$owner.':'.$ownerdom}{public} ++;
+                             }          
+                         } 
+                     }
+                 }
+                 untie %hash;
+               }
+            }
+            print "total items = $crsitems\n";
+            delete($ENV{'user.name'});
+            delete($ENV{'user.home'});
+            delete($ENV{'user.domain'});
         }
     }
-  }
 }
 
 # For each course owner..
 
 foreach my $cc (@allowners) {
+    print "Imported total = $external{$cc}\n";
+    print "Homegrown total = $homegrown{$cc}\n";
+    print "Uploaded total = $uploaded{$cc}\n";
+    print "Uploaded total bytes = $uploadtotal{$cc}\n";
+    foreach my $key (sort keys %{$crscount{$cc}}) {
+        print "Course item -- $key, value is $crscount{$cc}{$key}\n";
+    }
+
     my ($uname,$udom) = split/:/,$cc;
     %{$totals{$cc}} = ();
     %{$sizes{$cc}} = ();
+    %{$publish{$cc}} = ();
     if (grep/^$udom/,@domains) {
         print "$ownernames{$cc} ($cc) last activity ".localtime($lastactivity{$cc})." uses this server as a homeserver\n";
         if (-e "/home/$uname/public_html") {
-            print "reading tree for $uname\n";   
-            &readtree("/home/$uname/public_html",\%totals,\%sizes,$cc);
+            &readtree("/home/$uname/public_html",\%totals,\%sizes,\%publish,$cc,$uname,$udom);
         }
         foreach my $type (sort keys %{$totals{$cc}}) {
             print "$cc -- $type - total files = $totals{$cc}{$type}\n";
+            print "$cc -- $type - total published = $publish{$cc}{$type}\n";
             print "$cc -- $type - total bytes = $sizes{$cc}{$type}\n";
         }
     } else {
@@ -136,79 +238,54 @@
 
 
 sub readtree {
-    my ($dir,$totals,$sizes,$author) = @_;
+    my ($dir,$totals,$sizes,$publish,$author,$uname,$udom) = @_;
     opendir(DIR,$dir);
     my @items = grep(!/^\.\.?/,readdir(DIR));
     closedir(DIR);
     foreach my $item (@items) {
         if (-d "$dir/$item") {
-            $totals{$author}{dirs} ++;
-            &readtree("$dir/$item",$totals,$sizes,$author);
+            $$totals{$author}{dirs} ++;
+            my $resdir = "$dir/$item";
+            $resdir =~ s#/home/$uname/public_html#/home/httpd/html/res/$udom/$uname#;
+            if (-d $resdir) {
+                $$publish{$author}{dirs} ++;
+            } 
+            &readtree("$dir/$item",$totals,$sizes,$publish,$author,$uname,$udom);
         } else {
             my @statinfo = stat("$dir/$item");
+            my $published = 0;
             my $size = $statinfo[7];
+            my $resitem = "$dir/$item";
+            $resitem =~ s#/home/$uname/public_html#/home/httpd/html/res/$udom/$uname#;
+            if (-e "$resitem") {
+                $published = 1;
+            } 
             if ($item =~/\.(\w+)$/) {
               my $curfext = $1;
-              unless ($curfext eq 'bak' || $curfext eq 'log' ||$curfext eq 'meta' || $curfext eq 'save') { 
-                if ($curfext eq 'page') {
-                    $totals{$author}{page} ++;
-                    $sizes{$author}{page} += $size;
-                } elsif ($curfext eq 'sequence') {
-                    $totals{$author}{sequence} ++;
-                    $sizes{$author}{sequence} += $size;
-                } elsif ($curfext eq 'problem') {
-                    $totals{$author}{problem} ++;
-                    $sizes{$author}{problem} += $size;
-                } elsif ($curfext =~ /htm/i) {
-                    $totals{$author}{html} ++;
-                    $sizes{$author}{html} += $size;
-                } elsif ($curfext =~ /^(avi|mpg|qt|mov|asf)$/) {
-                    $totals{$author}{movie} ++;
-                    $sizes{$author}{movie} += $size;
-                } elsif ($curfext =~ /^(ppt|pps)$/) {
-                    $totals{$author}{ppt} ++;
-                    $sizes{$author}{ppt} += $size;
-                } elsif ($curfext =~ /^xls?$/) {
-                    $totals{$author}{xls} ++;
-                    $sizes{$author}{xls} += $size;
-                } elsif ($curfext eq 'doc') {
-                    $totals{$author}{doc} ++;
-                    $sizes{$author}{doc} += $size;
-                } elsif ($curfext eq 'txt' ) {
-                    $totals{$author}{txt} ++;
-                    $sizes{$author}{txt} += $size;
-                } elsif ($curfext eq 'pdf') {
-                    $totals{$author}{pdf} ++;
-                    $sizes{$author}{pdf} += $size;
-                } elsif ($curfext eq 'dat') {
-                    $totals{$author}{dat} ++;
-                    $sizes{$author}{dat} += $size;
-                } elsif ($curfext eq 'xml') {
-                    $totals{$author}{xml} ++;
-                    $sizes{$author}{xml} += $size;
-                } else {
-                    my $embstyle = &Apache::loncommon::fileembstyle($curfext);
-                    if ($embstyle eq 'img') {
-                        $totals{$author}{img} ++;
-                        $sizes{$author}{img} += $size;
-                    } else {
-                        $$totals{$author}{'other'} ++;
-                        $sizes{$author}{'other'} += $size;
+              $curfext = lc($curfext);
+              unless ($curfext eq 'bak' || $curfext eq 'log' ||$curfext eq 'meta' || $curfext eq 'save') {
+                $$totals{$author}{$curfext} ++;
+                if ($published) {
+                    $$publish{$author}{$curfext} ++;
+                }
+                $$sizes{$author}{$curfext} += $size;
+                my $embstyle = &Apache::loncommon::fileembstyle($curfext);
+                if ($embstyle eq 'img') {
+                    $$totals{$author}{img} ++;
+                    if ($published) {
+                        $$publish{$author}{img} ++;
                     }
+                    $$sizes{$author}{img} += $size;
                 }
               }
             } else {
-                $totals{$author}{noext} ++;
-                $sizes{$author}{noext} += $size;
+                $$totals{$author}{noext} ++;
+                if ($published) {
+                    $$publish{$author}{noext} ++;
+                }
+                $$sizes{$author}{noext} += $size;
             }
         }
     }
 }
 
-# how much is published?
-# how many resources used in course are homegrown versus from repository?
-# how many resources are uploaded docs versus res in courses?
-# how much discussion is there?
-# how much chat is there?
-# how much course e-mail is there?
-

--raeburn1111423156--