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

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 17 Mar 2005 20:36:48 -0000


This is a MIME encoded message

--raeburn1111091808
Content-Type: text/plain

raeburn		Thu Mar 17 15:36:48 2005 EDT

  Added files:                 
    /modules/raeburn	HS_usage.pl 
  Log:
  Script to gather information about course use and enrollment, and types of file in CSTR.
  
  
--raeburn1111091808
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20050317153648.txt"


Index: modules/raeburn/HS_usage.pl
+++ modules/raeburn/HS_usage.pl
#!/usr/bin/perl
use strict;
use lib '/home/httpd/lib/perl';
use Apache::lonnet;
use Apache::loncommon;
use LONCAPA::Configuration;
                                                                              
# Determine the library server's domain and hostID
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
my $logfile = $$perlvarref{'lonDaemons'}.'/logs/usage.log';
my @domains = &Apache::lonnet::current_machine_domains();
my @hostids = &Apache::lonnet::current_machine_ids();
my @allowners = ();
my %ownernames = ();
my %owneremails = ();
my %lastactivity = ();
my %totals = ();
my %sizes = ();

                                                                              
# 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;
        my $lastvisit = 0;
# get timestamp for activity log
        my $longcrs;
        if ($crs =~ m/^(\w)(\w)(\w)/) {
            $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
        }
        my $crsdir = $$perlvarref{'lonUsersDir'}.'/'.$dom.'/'.$longcrs;
        my $acfile = $crsdir.'/activity.log';
        my $classlist = $crsdir.'/classlist.db';
        if (-e $acfile) {
            my @statinfo = stat($acfile);
            $lastvisit = $statinfo[9];
        }
        my $stucount = 0;
        if (-e "$classlist") {
            my %classlist = &Apache::lonnet::dump('classlist',$cdom,$crs);
            foreach my $item (sort keys %classlist) {
                $stucount ++;
            }
        }
        my %crsenv = &Apache::lonnet::dump('environment',$cdom,$crs);
        my $owner;
        my $ownerdom;
        my $ownername;
        my $ownermail;

        foreach my $key (%crsenv) {
            if ($key eq 'internal.courseowner') {
                $owner = $crsenv{$key};
            }
        }

        my %roles = &Apache::lonnet::get_course_adv_roles($cdom.'_'.$crs);
        foreach my $role (sort keys %roles) {
            if ($role eq 'Course Coordinator') {
                my @ccroles = split/,/,$roles{$role};
                foreach (@ccroles) {
                    my ($uname,$udom) = split/:/,$_;
                    if ($uname eq $owner) {
                        $ownerdom = $udom;
                    } elsif ($uname ne 'felicia' && $uname ne 'raeburn' && $uname ne 'albertelli') {
                        if (!$owner) {
                            $owner = $uname;
                            $ownerdom = $udom;
                        }
                    }
                }
            }
        }
        if ($owner) {
            if (!$ownerdom) {
                $ownerdom = $cdom;
            }
            unless (grep/^$owner:$ownerdom/,@allowners) {
                push @allowners, $owner.':'.$ownerdom;
            }
            my %ownerhash =  &Apache::lonnet::dump('environment',$ownerdom,$owner);
            foreach my $key (sort keys %ownerhash) {
                if ($key eq 'firstname') {
                    $ownername = $ownerhash{$key};
                } elsif ($key eq 'lastname') {
                    $ownername .= ' '.$ownerhash{$key};
                } elsif ($key =~ /notification/) {
                    $ownermail = $ownerhash{$key};
                    $owneremails{$owner.':'.$ownerdom} = $ownermail;
                }
            }
            $ownernames{$owner.':'.$ownerdom} = $ownername;
            my %emailstatus = &Apache::lonnet::dump('email_status',$ownerdom,$owner);
            foreach my $key (sort keys %emailstatus) {
                if ($key eq 'logout') {
                    $lastactivity{$owner.':'.$ownerdom} = $emailstatus{$key};
                }
            }
        }

        if ($stucount > 0 && $lastvisit > 0) {
            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";
        }
    }
  }
}

# For each course owner..

foreach my $cc (@allowners) {
    my ($uname,$udom) = split/:/,$cc;
    %{$totals{$cc}} = ();
    %{$sizes{$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);
        }
        foreach my $type (sort keys %{$totals{$cc}}) {
            print "$cc -- $type - total files = $totals{$cc}{$type}\n";
            print "$cc -- $type - total bytes = $sizes{$cc}{$type}\n";
        }
    } else {
        print "$ownernames{$cc} ($cc) uses $udom server as a homeserver\n";
    }
}


sub readtree {
    my ($dir,$totals,$sizes,$author) = @_;
    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);
        } else {
            my @statinfo = stat("$dir/$item");
            my $size = $statinfo[7];
            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);
#                    print "$item -- embstyle is $embstyle\n";
                    if ($embstyle eq 'img') {
                        $totals{$author}{img} ++;
                        $sizes{$author}{img} += $size;
                    } else {
                        $$totals{$author}{'other'} ++;
                        $sizes{$author}{'other'} += $size;
                    }
                }
              }
            } else {
                $totals{$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?


--raeburn1111091808--