@golemio/energetics 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ /**
11
+ * We receive the dbmigrate dependency from dbmigrate initially.
12
+ * This enables us to not have to rely on NODE_PATH.
13
+ */
14
+ exports.setup = function(options, seedLink) {
15
+ dbm = options.dbmigrate;
16
+ type = dbm.dataType;
17
+ seed = seedLink;
18
+ Promise = options.Promise;
19
+ };
20
+
21
+ exports.up = function(db) {
22
+ var filePath = path.join(__dirname, 'sqls', '20230202122506-v_energetics_last_updates-up.sql');
23
+ return new Promise( function( resolve, reject ) {
24
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
25
+ if (err) return reject(err);
26
+ console.log('received data: ' + data);
27
+
28
+ resolve(data);
29
+ });
30
+ })
31
+ .then(function(data) {
32
+ return db.runSql(data);
33
+ });
34
+ };
35
+
36
+ exports.down = function(db) {
37
+ var filePath = path.join(__dirname, 'sqls', '20230202122506-v_energetics_last_updates-down.sql');
38
+ return new Promise( function( resolve, reject ) {
39
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
40
+ if (err) return reject(err);
41
+ console.log('received data: ' + data);
42
+
43
+ resolve(data);
44
+ });
45
+ })
46
+ .then(function(data) {
47
+ return db.runSql(data);
48
+ });
49
+ };
50
+
51
+ exports._meta = {
52
+ "version": 1
53
+ };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ /**
11
+ * We receive the dbmigrate dependency from dbmigrate initially.
12
+ * This enables us to not have to rely on NODE_PATH.
13
+ */
14
+ exports.setup = function(options, seedLink) {
15
+ dbm = options.dbmigrate;
16
+ type = dbm.dataType;
17
+ seed = seedLink;
18
+ Promise = options.Promise;
19
+ };
20
+
21
+ exports.up = function(db) {
22
+ var filePath = path.join(__dirname, 'sqls', '20230208144859-v_energetics_last_updates_corr-up.sql');
23
+ return new Promise( function( resolve, reject ) {
24
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
25
+ if (err) return reject(err);
26
+ console.log('received data: ' + data);
27
+
28
+ resolve(data);
29
+ });
30
+ })
31
+ .then(function(data) {
32
+ return db.runSql(data);
33
+ });
34
+ };
35
+
36
+ exports.down = function(db) {
37
+ var filePath = path.join(__dirname, 'sqls', '20230208144859-v_energetics_last_updates_corr-down.sql');
38
+ return new Promise( function( resolve, reject ) {
39
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
40
+ if (err) return reject(err);
41
+ console.log('received data: ' + data);
42
+
43
+ resolve(data);
44
+ });
45
+ })
46
+ .then(function(data) {
47
+ return db.runSql(data);
48
+ });
49
+ };
50
+
51
+ exports._meta = {
52
+ "version": 1
53
+ };
@@ -0,0 +1,64 @@
1
+ DROP VIEW v_consumption_energy_missing_devices_last_update_prague_10;
2
+
3
+ DROP VIEW v_consumption_energy_last_update_prague_10;
4
+
5
+ CREATE OR REPLACE VIEW v_consumption_energy_last_update
6
+ AS WITH last_update AS (
7
+ SELECT b.building_name,
8
+ replace(c.addr::text, concat('/', c.var), ''::text) AS addr,
9
+ max(c.time_utc) AS last_update
10
+ FROM consumption_energy_consumption c
11
+ JOIN consumption_energy_devices d ON replace(c.addr::text, concat('/', c.var), ''::text) = d.addr::text
12
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
13
+ GROUP BY b.building_name, (replace(c.addr::text, concat('/', c.var), ''::text))
14
+ ), last_not_zero AS (
15
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
16
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
17
+ FROM consumption_energy_consumption
18
+ WHERE consumption_energy_consumption.value > 0::numeric
19
+ GROUP BY (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text))
20
+ )
21
+ SELECT lu.building_name,
22
+ lu.last_update,
23
+ lu.addr,
24
+ CASE
25
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
26
+ ELSE lnz.last_not_zero_value
27
+ END AS zero_values_after
28
+ FROM last_update lu
29
+ LEFT JOIN last_not_zero lnz ON lu.addr = lnz.addr;
30
+
31
+ CREATE OR REPLACE VIEW v_consumption_energy_missing_devices_last_update
32
+ AS WITH missing_devices_last_update AS (
33
+ SELECT consumption_energy_consumption.addr,
34
+ "left"(consumption_energy_consumption.addr::text, "position"("right"(consumption_energy_consumption.addr::text, length(consumption_energy_consumption.addr::text) - 1), '/'::text)) AS building_code,
35
+ max(consumption_energy_consumption.time_utc) AS last_update
36
+ FROM consumption_energy_consumption
37
+ WHERE NOT (consumption_energy_consumption.addr::text IN ( SELECT consumption_energy_devices.addr
38
+ FROM consumption_energy_devices))
39
+ GROUP BY consumption_energy_consumption.addr
40
+ ), missing_devices_last_not_zero AS (
41
+ SELECT consumption_energy_consumption.addr,
42
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
43
+ FROM energetics.consumption_energy_consumption
44
+ WHERE consumption_energy_consumption.value > 0::numeric AND NOT (consumption_energy_consumption.addr::text IN ( SELECT consumption_energy_devices.addr
45
+ FROM consumption_energy_devices))
46
+ GROUP BY consumption_energy_consumption.addr
47
+ ), buildings_mapping AS (
48
+ SELECT "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text)) AS building_code,
49
+ b.building_name
50
+ FROM consumption_energy_devices d
51
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
52
+ )
53
+ SELECT bm.building_name,
54
+ lu.last_update,
55
+ lu.addr::text,
56
+ CASE
57
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
58
+ ELSE lnz.last_not_zero_value
59
+ END AS zero_values_after
60
+ FROM missing_devices_last_update lu
61
+ JOIN buildings_mapping bm ON lu.building_code = bm.building_code
62
+ LEFT JOIN missing_devices_last_not_zero lnz ON lu.addr = lnz.addr;
63
+
64
+
@@ -0,0 +1,168 @@
1
+ DROP VIEW v_consumption_energy_last_update;
2
+
3
+ DROP VIEW v_consumption_energy_missing_devices_last_update;
4
+
5
+ CREATE OR REPLACE VIEW v_consumption_energy_last_update
6
+ AS WITH last_update AS (
7
+ SELECT b.building_name,
8
+ replace(c.addr::text, concat('/', c.var), ''::text) AS addr,
9
+ max(c.time_utc) AS last_update
10
+ FROM consumption_energy_consumption c
11
+ JOIN consumption_energy_devices d ON replace(c.addr::text, concat('/', c.var), ''::text) =
12
+ CASE
13
+ WHEN d.addr::text !~~ '/%'::text THEN ('/'::text || d.addr::text)::character varying
14
+ ELSE d.addr
15
+ END::text
16
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
17
+ WHERE b.building_address_code::text !~~ '10.%'::text
18
+ GROUP BY b.building_name, (replace(c.addr::text, concat('/', c.var), ''::text))
19
+ ), last_not_zero AS (
20
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
21
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
22
+ FROM energetics.consumption_energy_consumption
23
+ WHERE consumption_energy_consumption.value > 0::numeric
24
+ GROUP BY (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text))
25
+ )
26
+ SELECT lu.building_name,
27
+ lu.last_update,
28
+ lu.addr,
29
+ CASE
30
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
31
+ ELSE lnz.last_not_zero_value
32
+ END AS zero_values_after
33
+ FROM last_update lu
34
+ LEFT JOIN last_not_zero lnz ON lu.addr = lnz.addr;
35
+
36
+ CREATE OR REPLACE VIEW v_consumption_energy_missing_devices_last_update
37
+ AS WITH missing_devices_last_update AS (
38
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
39
+ "left"(consumption_energy_consumption.addr::text, "position"("right"(consumption_energy_consumption.addr::text, length(consumption_energy_consumption.addr::text) - 1), '/'::text)) AS building_code,
40
+ max(consumption_energy_consumption.time_utc) AS last_update
41
+ FROM consumption_energy_consumption
42
+ WHERE NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
43
+ CASE
44
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
45
+ ELSE consumption_energy_devices.addr
46
+ END AS addr
47
+ FROM consumption_energy_devices))
48
+ GROUP BY (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text)), consumption_energy_consumption.addr
49
+ ), missing_devices_last_not_zero AS (
50
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
51
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
52
+ FROM consumption_energy_consumption
53
+ WHERE consumption_energy_consumption.value > 0::numeric AND NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
54
+ CASE
55
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
56
+ ELSE consumption_energy_devices.addr
57
+ END AS addr
58
+ FROM consumption_energy_devices))
59
+ GROUP BY consumption_energy_consumption.addr, (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text))
60
+ ), buildings_mapping AS (
61
+ SELECT DISTINCT
62
+ CASE
63
+ WHEN d.addr::text !~~ '/%'::text THEN '/'::text || "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text))
64
+ ELSE "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text))
65
+ END AS building_code,
66
+ b.building_name
67
+ FROM consumption_energy_devices d
68
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
69
+ WHERE b.building_address_code::text !~~ '10.%'::text
70
+ )
71
+ SELECT bm.building_name,
72
+ lu.last_update,
73
+ lu.addr,
74
+ CASE
75
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
76
+ ELSE lnz.last_not_zero_value
77
+ END AS zero_values_after
78
+ FROM missing_devices_last_update lu
79
+ JOIN buildings_mapping bm ON lu.building_code =
80
+ CASE
81
+ WHEN bm.building_code !~~ '/%'::text THEN '/'::text || bm.building_code
82
+ ELSE bm.building_code
83
+ END
84
+ LEFT JOIN missing_devices_last_not_zero lnz ON lu.addr = lnz.addr;
85
+
86
+ CREATE OR REPLACE VIEW v_consumption_energy_last_update_prague_10
87
+ AS WITH last_update AS (
88
+ SELECT b.building_name,
89
+ replace(c.addr::text, concat('/', c.var), ''::text) AS addr,
90
+ max(c.time_utc) AS last_update
91
+ FROM consumption_energy_consumption c
92
+ JOIN consumption_energy_devices d ON replace(c.addr::text, concat('/', c.var), ''::text) =
93
+ CASE
94
+ WHEN d.addr::text !~~ '/%'::text THEN ('/'::text || d.addr::text)::character varying
95
+ ELSE d.addr
96
+ END::text
97
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
98
+ WHERE b.building_address_code::text ~~ '10.%'::text
99
+ GROUP BY b.building_name, (replace(c.addr::text, concat('/', c.var), ''::text))
100
+ ), last_not_zero AS (
101
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
102
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
103
+ FROM consumption_energy_consumption
104
+ WHERE consumption_energy_consumption.value > 0::numeric
105
+ GROUP BY (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text))
106
+ )
107
+ SELECT lu.building_name,
108
+ lu.last_update,
109
+ lu.addr,
110
+ CASE
111
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
112
+ ELSE lnz.last_not_zero_value
113
+ END AS zero_values_after
114
+ FROM last_update lu
115
+ LEFT JOIN last_not_zero lnz ON lu.addr = lnz.addr;
116
+
117
+ CREATE OR REPLACE VIEW v_consumption_energy_missing_devices_last_update_prague_10
118
+ AS WITH missing_devices_last_update AS (
119
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
120
+ "left"(consumption_energy_consumption.addr::text, "position"("right"(consumption_energy_consumption.addr::text, length(consumption_energy_consumption.addr::text) - 1), '/'::text)) AS building_code,
121
+ max(consumption_energy_consumption.time_utc) AS last_update
122
+ FROM consumption_energy_consumption
123
+ WHERE NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
124
+ CASE
125
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
126
+ ELSE consumption_energy_devices.addr
127
+ END AS addr
128
+ FROM consumption_energy_devices))
129
+ GROUP BY (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text)), consumption_energy_consumption.addr
130
+ ), missing_devices_last_not_zero AS (
131
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
132
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
133
+ FROM consumption_energy_consumption
134
+ WHERE consumption_energy_consumption.value > 0::numeric AND NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
135
+ CASE
136
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
137
+ ELSE consumption_energy_devices.addr
138
+ END AS addr
139
+ FROM consumption_energy_devices))
140
+ GROUP BY consumption_energy_consumption.addr, (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text))
141
+ ), buildings_mapping AS (
142
+ SELECT DISTINCT
143
+ CASE
144
+ WHEN d.addr::text !~~ '/%'::text THEN '/'::text || "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text))
145
+ ELSE "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text))
146
+ END AS building_code,
147
+ b.building_name
148
+ FROM consumption_energy_devices d
149
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
150
+ WHERE b.building_address_code::text ~~ '10.%'::text
151
+ )
152
+ SELECT bm.building_name,
153
+ lu.last_update,
154
+ lu.addr,
155
+ CASE
156
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
157
+ ELSE lnz.last_not_zero_value
158
+ END AS zero_values_after
159
+ FROM missing_devices_last_update lu
160
+ JOIN buildings_mapping bm ON lu.building_code =
161
+ CASE
162
+ WHEN bm.building_code !~~ '/%'::text THEN '/'::text || bm.building_code
163
+ ELSE bm.building_code
164
+ END
165
+ LEFT JOIN missing_devices_last_not_zero lnz ON lu.addr = lnz.addr;
166
+
167
+
168
+
@@ -0,0 +1,50 @@
1
+ CREATE OR REPLACE VIEW v_consumption_energy_missing_devices_last_update_prague_10
2
+ AS WITH missing_devices_last_update AS (
3
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
4
+ "left"(consumption_energy_consumption.addr::text, "position"("right"(consumption_energy_consumption.addr::text, length(consumption_energy_consumption.addr::text) - 1), '/'::text)) AS building_code,
5
+ max(consumption_energy_consumption.time_utc) AS last_update
6
+ FROM consumption_energy_consumption
7
+ WHERE NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
8
+ CASE
9
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
10
+ ELSE consumption_energy_devices.addr
11
+ END AS addr
12
+ FROM consumption_energy_devices))
13
+ GROUP BY (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text)), consumption_energy_consumption.addr
14
+ ), missing_devices_last_not_zero AS (
15
+ SELECT replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) AS addr,
16
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
17
+ FROM consumption_energy_consumption
18
+ WHERE consumption_energy_consumption.value > 0::numeric AND NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
19
+ CASE
20
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
21
+ ELSE consumption_energy_devices.addr
22
+ END AS addr
23
+ FROM consumption_energy_devices))
24
+ GROUP BY consumption_energy_consumption.addr, (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text))
25
+ ), buildings_mapping AS (
26
+ SELECT DISTINCT
27
+ CASE
28
+ WHEN d.addr::text !~~ '/%'::text THEN '/'::text || "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text))
29
+ ELSE "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text))
30
+ END AS building_code,
31
+ b.building_name
32
+ FROM consumption_energy_devices d
33
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
34
+ WHERE b.building_address_code::text ~~ '10.%'::text
35
+ )
36
+ SELECT bm.building_name,
37
+ lu.last_update,
38
+ lu.addr,
39
+ CASE
40
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
41
+ ELSE lnz.last_not_zero_value
42
+ END AS zero_values_after
43
+ FROM missing_devices_last_update lu
44
+ JOIN buildings_mapping bm ON lu.building_code =
45
+ CASE
46
+ WHEN bm.building_code !~~ '/%'::text THEN '/'::text || bm.building_code
47
+ ELSE bm.building_code
48
+ END
49
+ LEFT JOIN missing_devices_last_not_zero lnz ON lu.addr = lnz.addr;
50
+
@@ -0,0 +1,51 @@
1
+ DROP VIEW v_consumption_energy_missing_devices_last_update_prague_10;
2
+
3
+ CREATE OR REPLACE VIEW v_consumption_energy_missing_devices_last_update_prague_10
4
+ AS WITH missing_devices_last_update AS (
5
+ SELECT replace(replace(replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text), '/NT'::text, '-NT'::text), '/VT'::text, '-VT'::text) AS addr,
6
+ "left"(consumption_energy_consumption.addr::text, "position"("right"(consumption_energy_consumption.addr::text, length(consumption_energy_consumption.addr::text) - 1), '/'::text)) AS building_code,
7
+ max(consumption_energy_consumption.time_utc) AS last_update
8
+ FROM energetics.consumption_energy_consumption
9
+ WHERE NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
10
+ CASE
11
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
12
+ ELSE consumption_energy_devices.addr
13
+ END AS addr
14
+ FROM consumption_energy_devices))
15
+ GROUP BY (replace(replace(replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text), '/NT'::text, '-NT'::text), '/VT'::text, '-VT'::text)), ("left"(consumption_energy_consumption.addr::text, "position"("right"(consumption_energy_consumption.addr::text, length(consumption_energy_consumption.addr::text) - 1), '/'::text)))
16
+ ), missing_devices_last_not_zero AS (
17
+ SELECT replace(replace(replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text), '/NT'::text, '-NT'::text), '/VT'::text, '-VT'::text) AS addr,
18
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
19
+ FROM consumption_energy_consumption
20
+ WHERE consumption_energy_consumption.value > 0::numeric AND NOT (replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text) IN ( SELECT
21
+ CASE
22
+ WHEN consumption_energy_devices.addr::text !~~ '/%'::text THEN ('/'::text || consumption_energy_devices.addr::text)::character varying
23
+ ELSE consumption_energy_devices.addr
24
+ END AS addr
25
+ FROM consumption_energy_devices))
26
+ GROUP BY (replace(replace(replace(consumption_energy_consumption.addr::text, concat('/', consumption_energy_consumption.var), ''::text), '/NT'::text, '-NT'::text), '/VT'::text, '-VT'::text))
27
+ ), buildings_mapping AS (
28
+ SELECT DISTINCT "left"(d.addr::text, "position"("right"(d.addr::text, length(d.addr::text) - 1), '/'::text)) AS building_code,
29
+ b.building_name,
30
+ b.id,
31
+ d.building_id
32
+ FROM consumption_energy_devices d
33
+ JOIN consumption_energy_buildings b ON d.building_id = b.id
34
+ WHERE b.building_address_code::text ~~ '10.%'::text
35
+ )
36
+ SELECT bm.building_name,
37
+ lu.last_update,
38
+ lu.addr,
39
+ CASE
40
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
41
+ ELSE lnz.last_not_zero_value
42
+ END AS zero_values_after
43
+ FROM missing_devices_last_update lu
44
+ JOIN buildings_mapping bm ON lu.building_code =
45
+ CASE
46
+ WHEN bm.building_code !~~ '/%'::text THEN '/'::text || bm.building_code
47
+ ELSE bm.building_code
48
+ END
49
+ LEFT JOIN missing_devices_last_not_zero lnz ON lu.addr = lnz.addr;
50
+
51
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/energetics",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Golemio Energetics Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",