line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sakai::Stats; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
41216
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
151
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
97
|
|
6
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
229
|
|
7
|
1
|
|
|
1
|
|
633
|
use Sakai::Stats::Database; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Sakai::Stats::Institutions; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use base qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = (); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#{{{sub new |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
|
|
|
|
|
|
my ($class) = @_; |
22
|
|
|
|
|
|
|
my $dbhost = 'localhost'; |
23
|
|
|
|
|
|
|
my $dbname = 'sakai'; |
24
|
|
|
|
|
|
|
my $dbpass = 'pass'; |
25
|
|
|
|
|
|
|
my $dbport = '3306'; |
26
|
|
|
|
|
|
|
my $dbuser = 'user'; |
27
|
|
|
|
|
|
|
my $help; |
28
|
|
|
|
|
|
|
my $institution; |
29
|
|
|
|
|
|
|
my $ldapbase; |
30
|
|
|
|
|
|
|
my $ldaphost; |
31
|
|
|
|
|
|
|
my $ldapinstbase; |
32
|
|
|
|
|
|
|
my $man; |
33
|
|
|
|
|
|
|
my $workdir = '.'; |
34
|
|
|
|
|
|
|
my @years; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $stats = { |
37
|
|
|
|
|
|
|
DBHost => $dbhost, |
38
|
|
|
|
|
|
|
DBName => $dbname, |
39
|
|
|
|
|
|
|
DBPass => $dbpass, |
40
|
|
|
|
|
|
|
DBPort => $dbport, |
41
|
|
|
|
|
|
|
DBUser => $dbuser, |
42
|
|
|
|
|
|
|
Help => $help, |
43
|
|
|
|
|
|
|
Institution => $institution, |
44
|
|
|
|
|
|
|
LdapBase => $ldapbase, |
45
|
|
|
|
|
|
|
LdapHost => $ldaphost, |
46
|
|
|
|
|
|
|
LdapInstBase => $ldapinstbase, |
47
|
|
|
|
|
|
|
Man => $man, |
48
|
|
|
|
|
|
|
WorkDir => $workdir, |
49
|
|
|
|
|
|
|
Years => \@years, |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
bless $stats, $class; |
52
|
|
|
|
|
|
|
return $stats; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#}}} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#{{{sub generate_institution_stats |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub generate_institution_stats { |
60
|
|
|
|
|
|
|
my ($stats) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Generate map of user to institution id(s): |
63
|
|
|
|
|
|
|
my $institutions = new Sakai::Stats::Institutions( \$stats ); |
64
|
|
|
|
|
|
|
$institutions->generate_user_insts |
65
|
|
|
|
|
|
|
|| croak 'Problem generating user to institution(s) map.'; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Generate map of instid to institution name: |
68
|
|
|
|
|
|
|
$institutions->generate_names_for_ids |
69
|
|
|
|
|
|
|
|| croak 'Problem generating institution id to name map.'; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$institutions->inst_membership_count |
72
|
|
|
|
|
|
|
|| croak 'Problem generating institution membership count map.'; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Connect to the database containing data: |
75
|
|
|
|
|
|
|
my $database = new Sakai::Stats::Database( \$stats ); |
76
|
|
|
|
|
|
|
$database->make_connection || croak 'Problem connecting to the database.'; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Clear the unique instid file if already present: |
79
|
|
|
|
|
|
|
if ( -e $stats->{'WorkDir'} . '/unique_instids.csv' ) { |
80
|
|
|
|
|
|
|
unlink $stats->{'WorkDir'} . '/unique_instids.csv'; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my @months = |
84
|
|
|
|
|
|
|
( '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', |
85
|
|
|
|
|
|
|
'12' ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
foreach my $year ( @{ $stats->{'Years'} } ) { |
88
|
|
|
|
|
|
|
foreach my $month (@months) { |
89
|
|
|
|
|
|
|
$institutions->unique_for_month( $year, $month, \$database ) |
90
|
|
|
|
|
|
|
|| croak |
91
|
|
|
|
|
|
|
'Problem generating unique institutions per month statistics.'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
return 1; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#}}} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#{{{sub generate |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub generate { |
102
|
|
|
|
|
|
|
my ($stats) = @_; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Set up default set of years if none have been specifed: |
105
|
|
|
|
|
|
|
if ( !defined @{ $stats->{'Years'} } ) { |
106
|
|
|
|
|
|
|
@{ $stats->{'Years'} } = |
107
|
|
|
|
|
|
|
( '2005', '2006', '2007', '2008', '2009', '2010', '2011' ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
if ( $stats->{'Institution'} ) { |
111
|
|
|
|
|
|
|
$stats->generate_institution_stats; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
return 1; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
#}}} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#{{{sub stats_config |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub stats_config { |
121
|
|
|
|
|
|
|
my ($stats) = @_; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my %stats_config = ( |
124
|
|
|
|
|
|
|
'dbhost' => \$stats->{'DBHost'}, |
125
|
|
|
|
|
|
|
'dbname' => \$stats->{'DBName'}, |
126
|
|
|
|
|
|
|
'dbpass' => \$stats->{'DBPass'}, |
127
|
|
|
|
|
|
|
'dbport' => \$stats->{'DBPort'}, |
128
|
|
|
|
|
|
|
'dbuser' => \$stats->{'DBUser'}, |
129
|
|
|
|
|
|
|
'help' => \$stats->{'Help'}, |
130
|
|
|
|
|
|
|
'institution' => \$stats->{'Institution'}, |
131
|
|
|
|
|
|
|
'ldapbase' => \$stats->{'LdapBase'}, |
132
|
|
|
|
|
|
|
'ldaphost' => \$stats->{'LdapHost'}, |
133
|
|
|
|
|
|
|
'ldapinstbase' => \$stats->{'LdapInstBase'}, |
134
|
|
|
|
|
|
|
'man' => \$stats->{'Man'}, |
135
|
|
|
|
|
|
|
'workdir' => \$stats->{'WorkDir'}, |
136
|
|
|
|
|
|
|
'years' => \@{ $stats->{'Years'} }, |
137
|
|
|
|
|
|
|
); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return \%stats_config; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#}}} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |