@golemio/energetics 1.4.3-dev.1411262009 → 1.4.3-rc.1417628927

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.
@@ -1,27 +1,27 @@
1
- DROP VIEW v_consumption_energy_last_update;
2
-
3
- CREATE OR REPLACE VIEW v_consumption_energy_last_update
4
- AS WITH last_update AS (
5
- SELECT b.building_name,
6
- c.addr,
7
- max(c.time_utc) AS last_update
8
- FROM energetics.consumption_energy_consumption c
9
- JOIN energetics.consumption_energy_devices d ON c.addr::text = d.addr::text
10
- JOIN energetics.consumption_energy_buildings b ON d.building_id = b.id
11
- GROUP BY b.building_name, c.addr
12
- ), last_not_zero AS (
13
- SELECT consumption_energy_consumption.addr,
14
- max(consumption_energy_consumption.time_utc) AS last_not_zero_value
15
- FROM energetics.consumption_energy_consumption
16
- WHERE consumption_energy_consumption.value > 0::numeric
17
- GROUP BY consumption_energy_consumption.addr
18
- )
19
- SELECT lu.building_name,
20
- lu.last_update,
21
- lu.addr,
22
- CASE
23
- WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
24
- ELSE lnz.last_not_zero_value
25
- END AS zero_values_after
26
- FROM last_update lu
27
- LEFT JOIN last_not_zero lnz ON lu.addr::text = lnz.addr::text;
1
+ DROP VIEW v_consumption_energy_last_update;
2
+
3
+ CREATE OR REPLACE VIEW v_consumption_energy_last_update
4
+ AS WITH last_update AS (
5
+ SELECT b.building_name,
6
+ c.addr,
7
+ max(c.time_utc) AS last_update
8
+ FROM energetics.consumption_energy_consumption c
9
+ JOIN energetics.consumption_energy_devices d ON c.addr::text = d.addr::text
10
+ JOIN energetics.consumption_energy_buildings b ON d.building_id = b.id
11
+ GROUP BY b.building_name, c.addr
12
+ ), last_not_zero AS (
13
+ SELECT consumption_energy_consumption.addr,
14
+ max(consumption_energy_consumption.time_utc) AS last_not_zero_value
15
+ FROM energetics.consumption_energy_consumption
16
+ WHERE consumption_energy_consumption.value > 0::numeric
17
+ GROUP BY consumption_energy_consumption.addr
18
+ )
19
+ SELECT lu.building_name,
20
+ lu.last_update,
21
+ lu.addr,
22
+ CASE
23
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
24
+ ELSE lnz.last_not_zero_value
25
+ END AS zero_values_after
26
+ FROM last_update lu
27
+ LEFT JOIN last_not_zero lnz ON lu.addr::text = lnz.addr::text;
@@ -1,28 +1,28 @@
1
- DROP VIEW v_consumption_energy_last_update;
2
-
3
- CREATE OR REPLACE VIEW v_consumption_energy_last_update
4
- AS WITH last_update AS (
5
- SELECT b.building_name,
6
- replace(c.addr, concat('/', c.var), '') as addr,
7
- max(c.time_utc) AS last_update
8
- FROM energetics.consumption_energy_consumption c
9
- JOIN energetics.consumption_energy_devices d ON replace(c.addr, concat('/', c.var), '') = d.addr::text
10
- JOIN energetics.consumption_energy_buildings b ON d.building_id = b.id
11
- GROUP BY b.building_name, replace(c.addr, concat('/', c.var), '')
12
- ), last_not_zero AS (
13
- SELECT replace(addr, concat('/', var), '') as addr,
14
- max(time_utc) AS last_not_zero_value
15
- FROM consumption_energy_consumption
16
- WHERE value > 0::numeric
17
- GROUP BY replace(addr, concat('/', var), '')
18
- )
19
- SELECT lu.building_name,
20
- lu.last_update,
21
- lu.addr,
22
- CASE
23
- WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
24
- ELSE lnz.last_not_zero_value
25
- END AS zero_values_after
26
- FROM last_update lu
27
- LEFT JOIN last_not_zero lnz ON lu.addr::text = lnz.addr::text
28
-
1
+ DROP VIEW v_consumption_energy_last_update;
2
+
3
+ CREATE OR REPLACE VIEW v_consumption_energy_last_update
4
+ AS WITH last_update AS (
5
+ SELECT b.building_name,
6
+ replace(c.addr, concat('/', c.var), '') as addr,
7
+ max(c.time_utc) AS last_update
8
+ FROM energetics.consumption_energy_consumption c
9
+ JOIN energetics.consumption_energy_devices d ON replace(c.addr, concat('/', c.var), '') = d.addr::text
10
+ JOIN energetics.consumption_energy_buildings b ON d.building_id = b.id
11
+ GROUP BY b.building_name, replace(c.addr, concat('/', c.var), '')
12
+ ), last_not_zero AS (
13
+ SELECT replace(addr, concat('/', var), '') as addr,
14
+ max(time_utc) AS last_not_zero_value
15
+ FROM consumption_energy_consumption
16
+ WHERE value > 0::numeric
17
+ GROUP BY replace(addr, concat('/', var), '')
18
+ )
19
+ SELECT lu.building_name,
20
+ lu.last_update,
21
+ lu.addr,
22
+ CASE
23
+ WHEN lnz.last_not_zero_value = lu.last_update THEN NULL::timestamp without time zone
24
+ ELSE lnz.last_not_zero_value
25
+ END AS zero_values_after
26
+ FROM last_update lu
27
+ LEFT JOIN last_not_zero lnz ON lu.addr::text = lnz.addr::text
28
+
@@ -1,64 +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
-
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
+
@@ -1,168 +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
-
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
+