@golemio/energetics 1.2.2 → 1.2.3-dev.781407526

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', '20230216151258-new_views_out_of_prague-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', '20230216151258-new_views_out_of_prague-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,470 @@
1
+ CREATE OR REPLACE VIEW v_consumption_energy_delta
2
+ AS WITH delta AS (
3
+ SELECT es.time_utc,
4
+ es.addr,
5
+ es.var,
6
+ es.commodity,
7
+ es.unit,
8
+ es.value,
9
+ es.meter,
10
+ lag(es.value) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc) AS last_value,
11
+ lag(es.time_utc) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc) AS last_timeutc,
12
+ es.value - lag(es.value) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc) AS delta_value,
13
+ min.consumption_min AS prumerna_spotreba,
14
+ date_part('epoch'::text, es.time_utc - lag(es.time_utc) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc)) / 60::double precision AS minut_mereni
15
+ FROM energetics.consumption_energy_consumption es
16
+ JOIN energetics.v_consumption_energy_avg_consumption_min min ON es.addr::text = min.addr::text AND es.var::text = min.var::text AND es.meter::text = min.meter::text
17
+ WHERE es.var::text = 'core'::text AND (es.addr::text ~~ '%F%'::text OR es.addr::text = '/2.1/VP2'::text) AND es.value > 0::numeric
18
+ )
19
+ SELECT delta.time_utc,
20
+ delta.addr,
21
+ delta.var,
22
+ delta.commodity,
23
+ delta.unit,
24
+ delta.value,
25
+ delta.meter,
26
+ delta.last_value,
27
+ delta.last_timeutc,
28
+ CASE
29
+ WHEN abs(delta.delta_value::double precision / 60::double precision) > abs(1000::double precision * delta.prumerna_spotreba) THEN 0::numeric
30
+ ELSE delta.delta_value
31
+ END AS delta_value,
32
+ delta.minut_mereni
33
+ FROM delta;
34
+
35
+ CREATE OR REPLACE VIEW v_consumption_energy_buildings_real
36
+ AS SELECT consumption_energy_buildings.id,
37
+ consumption_energy_buildings.building_name,
38
+ consumption_energy_buildings.description,
39
+ consumption_energy_buildings.building_address_code,
40
+ consumption_energy_buildings.building_label,
41
+ consumption_energy_buildings.current_note,
42
+ consumption_energy_buildings.main_use,
43
+ consumption_energy_buildings.secondary_use,
44
+ consumption_energy_buildings.year_of_construction,
45
+ consumption_energy_buildings.method_of_protection,
46
+ consumption_energy_buildings.built_up_area,
47
+ consumption_energy_buildings.heated_bulding_volume,
48
+ consumption_energy_buildings.students_count,
49
+ consumption_energy_buildings.employees_count,
50
+ consumption_energy_buildings.classrooms_count,
51
+ consumption_energy_buildings.beds_count,
52
+ consumption_energy_buildings.eno_id,
53
+ consumption_energy_buildings.csu_code,
54
+ consumption_energy_buildings.ku_code,
55
+ consumption_energy_buildings.allotment_number,
56
+ consumption_energy_buildings.registration_unit,
57
+ consumption_energy_buildings.gas_consumption_normatives,
58
+ consumption_energy_buildings.heat_consumption_normatives,
59
+ consumption_energy_buildings.water_consumption_normatives,
60
+ consumption_energy_buildings.electricity_consumption_normatives_per_person,
61
+ consumption_energy_buildings.electricity_consumption_normatives,
62
+ consumption_energy_buildings.energetic_management,
63
+ consumption_energy_buildings.opening_hours,
64
+ consumption_energy_buildings.weekend_opening_hours,
65
+ consumption_energy_buildings.latitude,
66
+ consumption_energy_buildings.longitude,
67
+ consumption_energy_buildings.address_street,
68
+ consumption_energy_buildings.address_house_number,
69
+ consumption_energy_buildings.address_city,
70
+ consumption_energy_buildings.address_country,
71
+ consumption_energy_buildings.address_mail,
72
+ consumption_energy_buildings.address_phone,
73
+ consumption_energy_buildings.address_web_address,
74
+ consumption_energy_buildings.penb_penbnumber,
75
+ consumption_energy_buildings.penb_issue_date,
76
+ consumption_energy_buildings.penb_total_building_envelope_area,
77
+ consumption_energy_buildings.penb_volume_factor_of_avshape,
78
+ consumption_energy_buildings.penb_total_energy_reference_area,
79
+ consumption_energy_buildings.penb_total_provided_energy,
80
+ consumption_energy_buildings.penb_total_provided_energy_category,
81
+ consumption_energy_buildings.penb_primary_non_renewable_energy,
82
+ consumption_energy_buildings.penb_primary_non_renewable_energy_category,
83
+ consumption_energy_buildings.penb_building_envelope,
84
+ consumption_energy_buildings.penb_building_envelope_category,
85
+ consumption_energy_buildings.penb_heating,
86
+ consumption_energy_buildings.penb_heating_category,
87
+ consumption_energy_buildings.penb_cooling,
88
+ consumption_energy_buildings.penb_cooling_category,
89
+ consumption_energy_buildings.penb_ventilation,
90
+ consumption_energy_buildings.penb_ventilation_category,
91
+ consumption_energy_buildings.penb_humidity_adjustment,
92
+ consumption_energy_buildings.penb_humidity_adjustment_category,
93
+ consumption_energy_buildings.penb_warm_water,
94
+ consumption_energy_buildings.penb_warm_water_category,
95
+ consumption_energy_buildings.penb_lighting,
96
+ consumption_energy_buildings.penb_lighting_category,
97
+ consumption_energy_buildings.energy_audits_energy_audit,
98
+ consumption_energy_buildings.energy_audits_earegistration_number,
99
+ consumption_energy_buildings.energy_audits_created_at,
100
+ consumption_energy_buildings.building_envelope_side_wall_prevailing_construction,
101
+ consumption_energy_buildings.building_envelope_side_wall_area,
102
+ consumption_energy_buildings.building_envelope_side_wall_heat_insulation,
103
+ consumption_energy_buildings.building_envelope_side_wall_year_of_adjustment,
104
+ consumption_energy_buildings.building_envelope_side_wall_technical_condition,
105
+ consumption_energy_buildings.building_envelope_filling_of_hole_construction,
106
+ consumption_energy_buildings.building_envelope_filling_of_hole_area,
107
+ consumption_energy_buildings.building_envelope_filling_of_hole_year_of_adjustment,
108
+ consumption_energy_buildings.building_envelope_filling_of_hole_technical_condition,
109
+ consumption_energy_buildings.building_envelope_roof_construction,
110
+ consumption_energy_buildings.building_envelope_roof_area,
111
+ consumption_energy_buildings.building_envelope_roof_thermal_insulation,
112
+ consumption_energy_buildings.building_envelope_roof_year_of_adjustment,
113
+ consumption_energy_buildings.building_envelope_roof_technical_condition,
114
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_construction,
115
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_area,
116
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_thermal_insulation,
117
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_year_of_adju,
118
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_technical_condition,
119
+ consumption_energy_buildings.fuel_and_energy_coal,
120
+ consumption_energy_buildings.fuel_and_energy_gas,
121
+ consumption_energy_buildings.fuel_and_energy_electricity,
122
+ consumption_energy_buildings.fuel_and_energy_czt,
123
+ consumption_energy_buildings.fuel_and_energy_oze,
124
+ consumption_energy_buildings.fuel_and_energy_other,
125
+ consumption_energy_buildings.technical_equipment_heating_main_source_of_heat,
126
+ consumption_energy_buildings.technical_equipment_heating_heat_percentage,
127
+ consumption_energy_buildings.technical_equipment_heating_secondary_source_of_heat,
128
+ consumption_energy_buildings.technical_equipment_heating_heating_system,
129
+ consumption_energy_buildings.technical_equipment_heating_year,
130
+ consumption_energy_buildings.technical_equipment_heating_technical_condition,
131
+ consumption_energy_buildings.technical_equipment_cooling_cooling_system,
132
+ consumption_energy_buildings.technical_equipment_cooling_cooling_area_percentage,
133
+ consumption_energy_buildings.technical_equipment_cooling_year,
134
+ consumption_energy_buildings.technical_equipment_cooling_technical_condition,
135
+ consumption_energy_buildings.technical_equipment_ventilation_ventilation,
136
+ consumption_energy_buildings.technical_equipment_ventilation_year,
137
+ consumption_energy_buildings.technical_equipment_ventilation_technical_condition,
138
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_humidity_adjustment,
139
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_year,
140
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_technical_condition,
141
+ consumption_energy_buildings.technical_equipment_hot_water_predominant_way_of_heating_tv,
142
+ consumption_energy_buildings.technical_equipment_hot_water_hot_water_source,
143
+ consumption_energy_buildings.technical_equipment_hot_water_year,
144
+ consumption_energy_buildings.technical_equipment_hot_water_technical_condition,
145
+ consumption_energy_buildings.technical_equipment_lighting_lighting,
146
+ consumption_energy_buildings.technical_equipment_lighting_year,
147
+ consumption_energy_buildings.technical_equipment_lighting_technical_condition,
148
+ consumption_energy_buildings.technical_equipment_lighting_other_technological_elements,
149
+ consumption_energy_buildings.technical_equipment_lighting_measurement_method,
150
+ consumption_energy_buildings.oze_energy_production_solar_energy_photovoltaic,
151
+ consumption_energy_buildings.oze_energy_production_solar_energy_photothermal,
152
+ consumption_energy_buildings.oze_energy_production_integrated_turbines_wind_energy,
153
+ consumption_energy_buildings.oze_energy_production_heat_pump,
154
+ consumption_energy_buildings.waste_and_emissions_solid_waste_production,
155
+ consumption_energy_buildings.waste_and_emissions_tied_co2_emissions,
156
+ consumption_energy_buildings.waste_and_emissions_sox_emissions,
157
+ consumption_energy_buildings.waste_and_emissions_operating_co_2emissions,
158
+ consumption_energy_buildings.link
159
+ FROM energetics.consumption_energy_buildings
160
+ WHERE consumption_energy_buildings.building_label::text <> ALL (ARRAY['ZKB 1'::character varying::text, 'ZKB 2'::character varying::text, 'TB1'::character varying::text, 'TB2'::character varying::text]);
161
+
162
+ CREATE OR REPLACE VIEW v_consumption_energy_buildings_w_data
163
+ AS SELECT consumption_energy_buildings.id,
164
+ consumption_energy_buildings.building_name,
165
+ consumption_energy_buildings.description,
166
+ consumption_energy_buildings.building_address_code,
167
+ consumption_energy_buildings.building_label,
168
+ consumption_energy_buildings.current_note,
169
+ consumption_energy_buildings.main_use,
170
+ consumption_energy_buildings.secondary_use,
171
+ consumption_energy_buildings.year_of_construction,
172
+ consumption_energy_buildings.method_of_protection,
173
+ consumption_energy_buildings.built_up_area,
174
+ consumption_energy_buildings.heated_bulding_volume,
175
+ consumption_energy_buildings.students_count,
176
+ consumption_energy_buildings.employees_count,
177
+ consumption_energy_buildings.classrooms_count,
178
+ consumption_energy_buildings.beds_count,
179
+ consumption_energy_buildings.eno_id,
180
+ consumption_energy_buildings.csu_code,
181
+ consumption_energy_buildings.ku_code,
182
+ consumption_energy_buildings.allotment_number,
183
+ consumption_energy_buildings.registration_unit,
184
+ consumption_energy_buildings.gas_consumption_normatives,
185
+ consumption_energy_buildings.heat_consumption_normatives,
186
+ consumption_energy_buildings.water_consumption_normatives,
187
+ consumption_energy_buildings.electricity_consumption_normatives_per_person,
188
+ consumption_energy_buildings.electricity_consumption_normatives,
189
+ consumption_energy_buildings.energetic_management,
190
+ consumption_energy_buildings.opening_hours,
191
+ consumption_energy_buildings.weekend_opening_hours,
192
+ consumption_energy_buildings.latitude,
193
+ consumption_energy_buildings.longitude,
194
+ consumption_energy_buildings.address_street,
195
+ consumption_energy_buildings.address_house_number,
196
+ consumption_energy_buildings.address_city,
197
+ consumption_energy_buildings.address_country,
198
+ consumption_energy_buildings.address_mail,
199
+ consumption_energy_buildings.address_phone,
200
+ consumption_energy_buildings.address_web_address,
201
+ consumption_energy_buildings.penb_penbnumber,
202
+ consumption_energy_buildings.penb_issue_date,
203
+ consumption_energy_buildings.penb_total_building_envelope_area,
204
+ consumption_energy_buildings.penb_volume_factor_of_avshape,
205
+ consumption_energy_buildings.penb_total_energy_reference_area,
206
+ consumption_energy_buildings.penb_total_provided_energy,
207
+ consumption_energy_buildings.penb_total_provided_energy_category,
208
+ consumption_energy_buildings.penb_primary_non_renewable_energy,
209
+ consumption_energy_buildings.penb_primary_non_renewable_energy_category,
210
+ consumption_energy_buildings.penb_building_envelope,
211
+ consumption_energy_buildings.penb_building_envelope_category,
212
+ consumption_energy_buildings.penb_heating,
213
+ consumption_energy_buildings.penb_heating_category,
214
+ consumption_energy_buildings.penb_cooling,
215
+ consumption_energy_buildings.penb_cooling_category,
216
+ consumption_energy_buildings.penb_ventilation,
217
+ consumption_energy_buildings.penb_ventilation_category,
218
+ consumption_energy_buildings.penb_humidity_adjustment,
219
+ consumption_energy_buildings.penb_humidity_adjustment_category,
220
+ consumption_energy_buildings.penb_warm_water,
221
+ consumption_energy_buildings.penb_warm_water_category,
222
+ consumption_energy_buildings.penb_lighting,
223
+ consumption_energy_buildings.penb_lighting_category,
224
+ consumption_energy_buildings.energy_audits_energy_audit,
225
+ consumption_energy_buildings.energy_audits_earegistration_number,
226
+ consumption_energy_buildings.energy_audits_created_at,
227
+ consumption_energy_buildings.building_envelope_side_wall_prevailing_construction,
228
+ consumption_energy_buildings.building_envelope_side_wall_area,
229
+ consumption_energy_buildings.building_envelope_side_wall_heat_insulation,
230
+ consumption_energy_buildings.building_envelope_side_wall_year_of_adjustment,
231
+ consumption_energy_buildings.building_envelope_side_wall_technical_condition,
232
+ consumption_energy_buildings.building_envelope_filling_of_hole_construction,
233
+ consumption_energy_buildings.building_envelope_filling_of_hole_area,
234
+ consumption_energy_buildings.building_envelope_filling_of_hole_year_of_adjustment,
235
+ consumption_energy_buildings.building_envelope_filling_of_hole_technical_condition,
236
+ consumption_energy_buildings.building_envelope_roof_construction,
237
+ consumption_energy_buildings.building_envelope_roof_area,
238
+ consumption_energy_buildings.building_envelope_roof_thermal_insulation,
239
+ consumption_energy_buildings.building_envelope_roof_year_of_adjustment,
240
+ consumption_energy_buildings.building_envelope_roof_technical_condition,
241
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_construction,
242
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_area,
243
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_thermal_insulation,
244
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_year_of_adju,
245
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_technical_condition,
246
+ consumption_energy_buildings.fuel_and_energy_coal,
247
+ consumption_energy_buildings.fuel_and_energy_gas,
248
+ consumption_energy_buildings.fuel_and_energy_electricity,
249
+ consumption_energy_buildings.fuel_and_energy_czt,
250
+ consumption_energy_buildings.fuel_and_energy_oze,
251
+ consumption_energy_buildings.fuel_and_energy_other,
252
+ consumption_energy_buildings.technical_equipment_heating_main_source_of_heat,
253
+ consumption_energy_buildings.technical_equipment_heating_heat_percentage,
254
+ consumption_energy_buildings.technical_equipment_heating_secondary_source_of_heat,
255
+ consumption_energy_buildings.technical_equipment_heating_heating_system,
256
+ consumption_energy_buildings.technical_equipment_heating_year,
257
+ consumption_energy_buildings.technical_equipment_heating_technical_condition,
258
+ consumption_energy_buildings.technical_equipment_cooling_cooling_system,
259
+ consumption_energy_buildings.technical_equipment_cooling_cooling_area_percentage,
260
+ consumption_energy_buildings.technical_equipment_cooling_year,
261
+ consumption_energy_buildings.technical_equipment_cooling_technical_condition,
262
+ consumption_energy_buildings.technical_equipment_ventilation_ventilation,
263
+ consumption_energy_buildings.technical_equipment_ventilation_year,
264
+ consumption_energy_buildings.technical_equipment_ventilation_technical_condition,
265
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_humidity_adjustment,
266
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_year,
267
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_technical_condition,
268
+ consumption_energy_buildings.technical_equipment_hot_water_predominant_way_of_heating_tv,
269
+ consumption_energy_buildings.technical_equipment_hot_water_hot_water_source,
270
+ consumption_energy_buildings.technical_equipment_hot_water_year,
271
+ consumption_energy_buildings.technical_equipment_hot_water_technical_condition,
272
+ consumption_energy_buildings.technical_equipment_lighting_lighting,
273
+ consumption_energy_buildings.technical_equipment_lighting_year,
274
+ consumption_energy_buildings.technical_equipment_lighting_technical_condition,
275
+ consumption_energy_buildings.technical_equipment_lighting_other_technological_elements,
276
+ consumption_energy_buildings.technical_equipment_lighting_measurement_method,
277
+ consumption_energy_buildings.oze_energy_production_solar_energy_photovoltaic,
278
+ consumption_energy_buildings.oze_energy_production_solar_energy_photothermal,
279
+ consumption_energy_buildings.oze_energy_production_integrated_turbines_wind_energy,
280
+ consumption_energy_buildings.oze_energy_production_heat_pump,
281
+ consumption_energy_buildings.waste_and_emissions_solid_waste_production,
282
+ consumption_energy_buildings.waste_and_emissions_tied_co2_emissions,
283
+ consumption_energy_buildings.waste_and_emissions_sox_emissions,
284
+ consumption_energy_buildings.waste_and_emissions_operating_co_2emissions,
285
+ consumption_energy_buildings.link
286
+ FROM energetics.consumption_energy_buildings
287
+ WHERE (btrim(consumption_energy_buildings.building_address_code::text) IN ( SELECT DISTINCT v_consumption_energy_consumption.building_address_code
288
+ FROM energetics.v_consumption_energy_consumption)) AND consumption_energy_buildings.building_address_code::text !~~ '10.%'::text;
289
+
290
+ CREATE OR REPLACE VIEW v_consumption_energy_consumption_month_el_f
291
+ AS SELECT date_part('year'::text, consumption_energy_consumption.time_utc) AS rok,
292
+ date_part('month'::text, consumption_energy_consumption.time_utc) AS mesic,
293
+ consumption_energy_consumption.addr,
294
+ consumption_energy_consumption.var,
295
+ consumption_energy_consumption.commodity,
296
+ consumption_energy_consumption.unit,
297
+ sum(consumption_energy_consumption.value::numeric(10,2)) / 4::numeric AS value,
298
+ max(consumption_energy_consumption.time_utc::date) AS data_do,
299
+ count(*) AS count
300
+ FROM energetics.consumption_energy_consumption
301
+ WHERE (consumption_energy_consumption.var::text = ANY (ARRAY['EFwActi'::character varying::text, 'EFwActiNT'::character varying::text, 'EFwActi'::character varying::text])) AND consumption_energy_consumption.addr::text ~~ '%/EF%'::text
302
+ GROUP BY (date_part('year'::text, consumption_energy_consumption.time_utc)), (date_part('month'::text, consumption_energy_consumption.time_utc)), consumption_energy_consumption.addr, consumption_energy_consumption.var, consumption_energy_consumption.commodity, consumption_energy_consumption.unit
303
+ UNION
304
+ SELECT v_consumption_vrtbovsky_palac.measure_year AS rok,
305
+ v_consumption_vrtbovsky_palac.measure_month AS mesic,
306
+ v_consumption_vrtbovsky_palac.addr::character varying(255) AS addr,
307
+ v_consumption_vrtbovsky_palac.var::character varying(255) AS var,
308
+ v_consumption_vrtbovsky_palac.commodity::character varying(255) AS commodity,
309
+ v_consumption_vrtbovsky_palac.unit::character varying(255) AS unit,
310
+ sum(v_consumption_vrtbovsky_palac.consumption) AS value,
311
+ v_consumption_vrtbovsky_palac.data_do::date AS data_do,
312
+ count(*) AS count
313
+ FROM energetics.v_consumption_vrtbovsky_palac
314
+ WHERE v_consumption_vrtbovsky_palac.commodity = 'electricity'::text
315
+ GROUP BY v_consumption_vrtbovsky_palac.measure_year, v_consumption_vrtbovsky_palac.measure_month, v_consumption_vrtbovsky_palac.data_do, v_consumption_vrtbovsky_palac.addr, v_consumption_vrtbovsky_palac.var, v_consumption_vrtbovsky_palac.commodity, v_consumption_vrtbovsky_palac.unit;
316
+
317
+ CREATE OR REPLACE VIEW v_consumption_gas_reserve
318
+ AS WITH kalendar AS (
319
+ SELECT den.den::date AS den
320
+ FROM generate_series('2019-01-01 00:00:00+01'::timestamp with time zone, now() - '1 day'::interval, '1 day'::interval) den(den)
321
+ ), meraky AS (
322
+ SELECT DISTINCT consumption_energy_devices.addr
323
+ FROM energetics.consumption_energy_devices
324
+ WHERE consumption_energy_devices.meter_type::text = 'Plynoměr'::text
325
+ ), daily_delta_core AS (
326
+ SELECT date_trunc('day'::text, v_consumption_energy_delta.time_utc - '06:00:00'::interval)::date AS measured_from,
327
+ v_consumption_energy_delta.addr,
328
+ v_consumption_energy_delta.var,
329
+ sum(v_consumption_energy_delta.delta_value) AS delta_value
330
+ FROM energetics.v_consumption_energy_delta
331
+ WHERE v_consumption_energy_delta.commodity::text = 'gas'::text AND date_part('year'::text, v_consumption_energy_delta.time_utc - '06:00:00'::interval) >= 2019::double precision
332
+ GROUP BY (date_trunc('day'::text, v_consumption_energy_delta.time_utc - '06:00:00'::interval)::date), v_consumption_energy_delta.addr, v_consumption_energy_delta.var
333
+ ), daily_delta_core2 AS (
334
+ SELECT date_trunc('day'::text, consumption_energy_consumption.time_utc - '06:00:00'::interval)::date AS measured_from,
335
+ consumption_energy_consumption.addr,
336
+ consumption_energy_consumption.var,
337
+ sum(consumption_energy_consumption.value) AS delta_value
338
+ FROM energetics.consumption_energy_consumption
339
+ WHERE consumption_energy_consumption.var::text = 'core2'::text AND consumption_energy_consumption.time_utc::date > '2018-12-31'::date
340
+ GROUP BY (date_trunc('day'::text, consumption_energy_consumption.time_utc - '06:00:00'::interval)::date), consumption_energy_consumption.addr, consumption_energy_consumption.var
341
+ ), delta_dates AS (
342
+ SELECT daily_delta_core.measured_from,
343
+ daily_delta_core.addr,
344
+ daily_delta_core.var,
345
+ daily_delta_core.delta_value,
346
+ lag(daily_delta_core.measured_from, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS measured_before,
347
+ lead(daily_delta_core.measured_from, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS measured_after,
348
+ lag(daily_delta_core.delta_value, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS delta_before,
349
+ lead(daily_delta_core.delta_value, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS delta_after
350
+ FROM daily_delta_core
351
+ ), delta_date_diff AS (
352
+ SELECT delta_dates.measured_from,
353
+ delta_dates.addr,
354
+ delta_dates.var,
355
+ delta_dates.delta_value,
356
+ delta_dates.measured_before,
357
+ delta_dates.measured_after,
358
+ delta_dates.delta_before,
359
+ delta_dates.delta_after,
360
+ CASE
361
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 AND (delta_dates.measured_from - delta_dates.measured_before) > 1 THEN 'mid'::text
362
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 THEN 'begin'::text
363
+ WHEN (delta_dates.measured_from - delta_dates.measured_before) > 1 THEN 'end'::text
364
+ ELSE 'ok'::text
365
+ END AS value_type,
366
+ CASE
367
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 AND (delta_dates.measured_from - delta_dates.measured_before) > 1 THEN (delta_dates.delta_value / 2::numeric + delta_dates.delta_after) / (delta_dates.measured_after - delta_dates.measured_from + 1)::numeric
368
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 THEN (delta_dates.delta_value + delta_dates.delta_after) / (delta_dates.measured_after - delta_dates.measured_from + 1)::numeric
369
+ ELSE NULL::numeric
370
+ END AS fix
371
+ FROM delta_dates
372
+ ), joined_table AS (
373
+ SELECT kalendar.den AS measured_from,
374
+ meraky.addr,
375
+ diff.delta_value,
376
+ diff.value_type,
377
+ diff.fix,
378
+ core2.delta_value AS core2_delta,
379
+ CASE
380
+ WHEN diff.value_type = 'ok'::text THEN COALESCE(core2.delta_value, diff.delta_value)
381
+ ELSE diff.fix
382
+ END AS final_fix,
383
+ CASE
384
+ WHEN diff.value_type = 'ok'::text THEN COALESCE(core2.var, diff.var)
385
+ ELSE 'core'::character varying
386
+ END AS final_var
387
+ FROM kalendar
388
+ LEFT JOIN meraky ON true
389
+ LEFT JOIN delta_date_diff diff ON diff.measured_from = kalendar.den AND diff.addr::text = meraky.addr::text
390
+ LEFT JOIN daily_delta_core2 core2 ON core2.measured_from = kalendar.den AND core2.addr::text = meraky.addr::text
391
+ ORDER BY meraky.addr, kalendar.den
392
+ ), fixed_table AS (
393
+ SELECT q.measured_from,
394
+ q.addr,
395
+ q.delta_value,
396
+ q.value_type,
397
+ q.fix,
398
+ q.core2_delta,
399
+ q.final_fix,
400
+ q.final_var,
401
+ q.value_partition,
402
+ first_value(q.final_fix) OVER w AS value
403
+ FROM ( SELECT joined_table.measured_from,
404
+ joined_table.addr,
405
+ joined_table.delta_value,
406
+ joined_table.value_type,
407
+ joined_table.fix,
408
+ joined_table.core2_delta,
409
+ joined_table.final_fix,
410
+ joined_table.final_var,
411
+ sum(
412
+ CASE
413
+ WHEN joined_table.final_fix IS NULL THEN 0
414
+ ELSE 1
415
+ END) OVER (PARTITION BY joined_table.addr ORDER BY joined_table.measured_from) AS value_partition
416
+ FROM joined_table) q
417
+ WINDOW w AS (PARTITION BY q.addr, q.value_partition ORDER BY q.measured_from)
418
+ )
419
+ SELECT fixed_table.measured_from,
420
+ fixed_table.addr,
421
+ fixed_table.value AS delta_value,
422
+ fixed_table.final_var,
423
+ row_number() OVER (PARTITION BY fixed_table.addr, (date_trunc('month'::text, fixed_table.measured_from::timestamp with time zone)) ORDER BY fixed_table.value DESC) AS ran
424
+ FROM fixed_table
425
+ WHERE fixed_table.value IS NOT NULL;
426
+
427
+ CREATE OR REPLACE VIEW v_consumption_electricity_oict_api
428
+ AS SELECT date_trunc('day'::text, c.timeutc::date::timestamp with time zone) AS den,
429
+ c.timeutc::timestamp with time zone AS time_utc,
430
+ c.addr,
431
+ 'kWh'::text AS unit,
432
+ c.value_txt::integer::numeric * 1.04 AS value_num,
433
+ row_number() OVER (PARTITION BY c.addr, (date_trunc('month'::text, c.timeutc::date::timestamp with time zone)) ORDER BY c.value_txt DESC) AS ran
434
+ FROM python.consumption_electricity_oict_api2 c;
435
+
436
+ CREATE OR REPLACE VIEW v_consumption_energy_devices_active
437
+ AS SELECT consumption_energy_devices.id,
438
+ consumption_energy_devices.addr,
439
+ consumption_energy_devices.description,
440
+ consumption_energy_devices.meter_number,
441
+ consumption_energy_devices.meter_index,
442
+ consumption_energy_devices.location_number,
443
+ consumption_energy_devices.location_description,
444
+ consumption_energy_devices.include_in_evaluation,
445
+ consumption_energy_devices.meter_type,
446
+ consumption_energy_devices.category,
447
+ consumption_energy_devices.unit,
448
+ consumption_energy_devices.replaced_meter_id,
449
+ consumption_energy_devices.deleted,
450
+ consumption_energy_devices.building_id
451
+ FROM energetics.consumption_energy_devices
452
+ WHERE NOT (consumption_energy_devices.id IN ( SELECT consumption_energy_devices_1.replaced_meter_id::integer AS replaced_meter_id
453
+ FROM energetics.consumption_energy_devices consumption_energy_devices_1
454
+ WHERE consumption_energy_devices_1.replaced_meter_id::text <> ''::text)) AND (consumption_energy_devices.addr::text <> ALL (ARRAY['aaa'::character varying::text, 'VF1'::character varying::text, 'TF1'::character varying::text, 'EF1'::character varying::text, 'PF1'::character varying::text, '01/VF1'::character varying::text, 'Návštěvnost'::character varying::text])) AND consumption_energy_devices.deleted::text <> '1'::text
455
+ UNION
456
+ SELECT me.me_id AS id,
457
+ me.me_id::character varying(255) AS addr,
458
+ NULL::character varying(255) AS description,
459
+ NULL::character varying(255) AS meter_number,
460
+ NULL::character varying(255) AS meter_index,
461
+ NULL::character varying(255) AS location_number,
462
+ NULL::character varying(255) AS location_description,
463
+ NULL::character varying(255) AS include_in_evaluation,
464
+ NULL::character varying(255) AS meter_type,
465
+ NULL::character varying(255) AS category,
466
+ NULL::character varying(255) AS unit,
467
+ NULL::character varying(255) AS replaced_meter_id,
468
+ NULL::character varying(255) AS deleted,
469
+ 111 AS building_id
470
+ FROM energetics.vpalac_measuring_equipment me;
@@ -0,0 +1,473 @@
1
+ CREATE OR REPLACE VIEW v_consumption_energy_delta
2
+ AS WITH delta AS (
3
+ SELECT es.time_utc,
4
+ replace(es.addr, concat('/', es.var), '') AS addr, -- od sloupce addr je odloučen sloupec var pomocí / aby získal původní podobu
5
+ es.var,
6
+ es.commodity,
7
+ es.unit,
8
+ es.value,
9
+ es.meter,
10
+ lag(es.value) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc) AS last_value,
11
+ lag(es.time_utc) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc) AS last_timeutc,
12
+ es.value - lag(es.value) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc) AS delta_value,
13
+ min.consumption_min AS prumerna_spotreba,
14
+ date_part('epoch'::text, es.time_utc - lag(es.time_utc) OVER (PARTITION BY es.addr, es.var, es.meter ORDER BY es.time_utc)) / 60::double precision AS minut_mereni
15
+ FROM energetics.consumption_energy_consumption es
16
+ JOIN energetics.v_consumption_energy_avg_consumption_min min ON es.addr::text = min.addr::text AND es.var::text = min.var::text AND es.meter::text = min.meter::text
17
+ WHERE es.var::text = 'core'::text AND (es.addr::text ~~ '%F%'::text OR es.addr::text = '/2.1/VP2'::text) AND es.value > 0::numeric AND es.addr::text !~~ '10.%'::text AND es.addr::text !~~ '/10.%'::text
18
+ )
19
+ SELECT delta.time_utc,
20
+ delta.addr::varchar(255),
21
+ delta.var,
22
+ delta.commodity,
23
+ delta.unit,
24
+ delta.value,
25
+ delta.meter,
26
+ delta.last_value,
27
+ delta.last_timeutc,
28
+ CASE
29
+ WHEN abs(delta.delta_value::double precision / 60::double precision) > abs(1000::double precision * delta.prumerna_spotreba) THEN 0::numeric
30
+ ELSE delta.delta_value
31
+ END AS delta_value,
32
+ delta.minut_mereni
33
+ FROM delta;
34
+
35
+
36
+ CREATE OR REPLACE VIEW v_consumption_energy_buildings_real
37
+ AS SELECT consumption_energy_buildings.id,
38
+ consumption_energy_buildings.building_name,
39
+ consumption_energy_buildings.description,
40
+ consumption_energy_buildings.building_address_code,
41
+ consumption_energy_buildings.building_label,
42
+ consumption_energy_buildings.current_note,
43
+ consumption_energy_buildings.main_use,
44
+ consumption_energy_buildings.secondary_use,
45
+ consumption_energy_buildings.year_of_construction,
46
+ consumption_energy_buildings.method_of_protection,
47
+ consumption_energy_buildings.built_up_area,
48
+ consumption_energy_buildings.heated_bulding_volume,
49
+ consumption_energy_buildings.students_count,
50
+ consumption_energy_buildings.employees_count,
51
+ consumption_energy_buildings.classrooms_count,
52
+ consumption_energy_buildings.beds_count,
53
+ consumption_energy_buildings.eno_id,
54
+ consumption_energy_buildings.csu_code,
55
+ consumption_energy_buildings.ku_code,
56
+ consumption_energy_buildings.allotment_number,
57
+ consumption_energy_buildings.registration_unit,
58
+ consumption_energy_buildings.gas_consumption_normatives,
59
+ consumption_energy_buildings.heat_consumption_normatives,
60
+ consumption_energy_buildings.water_consumption_normatives,
61
+ consumption_energy_buildings.electricity_consumption_normatives_per_person,
62
+ consumption_energy_buildings.electricity_consumption_normatives,
63
+ consumption_energy_buildings.energetic_management,
64
+ consumption_energy_buildings.opening_hours,
65
+ consumption_energy_buildings.weekend_opening_hours,
66
+ consumption_energy_buildings.latitude,
67
+ consumption_energy_buildings.longitude,
68
+ consumption_energy_buildings.address_street,
69
+ consumption_energy_buildings.address_house_number,
70
+ consumption_energy_buildings.address_city,
71
+ consumption_energy_buildings.address_country,
72
+ consumption_energy_buildings.address_mail,
73
+ consumption_energy_buildings.address_phone,
74
+ consumption_energy_buildings.address_web_address,
75
+ consumption_energy_buildings.penb_penbnumber,
76
+ consumption_energy_buildings.penb_issue_date,
77
+ consumption_energy_buildings.penb_total_building_envelope_area,
78
+ consumption_energy_buildings.penb_volume_factor_of_avshape,
79
+ consumption_energy_buildings.penb_total_energy_reference_area,
80
+ consumption_energy_buildings.penb_total_provided_energy,
81
+ consumption_energy_buildings.penb_total_provided_energy_category,
82
+ consumption_energy_buildings.penb_primary_non_renewable_energy,
83
+ consumption_energy_buildings.penb_primary_non_renewable_energy_category,
84
+ consumption_energy_buildings.penb_building_envelope,
85
+ consumption_energy_buildings.penb_building_envelope_category,
86
+ consumption_energy_buildings.penb_heating,
87
+ consumption_energy_buildings.penb_heating_category,
88
+ consumption_energy_buildings.penb_cooling,
89
+ consumption_energy_buildings.penb_cooling_category,
90
+ consumption_energy_buildings.penb_ventilation,
91
+ consumption_energy_buildings.penb_ventilation_category,
92
+ consumption_energy_buildings.penb_humidity_adjustment,
93
+ consumption_energy_buildings.penb_humidity_adjustment_category,
94
+ consumption_energy_buildings.penb_warm_water,
95
+ consumption_energy_buildings.penb_warm_water_category,
96
+ consumption_energy_buildings.penb_lighting,
97
+ consumption_energy_buildings.penb_lighting_category,
98
+ consumption_energy_buildings.energy_audits_energy_audit,
99
+ consumption_energy_buildings.energy_audits_earegistration_number,
100
+ consumption_energy_buildings.energy_audits_created_at,
101
+ consumption_energy_buildings.building_envelope_side_wall_prevailing_construction,
102
+ consumption_energy_buildings.building_envelope_side_wall_area,
103
+ consumption_energy_buildings.building_envelope_side_wall_heat_insulation,
104
+ consumption_energy_buildings.building_envelope_side_wall_year_of_adjustment,
105
+ consumption_energy_buildings.building_envelope_side_wall_technical_condition,
106
+ consumption_energy_buildings.building_envelope_filling_of_hole_construction,
107
+ consumption_energy_buildings.building_envelope_filling_of_hole_area,
108
+ consumption_energy_buildings.building_envelope_filling_of_hole_year_of_adjustment,
109
+ consumption_energy_buildings.building_envelope_filling_of_hole_technical_condition,
110
+ consumption_energy_buildings.building_envelope_roof_construction,
111
+ consumption_energy_buildings.building_envelope_roof_area,
112
+ consumption_energy_buildings.building_envelope_roof_thermal_insulation,
113
+ consumption_energy_buildings.building_envelope_roof_year_of_adjustment,
114
+ consumption_energy_buildings.building_envelope_roof_technical_condition,
115
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_construction,
116
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_area,
117
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_thermal_insulation,
118
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_year_of_adju,
119
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_technical_condition,
120
+ consumption_energy_buildings.fuel_and_energy_coal,
121
+ consumption_energy_buildings.fuel_and_energy_gas,
122
+ consumption_energy_buildings.fuel_and_energy_electricity,
123
+ consumption_energy_buildings.fuel_and_energy_czt,
124
+ consumption_energy_buildings.fuel_and_energy_oze,
125
+ consumption_energy_buildings.fuel_and_energy_other,
126
+ consumption_energy_buildings.technical_equipment_heating_main_source_of_heat,
127
+ consumption_energy_buildings.technical_equipment_heating_heat_percentage,
128
+ consumption_energy_buildings.technical_equipment_heating_secondary_source_of_heat,
129
+ consumption_energy_buildings.technical_equipment_heating_heating_system,
130
+ consumption_energy_buildings.technical_equipment_heating_year,
131
+ consumption_energy_buildings.technical_equipment_heating_technical_condition,
132
+ consumption_energy_buildings.technical_equipment_cooling_cooling_system,
133
+ consumption_energy_buildings.technical_equipment_cooling_cooling_area_percentage,
134
+ consumption_energy_buildings.technical_equipment_cooling_year,
135
+ consumption_energy_buildings.technical_equipment_cooling_technical_condition,
136
+ consumption_energy_buildings.technical_equipment_ventilation_ventilation,
137
+ consumption_energy_buildings.technical_equipment_ventilation_year,
138
+ consumption_energy_buildings.technical_equipment_ventilation_technical_condition,
139
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_humidity_adjustment,
140
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_year,
141
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_technical_condition,
142
+ consumption_energy_buildings.technical_equipment_hot_water_predominant_way_of_heating_tv,
143
+ consumption_energy_buildings.technical_equipment_hot_water_hot_water_source,
144
+ consumption_energy_buildings.technical_equipment_hot_water_year,
145
+ consumption_energy_buildings.technical_equipment_hot_water_technical_condition,
146
+ consumption_energy_buildings.technical_equipment_lighting_lighting,
147
+ consumption_energy_buildings.technical_equipment_lighting_year,
148
+ consumption_energy_buildings.technical_equipment_lighting_technical_condition,
149
+ consumption_energy_buildings.technical_equipment_lighting_other_technological_elements,
150
+ consumption_energy_buildings.technical_equipment_lighting_measurement_method,
151
+ consumption_energy_buildings.oze_energy_production_solar_energy_photovoltaic,
152
+ consumption_energy_buildings.oze_energy_production_solar_energy_photothermal,
153
+ consumption_energy_buildings.oze_energy_production_integrated_turbines_wind_energy,
154
+ consumption_energy_buildings.oze_energy_production_heat_pump,
155
+ consumption_energy_buildings.waste_and_emissions_solid_waste_production,
156
+ consumption_energy_buildings.waste_and_emissions_tied_co2_emissions,
157
+ consumption_energy_buildings.waste_and_emissions_sox_emissions,
158
+ consumption_energy_buildings.waste_and_emissions_operating_co_2emissions,
159
+ consumption_energy_buildings.link
160
+ FROM energetics.consumption_energy_buildings
161
+ WHERE (consumption_energy_buildings.building_label::text <> ALL (ARRAY['ZKB 1'::character varying::text, 'ZKB 2'::character varying::text, 'TB1'::character varying::text, 'TB2'::character varying::text])) AND consumption_energy_buildings.building_address_code::text !~~ '10.%'::text;
162
+
163
+ CREATE OR REPLACE VIEW v_consumption_energy_buildings_w_data
164
+ AS SELECT consumption_energy_buildings.id,
165
+ consumption_energy_buildings.building_name,
166
+ consumption_energy_buildings.description,
167
+ consumption_energy_buildings.building_address_code,
168
+ consumption_energy_buildings.building_label,
169
+ consumption_energy_buildings.current_note,
170
+ consumption_energy_buildings.main_use,
171
+ consumption_energy_buildings.secondary_use,
172
+ consumption_energy_buildings.year_of_construction,
173
+ consumption_energy_buildings.method_of_protection,
174
+ consumption_energy_buildings.built_up_area,
175
+ consumption_energy_buildings.heated_bulding_volume,
176
+ consumption_energy_buildings.students_count,
177
+ consumption_energy_buildings.employees_count,
178
+ consumption_energy_buildings.classrooms_count,
179
+ consumption_energy_buildings.beds_count,
180
+ consumption_energy_buildings.eno_id,
181
+ consumption_energy_buildings.csu_code,
182
+ consumption_energy_buildings.ku_code,
183
+ consumption_energy_buildings.allotment_number,
184
+ consumption_energy_buildings.registration_unit,
185
+ consumption_energy_buildings.gas_consumption_normatives,
186
+ consumption_energy_buildings.heat_consumption_normatives,
187
+ consumption_energy_buildings.water_consumption_normatives,
188
+ consumption_energy_buildings.electricity_consumption_normatives_per_person,
189
+ consumption_energy_buildings.electricity_consumption_normatives,
190
+ consumption_energy_buildings.energetic_management,
191
+ consumption_energy_buildings.opening_hours,
192
+ consumption_energy_buildings.weekend_opening_hours,
193
+ consumption_energy_buildings.latitude,
194
+ consumption_energy_buildings.longitude,
195
+ consumption_energy_buildings.address_street,
196
+ consumption_energy_buildings.address_house_number,
197
+ consumption_energy_buildings.address_city,
198
+ consumption_energy_buildings.address_country,
199
+ consumption_energy_buildings.address_mail,
200
+ consumption_energy_buildings.address_phone,
201
+ consumption_energy_buildings.address_web_address,
202
+ consumption_energy_buildings.penb_penbnumber,
203
+ consumption_energy_buildings.penb_issue_date,
204
+ consumption_energy_buildings.penb_total_building_envelope_area,
205
+ consumption_energy_buildings.penb_volume_factor_of_avshape,
206
+ consumption_energy_buildings.penb_total_energy_reference_area,
207
+ consumption_energy_buildings.penb_total_provided_energy,
208
+ consumption_energy_buildings.penb_total_provided_energy_category,
209
+ consumption_energy_buildings.penb_primary_non_renewable_energy,
210
+ consumption_energy_buildings.penb_primary_non_renewable_energy_category,
211
+ consumption_energy_buildings.penb_building_envelope,
212
+ consumption_energy_buildings.penb_building_envelope_category,
213
+ consumption_energy_buildings.penb_heating,
214
+ consumption_energy_buildings.penb_heating_category,
215
+ consumption_energy_buildings.penb_cooling,
216
+ consumption_energy_buildings.penb_cooling_category,
217
+ consumption_energy_buildings.penb_ventilation,
218
+ consumption_energy_buildings.penb_ventilation_category,
219
+ consumption_energy_buildings.penb_humidity_adjustment,
220
+ consumption_energy_buildings.penb_humidity_adjustment_category,
221
+ consumption_energy_buildings.penb_warm_water,
222
+ consumption_energy_buildings.penb_warm_water_category,
223
+ consumption_energy_buildings.penb_lighting,
224
+ consumption_energy_buildings.penb_lighting_category,
225
+ consumption_energy_buildings.energy_audits_energy_audit,
226
+ consumption_energy_buildings.energy_audits_earegistration_number,
227
+ consumption_energy_buildings.energy_audits_created_at,
228
+ consumption_energy_buildings.building_envelope_side_wall_prevailing_construction,
229
+ consumption_energy_buildings.building_envelope_side_wall_area,
230
+ consumption_energy_buildings.building_envelope_side_wall_heat_insulation,
231
+ consumption_energy_buildings.building_envelope_side_wall_year_of_adjustment,
232
+ consumption_energy_buildings.building_envelope_side_wall_technical_condition,
233
+ consumption_energy_buildings.building_envelope_filling_of_hole_construction,
234
+ consumption_energy_buildings.building_envelope_filling_of_hole_area,
235
+ consumption_energy_buildings.building_envelope_filling_of_hole_year_of_adjustment,
236
+ consumption_energy_buildings.building_envelope_filling_of_hole_technical_condition,
237
+ consumption_energy_buildings.building_envelope_roof_construction,
238
+ consumption_energy_buildings.building_envelope_roof_area,
239
+ consumption_energy_buildings.building_envelope_roof_thermal_insulation,
240
+ consumption_energy_buildings.building_envelope_roof_year_of_adjustment,
241
+ consumption_energy_buildings.building_envelope_roof_technical_condition,
242
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_construction,
243
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_area,
244
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_thermal_insulation,
245
+ consumption_energy_buildings.building_envelope_floor_of_the_lowest_heated_floor_year_of_adju,
246
+ consumption_energy_buildings.floor_of_the_lowest_heated_floor_technical_condition,
247
+ consumption_energy_buildings.fuel_and_energy_coal,
248
+ consumption_energy_buildings.fuel_and_energy_gas,
249
+ consumption_energy_buildings.fuel_and_energy_electricity,
250
+ consumption_energy_buildings.fuel_and_energy_czt,
251
+ consumption_energy_buildings.fuel_and_energy_oze,
252
+ consumption_energy_buildings.fuel_and_energy_other,
253
+ consumption_energy_buildings.technical_equipment_heating_main_source_of_heat,
254
+ consumption_energy_buildings.technical_equipment_heating_heat_percentage,
255
+ consumption_energy_buildings.technical_equipment_heating_secondary_source_of_heat,
256
+ consumption_energy_buildings.technical_equipment_heating_heating_system,
257
+ consumption_energy_buildings.technical_equipment_heating_year,
258
+ consumption_energy_buildings.technical_equipment_heating_technical_condition,
259
+ consumption_energy_buildings.technical_equipment_cooling_cooling_system,
260
+ consumption_energy_buildings.technical_equipment_cooling_cooling_area_percentage,
261
+ consumption_energy_buildings.technical_equipment_cooling_year,
262
+ consumption_energy_buildings.technical_equipment_cooling_technical_condition,
263
+ consumption_energy_buildings.technical_equipment_ventilation_ventilation,
264
+ consumption_energy_buildings.technical_equipment_ventilation_year,
265
+ consumption_energy_buildings.technical_equipment_ventilation_technical_condition,
266
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_humidity_adjustment,
267
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_year,
268
+ consumption_energy_buildings.technical_equipment_humidity_adjustment_technical_condition,
269
+ consumption_energy_buildings.technical_equipment_hot_water_predominant_way_of_heating_tv,
270
+ consumption_energy_buildings.technical_equipment_hot_water_hot_water_source,
271
+ consumption_energy_buildings.technical_equipment_hot_water_year,
272
+ consumption_energy_buildings.technical_equipment_hot_water_technical_condition,
273
+ consumption_energy_buildings.technical_equipment_lighting_lighting,
274
+ consumption_energy_buildings.technical_equipment_lighting_year,
275
+ consumption_energy_buildings.technical_equipment_lighting_technical_condition,
276
+ consumption_energy_buildings.technical_equipment_lighting_other_technological_elements,
277
+ consumption_energy_buildings.technical_equipment_lighting_measurement_method,
278
+ consumption_energy_buildings.oze_energy_production_solar_energy_photovoltaic,
279
+ consumption_energy_buildings.oze_energy_production_solar_energy_photothermal,
280
+ consumption_energy_buildings.oze_energy_production_integrated_turbines_wind_energy,
281
+ consumption_energy_buildings.oze_energy_production_heat_pump,
282
+ consumption_energy_buildings.waste_and_emissions_solid_waste_production,
283
+ consumption_energy_buildings.waste_and_emissions_tied_co2_emissions,
284
+ consumption_energy_buildings.waste_and_emissions_sox_emissions,
285
+ consumption_energy_buildings.waste_and_emissions_operating_co_2emissions,
286
+ consumption_energy_buildings.link
287
+ FROM energetics.consumption_energy_buildings
288
+ WHERE (btrim(consumption_energy_buildings.building_address_code::text) IN ( SELECT DISTINCT v_consumption_energy_consumption.building_address_code
289
+ FROM energetics.v_consumption_energy_consumption)) AND consumption_energy_buildings.building_address_code::text !~~ '10.%'::text;
290
+
291
+ CREATE OR REPLACE VIEW v_consumption_energy_consumption_month_el_f
292
+ AS SELECT date_part('year'::text, consumption_energy_consumption.time_utc) AS rok,
293
+ date_part('month'::text, consumption_energy_consumption.time_utc) AS mesic,
294
+ replace(consumption_energy_consumption.addr, concat('/', consumption_energy_consumption.var), '')::varchar(255) AS addr, --od sloupce addr je odloučen sloupec var pomocí / aby získal původní podobu
295
+ consumption_energy_consumption.var,
296
+ consumption_energy_consumption.commodity,
297
+ consumption_energy_consumption.unit,
298
+ sum(consumption_energy_consumption.value::numeric(10,2)) / 4::numeric AS value,
299
+ max(consumption_energy_consumption.time_utc::date) AS data_do,
300
+ count(*) AS count
301
+ FROM energetics.consumption_energy_consumption
302
+ WHERE (consumption_energy_consumption.var::text = ANY (ARRAY['EFwActi'::character varying::text, 'EFwActiNT'::character varying::text, 'EFwActi'::character varying::text])) AND consumption_energy_consumption.addr::text ~~ '%/EF%'::text AND consumption_energy_consumption.addr::text !~~ '/10.%'::text AND consumption_energy_consumption.addr::text !~~ '10.%'::text
303
+ GROUP BY (date_part('year'::text, consumption_energy_consumption.time_utc)), (date_part('month'::text, consumption_energy_consumption.time_utc)), consumption_energy_consumption.addr, consumption_energy_consumption.var, consumption_energy_consumption.commodity, consumption_energy_consumption.unit
304
+ UNION
305
+ SELECT v_consumption_vrtbovsky_palac.measure_year AS rok,
306
+ v_consumption_vrtbovsky_palac.measure_month AS mesic,
307
+ v_consumption_vrtbovsky_palac.addr::character varying(255) AS addr,
308
+ v_consumption_vrtbovsky_palac.var::character varying(255) AS var,
309
+ v_consumption_vrtbovsky_palac.commodity::character varying(255) AS commodity,
310
+ v_consumption_vrtbovsky_palac.unit::character varying(255) AS unit,
311
+ sum(v_consumption_vrtbovsky_palac.consumption) AS value,
312
+ v_consumption_vrtbovsky_palac.data_do::date AS data_do,
313
+ count(*) AS count
314
+ FROM energetics.v_consumption_vrtbovsky_palac
315
+ WHERE v_consumption_vrtbovsky_palac.commodity = 'electricity'::text
316
+ GROUP BY v_consumption_vrtbovsky_palac.measure_year, v_consumption_vrtbovsky_palac.measure_month, v_consumption_vrtbovsky_palac.data_do, v_consumption_vrtbovsky_palac.addr, v_consumption_vrtbovsky_palac.var, v_consumption_vrtbovsky_palac.commodity, v_consumption_vrtbovsky_palac.unit;
317
+
318
+ CREATE OR REPLACE VIEW v_consumption_gas_reserve
319
+ AS WITH kalendar AS (
320
+ SELECT den.den::date AS den
321
+ FROM generate_series('2019-01-01 00:00:00+01'::timestamp with time zone, now() - '1 day'::interval, '1 day'::interval) den(den)
322
+ ), meraky AS (
323
+ SELECT DISTINCT consumption_energy_devices.addr
324
+ FROM energetics.consumption_energy_devices
325
+ WHERE consumption_energy_devices.meter_type::text = 'Plynoměr'::text and consumption_energy_devices.addr not like '10.%' and consumption_energy_devices.addr not like '/10.%'
326
+ ), daily_delta_core AS (
327
+ SELECT date_trunc('day'::text, v_consumption_energy_delta.time_utc - '06:00:00'::interval)::date AS measured_from,
328
+ v_consumption_energy_delta.addr,
329
+ v_consumption_energy_delta.var,
330
+ sum(v_consumption_energy_delta.delta_value) AS delta_value
331
+ FROM energetics.v_consumption_energy_delta
332
+ WHERE v_consumption_energy_delta.commodity::text = 'gas'::text AND date_part('year'::text, v_consumption_energy_delta.time_utc - '06:00:00'::interval) >= 2019::double precision
333
+ GROUP BY (date_trunc('day'::text, v_consumption_energy_delta.time_utc - '06:00:00'::interval)::date), v_consumption_energy_delta.addr, v_consumption_energy_delta.var
334
+ ), daily_delta_core2 AS (
335
+ SELECT date_trunc('day'::text, consumption_energy_consumption.time_utc - '06:00:00'::interval)::date AS measured_from,
336
+ replace(consumption_energy_consumption.addr, concat('/', consumption_energy_consumption.var), '')::varchar(255) AS addr,
337
+ consumption_energy_consumption.var,
338
+ sum(consumption_energy_consumption.value) AS delta_value
339
+ FROM energetics.consumption_energy_consumption
340
+ WHERE consumption_energy_consumption.var::text = 'core2'::text AND consumption_energy_consumption.time_utc::date > '2018-12-31'::date and consumption_energy_consumption.addr not like '10.%' and consumption_energy_consumption.addr not like '/10.%'
341
+ GROUP BY (date_trunc('day'::text, consumption_energy_consumption.time_utc - '06:00:00'::interval)::date), consumption_energy_consumption.addr, consumption_energy_consumption.var
342
+ ), delta_dates AS (
343
+ SELECT daily_delta_core.measured_from,
344
+ daily_delta_core.addr,
345
+ daily_delta_core.var,
346
+ daily_delta_core.delta_value,
347
+ lag(daily_delta_core.measured_from, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS measured_before,
348
+ lead(daily_delta_core.measured_from, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS measured_after,
349
+ lag(daily_delta_core.delta_value, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS delta_before,
350
+ lead(daily_delta_core.delta_value, 1) OVER (PARTITION BY daily_delta_core.addr ORDER BY daily_delta_core.measured_from) AS delta_after
351
+ FROM daily_delta_core
352
+ ), delta_date_diff AS (
353
+ SELECT delta_dates.measured_from,
354
+ delta_dates.addr,
355
+ delta_dates.var,
356
+ delta_dates.delta_value,
357
+ delta_dates.measured_before,
358
+ delta_dates.measured_after,
359
+ delta_dates.delta_before,
360
+ delta_dates.delta_after,
361
+ CASE
362
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 AND (delta_dates.measured_from - delta_dates.measured_before) > 1 THEN 'mid'::text
363
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 THEN 'begin'::text
364
+ WHEN (delta_dates.measured_from - delta_dates.measured_before) > 1 THEN 'end'::text
365
+ ELSE 'ok'::text
366
+ END AS value_type,
367
+ CASE
368
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 AND (delta_dates.measured_from - delta_dates.measured_before) > 1 THEN (delta_dates.delta_value / 2::numeric + delta_dates.delta_after) / (delta_dates.measured_after - delta_dates.measured_from + 1)::numeric
369
+ WHEN (delta_dates.measured_after - delta_dates.measured_from) > 1 THEN (delta_dates.delta_value + delta_dates.delta_after) / (delta_dates.measured_after - delta_dates.measured_from + 1)::numeric
370
+ ELSE NULL::numeric
371
+ END AS fix
372
+ FROM delta_dates
373
+ ), joined_table AS (
374
+ SELECT kalendar.den AS measured_from,
375
+ meraky.addr,
376
+ diff.delta_value,
377
+ diff.value_type,
378
+ diff.fix,
379
+ core2.delta_value AS core2_delta,
380
+ CASE
381
+ WHEN diff.value_type = 'ok'::text THEN COALESCE(core2.delta_value, diff.delta_value)
382
+ ELSE diff.fix
383
+ END AS final_fix,
384
+ CASE
385
+ WHEN diff.value_type = 'ok'::text THEN COALESCE(core2.var, diff.var)
386
+ ELSE 'core'::character varying
387
+ END AS final_var
388
+ FROM kalendar
389
+ LEFT JOIN meraky ON true
390
+ LEFT JOIN delta_date_diff diff ON diff.measured_from = kalendar.den AND diff.addr::text = meraky.addr::text
391
+ LEFT JOIN daily_delta_core2 core2 ON core2.measured_from = kalendar.den AND core2.addr = meraky.addr::text
392
+ ORDER BY meraky.addr, kalendar.den
393
+ ), fixed_table AS (
394
+ SELECT q.measured_from,
395
+ q.addr,
396
+ q.delta_value,
397
+ q.value_type,
398
+ q.fix,
399
+ q.core2_delta,
400
+ q.final_fix,
401
+ q.final_var,
402
+ q.value_partition,
403
+ first_value(q.final_fix) OVER w AS value
404
+ FROM ( SELECT joined_table.measured_from,
405
+ joined_table.addr,
406
+ joined_table.delta_value,
407
+ joined_table.value_type,
408
+ joined_table.fix,
409
+ joined_table.core2_delta,
410
+ joined_table.final_fix,
411
+ joined_table.final_var,
412
+ sum(
413
+ CASE
414
+ WHEN joined_table.final_fix IS NULL THEN 0
415
+ ELSE 1
416
+ END) OVER (PARTITION BY joined_table.addr ORDER BY joined_table.measured_from) AS value_partition
417
+ FROM joined_table) q
418
+ WINDOW w AS (PARTITION BY q.addr, q.value_partition ORDER BY q.measured_from)
419
+ )
420
+ SELECT fixed_table.measured_from,
421
+ fixed_table.addr,
422
+ fixed_table.value AS delta_value,
423
+ fixed_table.final_var,
424
+ row_number() OVER (PARTITION BY fixed_table.addr, (date_trunc('month'::text, fixed_table.measured_from::timestamp with time zone)) ORDER BY fixed_table.value DESC) AS ran
425
+ FROM fixed_table
426
+ WHERE fixed_table.value IS NOT NULL;
427
+
428
+ CREATE OR REPLACE VIEW v_consumption_electricity_oict_api
429
+ AS SELECT date_trunc('day'::text, c.timeutc::date::timestamp with time zone) AS den,
430
+ c.timeutc::timestamp with time zone AS time_utc,
431
+ replace(c.addr, concat('/', c.var), '') AS addr,
432
+ 'kWh'::text AS unit,
433
+ c.value_txt::integer::numeric * 1.04 AS value_num,
434
+ row_number() OVER (PARTITION BY c.addr, (date_trunc('month'::text, c.timeutc::date::timestamp with time zone)) ORDER BY c.value_txt DESC) AS ran
435
+ FROM python.consumption_electricity_oict_api2 c;
436
+
437
+ CREATE OR REPLACE VIEW v_consumption_energy_devices_active
438
+ AS SELECT consumption_energy_devices.id,
439
+ consumption_energy_devices.addr,
440
+ consumption_energy_devices.description,
441
+ consumption_energy_devices.meter_number,
442
+ consumption_energy_devices.meter_index,
443
+ consumption_energy_devices.location_number,
444
+ consumption_energy_devices.location_description,
445
+ consumption_energy_devices.include_in_evaluation,
446
+ consumption_energy_devices.meter_type,
447
+ consumption_energy_devices.category,
448
+ consumption_energy_devices.unit,
449
+ consumption_energy_devices.replaced_meter_id,
450
+ consumption_energy_devices.deleted,
451
+ consumption_energy_devices.building_id
452
+ FROM energetics.consumption_energy_devices
453
+ WHERE NOT (consumption_energy_devices.id IN ( SELECT consumption_energy_devices_1.replaced_meter_id::integer AS replaced_meter_id
454
+ FROM energetics.consumption_energy_devices consumption_energy_devices_1
455
+ WHERE consumption_energy_devices_1.replaced_meter_id::text <> ''::text)) AND (consumption_energy_devices.addr::text <> ALL (ARRAY['aaa'::character varying::text, 'VF1'::character varying::text, 'TF1'::character varying::text, 'EF1'::character varying::text, 'PF1'::character varying::text, '01/VF1'::character varying::text, 'Návštěvnost'::character varying::text])) AND consumption_energy_devices.deleted::text <> '1'::text AND consumption_energy_devices.addr::text !~~ '/10.%'::text AND consumption_energy_devices.addr::text !~~ '10.%'::text
456
+ UNION
457
+ SELECT me.me_id AS id,
458
+ me.me_id::character varying(255) AS addr,
459
+ NULL::character varying(255) AS description,
460
+ NULL::character varying(255) AS meter_number,
461
+ NULL::character varying(255) AS meter_index,
462
+ NULL::character varying(255) AS location_number,
463
+ NULL::character varying(255) AS location_description,
464
+ NULL::character varying(255) AS include_in_evaluation,
465
+ NULL::character varying(255) AS meter_type,
466
+ NULL::character varying(255) AS category,
467
+ NULL::character varying(255) AS unit,
468
+ NULL::character varying(255) AS replaced_meter_id,
469
+ NULL::character varying(255) AS deleted,
470
+ 111 AS building_id
471
+ FROM energetics.vpalac_measuring_equipment me;
472
+
473
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/energetics",
3
- "version": "1.2.2",
3
+ "version": "1.2.3-dev.781407526",
4
4
  "description": "Golemio Energetics Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "url": "https://gitlab.com/operator-ict/golemio/code/modules/energetics"
25
25
  },
26
26
  "engines": {
27
- "node": ">=16.0.0",
27
+ "node": ">=18.0.0",
28
28
  "npm": ">=8.0.0",
29
29
  "yarn": "Use npm!"
30
30
  },
@@ -38,7 +38,7 @@
38
38
  "@types/chai": "4.2.3",
39
39
  "@types/chai-as-promised": "7.1.2",
40
40
  "@types/mocha": "^8.2.0",
41
- "@types/node": "^16.11.35",
41
+ "@types/node": "^18.13.0",
42
42
  "@types/sinon": "^9.0.10",
43
43
  "chai": "4.2.0",
44
44
  "chai-as-promised": "7.1.1",
@@ -59,10 +59,10 @@
59
59
  "typescript": "4.7.2"
60
60
  },
61
61
  "peerDependencies": {
62
- "@golemio/core": "^1.3.0"
62
+ "@golemio/core": ">=1.3.0"
63
63
  },
64
64
  "dependencies": {
65
65
  "JSONStream": "^1.3.5"
66
66
  },
67
67
  "overrides": {}
68
- }
68
+ }