line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::List::Rows; |
2
|
7
|
|
|
7
|
|
166
|
use 5.008_001; |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
269
|
|
3
|
7
|
|
|
7
|
|
38
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
238
|
|
4
|
7
|
|
|
7
|
|
38
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
229
|
|
5
|
7
|
|
|
7
|
|
38
|
use Time::Piece; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
38
|
|
6
|
7
|
|
|
7
|
|
7139
|
use Class::Accessor::Lite; |
|
7
|
|
|
|
|
7567
|
|
|
7
|
|
|
|
|
91
|
|
7
|
7
|
|
|
7
|
|
3949
|
use Time::List::Rows::Row; |
|
7
|
|
|
|
|
76
|
|
|
7
|
|
|
|
|
268
|
|
8
|
7
|
|
|
7
|
|
63
|
use Time::List::Constant; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
52
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $unit_time = { |
13
|
|
|
|
|
|
|
DAY() => 3600 * 24 , |
14
|
|
|
|
|
|
|
WEEK() => 3600 * 24 * 7 , |
15
|
|
|
|
|
|
|
HOUR() => 3600 , |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %DEFAULTS = ( |
19
|
|
|
|
|
|
|
time_unit => DAY() , |
20
|
|
|
|
|
|
|
output_type => ARRAY() , |
21
|
|
|
|
|
|
|
limit_rows => 0 , |
22
|
|
|
|
|
|
|
input_strftime_form => '%Y-%m-%d %H:%M:%S', |
23
|
|
|
|
|
|
|
output_strftime_form => '%Y-%m-%d %H:%M:%S', |
24
|
|
|
|
|
|
|
show_end_time => 0 , |
25
|
|
|
|
|
|
|
end_time_separate_chars => '~' , |
26
|
|
|
|
|
|
|
time_array => [], |
27
|
|
|
|
|
|
|
time_rows => [], |
28
|
|
|
|
|
|
|
unixtime_rows_hash => {}, |
29
|
|
|
|
|
|
|
datetime_rows_hash => {}, |
30
|
|
|
|
|
|
|
create_summary => 0 , |
31
|
|
|
|
|
|
|
summary_key_name => "summary" |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Class::Accessor::Lite->mk_accessors(keys %DEFAULTS); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
4
|
|
|
4
|
0
|
9
|
my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
4
|
50
|
|
|
|
22
|
my %args = @_ == 1 ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
40
|
4
|
|
|
|
|
52
|
my $self = bless { |
41
|
|
|
|
|
|
|
%DEFAULTS, |
42
|
|
|
|
|
|
|
%args, |
43
|
|
|
|
|
|
|
}, $class; |
44
|
|
|
|
|
|
|
|
45
|
4
|
50
|
|
|
|
19
|
die "set time array" unless $self->time_array; |
46
|
4
|
|
|
|
|
33
|
$self->_create_time_rows(\%args); |
47
|
4
|
|
|
|
|
41
|
$self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _create_time_rows{ |
51
|
4
|
|
|
4
|
|
7
|
my ($self , $args) = @_; |
52
|
4
|
|
|
|
|
23
|
my $time_array = $self->time_array; |
53
|
33
|
|
|
|
|
176
|
my $time_rows = [map{ |
54
|
4
|
|
|
|
|
19
|
Time::List::Rows::Row->new(%$args , unixtime => $_); |
55
|
|
|
|
|
|
|
}@$time_array]; |
56
|
33
|
|
|
|
|
149
|
my $unixtime_rows_hash = {map{ |
57
|
4
|
|
|
|
|
12
|
$_->unixtime => $_, |
58
|
|
|
|
|
|
|
}@$time_rows}; |
59
|
33
|
|
|
|
|
163
|
my $datetime_rows_hash = {map{ |
60
|
4
|
|
|
|
|
62
|
$_->datetime => $_, |
61
|
|
|
|
|
|
|
}@$time_rows}; |
62
|
4
|
|
|
|
|
63
|
$self->time_rows($time_rows); |
63
|
4
|
|
|
|
|
27
|
$self->unixtime_rows_hash($unixtime_rows_hash); |
64
|
4
|
|
|
|
|
30
|
$self->datetime_rows_hash($datetime_rows_hash); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_row_from_datetime{ |
68
|
0
|
|
|
0
|
1
|
0
|
my ($self , $datetime) = @_; |
69
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$datetime}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_row_from_unixtime{ |
73
|
0
|
|
|
0
|
1
|
0
|
my ($self , $unixtime) = @_; |
74
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$unixtime}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub set_row_from_datetime{ |
78
|
0
|
|
|
0
|
1
|
0
|
my ($self , $datetime , $values) = @_; |
79
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$datetime}->set($values); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub set_row_from_unixtime{ |
83
|
0
|
|
|
0
|
1
|
0
|
my ($self , $unixtime , $values) = @_; |
84
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$unixtime}->set($values); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub set_rows_from_input_strftime{ |
88
|
0
|
|
|
0
|
0
|
0
|
my ($self , $rows) = @_; |
89
|
0
|
|
|
|
|
0
|
my $strf_form = $self->input_strftime_form; |
90
|
0
|
|
|
|
|
0
|
my $keys = {}; |
91
|
0
|
|
|
|
|
0
|
for my $time(keys %$rows){ |
92
|
0
|
|
|
|
|
0
|
my $values = $rows->{$time}; |
93
|
0
|
|
|
|
|
0
|
for(keys %$values){ |
94
|
0
|
|
|
|
|
0
|
$keys->{$_} = 1; |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
0
|
my $unixtime = Time::Piece->strptime($time , $strf_form)->strftime('%s'); |
97
|
0
|
|
|
|
|
0
|
my $row = $self->unixtime_rows_hash()->{$unixtime}; |
98
|
0
|
0
|
|
|
|
0
|
$row->set($values) if $row; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
0
|
my $time_rows = $self->time_rows(); |
101
|
0
|
|
|
|
|
0
|
for(@$time_rows){ |
102
|
0
|
|
0
|
|
|
0
|
$_->{$keys} ||= undef; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub set_rows_from_datetime{ |
107
|
5
|
|
|
5
|
1
|
11174
|
my ($self , $rows) = @_; |
108
|
5
|
|
|
|
|
11
|
my $keys = {}; |
109
|
5
|
|
|
|
|
20
|
for my $datetime(keys %$rows){ |
110
|
39
|
|
|
|
|
390
|
my $values = $rows->{$datetime}; |
111
|
39
|
|
|
|
|
98
|
for(keys %$values){ |
112
|
78
|
|
|
|
|
151
|
$keys->{$_} = 1; |
113
|
|
|
|
|
|
|
} |
114
|
39
|
|
|
|
|
109
|
my $row = $self->datetime_rows_hash()->{$datetime}; |
115
|
39
|
50
|
|
|
|
251
|
$row->set($values) if $row; |
116
|
|
|
|
|
|
|
} |
117
|
5
|
|
|
|
|
69
|
my $time_rows = $self->time_rows(); |
118
|
5
|
|
|
|
|
24
|
for(@$time_rows){ |
119
|
57
|
|
50
|
|
|
252
|
$_->{$keys} ||= undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub set_rows_from_unixtime{ |
124
|
0
|
|
|
0
|
1
|
0
|
my ($self , $rows) = @_; |
125
|
0
|
|
|
|
|
0
|
my $keys = {}; |
126
|
0
|
|
|
|
|
0
|
for my $unixtime(keys %$rows){ |
127
|
0
|
|
|
|
|
0
|
my $values = $rows->{$unixtime}; |
128
|
0
|
|
|
|
|
0
|
for(keys %$values){ |
129
|
0
|
|
|
|
|
0
|
$keys->{$_} = 1; |
130
|
|
|
|
|
|
|
} |
131
|
0
|
|
|
|
|
0
|
my $row = $self->unixtime_rows_hash()->{$unixtime}; |
132
|
0
|
0
|
|
|
|
0
|
$row->set($values) if $row; |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
0
|
my $time_rows = $self->time_rows(); |
135
|
0
|
|
|
|
|
0
|
for(@$time_rows){ |
136
|
0
|
|
0
|
|
|
0
|
$_->{$keys} ||= undef; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub get_array{ |
141
|
7
|
|
|
7
|
1
|
6077
|
my ($self) = @_; |
142
|
7
|
|
|
|
|
25
|
my $unixtime_rows_hash = $self->unixtime_rows_hash; |
143
|
7
|
100
|
|
|
|
41
|
if($self->create_summary){ |
144
|
2
|
|
|
|
|
12
|
my $summary = {}; |
145
|
48
|
|
|
|
|
136
|
my $rows = [map{ |
146
|
2
|
|
|
|
|
8
|
my $row = $unixtime_rows_hash->{$_->unixtime}->get_values; |
147
|
48
|
|
|
|
|
138
|
for my $key(keys %$row){ |
148
|
204
|
|
|
|
|
256
|
my $value = $row->{$key}; |
149
|
204
|
100
|
100
|
|
|
1463
|
if($value && $value =~ /(^|^-)(\d+|\d+\.\d+)$/){ |
150
|
107
|
|
|
|
|
224
|
$summary->{$key} += $value; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
48
|
|
|
|
|
114
|
$row; |
154
|
2
|
|
|
|
|
4
|
}@{$self->time_rows}]; |
155
|
2
|
|
|
|
|
14
|
$summary->{output_time} = $self->summary_key_name; |
156
|
2
|
|
|
|
|
14
|
push @$rows , $summary ; |
157
|
2
|
|
|
|
|
13
|
unshift @$rows , $summary; |
158
|
2
|
|
|
|
|
6
|
return $rows; |
159
|
|
|
|
|
|
|
}else{ |
160
|
5
|
|
|
|
|
24
|
return [map{$unixtime_rows_hash->{$_->unixtime}->get_values}@{$self->time_rows}] |
|
57
|
|
|
|
|
158
|
|
|
5
|
|
|
|
|
14
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub get_hash{ |
165
|
1
|
|
|
1
|
1
|
8
|
my ($self) = @_; |
166
|
1
|
|
|
|
|
1
|
return {map{$_->get_hash_seed}@{$self->time_rows}}; |
|
3
|
|
|
|
|
149
|
|
|
1
|
|
|
|
|
4
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
__END__ |