[LON-CAPA-cvs] cvs: modules /gerd extract.pl makekeys.pl

www lon-capa-cvs@mail.lon-capa.org
Mon, 15 Jul 2002 12:34:25 -0000


www		Mon Jul 15 08:34:25 2002 EDT

  Added files:                 
    /modules/gerd	extract.pl makekeys.pl 
  Log:
  Helper programs to read, digests, and make anonymous "activity.log"
  
  

Index: modules/gerd/extract.pl
+++ modules/gerd/extract.pl
#!/usr/bin/perl
#
# The LearningOnline Network
#
# Extract datafiles, make anonymous
#
# $Id: extract.pl,v 1.1 2002/07/15 12:34:25 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###############################################################################
#
# Expects
#
# ../key/$class.key - key file $username:$keynumber
# ../rawdata/$class.log - log file
# ../rawdata/$class.seq - sequence file
# ../data writable
# ------------------------------------------------------------------ Course log

sub courselog {
    my $class=shift;
    open(IN,'../rawdata/'.$class.'.log') or die ('Input');
    open(OUT,'>../data/'.$class.'.log') or die('Output');
    while ($line=<IN>) {
        chomp($line);
        my ($timestamp,$host,$log)=split(/\:/,$line);
#
# $log has the actual log entries; currently still escaped, and
# %26(timestamp)%3a(url)%3a(user)%3a(domain)
# then additionally
# %3aPOST%3a(name)%3d(value)%3a(name)%3d(value)
# or
# %3aCSTORE%3a(name)%3d(value)%26(name)%3d(value)
#
# get delimiter between timestamped entries to be &&&
        $log=~s/\%26(\d+)\%3a/\&\&\&$1\%3a/g;
# now go over all log entries 
        foreach (split(/\&\&\&/,&unescape($log))) {
	    my ($time,$res,$uname,$udom,$action,@values)=split(/\:/,$_);
            my $values=&unescape(join(':',@values));
            $values=~s/\&/\:/g;
            $res=&unescape($res);
            $res=~s/^\/res\///;
            $res=~s/^\///;
            $res=~/([^\_]+)$/;
            if ($urlkey{$1}) { 
               $res=$urlkey{$1}; 
	    } elsif ($res!~/^adm\//) {
		$othernum++;
                &makeres('NONSEQ_'.$othernum,$1);
                $res=$urlkey{$1};
	    }
            $key=$mykey{$uname};
            if (($key) && ($res!~/^adm\//)) {
	    print OUT ($time<1000000000?'0':'').$time.':'.$key.':'.$res.':'.
                                            $action.':'.$values."\n";
            }
       }
    }
    close IN;
    close OUT;
}

# ----------------------------------------------------------- Read the key file

sub readkey {
    my $class=shift;
    open(KEYIN,'../key/'.$class.'.key') || die ('Keyfile');
    while ($line=<KEYIN>) {
	chomp($line);
        ($uname,$key)=split(/\:/,$line);
	$mykey{$uname}=$key;
    }
    close (KEYIN);
}

# ---------------------------------------------------------- Read sequence file
sub readseq {
    my $class=shift;
    %urlkey=('adm/logout' => 'LOGOUT',
             'adm/roles' => 'ROLES',
             'adm/navmaps' => 'NAV',
             'adm/flip' => 'FLIP',
             'adm/communicate' => 'CHECKMAIL',
             'adm/studentcalc' => 'CHECKGRADES',
             'adm/feedback' => 'COMMUNICATE');
    open(SEQIN,'../rawdata/'.$class.'.seq') || die ('Seqfile');
    while ($line=<SEQIN>) {
	chomp($line);
        ($key,$url)=split(/\:/,$line);
        $url=~s/^\/res\///;
        $url=~s/^\///;
        &makeres('RES_'.$key,$url);
    }
    close (SEQIN);
}

# ----------------------------------------------------- Make a res number entry
sub makeres {
    my ($name,$url)=@_;
    $urlkey{$url}=$name;
    print RESOUT $urlkey{$url}.':'.$url."\n";
}

# -------------------------------------------------------- Escape Special Chars

sub escape {
    my $str=shift;
    $str =~ s/(\W)/"%".unpack('H2',$1)/eg;
    return $str;
}

# ----------------------------------------------------- Un-Escape Special Chars

sub unescape {
    my $str=shift;
    $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
    return $str;
}

# ================================================================ Main Program

$class=shift;
&readkey($class);
$othernum=0;
open(RESOUT,'>../data/'.$class.'.res');
&readseq($class);
&courselog($class);
close(RESOUT);

Index: modules/gerd/makekeys.pl
+++ modules/gerd/makekeys.pl
$class=shift;
open(IN,'../rawdata/'.$class.'.grds') || die ('Could not open IN: '.$class);
open(OUT,'>../key/'.$class.'.key') || die ('Could not open OUT: '.$class);
$counter=1;
while ($line=<IN>) {
    $line=~/^(\w+)\s/;
    print OUT $1.':'.$counter."\n";
    $counter++;
}
close(OUT);
close(IN);