line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## Webalizer::Hist, created by //YorHel |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Webalizer::Hist; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
21102
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
825
|
|
8
|
|
|
|
|
|
|
$VERSION = "0.03"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @webalizerheader = qw( month year totalhits totalfiles totalsites |
13
|
|
|
|
|
|
|
totalkbytes firstday lastday totalpages totalvisits ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
4
|
|
|
4
|
1
|
815
|
my $self = shift; |
17
|
4
|
|
33
|
|
|
22
|
my $class = ref($self) || $self; |
18
|
4
|
50
|
|
|
|
6
|
my %args; $#_ % 2 ? %args = @_ : warn "Odd argument list at " . __PACKAGE__ . "::new"; |
|
4
|
|
|
|
|
27
|
|
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
|
|
21
|
my $my = bless { desc => 1, %args, _curmonth => 0 }, $class; |
21
|
4
|
50
|
|
|
|
14
|
return $my->_parse() ? $my : undef; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub month { |
25
|
12
|
|
|
12
|
1
|
10377
|
my $self = shift; |
26
|
12
|
|
50
|
|
|
47
|
my $month = shift || undef; |
27
|
12
|
50
|
|
|
|
25
|
if($month) { |
28
|
0
|
|
|
|
|
0
|
foreach my $i (0..$#{$self->{_data}}) { |
|
0
|
|
|
|
|
0
|
|
29
|
0
|
0
|
|
|
|
0
|
if($self->{_data}[$i]{month} == $month) { |
30
|
0
|
|
|
|
|
0
|
$month = $i; |
31
|
0
|
|
|
|
|
0
|
last; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} else { |
35
|
12
|
|
|
|
|
20
|
$month = $self->{_curmonth}++; |
36
|
|
|
|
|
|
|
} |
37
|
12
|
50
|
|
|
|
14
|
return 0 if $month > $#{$self->{_data}}; |
|
12
|
|
|
|
|
34
|
|
38
|
|
|
|
|
|
|
|
39
|
12
|
|
|
|
|
19
|
my %hash = %{$self->{_data}[$month]}; |
|
12
|
|
|
|
|
90
|
|
40
|
12
|
|
|
|
|
33
|
my $days = $hash{lastday} - $hash{firstday} + 1; |
41
|
12
|
50
|
|
|
|
25
|
return 0 if !$days; |
42
|
12
|
|
|
|
|
49
|
foreach my $key (keys %hash) { |
43
|
120
|
100
|
|
|
|
746
|
$hash{"avg$1"} = sprintf("%.2f", $hash{$key}/$days) |
44
|
|
|
|
|
|
|
if $key =~ /^total(.+)$/; |
45
|
|
|
|
|
|
|
} |
46
|
12
|
|
|
|
|
118
|
return \%hash; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub totals { |
50
|
4
|
|
|
4
|
1
|
1674
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
6
|
my %hash; |
53
|
4
|
|
|
|
|
7
|
foreach my $key (@webalizerheader) { |
54
|
40
|
100
|
|
|
|
146
|
$hash{$1} = 0 if $key =~ /^total(.+)$/; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
8
|
foreach my $month (@{$self->{_data}}) { |
|
4
|
|
|
|
|
12
|
|
58
|
12
|
|
|
|
|
37
|
foreach my $key (keys %$month) { |
59
|
120
|
100
|
|
|
|
387
|
$hash{$1} += $month->{$key} if $key =~ /^total(.+)$/; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
25
|
return \%hash; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _parse { |
67
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
6
|
my @data; |
70
|
|
|
|
|
|
|
my @raw; |
71
|
4
|
100
|
33
|
|
|
25
|
if(ref($self->{source}) eq "SCALAR") { |
|
|
50
|
|
|
|
|
|
72
|
2
|
|
|
|
|
5
|
@raw = split(/\r?\n/, ${$self->{source}}); |
|
2
|
|
|
|
|
29
|
|
73
|
|
|
|
|
|
|
} elsif(!ref($self->{source}) && $self->{source}) { |
74
|
2
|
50
|
|
|
|
136
|
open(my $FH, "<$self->{source}") || return 0; |
75
|
2
|
|
|
|
|
62
|
push(@raw, $_) while(<$FH>); |
76
|
2
|
|
|
|
|
27
|
close($FH); |
77
|
|
|
|
|
|
|
} else { |
78
|
0
|
|
|
|
|
0
|
return 0; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
9
|
foreach my $line (@raw) { |
82
|
12
|
|
|
|
|
18
|
chomp($line); |
83
|
12
|
|
|
|
|
14
|
my $c = 0; my %line; my $item; |
|
12
|
|
|
|
|
15
|
|
84
|
12
|
|
|
|
|
100
|
foreach $item (split(/[\t\s]+/, $line)) { |
85
|
120
|
|
|
|
|
257
|
$line{$webalizerheader[$c++]} = int($item); |
86
|
|
|
|
|
|
|
} |
87
|
12
|
|
|
|
|
49
|
push(@data, \%line); |
88
|
|
|
|
|
|
|
} |
89
|
4
|
|
|
|
|
23
|
@data = sort { sprintf("%04d%02d", $b->{year}, $b->{month}) <=> sprintf("%04d%02d", $a->{year}, $a->{month}) } @data; |
|
10
|
|
|
|
|
52
|
|
90
|
4
|
100
|
|
|
|
14
|
@data = reverse @data if !$self->{desc}; |
91
|
4
|
|
|
|
|
9
|
$self->{_data} = \@data; |
92
|
4
|
|
|
|
|
24
|
return 1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |