line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::List::Rows; |
2
|
7
|
|
|
7
|
|
121
|
use 5.008_001; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
220
|
|
3
|
7
|
|
|
7
|
|
24
|
use strict; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
169
|
|
4
|
7
|
|
|
7
|
|
49
|
use warnings; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
177
|
|
5
|
7
|
|
|
7
|
|
22
|
use Time::Piece; |
|
7
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
30
|
|
6
|
7
|
|
|
7
|
|
3670
|
use Class::Accessor::Lite; |
|
7
|
|
|
|
|
6222
|
|
|
7
|
|
|
|
|
71
|
|
7
|
7
|
|
|
7
|
|
2757
|
use Time::List::Rows::Row; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
213
|
|
8
|
7
|
|
|
7
|
|
41
|
use Time::List::Constant; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
38
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
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
|
|
|
|
|
|
|
filter => undef , |
33
|
|
|
|
|
|
|
filter_keys => [] , |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Class::Accessor::Lite->mk_accessors(keys %DEFAULTS); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
4
|
|
|
4
|
0
|
5
|
my $class = shift; |
40
|
|
|
|
|
|
|
|
41
|
4
|
50
|
|
|
|
16
|
my %args = @_ == 1 ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
42
|
4
|
|
|
|
|
43
|
my $self = bless { |
43
|
|
|
|
|
|
|
%DEFAULTS, |
44
|
|
|
|
|
|
|
%args, |
45
|
|
|
|
|
|
|
}, $class; |
46
|
|
|
|
|
|
|
|
47
|
4
|
50
|
|
|
|
14
|
die "set time array" unless $self->time_array; |
48
|
4
|
|
|
|
|
22
|
$self->_create_time_rows(\%args); |
49
|
4
|
|
|
|
|
29
|
$self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _create_time_rows{ |
53
|
4
|
|
|
4
|
|
5
|
my ($self , $args) = @_; |
54
|
4
|
|
|
|
|
7
|
my $time_array = $self->time_array; |
55
|
33
|
|
|
|
|
105
|
my $time_rows = [map{ |
56
|
4
|
|
|
|
|
13
|
Time::List::Rows::Row->new(%$args , unixtime => $_); |
57
|
|
|
|
|
|
|
}@$time_array]; |
58
|
33
|
|
|
|
|
95
|
my $unixtime_rows_hash = {map{ |
59
|
4
|
|
|
|
|
7
|
$_->unixtime => $_, |
60
|
|
|
|
|
|
|
}@$time_rows}; |
61
|
33
|
|
|
|
|
111
|
my $datetime_rows_hash = {map{ |
62
|
4
|
|
|
|
|
58
|
$_->datetime => $_, |
63
|
|
|
|
|
|
|
}@$time_rows}; |
64
|
4
|
|
|
|
|
44
|
$self->time_rows($time_rows); |
65
|
4
|
|
|
|
|
20
|
$self->unixtime_rows_hash($unixtime_rows_hash); |
66
|
4
|
|
|
|
|
15
|
$self->datetime_rows_hash($datetime_rows_hash); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_row_from_datetime{ |
70
|
0
|
|
|
0
|
1
|
0
|
my ($self , $datetime) = @_; |
71
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$datetime}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_row_from_unixtime{ |
75
|
0
|
|
|
0
|
1
|
0
|
my ($self , $unixtime) = @_; |
76
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$unixtime}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub set_row_from_datetime{ |
80
|
0
|
|
|
0
|
1
|
0
|
my ($self , $datetime , $values) = @_; |
81
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$datetime}->set($values); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub set_row_from_unixtime{ |
85
|
0
|
|
|
0
|
1
|
0
|
my ($self , $unixtime , $values) = @_; |
86
|
0
|
|
|
|
|
0
|
$self->unixtime_rows_hash()->{$unixtime}->set($values); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub set_rows_from_input_strftime{ |
90
|
0
|
|
|
0
|
0
|
0
|
my ($self , $rows) = @_; |
91
|
0
|
|
|
|
|
0
|
my $strf_form = $self->input_strftime_form; |
92
|
0
|
|
|
|
|
0
|
my $keys = {}; |
93
|
0
|
|
|
|
|
0
|
for my $time(keys %$rows){ |
94
|
0
|
|
|
|
|
0
|
my $values = $rows->{$time}; |
95
|
0
|
|
|
|
|
0
|
for(keys %$values){ |
96
|
0
|
|
|
|
|
0
|
$keys->{$_} = 1; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
0
|
my $unixtime = Time::Piece->strptime($time , $strf_form)->strftime('%s'); |
99
|
0
|
|
|
|
|
0
|
my $row = $self->unixtime_rows_hash()->{$unixtime}; |
100
|
0
|
0
|
|
|
|
0
|
$row->set($values) if $row; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
0
|
my $time_rows = $self->time_rows(); |
103
|
0
|
|
|
|
|
0
|
for(@$time_rows){ |
104
|
0
|
|
0
|
|
|
0
|
$_->{$keys} ||= undef; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub set_rows_from_datetime{ |
109
|
5
|
|
|
5
|
1
|
8976
|
my ($self , $rows) = @_; |
110
|
5
|
|
|
|
|
7
|
my $keys = {}; |
111
|
5
|
|
|
|
|
16
|
for my $datetime(keys %$rows){ |
112
|
39
|
|
|
|
|
279
|
my $values = $rows->{$datetime}; |
113
|
39
|
|
|
|
|
65
|
for(keys %$values){ |
114
|
78
|
|
|
|
|
94
|
$keys->{$_} = 1; |
115
|
|
|
|
|
|
|
} |
116
|
39
|
|
|
|
|
74
|
my $row = $self->datetime_rows_hash()->{$datetime}; |
117
|
39
|
50
|
|
|
|
179
|
$row->set($values) if $row; |
118
|
|
|
|
|
|
|
} |
119
|
5
|
|
|
|
|
42
|
my $time_rows = $self->time_rows(); |
120
|
5
|
|
|
|
|
17
|
for(@$time_rows){ |
121
|
57
|
|
50
|
|
|
191
|
$_->{$keys} ||= undef; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub set_rows_from_unixtime{ |
126
|
0
|
|
|
0
|
1
|
0
|
my ($self , $rows) = @_; |
127
|
0
|
|
|
|
|
0
|
my $keys = {}; |
128
|
0
|
|
|
|
|
0
|
for my $unixtime(keys %$rows){ |
129
|
0
|
|
|
|
|
0
|
my $values = $rows->{$unixtime}; |
130
|
0
|
|
|
|
|
0
|
for(keys %$values){ |
131
|
0
|
|
|
|
|
0
|
$keys->{$_} = 1; |
132
|
|
|
|
|
|
|
} |
133
|
0
|
|
|
|
|
0
|
my $row = $self->unixtime_rows_hash()->{$unixtime}; |
134
|
0
|
0
|
|
|
|
0
|
$row->set($values) if $row; |
135
|
|
|
|
|
|
|
} |
136
|
0
|
|
|
|
|
0
|
my $time_rows = $self->time_rows(); |
137
|
0
|
|
|
|
|
0
|
for(@$time_rows){ |
138
|
0
|
|
0
|
|
|
0
|
$_->{$keys} ||= undef; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub get_array{ |
143
|
9
|
|
|
9
|
1
|
13798
|
my ($self) = @_; |
144
|
9
|
|
|
|
|
22
|
my $unixtime_rows_hash = $self->unixtime_rows_hash; |
145
|
9
|
100
|
|
|
|
39
|
if($self->create_summary){ |
146
|
4
|
|
|
|
|
17
|
my $summary = {}; |
147
|
|
|
|
|
|
|
|
148
|
96
|
|
|
|
|
201
|
my $rows = [map{ |
149
|
4
|
|
|
|
|
10
|
my $row = $unixtime_rows_hash->{$_->unixtime}->get_values; |
150
|
96
|
100
|
|
|
|
199
|
if($self->filter){ |
151
|
48
|
|
|
|
|
245
|
$row = {%$row}; |
152
|
48
|
|
|
|
|
49
|
my @filter_keys = @{$self->filter_keys}; |
|
48
|
|
|
|
|
76
|
|
153
|
48
|
100
|
66
|
|
|
190
|
if(ref $filter_keys[0] eq "SCALAR" && ${$filter_keys[0]} eq "*"){ |
|
24
|
|
|
|
|
62
|
|
154
|
24
|
|
|
|
|
57
|
@filter_keys = keys $row |
155
|
|
|
|
|
|
|
} |
156
|
48
|
|
|
|
|
67
|
for my $key (@filter_keys){ |
157
|
126
|
100
|
|
|
|
664
|
if(exists $row->{$key}){ |
158
|
117
|
|
|
|
|
183
|
$row->{$key} = $self->filter->($row->{$key}); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
96
|
|
|
|
|
532
|
for my $key(keys %$row){ |
164
|
408
|
|
|
|
|
390
|
my $value = $row->{$key}; |
165
|
408
|
100
|
100
|
|
|
2368
|
if($value && $value =~ /(^|^-)(\d+|\d+\.\d+)$/){ |
166
|
213
|
|
|
|
|
311
|
$summary->{$key} += $value; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
96
|
|
|
|
|
181
|
$row; |
171
|
4
|
|
|
|
|
7
|
}@{$self->time_rows}]; |
172
|
4
|
|
|
|
|
14
|
$summary->{output_time} = $self->summary_key_name; |
173
|
4
|
|
|
|
|
20
|
push @$rows , $summary ; |
174
|
4
|
|
|
|
|
6
|
unshift @$rows , $summary; |
175
|
|
|
|
|
|
|
|
176
|
4
|
|
|
|
|
12
|
return $rows; |
177
|
|
|
|
|
|
|
}else{ |
178
|
57
|
|
|
|
|
120
|
return [map{ |
179
|
5
|
|
|
|
|
9
|
my $row = $unixtime_rows_hash->{$_->unixtime}->get_values; |
180
|
|
|
|
|
|
|
|
181
|
57
|
100
|
|
|
|
161
|
if($self->filter){ |
182
|
9
|
|
|
|
|
49
|
$row = {%$row}; |
183
|
9
|
|
|
|
|
9
|
my @filter_keys = @{$self->filter_keys}; |
|
9
|
|
|
|
|
16
|
|
184
|
9
|
50
|
33
|
|
|
37
|
if(ref $filter_keys[0] eq "SCALAR" && ${$filter_keys[0]} eq "*"){ |
|
0
|
|
|
|
|
0
|
|
185
|
0
|
|
|
|
|
0
|
@filter_keys = keys $row |
186
|
|
|
|
|
|
|
} |
187
|
9
|
|
|
|
|
13
|
for my $key (@filter_keys){ |
188
|
0
|
0
|
|
|
|
0
|
if(exists $row->{$key}){ |
189
|
0
|
|
|
|
|
0
|
$row->{$key} = $self->filter->($row->{$key}); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
57
|
|
|
|
|
249
|
$row; |
195
|
5
|
|
|
|
|
18
|
}@{$self->time_rows}] |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub get_hash{ |
200
|
1
|
|
|
1
|
1
|
6
|
my ($self) = @_; |
201
|
1
|
|
|
|
|
2
|
return {map{$_->get_hash_seed}@{$self->time_rows}}; |
|
3
|
|
|
|
|
87
|
|
|
1
|
|
|
|
|
2
|
|
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |
208
|
|
|
|
|
|
|
__END__ |