[LON-CAPA-cvs] cvs: modules /albertel get_access_times.pl
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 07 Sep 2007 21:26:59 -0000
albertel Fri Sep 7 17:26:59 2007 EDT
Added files:
/modules/albertel get_access_times.pl
Log:
- adding script to list all started timings in a course
Index: modules/albertel/get_access_times.pl
+++ modules/albertel/get_access_times.pl
use strict;
use Time::HiRes;
use lib '/home/httpd/lib/perl';
use LONCAPA;
use Apache::loncommon();
use Apache::lonnet;
use Apache::lonuserstate();
use Apache::lonnavmaps();
use Apache::loncoursedata();
use Getopt::Long;
my ($course_id,$username,$domain,$help);
sub get_opts {
&GetOptions("courseid=s" => \$course_id,
"username=s" => \$username,
"domain=s" => \$domain,
"help" => \$help);
if ($help || (!$course_id || !$username || !$domain)) {
print <<END;
Produces a listing of all resources that have Timer starts, in order
of time started. and the username of the user starting the timer.
Usage is:
--username=<username> --domain=<domain> --courseid=<courseid>
username domain is for a CC in the course, courseid should be the
internal course id of the course.
END
exit;
}
}
sub main {
&get_opts();
my $home = &Apache::lonnet::homeserver($username,$domain);
die("$username $domain has no home") if ($home eq 'no_host');
my $cookie =
&Apache::loncommon::init_user_environment(undef, $username, $domain,
$home, undef,
{'robot' =>
'get_access_times',});
die("$cookie") if ($cookie =~ 'error:');
my ($furl,$ferr) =
&Apache::lonuserstate::readmap(join('/',split('_',$course_id)));
die("$ferr") if ($ferr ne '');
my %access_by_symb;
my $classlist = &Apache::loncoursedata::get_classlist();
my $total = scalar(keys(%{ $classlist }));
my $i=0;
print("Processing classlist\n");
foreach my $student (sort(keys(%{ $classlist }))) {
#print(++$i."/$total\n");
my ($suname, $sudom) = split(/:/,$student);
my %data = &Apache::lonnet::dump('firstaccesstimes',
$sudom,$suname,
'^'.$env{'request.course.id'});
next if (&Apache::lonnet::error(%data));
foreach my $which (keys(%data)) {
my (undef,$symb) = split("\0", $which);
push(@{ $access_by_symb{$symb} }, [$suname,$data{$which}]);
}
}
foreach my $symb (sort(keys(%access_by_symb))) {
print("--- $symb\n");
my @all_access =
sort {$a->[1] <=> $b->[1]} (@{ $access_by_symb{$symb} });
foreach my $access (@all_access) {
printf("%10s on %s\n",$access->[0],
scalar(localtime($access->[1])));
}
}
}
&main();