@golemio/energetics 1.13.0 → 1.13.1-dev.2769672204
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.
- package/db/example/07_enapo_om_detail.sql +15 -10
- package/db/example/09_enapo_consumption_history.sql +196 -0
- package/db/migrations/postgresql/20260813090000-enapo-consumption-history.js +53 -0
- package/db/migrations/postgresql/sqls/20260813090000-enapo-consumption-history-down.sql +12 -0
- package/db/migrations/postgresql/sqls/20260813090000-enapo-consumption-history-up.sql +504 -0
- package/dist/integration-engine/enapo/ioc/Di.js +5 -1
- package/dist/integration-engine/enapo/ioc/Di.js.map +1 -1
- package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.d.ts +2 -0
- package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.js +2 -0
- package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.js.map +1 -1
- package/dist/integration-engine/enapo/repositories/AbstractMaterializedViewIndexRepository.d.ts +8 -0
- package/dist/integration-engine/enapo/repositories/AbstractMaterializedViewIndexRepository.js +25 -0
- package/dist/integration-engine/enapo/repositories/AbstractMaterializedViewIndexRepository.js.map +1 -0
- package/dist/integration-engine/enapo/repositories/DedSearchIndexRepository.d.ts +2 -3
- package/dist/integration-engine/enapo/repositories/DedSearchIndexRepository.js +3 -23
- package/dist/integration-engine/enapo/repositories/DedSearchIndexRepository.js.map +1 -1
- package/dist/integration-engine/enapo/repositories/EnapoConsumptionHistoryIndexRepository.d.ts +6 -0
- package/dist/integration-engine/enapo/repositories/EnapoConsumptionHistoryIndexRepository.js +30 -0
- package/dist/integration-engine/enapo/repositories/EnapoConsumptionHistoryIndexRepository.js.map +1 -0
- package/dist/integration-engine/enapo/repositories/interfaces/IEnapoConsumptionHistoryIndexRepository.d.ts +7 -0
- package/dist/integration-engine/enapo/repositories/interfaces/IEnapoConsumptionHistoryIndexRepository.js +3 -0
- package/dist/integration-engine/enapo/repositories/interfaces/IEnapoConsumptionHistoryIndexRepository.js.map +1 -0
- package/dist/integration-engine/enapo/workers/EnapoWorker.js +1 -0
- package/dist/integration-engine/enapo/workers/EnapoWorker.js.map +1 -1
- package/dist/integration-engine/enapo/workers/task/EnapoConsumptionHistoryRefreshTask.d.ts +10 -0
- package/dist/integration-engine/enapo/workers/task/EnapoConsumptionHistoryRefreshTask.js +47 -0
- package/dist/integration-engine/enapo/workers/task/EnapoConsumptionHistoryRefreshTask.js.map +1 -0
- package/dist/output-gateway/constants/ConsumptionHistory.d.ts +2 -0
- package/dist/output-gateway/constants/ConsumptionHistory.js +6 -0
- package/dist/output-gateway/constants/ConsumptionHistory.js.map +1 -0
- package/dist/output-gateway/controllers/v2/EnoBuildingsController.js +3 -3
- package/dist/output-gateway/controllers/v2/EnoBuildingsController.js.map +1 -1
- package/dist/output-gateway/helpers/ConsumptionHistoryWindow.d.ts +12 -0
- package/dist/output-gateway/helpers/ConsumptionHistoryWindow.js +30 -0
- package/dist/output-gateway/helpers/ConsumptionHistoryWindow.js.map +1 -0
- package/dist/output-gateway/models/EnapoOmConsumptionViewModel.d.ts +23 -0
- package/dist/output-gateway/models/EnapoOmConsumptionViewModel.js +48 -0
- package/dist/output-gateway/models/EnapoOmConsumptionViewModel.js.map +1 -0
- package/dist/output-gateway/models/interfaces/IEnapoOmConsumptionView.d.ts +20 -0
- package/dist/output-gateway/models/interfaces/IEnapoOmConsumptionView.js +3 -0
- package/dist/output-gateway/models/interfaces/IEnapoOmConsumptionView.js.map +1 -0
- package/dist/output-gateway/repositories/EnapoOmConsumptionRepository.d.ts +8 -0
- package/dist/output-gateway/repositories/EnapoOmConsumptionRepository.js +59 -0
- package/dist/output-gateway/repositories/EnapoOmConsumptionRepository.js.map +1 -0
- package/dist/output-gateway/repositories/EnoBuildingDetailRepository.d.ts +2 -1
- package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js +13 -3
- package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js.map +1 -1
- package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.d.ts +2 -0
- package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js +34 -0
- package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js.map +1 -1
- package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.d.ts +6 -1
- package/dist/output-gateway/repositories/interfaces/IEnoSharedPointRow.d.ts +5 -0
- package/dist/output-gateway/repositories/interfaces/IEnoSharedPointRow.js +3 -0
- package/dist/output-gateway/repositories/interfaces/IEnoSharedPointRow.js.map +1 -0
- package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.d.ts +43 -18
- package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js +2 -1
- package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js.map +1 -1
- package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.d.ts +6 -0
- package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js +53 -14
- package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js.map +1 -1
- package/dist/output-gateway/transformations/helpers/ConsumptionHistoryBuilder.d.ts +16 -0
- package/dist/output-gateway/transformations/helpers/ConsumptionHistoryBuilder.js +133 -0
- package/dist/output-gateway/transformations/helpers/ConsumptionHistoryBuilder.js.map +1 -0
- package/dist/output-gateway/transformations/helpers/PorsennaCoverage.d.ts +5 -0
- package/dist/output-gateway/transformations/helpers/PorsennaCoverage.js +40 -0
- package/dist/output-gateway/transformations/helpers/PorsennaCoverage.js.map +1 -0
- package/docs/implementation_documentation.md +67 -1
- package/docs/openapi-output.yaml +663 -43
- package/package.json +1 -1
|
@@ -56,11 +56,11 @@ INSERT INTO enapo_ppas_distribution_installation (invoice_id, customer_id, place
|
|
|
56
56
|
INSERT INTO enapo_ppas_distribution_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
|
|
57
57
|
"type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
|
|
58
58
|
volume_coefficient, combustion_heat, normometers_nm3) VALUES
|
|
59
|
-
('PLYN-001', 'DI-2026-001', '10101325', '2025-03-01', '2026-02-28', 'G4', '
|
|
60
|
-
'
|
|
59
|
+
('PLYN-001', 'DI-2026-001', '10101325', '2025-03-01', '2026-02-28', 'G4', 'ZIZWC',
|
|
60
|
+
'STANDARD', 10250.0, 11930.0, 1680.0, 'M3', 'dálkový', 17750.4,
|
|
61
61
|
1.0043, 10.55, 1687.2),
|
|
62
|
-
('PLYN-999', 'DI-2026-001', '10101999', '2025-03-01', '2026-02-28', 'G4', '
|
|
63
|
-
'
|
|
62
|
+
('PLYN-999', 'DI-2026-001', '10101999', '2025-03-01', '2026-02-28', 'G4', 'ZIZWC',
|
|
63
|
+
'STANDARD', 500.0, 700.0, 200.0, 'M3', 'dálkový', 2113.1,
|
|
64
64
|
1.0043, 10.55, 200.9);
|
|
65
65
|
|
|
66
66
|
INSERT INTO enapo_ppas_distribution_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
|
|
@@ -104,7 +104,7 @@ INSERT INTO enapo_ppas_commercial_invoice_device (device_serial_number, invoice_
|
|
|
104
104
|
"type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
|
|
105
105
|
volume_coefficient, combustion_heat, normometers_nm3) VALUES
|
|
106
106
|
('PLYN-001', 'CI-2026-001', '10101325', '2025-03-01', '2026-02-28',
|
|
107
|
-
'G4', '
|
|
107
|
+
'G4', 'ZIZWC', 'STANDARD', 10250.0, 11930.0, 1680.0, 'M3', 'dálkový', 17750.4,
|
|
108
108
|
1.0043, 10.55, 1687.2);
|
|
109
109
|
|
|
110
110
|
INSERT INTO enapo_ppas_commercial_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
|
|
@@ -132,9 +132,14 @@ INSERT INTO enapo_porsenna_devices (source, id, building_id, parent_device_id, "
|
|
|
132
132
|
('prague-7', '55555555-5555-5555-5555-555555555555', 2, NULL, 'main', 'electricity_meter', 'Elektroměr vrátnice',
|
|
133
133
|
'consumption', NULL, NULL, true, '859182400000000099', 'OP-200', 'EL-999', 'GIDPOR1');
|
|
134
134
|
|
|
135
|
+
-- `commodity` is the normalised commodity name, NOT the raw device type: PorsennaConsumptionTransformation
|
|
136
|
+
-- maps electricity_meter -> electricity, heat_meter -> heat, water_meter -> water, gasometer -> gas.
|
|
137
|
+
-- `unit` comes straight from the API and is lowercase there (kwh / m3), heat included - it is not GJ.
|
|
138
|
+
-- Both were verified against production 2026-08-13; this fixture previously carried the raw device type
|
|
139
|
+
-- and uppercase MWH/GJ/M3, which matched neither the ingest nor the data.
|
|
135
140
|
INSERT INTO enapo_porsenna_consumption (source, device_id, "var", "period", value, unit, commodity, "count") VALUES
|
|
136
|
-
('prague-7', '11111111-1111-1111-1111-111111111111', 'yearly', '2025', 12.4, '
|
|
137
|
-
('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2023', 512.3, '
|
|
138
|
-
('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2024', 498.1, '
|
|
139
|
-
('prague-7', '33333333-3333-3333-3333-333333333333', 'yearly', '2023', 210, '
|
|
140
|
-
('prague-7', '55555555-5555-5555-5555-555555555555', 'yearly', '2024', 5.5, '
|
|
141
|
+
('prague-7', '11111111-1111-1111-1111-111111111111', 'yearly', '2025', 12.4, 'kwh', 'electricity', 365),
|
|
142
|
+
('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2023', 512.3, 'kwh', 'heat', 365),
|
|
143
|
+
('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2024', 498.1, 'kwh', 'heat', 366),
|
|
144
|
+
('prague-7', '33333333-3333-3333-3333-333333333333', 'yearly', '2023', 210, 'm3', 'water', 365),
|
|
145
|
+
('prague-7', '55555555-5555-5555-5555-555555555555', 'yearly', '2024', 5.5, 'kwh', 'electricity', 366);
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
-- Fixtures for the consumption-history block of the DeD building detail endpoint
|
|
2
|
+
-- (mv_enapo_om_consumption, migration 20260813090000).
|
|
3
|
+
--
|
|
4
|
+
-- Deliberately on its own GIDs (GIDCH1 / GIDCH2 / GIDCH3) rather than GID100, so the assertions of
|
|
5
|
+
-- the existing detail tests are untouched. Every row here buys one specific assertion; the comments
|
|
6
|
+
-- say which, and most of them exist because a real-data verification run found the case.
|
|
7
|
+
--
|
|
8
|
+
-- Daily and hourly rows are generated rather than spelled out: 31 literal INSERTs per month says
|
|
9
|
+
-- nothing that `generate_series` does not, and the point of these fixtures is the aggregate.
|
|
10
|
+
--
|
|
11
|
+
-- Loaded after 08_ded_search.sql, which rebuilds mv_ded_building_search; the two are independent.
|
|
12
|
+
-- This file refreshes mv_enapo_om_consumption at the end.
|
|
13
|
+
|
|
14
|
+
INSERT INTO eno_budova (gid, zdroj, nazev, oznaceni, platnost_od) VALUES
|
|
15
|
+
('GIDCH1', 'mhmp', 'ZŠ Spotřeba', 'ZSS', '2019-01-01'),
|
|
16
|
+
('GIDCH2', 'mhmp', 'Objekt s více plynoměry', 'OVP', '2019-01-01');
|
|
17
|
+
|
|
18
|
+
INSERT INTO enapo_gid_mapping (place_id, id_type, commodity, gid, is_first_gid, link_source, valid_from, valid_to) VALUES
|
|
19
|
+
('859182400000000101', 'ean', 'electricity', 'GIDCH1', true, 'mock', '2022-01-01', NULL),
|
|
20
|
+
('27ZG100Z0000CH01', 'eic', 'gas', 'GIDCH1', true, 'mock', '2022-01-01', NULL),
|
|
21
|
+
-- one physical meter behind two PPAS registrations
|
|
22
|
+
('27ZG100Z0000CH02', 'eic', 'gas', 'GIDCH2', true, 'mock', '2022-01-01', NULL),
|
|
23
|
+
-- two physical meters on one EIC
|
|
24
|
+
('27ZG100Z0000CH03', 'eic', 'gas', 'GIDCH2', true, 'mock', '2022-01-01', NULL);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
-- =================================================================================================
|
|
28
|
+
-- Electricity, metered (PRE)
|
|
29
|
+
-- =================================================================================================
|
|
30
|
+
|
|
31
|
+
-- 2026-05: the pre-computed total AND its VT/NT parts for all 31 days. Proves the three vars are
|
|
32
|
+
-- never added together (31 * 100 = 3100 kWh, not 6200): EActi_VT_NT_DaySum is the sum of the parts.
|
|
33
|
+
-- Timestamps are UTC midnight, which is how PreDailyMeasurementsTransformation writes them.
|
|
34
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number)
|
|
35
|
+
SELECT '859182400000000101', 'ean', v.value, d, v.var, 'predi_input', '8110000101', 'EL-CH-1'
|
|
36
|
+
FROM generate_series(timestamptz '2026-05-01 00:00:00+00', timestamptz '2026-05-31 00:00:00+00', interval '1 day') d
|
|
37
|
+
CROSS JOIN (VALUES (100.0, 'EActi_VT_NT_DaySum'), (60.0, 'EActi_VT_DaySum'), (40.0, 'EActi_NT_DaySum')) AS v(value, var);
|
|
38
|
+
|
|
39
|
+
-- 2026-05 again: 15-minute raw rows for the same month. These are average POWER and 4x the energy,
|
|
40
|
+
-- so if they ever leaked into the aggregate the month would not stay at 3100.
|
|
41
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number)
|
|
42
|
+
SELECT '859182400000000101', 'ean', 400.0, d, 'EFwActi_VT', 'predi_input', '8110000101', 'EL-CH-1'
|
|
43
|
+
FROM generate_series(timestamptz '2026-05-01 00:15:00+00', timestamptz '2026-05-02 00:00:00+00', interval '15 minutes') d;
|
|
44
|
+
|
|
45
|
+
-- 2026-06 is deliberately absent: the month must come back as null, not as a zero or an error.
|
|
46
|
+
|
|
47
|
+
-- 2026-07: 31 days at 200 kWh = 6200 kWh, fully covered.
|
|
48
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number)
|
|
49
|
+
SELECT '859182400000000101', 'ean', 200.0, d, 'EActi_VT_NT_DaySum', 'predi_input', '8110000101', 'EL-CH-1'
|
|
50
|
+
FROM generate_series(timestamptz '2026-07-01 00:00:00+00', timestamptz '2026-07-31 00:00:00+00', interval '1 day') d;
|
|
51
|
+
|
|
52
|
+
-- 2026-04: only the VT and NT parts, no pre-computed total. Exercises the COALESCE(total, vt + nt)
|
|
53
|
+
-- fallback, which real data never reaches (EActi_VT_NT_DaySum is always present in production), so
|
|
54
|
+
-- without this fixture that branch would ship untested. 30 * (50 + 25) = 2250 kWh.
|
|
55
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number)
|
|
56
|
+
SELECT '859182400000000101', 'ean', v.value, d, v.var, 'predi_input', '8110000101', 'EL-CH-1'
|
|
57
|
+
FROM generate_series(timestamptz '2026-04-01 00:00:00+00', timestamptz '2026-04-30 00:00:00+00', interval '1 day') d
|
|
58
|
+
CROSS JOIN (VALUES (50.0, 'EActi_VT_DaySum'), (25.0, 'EActi_NT_DaySum')) AS v(value, var);
|
|
59
|
+
|
|
60
|
+
-- An electricity row stored with id_type = 'eic'. Production contains this, so the join must ignore
|
|
61
|
+
-- id_type entirely; if anyone "fixes" the join by matching on it, 2026-03 disappears.
|
|
62
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number)
|
|
63
|
+
SELECT '859182400000000101', 'eic', 10.0, d, 'EActi_VT_NT_DaySum', 'predi_input', '8110000101', 'EL-CH-1'
|
|
64
|
+
FROM generate_series(timestamptz '2026-03-01 00:00:00+00', timestamptz '2026-03-31 00:00:00+00', interval '1 day') d;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
-- =================================================================================================
|
|
68
|
+
-- Gas, metered (PPAS InternetAVE)
|
|
69
|
+
-- =================================================================================================
|
|
70
|
+
|
|
71
|
+
-- 27ZG100Z0000CH01, 2026-07: corediff is the primary value -> 3 * 50 = 150 m3, over 3 distinct days.
|
|
72
|
+
-- core2 is present and non-zero but must NOT win.
|
|
73
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number) VALUES
|
|
74
|
+
('27ZG100Z0000CH01', 'eic', 50.0, '2026-07-01 01:00:00+02', 'corediff', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
75
|
+
('27ZG100Z0000CH01', 'eic', 50.0, '2026-07-02 01:00:00+02', 'corediff', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
76
|
+
('27ZG100Z0000CH01', 'eic', 50.0, '2026-07-03 01:00:00+02', 'corediff', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
77
|
+
('27ZG100Z0000CH01', 'eic', 55.0, '2026-07-01 01:00:00+02', 'core2', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
78
|
+
('27ZG100Z0000CH01', 'eic', 55.0, '2026-07-02 01:00:00+02', 'core2', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
79
|
+
('27ZG100Z0000CH01', 'eic', 55.0, '2026-07-03 01:00:00+02', 'core2', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
80
|
+
-- the cumulative meter state: present, and deliberately unused (max - min across an EIC's
|
|
81
|
+
-- registrations is the distance between unrelated counters, so it is not a fallback)
|
|
82
|
+
('27ZG100Z0000CH01', 'eic', 900000.0, '2026-07-01 01:00:00+02', 'core', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
83
|
+
('27ZG100Z0000CH01', 'eic', 900150.0, '2026-07-03 01:00:00+02', 'core', 'ppas_ave_api', '9900001', 'GAS-CH-1');
|
|
84
|
+
|
|
85
|
+
-- 2026-06: corediff has data, core2 is present but ALL ZERO. 0 is not NULL, so a bare COALESCE
|
|
86
|
+
-- would return a flat-zero Nm3 series here - exactly what production does for some EICs. The
|
|
87
|
+
-- expected result is 120 m3 from corediff.
|
|
88
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number) VALUES
|
|
89
|
+
('27ZG100Z0000CH01', 'eic', 60.0, '2026-06-01 01:00:00+02', 'corediff', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
90
|
+
('27ZG100Z0000CH01', 'eic', 60.0, '2026-06-02 01:00:00+02', 'corediff', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
91
|
+
('27ZG100Z0000CH01', 'eic', 0.0, '2026-06-01 01:00:00+02', 'core2', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
92
|
+
('27ZG100Z0000CH01', 'eic', 0.0, '2026-06-02 01:00:00+02', 'core2', 'ppas_ave_api', '9900001', 'GAS-CH-1');
|
|
93
|
+
|
|
94
|
+
-- 2026-05: only core2. The series falls back to Nm3 for this month, which means one point can change
|
|
95
|
+
-- unit mid-window and therefore appears as two series - honest, and why `unit` is part of the key.
|
|
96
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number) VALUES
|
|
97
|
+
('27ZG100Z0000CH01', 'eic', 30.0, '2026-05-01 01:00:00+02', 'core2', 'ppas_ave_api', '9900001', 'GAS-CH-1'),
|
|
98
|
+
('27ZG100Z0000CH01', 'eic', 30.0, '2026-05-02 01:00:00+02', 'core2', 'ppas_ave_api', '9900001', 'GAS-CH-1');
|
|
99
|
+
|
|
100
|
+
-- 27ZG100Z0000CH02, 2026-07: TWO place_ids, ONE meter serial - two live registrations of the same
|
|
101
|
+
-- physical meter, both reporting the same intervals. Expected 100 m3, NOT 200: the aggregate picks
|
|
102
|
+
-- one registration per serial (the most recently reporting one, here 9900012).
|
|
103
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number) VALUES
|
|
104
|
+
('27ZG100Z0000CH02', 'eic', 100.0, '2026-07-01 01:00:00+02', 'corediff', 'ppas_ave_api', '9900011', 'GAS-CH-DUP'),
|
|
105
|
+
('27ZG100Z0000CH02', 'eic', 100.0, '2026-07-01 01:00:00+02', 'corediff', 'ppas_ave_api', '9900012', 'GAS-CH-DUP');
|
|
106
|
+
|
|
107
|
+
-- 27ZG100Z0000CH03, 2026-07: TWO place_ids, TWO serials - genuinely two meters on one delivery
|
|
108
|
+
-- point. Expected 200 m3: deltas from distinct meters do add up.
|
|
109
|
+
INSERT INTO enapo_measurements (id, id_type, value, "timestamp", var, source, place_id, device_serial_number) VALUES
|
|
110
|
+
('27ZG100Z0000CH03', 'eic', 100.0, '2026-07-01 01:00:00+02', 'corediff', 'ppas_ave_api', '9900021', 'GAS-CH-A'),
|
|
111
|
+
('27ZG100Z0000CH03', 'eic', 100.0, '2026-07-01 01:00:00+02', 'corediff', 'ppas_ave_api', '9900022', 'GAS-CH-B');
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
-- =================================================================================================
|
|
115
|
+
-- Gas, invoices (PPAS distribution) for 27ZG100Z0000CH01
|
|
116
|
+
-- =================================================================================================
|
|
117
|
+
|
|
118
|
+
INSERT INTO enapo_ppas_distribution_invoice (id, preceding_id, customer_id, customer_name,
|
|
119
|
+
facts_doc_date, facts_to_pay_amount, facts_currency, is_canceled) VALUES
|
|
120
|
+
('DI-CH-001', NULL, 'CUST-CH', 'Hlavní město Praha', '2026-07-10', 5000.00, 'CZK', false),
|
|
121
|
+
-- A second, later invoice repeating DI-CH-001's device rows verbatim, with NO preceding_id link.
|
|
122
|
+
-- Production has these. Deduplicating on invoice lineage alone would count 2026-06 twice.
|
|
123
|
+
('DI-CH-002', NULL, 'CUST-CH', 'Hlavní město Praha', '2026-07-20', 5000.00, 'CZK', false);
|
|
124
|
+
|
|
125
|
+
INSERT INTO enapo_ppas_distribution_installation (invoice_id, customer_id, place_id, eic, tdd_class) VALUES
|
|
126
|
+
('DI-CH-001', 'CUST-CH', '9900001', '27ZG100Z0000CH01', 'DOM4'),
|
|
127
|
+
('DI-CH-002', 'CUST-CH', '9900001', '27ZG100Z0000CH01', 'DOM4');
|
|
128
|
+
|
|
129
|
+
INSERT INTO enapo_ppas_distribution_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
|
|
130
|
+
"type", kind, reading_type, consumption, unit, gas_consumption_kwh, volume_coefficient, combustion_heat,
|
|
131
|
+
normometers_nm3) VALUES
|
|
132
|
+
-- The kept row: ZIZWC is the broad volume kind. One whole month, so no pro-rata and
|
|
133
|
+
-- is_estimated stays false. 500 m3 -> 5275 kWh at 10.55 kWh/m3.
|
|
134
|
+
('GAS-CH-1', 'DI-CH-001', '9900001', '2026-06-01', '2026-06-30', 'G4', 'ZIZWC', 'STANDARD',
|
|
135
|
+
500.0, 'M3', 5275.0, 1.0043, 10.55, 500.0),
|
|
136
|
+
-- ZSATN3 is the SAME gas expressed in Nm3 (production has identical totals across the two).
|
|
137
|
+
-- It must be excluded, or June doubles.
|
|
138
|
+
('GAS-CH-1', 'DI-CH-001', '9900001', '2026-06-01', '2026-06-30', 'G4', 'ZSATN3', 'STANDARD',
|
|
139
|
+
500.0, 'NM3', 0.0, 1.0043, 10.55, 500.0),
|
|
140
|
+
-- A CORRECTION sibling. Additive in production but signed only in gas_consumption_kwh, so it is
|
|
141
|
+
-- excluded in v1; if it were summed naively June would gain 40 m3 and lose 422 kWh.
|
|
142
|
+
('GAS-CH-1', 'DI-CH-001', '9900001', '2026-06-01', '2026-06-30', 'G4', 'ZIZWC', 'CORRECTION',
|
|
143
|
+
40.0, 'M3', -422.0, 1.0043, 10.55, 40.0),
|
|
144
|
+
-- The byte-identical duplicate on the later invoice. June must stay at 500 m3.
|
|
145
|
+
('GAS-CH-1', 'DI-CH-002', '9900001', '2026-06-01', '2026-06-30', 'G4', 'ZIZWC', 'STANDARD',
|
|
146
|
+
500.0, 'M3', 5275.0, 1.0043, 10.55, 500.0),
|
|
147
|
+
-- An inverted period. generate_series would produce nothing for it anyway, but the explicit
|
|
148
|
+
-- guard keeps it from silently disappearing into a NULL share.
|
|
149
|
+
('GAS-CH-1', 'DI-CH-001', '9900001', '2026-05-31', '2026-05-01', 'G4', 'ZIZWC', 'STANDARD',
|
|
150
|
+
99.0, 'M3', 999.0, 1.0043, 10.55, 99.0),
|
|
151
|
+
-- combustion_heat = 0 means "not supplied", not a real coefficient: value_kwh must be null here,
|
|
152
|
+
-- not 0, because 0 would be charted as a real reading. April, so it does not disturb June.
|
|
153
|
+
('GAS-CH-1', 'DI-CH-001', '9900001', '2026-04-01', '2026-04-30', 'G4', 'ZIZWC', 'STANDARD',
|
|
154
|
+
300.0, 'M3', 0.0, 0.0, 0.0, 300.0);
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
-- =================================================================================================
|
|
158
|
+
-- Porsenna: yearly only, on its own GID namespace (porsenna gid is not an ENO gid - 0 of 32 match in
|
|
159
|
+
-- production - so these points are servable by GID but invisible to the DeD map)
|
|
160
|
+
-- =================================================================================================
|
|
161
|
+
|
|
162
|
+
INSERT INTO enapo_porsenna_buildings (source, id, name, street, house_number, city, postcode, gid) VALUES
|
|
163
|
+
('prague-7', 90, 'Objekt s teplem', 'Tepelná', '9', 'Praha 7', '17000', 'GIDCH3');
|
|
164
|
+
|
|
165
|
+
INSERT INTO enapo_porsenna_devices (source, id, building_id, parent_device_id, "level", "type", name,
|
|
166
|
+
measurement_target, disabled_at, show_in_output, identifier, supply_point_number, meter_number) VALUES
|
|
167
|
+
('prague-7', '9a000000-0000-0000-0000-000000000001', 90, NULL, 'main', 'heat_meter',
|
|
168
|
+
'Předávací stanice', 'budova', NULL, true, '10109901', 'OP-901', 'TEP-901'),
|
|
169
|
+
('prague-7', '9a000000-0000-0000-0000-000000000002', 90, NULL, 'main', 'water_meter',
|
|
170
|
+
'Vodoměr', 'budova', NULL, true, '10109902', 'OP-902', 'VOD-902'),
|
|
171
|
+
-- TWO devices sharing one identifier. Porsenna heat/water identifiers are labels ("R1"), not the
|
|
172
|
+
-- numeric OM the column comment suggests, so they are not unique within a building - production
|
|
173
|
+
-- has exactly this and it broke the unique index on the first real refresh.
|
|
174
|
+
('prague-7', '9a000000-0000-0000-0000-000000000003', 90, NULL, 'main', 'water_meter',
|
|
175
|
+
'Vodoměr R1 přední', 'budova', NULL, true, 'R1', 'OP-903', 'VOD-903'),
|
|
176
|
+
('prague-7', '9a000000-0000-0000-0000-000000000004', 90, NULL, 'main', 'water_meter',
|
|
177
|
+
'Vodoměr R1 zadní', 'budova', NULL, true, 'R1', 'OP-904', 'VOD-904');
|
|
178
|
+
|
|
179
|
+
-- Yearly rows only, bare YYYY periods, lowercase units, commodity normalised to the commodity name
|
|
180
|
+
-- (not the device type) - all four verified against production. Heat is kwh, not GJ.
|
|
181
|
+
-- The 2025 water row is a real 0 with a full year of coverage: zero consumption is data, and must
|
|
182
|
+
-- come back as 0 rather than being dropped or turned into null.
|
|
183
|
+
INSERT INTO enapo_porsenna_consumption (source, device_id, "var", "period", value, unit, commodity, "count") VALUES
|
|
184
|
+
('prague-7', '9a000000-0000-0000-0000-000000000001', 'yearly', '2023', 41000.5, 'kwh', 'heat', 365),
|
|
185
|
+
('prague-7', '9a000000-0000-0000-0000-000000000001', 'yearly', '2024', 39500.0, 'kwh', 'heat', 366),
|
|
186
|
+
('prague-7', '9a000000-0000-0000-0000-000000000002', 'yearly', '2025', 0.0, 'm3', 'water', 365),
|
|
187
|
+
-- The two devices sharing identifier 'R1', both reporting 2022: they collapse onto one key of the
|
|
188
|
+
-- unique index, so the view has to aggregate them (12 + 8 = 20 m3) rather than emit two rows.
|
|
189
|
+
('prague-7', '9a000000-0000-0000-0000-000000000003', 'yearly', '2022', 12.0, 'm3', 'water', 365),
|
|
190
|
+
('prague-7', '9a000000-0000-0000-0000-000000000004', 'yearly', '2022', 8.0, 'm3', 'water', 365),
|
|
191
|
+
-- An unparsable period: skipped by f_enapo_safe_period rather than aborting the whole refresh.
|
|
192
|
+
('prague-7', '9a000000-0000-0000-0000-000000000002', 'monthly', '2025-13', 5.0, 'm3', 'water', 30);
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
REFRESH MATERIALIZED VIEW mv_ded_building_search;
|
|
196
|
+
REFRESH MATERIALIZED VIEW mv_enapo_om_consumption;
|
|
@@ -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', '20260813090000-enapo-consumption-history-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', '20260813090000-enapo-consumption-history-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,12 @@
|
|
|
1
|
+
DROP MATERIALIZED VIEW IF EXISTS mv_enapo_om_consumption;
|
|
2
|
+
|
|
3
|
+
DROP FUNCTION IF EXISTS f_enapo_safe_period(text, text);
|
|
4
|
+
|
|
5
|
+
DROP INDEX IF EXISTS enapo_measurements_source_var_ts_idx;
|
|
6
|
+
|
|
7
|
+
DROP INDEX IF EXISTS enapo_ppas_distribution_invoice_preceding_id_idx;
|
|
8
|
+
DROP INDEX IF EXISTS enapo_ppas_commercial_invoice_preceding_id_idx;
|
|
9
|
+
|
|
10
|
+
-- Restore the original (misleading) wording so the down migration is a true inverse.
|
|
11
|
+
COMMENT ON COLUMN enapo_porsenna_consumption.commodity IS
|
|
12
|
+
'Denormalised from enapo_porsenna_devices.type for fast filtered reads.';
|