@golemio/energetics 1.12.2-dev.2740928370 → 1.12.2-dev.2740931754

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.
Files changed (90) hide show
  1. package/db/example/00_clear_test_data.sql +14 -0
  2. package/db/example/06_eno.sql +25 -0
  3. package/db/example/07_enapo_om_detail.sql +140 -0
  4. package/db/migrations/postgresql/20260807090000-enapo-gid-mapping-om-detail.js +53 -0
  5. package/db/migrations/postgresql/20260807091000-enapo-om-detail-porsenna.js +53 -0
  6. package/db/migrations/postgresql/sqls/20260807090000-enapo-gid-mapping-om-detail-down.sql +3 -0
  7. package/db/migrations/postgresql/sqls/20260807090000-enapo-gid-mapping-om-detail-up.sql +182 -0
  8. package/db/migrations/postgresql/sqls/20260807091000-enapo-om-detail-porsenna-down.sql +135 -0
  9. package/db/migrations/postgresql/sqls/20260807091000-enapo-om-detail-porsenna-up.sql +292 -0
  10. package/db/scripts/ded_gid_mapping_mock_import.sql +48 -0
  11. package/dist/output-gateway/constants/Links.d.ts +1 -0
  12. package/dist/output-gateway/constants/Links.js +2 -1
  13. package/dist/output-gateway/constants/Links.js.map +1 -1
  14. package/dist/output-gateway/controllers/v2/EnoBuildingsController.d.ts +11 -0
  15. package/dist/output-gateway/controllers/v2/EnoBuildingsController.js +53 -0
  16. package/dist/output-gateway/controllers/v2/EnoBuildingsController.js.map +1 -0
  17. package/dist/output-gateway/helpers/objectMappers.d.ts +10 -0
  18. package/dist/output-gateway/helpers/objectMappers.js +37 -0
  19. package/dist/output-gateway/helpers/objectMappers.js.map +1 -0
  20. package/dist/output-gateway/index.js +8 -1
  21. package/dist/output-gateway/index.js.map +1 -1
  22. package/dist/output-gateway/ioc/Di.js +9 -1
  23. package/dist/output-gateway/ioc/Di.js.map +1 -1
  24. package/dist/output-gateway/ioc/ModuleContainerToken.d.ts +4 -0
  25. package/dist/output-gateway/ioc/ModuleContainerToken.js +4 -0
  26. package/dist/output-gateway/ioc/ModuleContainerToken.js.map +1 -1
  27. package/dist/output-gateway/models/EnoBuildingDetailViewModel.d.ts +35 -0
  28. package/dist/output-gateway/models/EnoBuildingDetailViewModel.js +43 -0
  29. package/dist/output-gateway/models/EnoBuildingDetailViewModel.js.map +1 -0
  30. package/dist/output-gateway/models/EnoConsumptionPointViewModel.d.ts +106 -0
  31. package/dist/output-gateway/models/EnoConsumptionPointViewModel.js +119 -0
  32. package/dist/output-gateway/models/EnoConsumptionPointViewModel.js.map +1 -0
  33. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.d.ts +27 -0
  34. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.js +41 -0
  35. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.js.map +1 -0
  36. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.d.ts +30 -0
  37. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.js +3 -0
  38. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.js.map +1 -0
  39. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.d.ts +106 -0
  40. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.js +3 -0
  41. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.js.map +1 -0
  42. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.d.ts +22 -0
  43. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.js +3 -0
  44. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.js.map +1 -0
  45. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.d.ts +12 -0
  46. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.js +41 -0
  47. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.js.map +1 -0
  48. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.d.ts +8 -0
  49. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.js +62 -0
  50. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.js.map +1 -0
  51. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.d.ts +18 -0
  52. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js +100 -0
  53. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js.map +1 -0
  54. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.d.ts +8 -0
  55. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js +51 -0
  56. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js.map +1 -0
  57. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.d.ts +8 -0
  58. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.js +51 -0
  59. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.js.map +1 -0
  60. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.d.ts +8 -0
  61. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.js +52 -0
  62. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.js.map +1 -0
  63. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.d.ts +13 -0
  64. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.js +39 -0
  65. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.js.map +1 -0
  66. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.d.ts +22 -0
  67. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.js +3 -0
  68. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.js.map +1 -0
  69. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.d.ts +108 -0
  70. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.js +3 -0
  71. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.js.map +1 -0
  72. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.d.ts +9 -0
  73. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js +40 -0
  74. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js.map +1 -0
  75. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.d.ts +14 -0
  76. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js +150 -0
  77. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js.map +1 -0
  78. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.d.ts +17 -0
  79. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.js +63 -0
  80. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.js.map +1 -0
  81. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.d.ts +11 -0
  82. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.js +3 -0
  83. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.js.map +1 -0
  84. package/dist/schema-definitions/models/eno/AddressModel.d.ts +1 -1
  85. package/dist/schema-definitions/models/eno/AddressModel.js +1 -1
  86. package/dist/schema-definitions/models/eno/AddressModel.js.map +1 -1
  87. package/dist/schema-definitions/models/eno/interfaces/IAddress.d.ts +1 -1
  88. package/docs/implementation_documentation.md +41 -2
  89. package/docs/openapi-output.yaml +263 -1
  90. package/package.json +1 -1
@@ -9,3 +9,17 @@ truncate organizations;
9
9
  truncate access_limitation;
10
10
  truncate enapo_measurements;
11
11
  truncate enapo_pre_metadata_history;
12
+ truncate enapo_gid_mapping;
13
+ truncate eno_budova;
14
+ truncate eno_adresa;
15
+ truncate enapo_ppas_distribution_invoice;
16
+ truncate enapo_ppas_distribution_installation;
17
+ truncate enapo_ppas_distribution_invoice_device;
18
+ truncate enapo_ppas_distribution_invoice_price;
19
+ truncate enapo_ppas_commercial_invoice;
20
+ truncate enapo_ppas_commercial_invoice_installations;
21
+ truncate enapo_ppas_commercial_invoice_device;
22
+ truncate enapo_ppas_commercial_invoice_price;
23
+ truncate enapo_porsenna_buildings;
24
+ truncate enapo_porsenna_devices;
25
+ truncate enapo_porsenna_consumption;
@@ -0,0 +1,25 @@
1
+ INSERT INTO eno_budova (gid, zdroj, nazev, oznaceni, druh_vytapeni, pripojka_elektro, pripojka_voda, pripojka_kanalizace,
2
+ budova_rozdelena_byt_nebyt, celkova_plocha_budova, zastavena_plocha, obestaveny_prostor,
3
+ pocet_byt, pocet_nebyt_budova, pocet_nadzem_podlazi, pocet_podzem_podlazi, pocet_podkrovi, vytah,
4
+ czcc, id_cuzk, id_objekt, kod_vyuziti, nazev_vyuziti, kod_ochrana, nazev_ochrana, platnost_od) VALUES
5
+ ('GID100', 'mhmp', 'ZŠ Testovací', 'ZŠT', 'ústřední dálkové', 'ano', 'ano', 'ano',
6
+ 'ne', 1200.5, 450.0, 5200.0,
7
+ 0, 12, 3, 1, 0, true,
8
+ 112, 100000001, 1001, '7', 'budova pro vzdělávání', NULL, NULL, '2020-01-01'),
9
+ ('GID100', 'stat', 'ZŠ Testovací (stat)', 'ZŠT', 'ústřední dálkové', 'ano', 'ano', 'ano',
10
+ 'ne', 1200.5, 450.0, 5200.0,
11
+ 0, 12, 3, 1, 0, true,
12
+ 112, 100000001, 1001, '7', 'budova pro vzdělávání', NULL, NULL, '2020-01-01'),
13
+ ('GID200', 'mhmp', 'MŠ Vedlejší', 'MŠV', 'plynová kotelna', 'ano', 'ano', 'ne',
14
+ 'ne', 480.0, 220.0, 1600.0,
15
+ 0, 5, 2, 0, 1, false,
16
+ 112, 100000002, 1002, '7', 'budova pro vzdělávání', NULL, NULL, '2021-06-15');
17
+
18
+ INSERT INTO eno_adresa (gid, gid_typ, poradi, zdroj, id, popis, hlavni) VALUES
19
+ ('GID100', 'budova', 1, 'mhmp', 501, 'Testovací 123/4, 100 00 Praha 10', true),
20
+ ('GID100', 'budova', 2, 'mhmp', 502, 'Testovací 125/6, 100 00 Praha 10', false),
21
+ ('GID100', 'budova', 1, 'stat', 501, 'Testovací 123/4, 100 00 Praha 10', true),
22
+ ('GID100', 'budova', 3, 'mhmp', 504, NULL, false),
23
+ ('GID100', 'budova', 4, 'mhmp', 505, NULL, false),
24
+ ('GID200', 'budova', 1, 'mhmp', 503, 'Vedlejší 7, 100 00 Praha 10', true),
25
+ ('GIDADDR1', 'stavba', 1, 'mhmp', 506, 'Stavební 9, 100 00 Praha 10', true);
@@ -0,0 +1,140 @@
1
+ -- Mock GID mapping (link_source = 'mock'); real rows will come from the data-team dbt output later
2
+ INSERT INTO enapo_gid_mapping (place_id, id_type, commodity, gid, is_first_gid, link_source, valid_from, valid_to) VALUES
3
+ ('27ZG100Z0000192O', 'eic', 'gas', 'GID100', true, 'mock', '2019-12-05', NULL),
4
+ ('27ZG100Z0000192O', 'eic', 'gas', 'GID200', false, 'mock', '2019-12-05', NULL),
5
+ ('859182400000000001', 'ean', 'electricity', 'GID100', true, 'mock', '2022-07-28', NULL),
6
+ ('859182400000000002', 'ean', 'electricity', 'GID100', true, 'mock', '2019-12-05', '2025-01-01'),
7
+ ('859182400000000003', 'ean', 'electricity', 'GID999', true, 'mock', '2022-07-28', NULL);
8
+
9
+ -- PRE metadata history: two months for the active EAN (the newer one must win)
10
+ INSERT INTO enapo_pre_metadata_history (ean, "year", "month", month_name, days_in_stored_month, consumption_point,
11
+ address, location_type, company_name, company_id, tarif_type, tarif_1t2t, phases, circuit_breaker, type_b_meter,
12
+ meter_replaced, created_at, updated_at) VALUES
13
+ ('859182400000000001', 2026, 5, 'květen', 31, 'OM Testovací 123',
14
+ 'Testovací 123/4, Praha 10', 'škola', 'Hlavní město Praha', '00064581', 'C02d', '1T', '3', '3x100A', 'ano',
15
+ '53435572', '2026-06-05 00:00:00', NULL),
16
+ ('859182400000000001', 2026, 6, 'červen', 30, 'OM Testovací 123',
17
+ 'Testovací 123/4, Praha 10', 'škola', 'Hlavní město Praha', '00064581', 'C02d', '1T', '3', '3x125A', 'ano',
18
+ '2026-06-19|53435572|54292510', '2026-07-05 00:00:00', NULL);
19
+
20
+ -- PPAS distribution invoices: an older valid one, a newer canceled one (must be skipped)
21
+ INSERT INTO enapo_ppas_distribution_invoice (id, preceding_id, customer_id, customer_company_id, customer_name,
22
+ customer_contract_account_id, customer_address_street, customer_address_house_number, customer_address_house_org_number,
23
+ customer_address_city, customer_address_city_part, customer_address_post_code, customer_address_country,
24
+ customer_address_ruian_id, facts_doc_date, facts_net_date, facts_billing_transaction, facts_to_pay_amount,
25
+ facts_currency, facts_price_brutto, is_canceled, canceled_reason) VALUES
26
+ ('DI-2026-001', NULL, 'CUST-1', '00064581', 'Hlavní město Praha',
27
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
28
+ 'Praha', 'Staré Město', '11000', 'CZ',
29
+ 22349995, '2026-03-15', '2026-03-29', 'FAKTURACE', 15250.50,
30
+ 'CZK', 18453.11, false, NULL),
31
+ ('DI-2026-002', 'DI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
32
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
33
+ 'Praha', 'Staré Město', '11000', 'CZ',
34
+ 22349995, '2026-05-20', '2026-06-03', 'STORNO', -15250.50,
35
+ 'CZK', -18453.11, true, 'oprava odečtu');
36
+
37
+ -- Two installations on the valid invoice: only the first one is mapped to a GID, the second exists
38
+ -- to prove devices/prices are scoped by place_id and do not leak across consumption points.
39
+ INSERT INTO enapo_ppas_distribution_installation (invoice_id, customer_id, place_id, eic, billing_class,
40
+ measurement_type, contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
41
+ address_street, address_house_number, address_house_org_number, address_city, address_city_part,
42
+ address_post_code, address_country, address_ruian_id) VALUES
43
+ ('DI-2026-001', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
44
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
45
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
46
+ '10000', 'CZ', 22349996),
47
+ ('DI-2026-001', 'CUST-1', '10101999', '27ZG100Z0000999O', 'MO',
48
+ 'C', 'SML-9', '2019-12-05', '9999-12-31', 'DOM4',
49
+ 'Jiná', '9', NULL, 'Praha', 'Praha 9',
50
+ '19000', 'CZ', 22349999),
51
+ ('DI-2026-002', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
52
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
53
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
54
+ '10000', 'CZ', 22349996);
55
+
56
+ INSERT INTO enapo_ppas_distribution_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
57
+ "type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
58
+ volume_coefficient, combustion_heat, normometers_nm3) VALUES
59
+ ('PLYN-001', 'DI-2026-001', '10101325', '2025-03-01', '2026-02-28', 'G4', 'plynoměr',
60
+ 'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
61
+ 1.0043, 10.55, 1687.2),
62
+ ('PLYN-999', 'DI-2026-001', '10101999', '2025-03-01', '2026-02-28', 'G4', 'plynoměr',
63
+ 'řádný', 500.0, 700.0, 200.0, 'm3', 'dálkový', 2113.1,
64
+ 1.0043, 10.55, 200.9);
65
+
66
+ INSERT INTO enapo_ppas_distribution_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
67
+ description, price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
68
+ ('DI-2026-001', 'CUST-1', '10101325', '2025-03-01', '2026-02-28', 'distribuce', 'Distribuce plynu',
69
+ 'D1', 17750.4, 'kWh', 0.35, 0.19355, 6212.64, 'variabilní', 'CZK', 21.0),
70
+ ('DI-2026-001', 'CUST-1', '10101999', '2025-03-01', '2026-02-28', 'distribuce', 'Distribuce plynu',
71
+ 'D1', 2113.1, 'kWh', 0.35, NULL, 739.59, 'variabilní', 'CZK', 21.0);
72
+
73
+ -- PPAS commercial invoices: a valid one and a newer canceled one (must be skipped)
74
+ INSERT INTO enapo_ppas_commercial_invoice (id, preceding_id, customer_id, customer_company_id, customer_name,
75
+ customer_contract_account_id, customer_address_street, customer_address_house_number, customer_address_house_org_number,
76
+ customer_address_city, customer_address_city_part, customer_address_post_code, customer_address_country,
77
+ customer_address_ruian_id, facts_doc_date, facts_net_date, facts_billing_transaction, facts_to_pay_amount,
78
+ facts_currency, facts_price_brutto, is_canceled, canceled_reason) VALUES
79
+ ('CI-2026-001', NULL, 'CUST-1', '00064581', 'Hlavní město Praha',
80
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
81
+ 'Praha', 'Staré Město', '11000', 'CZ',
82
+ 22349995, '2026-04-10', '2026-04-24', 'FAKTURACE', 28900.00,
83
+ 'CZK', 34969.00, false, NULL),
84
+ ('CI-2026-002', 'CI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
85
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
86
+ 'Praha', 'Staré Město', '11000', 'CZ',
87
+ 22349995, '2026-06-01', '2026-06-15', 'STORNO', -28900.00,
88
+ 'CZK', -34969.00, true, 'reklamace');
89
+
90
+ INSERT INTO enapo_ppas_commercial_invoice_installations (invoice_id, customer_id, place_id, eic, billing_class,
91
+ measurement_type, contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
92
+ address_street, address_house_number, address_house_org_number, address_city, address_city_part,
93
+ address_post_code, address_country, address_ruian_id) VALUES
94
+ ('CI-2026-001', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
95
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
96
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
97
+ '10000', 'CZ', 22349996),
98
+ ('CI-2026-002', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
99
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
100
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
101
+ '10000', 'CZ', 22349996);
102
+
103
+ INSERT INTO enapo_ppas_commercial_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
104
+ "type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
105
+ volume_coefficient, combustion_heat, normometers_nm3) VALUES
106
+ ('PLYN-001', 'CI-2026-001', '10101325', '2025-03-01', '2026-02-28',
107
+ 'G4', 'plynoměr', 'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
108
+ 1.0043, 10.55, 1687.2);
109
+
110
+ INSERT INTO enapo_ppas_commercial_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
111
+ description, price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
112
+ ('CI-2026-001', 'CUST-1', '10101325', '2025-03-01', '2026-02-28', 'komodita',
113
+ 'Dodávka plynu', 'K1', 17750.4, 'kWh', 1.45, NULL, 25738.08, 'variabilní', 'CZK', 21.0);
114
+
115
+ -- Porsenna (e-manazer): buildings, devices (incl. heat/water and a sub-meter), yearly consumption.
116
+ -- Device types and tenant naming mirror real Porsenna data (electricity_meter/heat_meter/water_meter, tenant prague-7).
117
+ INSERT INTO enapo_porsenna_buildings (source, id, name, street, house_number, street_number, city, postcode, gid) VALUES
118
+ ('prague-7', 1, 'ZŠ Testovací (e-manažer)', 'Testovací', '123', '4', 'Praha 10', '10000', 'GID100'),
119
+ ('prague-7', 2, 'Vrátnice Kundratka', 'Kundratka', '19', NULL, 'Praha 8', '18000', 'GIDPOR1');
120
+
121
+ INSERT INTO enapo_porsenna_devices (source, id, building_id, parent_device_id, "level", "type", name,
122
+ measurement_target, disabled_at, disable_reason_id, show_in_output, identifier, supply_point_number,
123
+ meter_number, identification_gid) VALUES
124
+ ('prague-7', '11111111-1111-1111-1111-111111111111', 1, NULL, 'main', 'electricity_meter', 'Hlavní elektroměr',
125
+ 'consumption', NULL, NULL, true, '859182400000000001', 'OP-100', 'EL-123', 'GID100'),
126
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 1, NULL, 'main', 'heat_meter', 'Předávací stanice CZT',
127
+ 'consumption', NULL, NULL, true, '40001234', 'OP-101', 'TEP-77', 'GID100'),
128
+ ('prague-7', '33333333-3333-3333-3333-333333333333', 1, NULL, 'main', 'water_meter', 'Hlavní vodoměr',
129
+ 'consumption', '2024-05-31 00:00:00+00', 4, true, '50005678', 'OP-102', 'VOD-55', 'GID100'),
130
+ ('prague-7', '44444444-4444-4444-4444-444444444444', 1, '22222222-2222-2222-2222-222222222222', 'sub',
131
+ 'heat_meter', 'Podružné měření tělocvična', 'tělocvična', NULL, NULL, true, NULL, NULL, 'TEP-78', NULL),
132
+ ('prague-7', '55555555-5555-5555-5555-555555555555', 2, NULL, 'main', 'electricity_meter', 'Elektroměr vrátnice',
133
+ 'consumption', NULL, NULL, true, '859182400000000099', 'OP-200', 'EL-999', 'GIDPOR1');
134
+
135
+ 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, 'MWH', 'electricity_meter', 365),
137
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2023', 512.3, 'GJ', 'heat_meter', 365),
138
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2024', 498.1, 'GJ', 'heat_meter', 366),
139
+ ('prague-7', '33333333-3333-3333-3333-333333333333', 'yearly', '2023', 210, 'M3', 'water_meter', 365),
140
+ ('prague-7', '55555555-5555-5555-5555-555555555555', 'yearly', '2024', 5.5, 'MWH', 'electricity_meter', 366);
@@ -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', '20260807090000-enapo-gid-mapping-om-detail-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', '20260807090000-enapo-gid-mapping-om-detail-down.sql');
38
+ return new Promise( function( resolve, reject ) {
39
+ fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
40
+ if (err) return reject(err);
41
+ console.log('received data: ' + data);
42
+
43
+ resolve(data);
44
+ });
45
+ })
46
+ .then(function(data) {
47
+ return db.runSql(data);
48
+ });
49
+ };
50
+
51
+ exports._meta = {
52
+ "version": 1
53
+ };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var dbm;
4
+ var type;
5
+ var seed;
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+ var Promise;
9
+
10
+ /**
11
+ * We receive the dbmigrate dependency from dbmigrate initially.
12
+ * This enables us to not have to rely on NODE_PATH.
13
+ */
14
+ exports.setup = function(options, seedLink) {
15
+ dbm = options.dbmigrate;
16
+ type = dbm.dataType;
17
+ seed = seedLink;
18
+ Promise = options.Promise;
19
+ };
20
+
21
+ exports.up = function(db) {
22
+ var filePath = path.join(__dirname, 'sqls', '20260807091000-enapo-om-detail-porsenna-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', '20260807091000-enapo-om-detail-porsenna-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,3 @@
1
+ DROP VIEW IF EXISTS v_enapo_building_consumption_points;
2
+ DROP VIEW IF EXISTS v_enapo_building_detail;
3
+ DROP TABLE IF EXISTS enapo_gid_mapping;
@@ -0,0 +1,182 @@
1
+ CREATE TABLE enapo_gid_mapping (
2
+ place_id varchar(50) NOT NULL,
3
+ id_type varchar(10) NOT NULL,
4
+ commodity varchar(20) NOT NULL,
5
+ gid varchar NOT NULL,
6
+ is_first_gid bool NOT NULL DEFAULT false,
7
+ link_source varchar(50) NOT NULL,
8
+ valid_from date NULL,
9
+ valid_to date NULL,
10
+ created_at timestamptz NULL DEFAULT now(),
11
+ updated_at timestamptz NULL,
12
+ CONSTRAINT enapo_gid_mapping_pk PRIMARY KEY (place_id, gid, link_source)
13
+ );
14
+
15
+ COMMENT ON TABLE enapo_gid_mapping IS 'Mapping of consumption points (EAN/EIC) to ENO building GIDs. Module-owned contract; currently seeded with mock data (link_source = ''mock''), the future sync task from the data-team dbt output (tmp.ded_gid_mapping) will use link_source = ''energobroker_kod_eno''.';
16
+
17
+ CREATE INDEX enapo_gid_mapping_gid_idx ON enapo_gid_mapping (gid);
18
+
19
+ CREATE OR REPLACE VIEW v_enapo_building_detail AS
20
+ SELECT DISTINCT ON (b.gid)
21
+ b.gid,
22
+ b.zdroj,
23
+ b.nazev,
24
+ b.oznaceni,
25
+ b.druh_vytapeni,
26
+ b.pripojka_elektro,
27
+ b.pripojka_voda,
28
+ b.pripojka_kanalizace,
29
+ b.budova_rozdelena_byt_nebyt,
30
+ b.celkova_plocha_budova,
31
+ b.celkova_plocha_byt_budova,
32
+ b.celkova_plocha_nebyt_budova,
33
+ b.zastavena_plocha,
34
+ b.obestaveny_prostor,
35
+ b.pocet_byt,
36
+ b.pocet_nebyt_budova,
37
+ b.pocet_nadzem_podlazi,
38
+ b.pocet_podzem_podlazi,
39
+ b.pocet_podkrovi,
40
+ b.vytah,
41
+ b.czcc,
42
+ b.id_cuzk,
43
+ b.id_objekt,
44
+ b.kod_vyuziti,
45
+ b.nazev_vyuziti,
46
+ b.kod_ochrana,
47
+ b.nazev_ochrana,
48
+ b.platnost_od
49
+ FROM eno_budova b
50
+ ORDER BY b.gid, b.zdroj;
51
+
52
+ CREATE OR REPLACE VIEW v_enapo_building_consumption_points AS
53
+ SELECT
54
+ m.gid,
55
+ m.place_id,
56
+ m.id_type,
57
+ m.commodity,
58
+ m.is_first_gid,
59
+ m.link_source,
60
+ m.valid_from,
61
+ m.valid_to,
62
+ (m.valid_to IS NULL OR m.valid_to >= CURRENT_DATE) AS is_active,
63
+ pm.*,
64
+ di.*,
65
+ ci.*
66
+ FROM enapo_gid_mapping m
67
+ LEFT JOIN LATERAL (
68
+ SELECT
69
+ h."year" AS md_year,
70
+ h."month" AS md_month,
71
+ h.month_name AS md_month_name,
72
+ h.days_in_stored_month AS md_days_in_stored_month,
73
+ h.consumption_point AS md_consumption_point,
74
+ h.address AS md_address,
75
+ h.location_type AS md_location_type,
76
+ h.company_name AS md_company_name,
77
+ h.company_id AS md_company_id,
78
+ h.tarif_type AS md_tarif_type,
79
+ h.tarif_1t2t AS md_tarif_1t2t,
80
+ h.phases AS md_phases,
81
+ h.circuit_breaker AS md_circuit_breaker,
82
+ h.type_b_meter AS md_type_b_meter,
83
+ h.meter_replaced AS md_meter_replaced
84
+ FROM enapo_pre_metadata_history h
85
+ WHERE h.ean = m.place_id
86
+ ORDER BY h."year" DESC, h."month" DESC
87
+ LIMIT 1
88
+ ) pm ON m.id_type = 'ean'
89
+ LEFT JOIN LATERAL (
90
+ SELECT
91
+ i.id AS di_id,
92
+ i.preceding_id AS di_preceding_id,
93
+ i.customer_id AS di_customer_id,
94
+ i.customer_company_id AS di_customer_company_id,
95
+ i.customer_name AS di_customer_name,
96
+ i.customer_contract_account_id AS di_customer_contract_account_id,
97
+ i.customer_address_street AS di_customer_address_street,
98
+ i.customer_address_house_number AS di_customer_address_house_number,
99
+ i.customer_address_house_org_number AS di_customer_address_house_org_number,
100
+ i.customer_address_city AS di_customer_address_city,
101
+ i.customer_address_city_part AS di_customer_address_city_part,
102
+ i.customer_address_post_code AS di_customer_address_post_code,
103
+ i.customer_address_country AS di_customer_address_country,
104
+ i.customer_address_ruian_id AS di_customer_address_ruian_id,
105
+ i.facts_doc_date AS di_facts_doc_date,
106
+ i.facts_net_date AS di_facts_net_date,
107
+ i.facts_billing_transaction AS di_facts_billing_transaction,
108
+ i.facts_to_pay_amount AS di_facts_to_pay_amount,
109
+ i.facts_currency AS di_facts_currency,
110
+ i.facts_price_brutto AS di_facts_price_brutto,
111
+ i.is_canceled AS di_is_canceled,
112
+ i.canceled_reason AS di_canceled_reason,
113
+ ins.place_id AS dinst_place_id,
114
+ ins.billing_class AS dinst_billing_class,
115
+ ins.measurement_type AS dinst_measurement_type,
116
+ ins.contract_contract_id AS dinst_contract_contract_id,
117
+ ins.contract_move_in_date AS dinst_contract_move_in_date,
118
+ ins.contract_move_out_date AS dinst_contract_move_out_date,
119
+ ins.tdd_class AS dinst_tdd_class,
120
+ ins.address_street AS dinst_address_street,
121
+ ins.address_house_number AS dinst_address_house_number,
122
+ ins.address_house_org_number AS dinst_address_house_org_number,
123
+ ins.address_city AS dinst_address_city,
124
+ ins.address_city_part AS dinst_address_city_part,
125
+ ins.address_post_code AS dinst_address_post_code,
126
+ ins.address_country AS dinst_address_country,
127
+ ins.address_ruian_id AS dinst_address_ruian_id
128
+ FROM enapo_ppas_distribution_installation ins
129
+ INNER JOIN enapo_ppas_distribution_invoice i
130
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
131
+ WHERE ins.eic = m.place_id
132
+ AND COALESCE(i.is_canceled, false) = false
133
+ ORDER BY i.facts_doc_date DESC
134
+ LIMIT 1
135
+ ) di ON m.id_type = 'eic'
136
+ LEFT JOIN LATERAL (
137
+ SELECT
138
+ i.id AS ci_id,
139
+ i.preceding_id AS ci_preceding_id,
140
+ i.customer_id AS ci_customer_id,
141
+ i.customer_company_id AS ci_customer_company_id,
142
+ i.customer_name AS ci_customer_name,
143
+ i.customer_contract_account_id AS ci_customer_contract_account_id,
144
+ i.customer_address_street AS ci_customer_address_street,
145
+ i.customer_address_house_number AS ci_customer_address_house_number,
146
+ i.customer_address_house_org_number AS ci_customer_address_house_org_number,
147
+ i.customer_address_city AS ci_customer_address_city,
148
+ i.customer_address_city_part AS ci_customer_address_city_part,
149
+ i.customer_address_post_code AS ci_customer_address_post_code,
150
+ i.customer_address_country AS ci_customer_address_country,
151
+ i.customer_address_ruian_id AS ci_customer_address_ruian_id,
152
+ i.facts_doc_date AS ci_facts_doc_date,
153
+ i.facts_net_date AS ci_facts_net_date,
154
+ i.facts_billing_transaction AS ci_facts_billing_transaction,
155
+ i.facts_to_pay_amount AS ci_facts_to_pay_amount,
156
+ i.facts_currency AS ci_facts_currency,
157
+ i.facts_price_brutto AS ci_facts_price_brutto,
158
+ i.is_canceled AS ci_is_canceled,
159
+ i.canceled_reason AS ci_canceled_reason,
160
+ ins.place_id AS cinst_place_id,
161
+ ins.billing_class AS cinst_billing_class,
162
+ ins.measurement_type AS cinst_measurement_type,
163
+ ins.contract_contract_id AS cinst_contract_contract_id,
164
+ ins.contract_move_in_date AS cinst_contract_move_in_date,
165
+ ins.contract_move_out_date AS cinst_contract_move_out_date,
166
+ ins.tdd_class AS cinst_tdd_class,
167
+ ins.address_street AS cinst_address_street,
168
+ ins.address_house_number AS cinst_address_house_number,
169
+ ins.address_house_org_number AS cinst_address_house_org_number,
170
+ ins.address_city AS cinst_address_city,
171
+ ins.address_city_part AS cinst_address_city_part,
172
+ ins.address_post_code AS cinst_address_post_code,
173
+ ins.address_country AS cinst_address_country,
174
+ ins.address_ruian_id AS cinst_address_ruian_id
175
+ FROM enapo_ppas_commercial_invoice_installations ins
176
+ INNER JOIN enapo_ppas_commercial_invoice i
177
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
178
+ WHERE ins.eic = m.place_id
179
+ AND COALESCE(i.is_canceled, false) = false
180
+ ORDER BY i.facts_doc_date DESC
181
+ LIMIT 1
182
+ ) ci ON m.id_type = 'eic';
@@ -0,0 +1,135 @@
1
+ DROP VIEW IF EXISTS v_enapo_building_consumption_points;
2
+
3
+ CREATE VIEW v_enapo_building_consumption_points AS
4
+ SELECT
5
+ m.gid,
6
+ m.place_id,
7
+ m.id_type,
8
+ m.commodity,
9
+ m.is_first_gid,
10
+ m.link_source,
11
+ m.valid_from,
12
+ m.valid_to,
13
+ (m.valid_to IS NULL OR m.valid_to >= CURRENT_DATE) AS is_active,
14
+ pm.*,
15
+ di.*,
16
+ ci.*
17
+ FROM enapo_gid_mapping m
18
+ LEFT JOIN LATERAL (
19
+ SELECT
20
+ h."year" AS md_year,
21
+ h."month" AS md_month,
22
+ h.month_name AS md_month_name,
23
+ h.days_in_stored_month AS md_days_in_stored_month,
24
+ h.consumption_point AS md_consumption_point,
25
+ h.address AS md_address,
26
+ h.location_type AS md_location_type,
27
+ h.company_name AS md_company_name,
28
+ h.company_id AS md_company_id,
29
+ h.tarif_type AS md_tarif_type,
30
+ h.tarif_1t2t AS md_tarif_1t2t,
31
+ h.phases AS md_phases,
32
+ h.circuit_breaker AS md_circuit_breaker,
33
+ h.type_b_meter AS md_type_b_meter,
34
+ h.meter_replaced AS md_meter_replaced
35
+ FROM enapo_pre_metadata_history h
36
+ WHERE h.ean = m.place_id
37
+ ORDER BY h."year" DESC, h."month" DESC
38
+ LIMIT 1
39
+ ) pm ON m.id_type = 'ean'
40
+ LEFT JOIN LATERAL (
41
+ SELECT
42
+ i.id AS di_id,
43
+ i.preceding_id AS di_preceding_id,
44
+ i.customer_id AS di_customer_id,
45
+ i.customer_company_id AS di_customer_company_id,
46
+ i.customer_name AS di_customer_name,
47
+ i.customer_contract_account_id AS di_customer_contract_account_id,
48
+ i.customer_address_street AS di_customer_address_street,
49
+ i.customer_address_house_number AS di_customer_address_house_number,
50
+ i.customer_address_house_org_number AS di_customer_address_house_org_number,
51
+ i.customer_address_city AS di_customer_address_city,
52
+ i.customer_address_city_part AS di_customer_address_city_part,
53
+ i.customer_address_post_code AS di_customer_address_post_code,
54
+ i.customer_address_country AS di_customer_address_country,
55
+ i.customer_address_ruian_id AS di_customer_address_ruian_id,
56
+ i.facts_doc_date AS di_facts_doc_date,
57
+ i.facts_net_date AS di_facts_net_date,
58
+ i.facts_billing_transaction AS di_facts_billing_transaction,
59
+ i.facts_to_pay_amount AS di_facts_to_pay_amount,
60
+ i.facts_currency AS di_facts_currency,
61
+ i.facts_price_brutto AS di_facts_price_brutto,
62
+ i.is_canceled AS di_is_canceled,
63
+ i.canceled_reason AS di_canceled_reason,
64
+ ins.place_id AS dinst_place_id,
65
+ ins.billing_class AS dinst_billing_class,
66
+ ins.measurement_type AS dinst_measurement_type,
67
+ ins.contract_contract_id AS dinst_contract_contract_id,
68
+ ins.contract_move_in_date AS dinst_contract_move_in_date,
69
+ ins.contract_move_out_date AS dinst_contract_move_out_date,
70
+ ins.tdd_class AS dinst_tdd_class,
71
+ ins.address_street AS dinst_address_street,
72
+ ins.address_house_number AS dinst_address_house_number,
73
+ ins.address_house_org_number AS dinst_address_house_org_number,
74
+ ins.address_city AS dinst_address_city,
75
+ ins.address_city_part AS dinst_address_city_part,
76
+ ins.address_post_code AS dinst_address_post_code,
77
+ ins.address_country AS dinst_address_country,
78
+ ins.address_ruian_id AS dinst_address_ruian_id
79
+ FROM enapo_ppas_distribution_installation ins
80
+ INNER JOIN enapo_ppas_distribution_invoice i
81
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
82
+ WHERE ins.eic = m.place_id
83
+ AND COALESCE(i.is_canceled, false) = false
84
+ ORDER BY i.facts_doc_date DESC
85
+ LIMIT 1
86
+ ) di ON m.id_type = 'eic'
87
+ LEFT JOIN LATERAL (
88
+ SELECT
89
+ i.id AS ci_id,
90
+ i.preceding_id AS ci_preceding_id,
91
+ i.customer_id AS ci_customer_id,
92
+ i.customer_company_id AS ci_customer_company_id,
93
+ i.customer_name AS ci_customer_name,
94
+ i.customer_contract_account_id AS ci_customer_contract_account_id,
95
+ i.customer_address_street AS ci_customer_address_street,
96
+ i.customer_address_house_number AS ci_customer_address_house_number,
97
+ i.customer_address_house_org_number AS ci_customer_address_house_org_number,
98
+ i.customer_address_city AS ci_customer_address_city,
99
+ i.customer_address_city_part AS ci_customer_address_city_part,
100
+ i.customer_address_post_code AS ci_customer_address_post_code,
101
+ i.customer_address_country AS ci_customer_address_country,
102
+ i.customer_address_ruian_id AS ci_customer_address_ruian_id,
103
+ i.facts_doc_date AS ci_facts_doc_date,
104
+ i.facts_net_date AS ci_facts_net_date,
105
+ i.facts_billing_transaction AS ci_facts_billing_transaction,
106
+ i.facts_to_pay_amount AS ci_facts_to_pay_amount,
107
+ i.facts_currency AS ci_facts_currency,
108
+ i.facts_price_brutto AS ci_facts_price_brutto,
109
+ i.is_canceled AS ci_is_canceled,
110
+ i.canceled_reason AS ci_canceled_reason,
111
+ ins.place_id AS cinst_place_id,
112
+ ins.billing_class AS cinst_billing_class,
113
+ ins.measurement_type AS cinst_measurement_type,
114
+ ins.contract_contract_id AS cinst_contract_contract_id,
115
+ ins.contract_move_in_date AS cinst_contract_move_in_date,
116
+ ins.contract_move_out_date AS cinst_contract_move_out_date,
117
+ ins.tdd_class AS cinst_tdd_class,
118
+ ins.address_street AS cinst_address_street,
119
+ ins.address_house_number AS cinst_address_house_number,
120
+ ins.address_house_org_number AS cinst_address_house_org_number,
121
+ ins.address_city AS cinst_address_city,
122
+ ins.address_city_part AS cinst_address_city_part,
123
+ ins.address_post_code AS cinst_address_post_code,
124
+ ins.address_country AS cinst_address_country,
125
+ ins.address_ruian_id AS cinst_address_ruian_id
126
+ FROM enapo_ppas_commercial_invoice_installations ins
127
+ INNER JOIN enapo_ppas_commercial_invoice i
128
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
129
+ WHERE ins.eic = m.place_id
130
+ AND COALESCE(i.is_canceled, false) = false
131
+ ORDER BY i.facts_doc_date DESC
132
+ LIMIT 1
133
+ ) ci ON m.id_type = 'eic';
134
+
135
+ DROP VIEW IF EXISTS v_enapo_building_porsenna_devices;