| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Device::NeurioTools; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
505
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
33
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
5
|
1
|
|
|
1
|
|
17
|
use 5.006_001; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
95
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Device::NeurioTools ':all'; |
|
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
17
|
|
|
|
|
|
|
# will save memory. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( new |
|
20
|
|
|
|
|
|
|
get_flat_cost get_flat_rate get_ISO8601_date get_ISO8601_time get_ISO8601_timezone |
|
21
|
|
|
|
|
|
|
get_kwh_consumed get kwh_generated get_power_consumed get_TwoTier_cost |
|
22
|
|
|
|
|
|
|
get_TwoTier_rate set_flat_rate set_ISO8601_timezone set_TwoTier_rate |
|
23
|
|
|
|
|
|
|
) ] ); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
26
|
|
|
|
|
|
|
our @EXPORT = qw(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
BEGIN |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
1
|
50
|
|
1
|
|
1562
|
if ($^O eq "MSWin32"){ |
|
31
|
1
|
|
|
1
|
|
572
|
use Device::Neurio; |
|
|
1
|
|
|
|
|
45677
|
|
|
|
1
|
|
|
|
|
94
|
|
|
32
|
1
|
|
|
1
|
|
8
|
use Time::Local; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
35
|
|
|
33
|
1
|
|
|
1
|
|
525
|
use DateTime::Format::ISO8601; |
|
|
1
|
|
|
|
|
180933
|
|
|
|
1
|
|
|
|
|
110
|
|
|
34
|
1
|
|
|
1
|
|
16
|
use POSIX; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
35
|
1
|
|
|
1
|
|
3049
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
80
|
|
|
36
|
|
|
|
|
|
|
} else { |
|
37
|
1
|
|
|
1
|
|
7
|
use Device::Neurio; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
107
|
|
|
38
|
1
|
|
|
1
|
|
8
|
use Time::Local; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
62
|
|
|
39
|
1
|
|
|
1
|
|
7
|
use DateTime::Format::ISO8601; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
29
|
|
|
40
|
1
|
|
|
1
|
|
7
|
use POSIX; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
41
|
1
|
|
|
1
|
|
2697
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
39
|
|
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Device::NeurioTools - More complex methods and tools for accessing data |
|
49
|
|
|
|
|
|
|
collected by a Neurio sensor module. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 VERSION |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Version 0.07 |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#***************************************************************** |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This module allows access to more complex and detailed data derived from data |
|
64
|
|
|
|
|
|
|
collected by a Neurio sensor. This is done via an extended set of methods: |
|
65
|
|
|
|
|
|
|
- new |
|
66
|
|
|
|
|
|
|
- connect |
|
67
|
|
|
|
|
|
|
- set_flat_rate |
|
68
|
|
|
|
|
|
|
- get_flat_rate |
|
69
|
|
|
|
|
|
|
- get_flat_cost |
|
70
|
|
|
|
|
|
|
- get_kwh |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Please note that in order to use this module you will require three parameters |
|
73
|
|
|
|
|
|
|
(key, secret, sensor_id) as well as an Energy Aware Neurio sensor installed in |
|
74
|
|
|
|
|
|
|
your house. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The module is written entirely in Perl and has been developped on Raspbian Linux. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SAMPLE CODE |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use Device::Neurio; |
|
82
|
|
|
|
|
|
|
use Device::NeurioTools; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$my_Neurio = Device::Neurio->new($key,$secret,$sensor_id); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$my_Neurio->connect(); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$my_NeurioTools = Device::NeurioTools->new($my_Neurio,$debug); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$my_NeurioTools->set_timezone(); |
|
91
|
|
|
|
|
|
|
$my_NeurioTools->set_flat_rate(0.08); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$start = "2014-06-24T00:00:00".$my_NeurioTools->get_timezone(); |
|
94
|
|
|
|
|
|
|
$end = "2014-06-24T23:59:59".$my_NeurioTools->get_timezone(); |
|
95
|
|
|
|
|
|
|
$kwh = $my_NeurioTools->get_kwh($start,"minutes",$end,"5"); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
undef $my_NeurioTools; |
|
98
|
|
|
|
|
|
|
undef $my_Neurio; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 EXPORT |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
All by default. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#***************************************************************** |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 new - the constructor for a NeurioTools object |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Creates a new instance of NeurioTools which will be able to fetch data from |
|
110
|
|
|
|
|
|
|
a unique Neurio sensor. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $Neurio = Device::NeurioTools->new($neurio, $debug); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
115
|
|
|
|
|
|
|
- $neurio : a valid CONNECTED Neurio object |
|
116
|
|
|
|
|
|
|
- $debug : enable or disable debug messages (disabled by default - optional) |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns 1 on success |
|
119
|
|
|
|
|
|
|
Returns 0 on failure |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub new { |
|
124
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
125
|
0
|
|
|
|
|
|
my $self; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
$self->{'neurio'} = shift; |
|
128
|
0
|
|
|
|
|
|
$self->{'debug'} = shift; |
|
129
|
0
|
|
|
|
|
|
$self->{'flat_rate'} = 0; |
|
130
|
0
|
|
|
|
|
|
$self->{'TwoTier_rate1'} = 0; |
|
131
|
0
|
|
|
|
|
|
$self->{'TwoTier_cutoff'} = 0; |
|
132
|
0
|
|
|
|
|
|
$self->{'TwoTier_rate2'} = 0; |
|
133
|
0
|
|
|
|
|
|
$self->{'timezone'} = "+00:00"; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if (!defined $self->{'debug'}) { |
|
136
|
0
|
|
|
|
|
|
$self->{'debug'} = 0; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
if (!defined $self->{'neurio'}) { |
|
140
|
0
|
0
|
|
|
|
|
print "NeurioTools->new(): a valid Neurio object is a REQUIRED parameter.\n" if ($self->{'debug'}); |
|
141
|
0
|
|
|
|
|
|
return 0; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
0
|
|
|
|
|
|
bless $self, $class; |
|
144
|
0
|
|
|
|
|
|
return $self; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
#***************************************************************** |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 set_flat_rate - set the rate charged by your electicity provider |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Defines the rate charged by your electricity provider. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$NeurioTools->set_flat_rate($rate); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
157
|
|
|
|
|
|
|
- $rate : rate charged per kwh - Required |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Returns 1 on success |
|
160
|
|
|
|
|
|
|
Returns 0 on failure |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub set_flat_rate { |
|
165
|
0
|
|
|
0
|
1
|
|
my ($self,$rate) = @_; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
if (defined $rate) { |
|
168
|
0
|
|
|
|
|
|
$self->{'flat_rate'} = $rate; |
|
169
|
0
|
0
|
|
|
|
|
print "NeurioTools->set_flat_rate(): $self->{'flat_rate'}\n" if ($self->{'debug'}); |
|
170
|
0
|
|
|
|
|
|
return 1; |
|
171
|
|
|
|
|
|
|
} else { |
|
172
|
0
|
0
|
|
|
|
|
print "NeurioTools->set_flat_rate(): No rate specified\n" if ($self->{'debug'}); |
|
173
|
0
|
|
|
|
|
|
return 0; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
#***************************************************************** |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 set_TwoTier_rate - set the two tier rates charged by your electicity provider |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Defines the two tier rates charged by your electricity provider. |
|
183
|
|
|
|
|
|
|
The two tiers are defined according to the power consumed. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
For example: |
|
186
|
|
|
|
|
|
|
- $0.05 for the first 20 kWh per day |
|
187
|
|
|
|
|
|
|
- $0.08 for the remaining kWh per day |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$NeurioTools->set_TwoTier_rate($rate1,$cutoff,$rate2); |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
192
|
|
|
|
|
|
|
- $rate1 : rate charged per kwh for usage up to the cutoff - Required |
|
193
|
|
|
|
|
|
|
- $cutoff : power consumtion point in kWh at which the rate changes - Required |
|
194
|
|
|
|
|
|
|
- $rate2 : rate charged per kwh for usage abpve the cutoff - Required |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Returns 1 on success |
|
197
|
|
|
|
|
|
|
Returns 0 on failure |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub set_TwoTier_rate { |
|
202
|
0
|
|
|
0
|
1
|
|
my ($self,$rate1,$cutoff,$rate2) = @_; |
|
203
|
|
|
|
|
|
|
|
|
204
|
0
|
0
|
0
|
|
|
|
if (defined $rate1 and defined $cutoff and defined $rate2) { |
|
|
|
|
0
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
$self->{'TwoTier_rate1'} = $rate1; |
|
206
|
0
|
|
|
|
|
|
$self->{'TwoTier_cutoff'} = $cutoff; |
|
207
|
0
|
|
|
|
|
|
$self->{'TwoTier_rate2'} = $rate2; |
|
208
|
0
|
0
|
|
|
|
|
print "NeurioTools->set_TwoTier_rate(): $self->{'TwoTier_rate1'}\n" if ($self->{'debug'}); |
|
209
|
0
|
0
|
|
|
|
|
print "NeurioTools->set_TwoTier_rate(): $self->{'TwoTier_cutoff'}\n" if ($self->{'debug'}); |
|
210
|
0
|
0
|
|
|
|
|
print "NeurioTools->set_TwoTier_rate(): $self->{'TwoTier_rate2'}\n" if ($self->{'debug'}); |
|
211
|
0
|
|
|
|
|
|
return 1; |
|
212
|
|
|
|
|
|
|
} else { |
|
213
|
0
|
0
|
|
|
|
|
print "NeurioTools->set_TwoTier_rate(): No rate specified\n" if ($self->{'debug'}); |
|
214
|
0
|
|
|
|
|
|
return 0; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#***************************************************************** |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 get_flat_rate - return the flat rate charged by your electicity provider |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Returns the value for the flat rate set using 'set_flat_rate()' |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$NeurioTools->get_flat_rate(); |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This method accepts no parameters |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Returns rate |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=cut |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub get_flat_rate { |
|
234
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
235
|
0
|
|
|
|
|
|
return $self->{'flat_rate'}; |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
#***************************************************************** |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 get_TwoTier_rate - return the cutoff and two tier rates charged by your electicity provider |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Returns the value for the cutoff and two tier rates set using 'set_TwoTier_rate()' |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
$NeurioTools->get_TwoTier_rate(); |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
This method accepts no parameters |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Returns list containing cutoff and rates |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub get_TwoTier_rate { |
|
254
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
255
|
0
|
|
|
|
|
|
return ($self->{'TwoTier_rate1'},$self->{'TwoTier_cutoff'},$self->{'TwoTier_rate2'}); |
|
256
|
|
|
|
|
|
|
} |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
#***************************************************************** |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head2 set_ISO8601_timezone - set the timezone offset for ISO8601 |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Sets the timezone offset in ISO8601 format. If no parameter is specified it |
|
264
|
|
|
|
|
|
|
sets the system defined timezone offset. |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
$NeurioTools->set_ISO8601_timezone($offset); |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
269
|
|
|
|
|
|
|
- $offset : specified timezone offset in minutes - Optional |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Returns 1 on success |
|
272
|
|
|
|
|
|
|
Returns 0 on failure |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=cut |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub set_ISO8601_timezone { |
|
277
|
0
|
|
|
0
|
1
|
|
my ($self,$offset) = @_; |
|
278
|
0
|
|
|
|
|
|
my ($total,$hours,$mins,$tz); |
|
279
|
|
|
|
|
|
|
|
|
280
|
0
|
0
|
|
|
|
|
if (defined $offset) { |
|
281
|
0
|
|
|
|
|
|
$total = $offset; |
|
282
|
0
|
|
|
|
|
|
$hours = sprintf("%+03d",$total / 60); |
|
283
|
0
|
|
|
|
|
|
$mins = sprintf("%02d",$total % 60); |
|
284
|
0
|
|
|
|
|
|
$tz = "$hours:$mins"; |
|
285
|
|
|
|
|
|
|
} else { |
|
286
|
0
|
|
|
|
|
|
$tz = strftime("%z", localtime(time())); |
|
287
|
0
|
|
|
|
|
|
substr($tz,3,0,":"); |
|
288
|
|
|
|
|
|
|
} |
|
289
|
0
|
|
|
|
|
|
$self->{'timezone'} = $tz; |
|
290
|
0
|
0
|
|
|
|
|
print "NeurioTools->set_ISO8601_timezone(): $self->{'timezone'}\n" if ($self->{'debug'}); |
|
291
|
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
return 1; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
#***************************************************************** |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head2 get_flat_cost - calculate the cost of consumed power for the specified period |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Calculates the cost of consumed power over the period specified. |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
$NeurioTools->get_flat_cost($start,$granularity,$end,$frequency); |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
This method requires that a 'flat rate' be set using the set_flat_rate() method |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
307
|
|
|
|
|
|
|
- $start : yyyy-mm-ddThh:mm:ssZ - Required |
|
308
|
|
|
|
|
|
|
- $granularity : seconds|minutes|hours|days - Required |
|
309
|
|
|
|
|
|
|
- $end : yyyy-mm-ddThh:mm:ssZ - Optional |
|
310
|
|
|
|
|
|
|
- $frequency : an integer - Optional |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Returns the cost on success |
|
313
|
|
|
|
|
|
|
Returns 0 on failure |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=cut |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub get_flat_cost { |
|
318
|
0
|
|
|
0
|
1
|
|
my ($self,$start,$granularity,$end,$frequency) = @_; |
|
319
|
0
|
|
|
|
|
|
my $i=0; |
|
320
|
|
|
|
|
|
|
|
|
321
|
0
|
0
|
|
|
|
|
if ($self->{'flat_rate'} == 0 ) { |
|
322
|
0
|
0
|
|
|
|
|
print "NeurioTools->get_flat_cost(): Cannot calculate cost since rate is set to zero\n" if ($self->{'debug'}); |
|
323
|
0
|
|
|
|
|
|
return 0; |
|
324
|
|
|
|
|
|
|
} |
|
325
|
|
|
|
|
|
|
|
|
326
|
0
|
|
|
|
|
|
my $kwh = $self->get_kwh_consumed($start,$granularity,$end,$frequency); |
|
327
|
0
|
|
|
|
|
|
my $cost = $kwh*$self->{'flat_rate'}; |
|
328
|
|
|
|
|
|
|
|
|
329
|
0
|
|
|
|
|
|
return $cost; |
|
330
|
|
|
|
|
|
|
} |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
#***************************************************************** |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=head2 get_TwoTier_cost - calculate the cost of consumed power for the specified period |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
Calculates the cost of consumed power over the period specified. |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
$NeurioTools->get_TwoTier_cost($start,$granularity,$end,$frequency); |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
This method requires that a 'TwoTier rate' be set using the set_TwoTier_rate() method |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
344
|
|
|
|
|
|
|
- $start : yyyy-mm-ddThh:mm:ssZ - Required |
|
345
|
|
|
|
|
|
|
- $granularity : seconds|minutes|hours|days - Required |
|
346
|
|
|
|
|
|
|
- $end : yyyy-mm-ddThh:mm:ssZ - Optional |
|
347
|
|
|
|
|
|
|
- $frequency : an integer - Optional |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Returns the cost on success |
|
350
|
|
|
|
|
|
|
Returns 0 on failure |
|
351
|
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=cut |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
sub get_TwoTier_cost { |
|
355
|
0
|
|
|
0
|
1
|
|
my ($self,$start,$granularity,$end,$frequency) = @_; |
|
356
|
0
|
|
|
|
|
|
my $i = 0; |
|
357
|
0
|
|
|
|
|
|
my $cost = 0; |
|
358
|
|
|
|
|
|
|
|
|
359
|
0
|
0
|
0
|
|
|
|
if ($self->{'TwoTier_rate1'} == 0 or $self->{'TwoTier_cutoff'} == 0 or $self->{'TwoTier_rate2'} == 0) { |
|
|
|
|
0
|
|
|
|
|
|
360
|
0
|
0
|
|
|
|
|
print "NeurioTools->get_TwoTier_cost(): Cannot calculate cost since a parameter is set to zero\n" if ($self->{'debug'}); |
|
361
|
0
|
|
|
|
|
|
return 0; |
|
362
|
|
|
|
|
|
|
} |
|
363
|
|
|
|
|
|
|
|
|
364
|
0
|
|
|
|
|
|
my $kwh = $self->get_kwh_consumed($start,$granularity,$end,$frequency); |
|
365
|
|
|
|
|
|
|
|
|
366
|
0
|
0
|
|
|
|
|
if ($kwh != 0) { |
|
367
|
0
|
0
|
|
|
|
|
if ($kwh <= $self->{'TwoTier_cutoff'}) { |
|
368
|
0
|
|
|
|
|
|
$cost = $kwh * $self->{'TwoTier_rate1'}; |
|
369
|
|
|
|
|
|
|
} else { |
|
370
|
0
|
|
|
|
|
|
$cost = $self->{'TwoTier_cutoff'} * $self->{'TwoTier_rate1'}; |
|
371
|
0
|
|
|
|
|
|
$cost = $cost + ($kwh - $self->{'TwoTier_cutoff'})*$self->{'TwoTier_rate2'}; |
|
372
|
|
|
|
|
|
|
} |
|
373
|
|
|
|
|
|
|
} |
|
374
|
0
|
|
|
|
|
|
return $cost; |
|
375
|
|
|
|
|
|
|
} |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
#***************************************************************** |
|
379
|
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
=head2 get_kwh_consumed - kwh of consumed power for the specified period |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
Calculates the total kwh of consumed power over the period specified. |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
$NeurioTools->get_kwh_consumed($start,$granularity,$end,$frequency); |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
387
|
|
|
|
|
|
|
- $start : yyyy-mm-ddThh:mm:ssZ - Required |
|
388
|
|
|
|
|
|
|
specified using ISO8601 format |
|
389
|
|
|
|
|
|
|
- $granularity : seconds|minutes|hours|days - Required |
|
390
|
|
|
|
|
|
|
- $end : yyyy-mm-ddThh:mm:ssZ - Optional |
|
391
|
|
|
|
|
|
|
specified using ISO8601 format |
|
392
|
|
|
|
|
|
|
- $frequency : an integer - Optional |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
Returns the kwh on success |
|
395
|
|
|
|
|
|
|
Returns 0 on failure |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
=cut |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub get_kwh_consumed { |
|
400
|
0
|
|
|
0
|
1
|
|
my ($self,$start,$granularity,$end,$frequency) = @_; |
|
401
|
0
|
|
|
|
|
|
my $energy = 0; |
|
402
|
0
|
|
|
|
|
|
my $samples = 0; |
|
403
|
0
|
|
|
|
|
|
my $kwh = 0; |
|
404
|
|
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
my $data = $self->{'neurio'}->fetch_Stats_Energy($start,$granularity,$end,$frequency,"1","5000"); |
|
406
|
0
|
0
|
|
|
|
|
if ($data != 0) { |
|
407
|
0
|
|
|
|
|
|
my $start_obj = DateTime::Format::ISO8601->parse_datetime($start); |
|
408
|
0
|
|
|
|
|
|
my $end_obj = DateTime::Format::ISO8601->parse_datetime($end); |
|
409
|
0
|
|
|
|
|
|
my $dur_obj = $end_obj->subtract_datetime($start_obj); |
|
410
|
0
|
|
|
|
|
|
my $duration = eval($dur_obj->{'minutes'}*60+$dur_obj->{'seconds'}); |
|
411
|
|
|
|
|
|
|
|
|
412
|
0
|
|
|
|
|
|
while (defined $data->[$samples]->{'consumptionEnergy'}) { |
|
413
|
0
|
|
|
|
|
|
$energy = $energy + $data->[$samples]->{'consumptionEnergy'}; |
|
414
|
0
|
|
|
|
|
|
$samples++; |
|
415
|
|
|
|
|
|
|
} |
|
416
|
0
|
|
|
|
|
|
$kwh = $energy/(1000*3600); |
|
417
|
|
|
|
|
|
|
} |
|
418
|
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
|
return $kwh; |
|
420
|
|
|
|
|
|
|
} |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
#***************************************************************** |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
=head2 get_kwh_generated - kwh of generated power for the specified period |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
Calculates the total kwh of generated power over the period specified. |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
$NeurioTools->get_kwh_generated($start,$granularity,$end,$frequency); |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
432
|
|
|
|
|
|
|
- $start : yyyy-mm-ddThh:mm:ssZ - Required |
|
433
|
|
|
|
|
|
|
specified using ISO8601 format |
|
434
|
|
|
|
|
|
|
- $granularity : seconds|minutes|hours|days - Required |
|
435
|
|
|
|
|
|
|
- $end : yyyy-mm-ddThh:mm:ssZ - Optional |
|
436
|
|
|
|
|
|
|
specified using ISO8601 format |
|
437
|
|
|
|
|
|
|
- $frequency : an integer - Optional |
|
438
|
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
Returns the kwh on success |
|
440
|
|
|
|
|
|
|
Returns 0 on failure |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
=cut |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
sub get_kwh_generated { |
|
445
|
0
|
|
|
0
|
1
|
|
my ($self,$start,$granularity,$end,$frequency) = @_; |
|
446
|
0
|
|
|
|
|
|
my $samples = 0; |
|
447
|
0
|
|
|
|
|
|
my $power = 0; |
|
448
|
0
|
|
|
|
|
|
my $kwh = 0; |
|
449
|
|
|
|
|
|
|
|
|
450
|
0
|
|
|
|
|
|
my $data = $self->{'neurio'}->fetch_Samples($start,$granularity,$end,$frequency); |
|
451
|
0
|
0
|
|
|
|
|
if ($data != 0) { |
|
452
|
0
|
|
|
|
|
|
my $start_obj = DateTime::Format::ISO8601->parse_datetime($start); |
|
453
|
0
|
|
|
|
|
|
my $end_obj = DateTime::Format::ISO8601->parse_datetime($end); |
|
454
|
0
|
|
|
|
|
|
my $dur_obj = $end_obj->subtract_datetime($start_obj); |
|
455
|
0
|
|
|
|
|
|
my $duration = eval($dur_obj->{'minutes'}*60+$dur_obj->{'seconds'}); |
|
456
|
|
|
|
|
|
|
|
|
457
|
0
|
|
|
|
|
|
while (defined $data->[$samples]->{'generationPower'}) { |
|
458
|
0
|
|
|
|
|
|
$power = $power + $data->[$samples]->{'generationPower'}; |
|
459
|
0
|
|
|
|
|
|
$samples++; |
|
460
|
|
|
|
|
|
|
} |
|
461
|
0
|
|
|
|
|
|
$kwh = $power/1000*$duration/60/60/$samples; |
|
462
|
|
|
|
|
|
|
} |
|
463
|
|
|
|
|
|
|
|
|
464
|
0
|
|
|
|
|
|
return $kwh; |
|
465
|
|
|
|
|
|
|
} |
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
#***************************************************************** |
|
469
|
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=head2 get_energy_consumed - energy consumed for the specified period |
|
471
|
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
Calculates the total energy consumed over the period specified. |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
$NeurioTools->get_energy_consumed($start,$granularity,$end,$frequency); |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
477
|
|
|
|
|
|
|
- $start : yyyy-mm-ddThh:mm:ssZ - Required |
|
478
|
|
|
|
|
|
|
specified using ISO8601 format |
|
479
|
|
|
|
|
|
|
- $granularity : seconds|minutes|hours|days - Required |
|
480
|
|
|
|
|
|
|
- $end : yyyy-mm-ddThh:mm:ssZ - Optional |
|
481
|
|
|
|
|
|
|
specified using ISO8601 format |
|
482
|
|
|
|
|
|
|
- $frequency : an integer - Optional |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
Returns the energy on success |
|
485
|
|
|
|
|
|
|
Returns 0 on failure |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=cut |
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
sub get_energy_consumed { |
|
490
|
0
|
|
|
0
|
1
|
|
my ($self,$start,$granularity,$end,$frequency) = @_; |
|
491
|
0
|
|
|
|
|
|
my $samples = 0; |
|
492
|
0
|
|
|
|
|
|
my $energy = 0; |
|
493
|
0
|
|
|
|
|
|
my $kwh = 0; |
|
494
|
|
|
|
|
|
|
|
|
495
|
0
|
|
|
|
|
|
my $data = $self->{'neurio'}->fetch_Samples($start,$granularity,$end,$frequency); |
|
496
|
0
|
0
|
|
|
|
|
if ($data != 0) { |
|
497
|
0
|
|
|
|
|
|
my $start_obj = DateTime::Format::ISO8601->parse_datetime($start); |
|
498
|
0
|
|
|
|
|
|
my $end_obj = DateTime::Format::ISO8601->parse_datetime($end); |
|
499
|
0
|
|
|
|
|
|
my $dur_obj = $end_obj->subtract_datetime($start_obj); |
|
500
|
0
|
|
|
|
|
|
my $duration = eval($dur_obj->{'minutes'}*60+$dur_obj->{'seconds'}); |
|
501
|
|
|
|
|
|
|
|
|
502
|
0
|
|
|
|
|
|
while (defined $data->[$samples]->{'consumptionEnergy'}) { |
|
503
|
0
|
|
|
|
|
|
$energy = $energy + $data->[$samples]->{'consumptionEnergy'}; |
|
504
|
0
|
|
|
|
|
|
$samples++; |
|
505
|
|
|
|
|
|
|
} |
|
506
|
0
|
|
|
|
|
|
return $energy; |
|
507
|
|
|
|
|
|
|
} |
|
508
|
|
|
|
|
|
|
} |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
#***************************************************************** |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
=head2 get_appliance_ID - return the id for the appliance specified |
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
Returns the appliance ID for the name specified. |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
$NeurioTools->get_appliance_ID($name); |
|
518
|
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
520
|
|
|
|
|
|
|
- $name : textual name of appliance - Required |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
Returns the appliance ID on success |
|
523
|
|
|
|
|
|
|
Returns 0 on failure |
|
524
|
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=cut |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
sub get_appliance_ID { |
|
528
|
0
|
|
|
0
|
1
|
|
my ($self,$name) = @_; |
|
529
|
0
|
|
|
|
|
|
my $appliance; |
|
530
|
|
|
|
|
|
|
|
|
531
|
0
|
|
|
|
|
|
my $data = $self->{'neurio'}->fetch_Appliances(); |
|
532
|
0
|
0
|
|
|
|
|
if ($data != 0) { |
|
533
|
0
|
|
|
|
|
|
foreach $appliance (@{$data}) { |
|
|
0
|
|
|
|
|
|
|
|
534
|
0
|
0
|
|
|
|
|
if ($appliance->{'name'} eq $name) { |
|
535
|
0
|
|
|
|
|
|
return $appliance->{'id'}; |
|
536
|
|
|
|
|
|
|
} |
|
537
|
|
|
|
|
|
|
} |
|
538
|
|
|
|
|
|
|
} |
|
539
|
0
|
|
|
|
|
|
return 0; |
|
540
|
|
|
|
|
|
|
} |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
#***************************************************************** |
|
543
|
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=head2 get_power_consumed - power consumed for the specified period |
|
545
|
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
Calculates the total power consumed over the period specified. |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
$NeurioTools->get_energy_consumed($start,$granularity,$end,$frequency); |
|
549
|
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
551
|
|
|
|
|
|
|
- $start : yyyy-mm-ddThh:mm:ssZ - Required |
|
552
|
|
|
|
|
|
|
specified using ISO8601 format |
|
553
|
|
|
|
|
|
|
- $granularity : seconds|minutes|hours|days - Required |
|
554
|
|
|
|
|
|
|
- $end : yyyy-mm-ddThh:mm:ssZ - Optional |
|
555
|
|
|
|
|
|
|
specified using ISO8601 format |
|
556
|
|
|
|
|
|
|
- $frequency : an integer - Optional |
|
557
|
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
Returns the energy on success |
|
559
|
|
|
|
|
|
|
Returns 0 on failure |
|
560
|
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
=cut |
|
562
|
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
sub get_power_consumed { |
|
564
|
0
|
|
|
0
|
1
|
|
my ($self,$start,$granularity,$end,$frequency) = @_; |
|
565
|
0
|
|
|
|
|
|
my $samples = 0; |
|
566
|
0
|
|
|
|
|
|
my $power = 0; |
|
567
|
|
|
|
|
|
|
|
|
568
|
0
|
|
|
|
|
|
my $data = $self->{'neurio'}->fetch_Samples($start,$granularity,$end,$frequency); |
|
569
|
0
|
0
|
|
|
|
|
if ($data != 0) { |
|
570
|
0
|
|
|
|
|
|
my $start_obj = DateTime::Format::ISO8601->parse_datetime($start); |
|
571
|
0
|
|
|
|
|
|
my $end_obj = DateTime::Format::ISO8601->parse_datetime($end); |
|
572
|
0
|
|
|
|
|
|
my $dur_obj = $end_obj->subtract_datetime($start_obj); |
|
573
|
0
|
|
|
|
|
|
my $duration = eval($dur_obj->{'minutes'}*60+$dur_obj->{'seconds'}); |
|
574
|
|
|
|
|
|
|
|
|
575
|
0
|
|
|
|
|
|
while (defined $data->[$samples]->{'consumptionPower'}) { |
|
576
|
0
|
|
|
|
|
|
$power = $power + $data->[$samples]->{'consumptionPower'}; |
|
577
|
0
|
|
|
|
|
|
$samples++; |
|
578
|
|
|
|
|
|
|
} |
|
579
|
0
|
|
|
|
|
|
return $power; |
|
580
|
|
|
|
|
|
|
} |
|
581
|
|
|
|
|
|
|
} |
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
#***************************************************************** |
|
585
|
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
=head2 get_ISO8601_time - convert linux time to the time part of ISO8601 |
|
587
|
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
Returns the time part in ISO8601 format of the specified linux time. |
|
589
|
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
$NeurioTools->get_ISO8601_time($time); |
|
591
|
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
593
|
|
|
|
|
|
|
- $time : linux time - Required |
|
594
|
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
Returns time part of ISO8601 format on success |
|
596
|
|
|
|
|
|
|
Returns 0 on failure |
|
597
|
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
=cut |
|
599
|
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
sub get_ISO8601_time { |
|
601
|
0
|
|
|
0
|
1
|
|
my ($self,$time) = @_; |
|
602
|
0
|
|
|
|
|
|
my $ISO8601_time; |
|
603
|
|
|
|
|
|
|
|
|
604
|
0
|
0
|
|
|
|
|
if (!defined $time) { |
|
605
|
0
|
0
|
|
|
|
|
print "\$$time is a required parameter\n" if ($self->{'debug'}); |
|
606
|
0
|
|
|
|
|
|
return 0; |
|
607
|
|
|
|
|
|
|
} else { |
|
608
|
0
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($time); |
|
609
|
0
|
|
|
|
|
|
$ISO8601_time = sprintf("%02d:%02d:%02d",$hour,$min,$sec); |
|
610
|
|
|
|
|
|
|
} |
|
611
|
0
|
|
|
|
|
|
return $ISO8601_time; |
|
612
|
|
|
|
|
|
|
} |
|
613
|
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
#***************************************************************** |
|
616
|
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
=head2 get_ISO8601_date - convert linux time to the date part of ISO8601 |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
Returns the date part in ISO8601 fomrat of the specified linux time. |
|
620
|
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
$NeurioTools->get_ISO8601_date($time); |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
624
|
|
|
|
|
|
|
- $time : linux time - Required |
|
625
|
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
Returns date part of ISO8601 format on success |
|
627
|
|
|
|
|
|
|
Returns 0 on failure |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
=cut |
|
630
|
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
sub get_ISO8601_date { |
|
632
|
0
|
|
|
0
|
1
|
|
my ($self,$time) = @_; |
|
633
|
0
|
|
|
|
|
|
my $ISO8601_date; |
|
634
|
|
|
|
|
|
|
|
|
635
|
0
|
0
|
|
|
|
|
if (!defined $time) { |
|
636
|
0
|
0
|
|
|
|
|
print "\$$time is a required parameter\n" if ($self->{'debug'}); |
|
637
|
0
|
|
|
|
|
|
return 0; |
|
638
|
|
|
|
|
|
|
} else { |
|
639
|
0
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($time); |
|
640
|
0
|
|
|
|
|
|
$ISO8601_date = sprintf("%04d\-%02d\-%02d",$year+1900,$mon+1,$mday); |
|
641
|
|
|
|
|
|
|
} |
|
642
|
0
|
|
|
|
|
|
return $ISO8601_date; |
|
643
|
|
|
|
|
|
|
} |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
#***************************************************************** |
|
647
|
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
=head2 get_ISO8601_timezone - return the ISOS8601 timezone offset |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
Returns the timezone part in ISO8601 format for the current location |
|
651
|
|
|
|
|
|
|
from the value specified with set_ISO8601_timezone |
|
652
|
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
$NeurioTools->get_ISO8601_timezone(); |
|
654
|
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
This method accepts no parameters |
|
656
|
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
Returns timezone offset |
|
658
|
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
=cut |
|
660
|
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
sub get_ISO8601_timezone { |
|
662
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
663
|
0
|
|
|
|
|
|
return $self->{'timezone'}; |
|
664
|
|
|
|
|
|
|
} |
|
665
|
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
#***************************************************************** |
|
668
|
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
=head2 get_ISO8601 - return the entire ISOS8601 formatted date/time/timezone |
|
670
|
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
Returns the entire ISO8601 formatted date/time/timezone based on the time |
|
672
|
|
|
|
|
|
|
parameter passed |
|
673
|
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
$NeurioTools->get_ISO8601($time); |
|
675
|
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
This method accepts the following parameters: |
|
677
|
|
|
|
|
|
|
- $time : linux time - Required |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
Returns entire ISO8601 string on success |
|
680
|
|
|
|
|
|
|
Returns 0 on failure |
|
681
|
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
=cut |
|
683
|
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
sub get_ISO8601 { |
|
685
|
0
|
|
|
0
|
1
|
|
my ($self,$time) = @_; |
|
686
|
0
|
|
|
|
|
|
my $ISO8601; |
|
687
|
|
|
|
|
|
|
|
|
688
|
0
|
0
|
|
|
|
|
if (!defined $time) { |
|
689
|
0
|
0
|
|
|
|
|
print "\$$time is a required parameter\n" if ($self->{'debug'}); |
|
690
|
0
|
|
|
|
|
|
return 0; |
|
691
|
|
|
|
|
|
|
} else { |
|
692
|
0
|
|
|
|
|
|
my $tz = $self->get_ISO8601_timezone(); |
|
693
|
0
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($time); |
|
694
|
0
|
|
|
|
|
|
$ISO8601 = sprintf("%04d\-%02d\-%02dT%02d:%02d:%02d".$tz,$year+1900,$mon+1,$mday,$hour,$min,$sec); |
|
695
|
|
|
|
|
|
|
} |
|
696
|
0
|
|
|
|
|
|
return $ISO8601; |
|
697
|
|
|
|
|
|
|
} |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
#***************************************************************** |
|
701
|
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
=head1 AUTHOR |
|
703
|
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
Kedar Warriner, C |
|
705
|
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
=head1 BUGS |
|
707
|
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
Please report any bugs or feature requests to C |
|
709
|
|
|
|
|
|
|
or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Device-NeurioTools |
|
710
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
711
|
|
|
|
|
|
|
your bug as I make changes. |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
=head1 SUPPORT |
|
715
|
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
717
|
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
perldoc Device::NeurioTools |
|
719
|
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
You can also look for information at: |
|
722
|
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
=over 5 |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
726
|
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
L |
|
728
|
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
730
|
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
L |
|
732
|
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
L |
|
736
|
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
=item * Search CPAN |
|
738
|
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
L |
|
740
|
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
=back |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
745
|
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
Many thanks to: |
|
747
|
|
|
|
|
|
|
The guys at Energy Aware Technologies for creating the Neurio sensor and |
|
748
|
|
|
|
|
|
|
developping the API. |
|
749
|
|
|
|
|
|
|
Everyone involved with CPAN. |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
752
|
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
Copyright 2014 Kedar Warriner . |
|
754
|
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
756
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
757
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
758
|
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
760
|
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
=cut |
|
763
|
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
#************************************************************************ |
|
765
|
|
|
|
|
|
|
1; # End of Device::NeurioTools - Return success to require/use statement |
|
766
|
|
|
|
|
|
|
#************************************************************************ |
|
767
|
|
|
|
|
|
|
|