-
Notifications
You must be signed in to change notification settings - Fork 1
/
solar-usage
executable file
·48 lines (37 loc) · 1.14 KB
/
solar-usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env perl
use strict;
use warnings;
use JSON;
use Search::Elasticsearch;
use Data::Dump qw/ dump /;
my $e = Search::Elasticsearch->new();
my $results = $e->search(
index => 'solar',
body => {
"size" => 1000,
"sort" => [ { "tstamp" => "desc" } ],
#query => { match => { 'DEVICE_TYPE' => 'Power Meter' } }
#query => { match => { 'TYPE' => 'PVS5-METER-C' } }
}
);
my $usage = {};
my $power = {};
for my $r ( @{ $results->{hits}->{hits} } ) {
next if $r->{_source}->{DEVICE_TYPE} eq 'PVS';
warn dump $r;
warn sprintf( "[%s] %s => %s\n",
$r->{_source}->{DESCR},
$r->{_source}->{tstamp},
$r->{_source}->{p_3phsum_kw} );
#$r->{_source}->{net_ltea_3phsum_kwh} );
my $type = $r->{_source}->{DESCR};
my $time = $r->{_source}->{tstamp};
my $kwh = $r->{_source}->{net_ltea_3phsum_kwh} || $r->{_source}->{p_3phsum_kw};
#my $kwh = $r->{_source}->{p_3phsum_kw};
$usage->{$type} ||= [];
$power->{$type} += $kwh;
push @{ $usage->{$type} }, { kwh => $kwh, time => $time };
}
warn dump [keys %$usage];
warn dump $power;
print to_json($usage);