@golemio/energetics 1.12.1 → 1.12.2-dev.2727447026

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 +13 -0
  2. package/db/example/06_eno.sql +25 -0
  3. package/db/example/07_enapo_om_detail.sql +131 -0
  4. package/db/migrations/postgresql/20260729100000-enapo-gid-mapping-om-detail.js +53 -0
  5. package/db/migrations/postgresql/20260730120000-enapo-om-detail-porsenna.js +53 -0
  6. package/db/migrations/postgresql/sqls/20260729100000-enapo-gid-mapping-om-detail-down.sql +3 -0
  7. package/db/migrations/postgresql/sqls/20260729100000-enapo-gid-mapping-om-detail-up.sql +179 -0
  8. package/db/migrations/postgresql/sqls/20260730120000-enapo-om-detail-porsenna-down.sql +132 -0
  9. package/db/migrations/postgresql/sqls/20260730120000-enapo-om-detail-porsenna-up.sql +287 -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 +105 -0
  31. package/dist/output-gateway/models/EnoConsumptionPointViewModel.js +118 -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 +104 -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 +106 -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 +149 -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 +260 -1
  90. package/package.json +1 -1
@@ -9,3 +9,16 @@ 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_invoice_device;
17
+ truncate enapo_ppas_distribution_invoice_price;
18
+ truncate enapo_ppas_commercial_invoice;
19
+ truncate enapo_ppas_commercial_invoice_installations;
20
+ truncate enapo_ppas_commercial_invoice_device;
21
+ truncate enapo_ppas_commercial_invoice_price;
22
+ truncate enapo_porsenna_buildings;
23
+ truncate enapo_porsenna_devices;
24
+ 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,131 @@
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, eic, place_id,
26
+ installations_billing_class, installations_measurement_type, installations_contract_contract_id,
27
+ installations_contract_move_in_date, installations_contract_move_out_date, installations_tdd_class,
28
+ installations_address_street, installations_address_house_number, installations_address_house_org_number,
29
+ installations_address_city, installations_address_city_part, installations_address_post_code,
30
+ installations_address_country, installations_address_ruian_id) VALUES
31
+ ('DI-2026-001', NULL, '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-03-15', '2026-03-29', 'FAKTURACE', 15250.50,
35
+ 'CZK', 18453.11, false, NULL, '27ZG100Z0000192O', '10101325',
36
+ 'MO', 'C', 'SML-1',
37
+ '2019-12-05', '9999-12-31', 'DOM4',
38
+ 'Testovací', '123', '4',
39
+ 'Praha', 'Praha 10', '10000',
40
+ 'CZ', 22349996),
41
+ ('DI-2026-002', 'DI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
42
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
43
+ 'Praha', 'Staré Město', '11000', 'CZ',
44
+ 22349995, '2026-05-20', '2026-06-03', 'STORNO', -15250.50,
45
+ 'CZK', -18453.11, true, 'oprava odečtu', '27ZG100Z0000192O', '10101325',
46
+ 'MO', 'C', 'SML-1',
47
+ '2019-12-05', '9999-12-31', 'DOM4',
48
+ 'Testovací', '123', '4',
49
+ 'Praha', 'Praha 10', '10000',
50
+ 'CZ', 22349996);
51
+
52
+ INSERT INTO enapo_ppas_distribution_invoice_device (device_serial_number, invoice_id, date_from, date_to, "type", kind,
53
+ reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
54
+ volume_coefficient, combustion_heat, normometers_nm3) VALUES
55
+ ('PLYN-001', 'DI-2026-001', '2025-03-01', '2026-02-28', 'G4', 'plynoměr',
56
+ 'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
57
+ 1.0043, 10.55, 1687.2);
58
+
59
+ INSERT INTO enapo_ppas_distribution_invoice_price (invoice_id, customer_id, date_from, date_to, kind, description,
60
+ price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
61
+ ('DI-2026-001', 'CUST-1', '2025-03-01', '2026-02-28', 'distribuce', 'Distribuce plynu',
62
+ 'D1', 17750.4, 'kWh', 0.35, NULL, 6212.64, 'variabilní', 'CZK', 21.0);
63
+
64
+ -- PPAS commercial invoices: a valid one and a newer canceled one (must be skipped)
65
+ INSERT INTO enapo_ppas_commercial_invoice (id, preceding_id, customer_id, customer_company_id, customer_name,
66
+ customer_contract_account_id, customer_address_street, customer_address_house_number, customer_address_house_org_number,
67
+ customer_address_city, customer_address_city_part, customer_address_post_code, customer_address_country,
68
+ customer_address_ruian_id, facts_doc_date, facts_net_date, facts_billing_transaction, facts_to_pay_amount,
69
+ facts_currency, facts_price_brutto, is_canceled, canceled_reason) VALUES
70
+ ('CI-2026-001', NULL, 'CUST-1', '00064581', 'Hlavní město Praha',
71
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
72
+ 'Praha', 'Staré Město', '11000', 'CZ',
73
+ 22349995, '2026-04-10', '2026-04-24', 'FAKTURACE', 28900.00,
74
+ 'CZK', 34969.00, false, NULL),
75
+ ('CI-2026-002', 'CI-2026-001', 'CUST-1', '00064581', 'Hlavní město Praha',
76
+ 'CA-1', 'Mariánské náměstí', '2', NULL,
77
+ 'Praha', 'Staré Město', '11000', 'CZ',
78
+ 22349995, '2026-06-01', '2026-06-15', 'STORNO', -28900.00,
79
+ 'CZK', -34969.00, true, 'reklamace');
80
+
81
+ INSERT INTO enapo_ppas_commercial_invoice_installations (invoice_id, customer_id, place_id, eic, billing_class,
82
+ measurement_type, contract_contract_id, contract_move_in_date, contract_move_out_date, tdd_class,
83
+ address_street, address_house_number, address_house_org_number, address_city, address_city_part,
84
+ address_post_code, address_country, address_ruian_id) VALUES
85
+ ('CI-2026-001', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
86
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
87
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
88
+ '10000', 'CZ', 22349996),
89
+ ('CI-2026-002', 'CUST-1', '10101325', '27ZG100Z0000192O', 'MO',
90
+ 'C', 'SML-1', '2019-12-05', '9999-12-31', 'DOM4',
91
+ 'Testovací', '123', '4', 'Praha', 'Praha 10',
92
+ '10000', 'CZ', 22349996);
93
+
94
+ INSERT INTO enapo_ppas_commercial_invoice_device (device_serial_number, invoice_id, place_id, date_from, date_to,
95
+ "type", kind, reading_type, reading_from, reading_to, consumption, unit, meter_reading_type, gas_consumption_kwh,
96
+ volume_coefficient, combustion_heat, normometers_nm3) VALUES
97
+ ('PLYN-001', 'CI-2026-001', '10101325', '2025-03-01', '2026-02-28',
98
+ 'G4', 'plynoměr', 'řádný', 10250.0, 11930.0, 1680.0, 'm3', 'dálkový', 17750.4,
99
+ 1.0043, 10.55, 1687.2);
100
+
101
+ INSERT INTO enapo_ppas_commercial_invoice_price (invoice_id, customer_id, place_id, date_from, date_to, kind,
102
+ description, price_group, quantity, unit, unit_price, time_slot, price_netto, price_type, currency, tax_rate) VALUES
103
+ ('CI-2026-001', 'CUST-1', '10101325', '2025-03-01', '2026-02-28', 'komodita',
104
+ 'Dodávka plynu', 'K1', 17750.4, 'kWh', 1.45, NULL, 25738.08, 'variabilní', 'CZK', 21.0);
105
+
106
+ -- Porsenna (e-manazer): buildings, devices (incl. heat/water and a sub-meter), yearly consumption.
107
+ -- Device types and tenant naming mirror real Porsenna data (electricity_meter/heat_meter/water_meter, tenant prague-7).
108
+ INSERT INTO enapo_porsenna_buildings (source, id, name, street, house_number, street_number, city, postcode, gid) VALUES
109
+ ('prague-7', 1, 'ZŠ Testovací (e-manažer)', 'Testovací', '123', '4', 'Praha 10', '10000', 'GID100'),
110
+ ('prague-7', 2, 'Vrátnice Kundratka', 'Kundratka', '19', NULL, 'Praha 8', '18000', 'GIDPOR1');
111
+
112
+ INSERT INTO enapo_porsenna_devices (source, id, building_id, parent_device_id, "level", "type", name,
113
+ measurement_target, disabled_at, disable_reason_id, show_in_output, identifier, supply_point_number,
114
+ meter_number, identification_gid) VALUES
115
+ ('prague-7', '11111111-1111-1111-1111-111111111111', 1, NULL, 'main', 'electricity_meter', 'Hlavní elektroměr',
116
+ 'consumption', NULL, NULL, true, '859182400000000001', 'OP-100', 'EL-123', 'GID100'),
117
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 1, NULL, 'main', 'heat_meter', 'Předávací stanice CZT',
118
+ 'consumption', NULL, NULL, true, '40001234', 'OP-101', 'TEP-77', 'GID100'),
119
+ ('prague-7', '33333333-3333-3333-3333-333333333333', 1, NULL, 'main', 'water_meter', 'Hlavní vodoměr',
120
+ 'consumption', '2024-05-31 00:00:00+00', 4, true, '50005678', 'OP-102', 'VOD-55', 'GID100'),
121
+ ('prague-7', '44444444-4444-4444-4444-444444444444', 1, '22222222-2222-2222-2222-222222222222', 'sub',
122
+ 'heat_meter', 'Podružné měření tělocvična', 'tělocvična', NULL, NULL, true, NULL, NULL, 'TEP-78', NULL),
123
+ ('prague-7', '55555555-5555-5555-5555-555555555555', 2, NULL, 'main', 'electricity_meter', 'Elektroměr vrátnice',
124
+ 'consumption', NULL, NULL, true, '859182400000000099', 'OP-200', 'EL-999', 'GIDPOR1');
125
+
126
+ INSERT INTO enapo_porsenna_consumption (source, device_id, "var", "period", value, unit, commodity, "count") VALUES
127
+ ('prague-7', '11111111-1111-1111-1111-111111111111', 'yearly', '2025', 12.4, 'MWH', 'electricity_meter', 365),
128
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2023', 512.3, 'GJ', 'heat_meter', 365),
129
+ ('prague-7', '22222222-2222-2222-2222-222222222222', 'yearly', '2024', 498.1, 'GJ', 'heat_meter', 366),
130
+ ('prague-7', '33333333-3333-3333-3333-333333333333', 'yearly', '2023', 210, 'M3', 'water_meter', 365),
131
+ ('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', '20260729100000-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', '20260729100000-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', '20260730120000-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', '20260730120000-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,179 @@
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
+ i.installations_billing_class AS di_installations_billing_class,
114
+ i.installations_measurement_type AS di_installations_measurement_type,
115
+ i.installations_contract_contract_id AS di_installations_contract_contract_id,
116
+ i.installations_contract_move_in_date AS di_installations_contract_move_in_date,
117
+ i.installations_contract_move_out_date AS di_installations_contract_move_out_date,
118
+ i.installations_tdd_class AS di_installations_tdd_class,
119
+ i.installations_address_street AS di_installations_address_street,
120
+ i.installations_address_house_number AS di_installations_address_house_number,
121
+ i.installations_address_house_org_number AS di_installations_address_house_org_number,
122
+ i.installations_address_city AS di_installations_address_city,
123
+ i.installations_address_city_part AS di_installations_address_city_part,
124
+ i.installations_address_post_code AS di_installations_address_post_code,
125
+ i.installations_address_country AS di_installations_address_country,
126
+ i.installations_address_ruian_id AS di_installations_address_ruian_id
127
+ FROM enapo_ppas_distribution_invoice i
128
+ WHERE i.eic = m.place_id
129
+ AND COALESCE(i.is_canceled, false) = false
130
+ ORDER BY i.facts_doc_date DESC
131
+ LIMIT 1
132
+ ) di ON m.id_type = 'eic'
133
+ LEFT JOIN LATERAL (
134
+ SELECT
135
+ i.id AS ci_id,
136
+ i.preceding_id AS ci_preceding_id,
137
+ i.customer_id AS ci_customer_id,
138
+ i.customer_company_id AS ci_customer_company_id,
139
+ i.customer_name AS ci_customer_name,
140
+ i.customer_contract_account_id AS ci_customer_contract_account_id,
141
+ i.customer_address_street AS ci_customer_address_street,
142
+ i.customer_address_house_number AS ci_customer_address_house_number,
143
+ i.customer_address_house_org_number AS ci_customer_address_house_org_number,
144
+ i.customer_address_city AS ci_customer_address_city,
145
+ i.customer_address_city_part AS ci_customer_address_city_part,
146
+ i.customer_address_post_code AS ci_customer_address_post_code,
147
+ i.customer_address_country AS ci_customer_address_country,
148
+ i.customer_address_ruian_id AS ci_customer_address_ruian_id,
149
+ i.facts_doc_date AS ci_facts_doc_date,
150
+ i.facts_net_date AS ci_facts_net_date,
151
+ i.facts_billing_transaction AS ci_facts_billing_transaction,
152
+ i.facts_to_pay_amount AS ci_facts_to_pay_amount,
153
+ i.facts_currency AS ci_facts_currency,
154
+ i.facts_price_brutto AS ci_facts_price_brutto,
155
+ i.is_canceled AS ci_is_canceled,
156
+ i.canceled_reason AS ci_canceled_reason,
157
+ ins.place_id AS cii_place_id,
158
+ ins.billing_class AS cii_billing_class,
159
+ ins.measurement_type AS cii_measurement_type,
160
+ ins.contract_contract_id AS cii_contract_contract_id,
161
+ ins.contract_move_in_date AS cii_contract_move_in_date,
162
+ ins.contract_move_out_date AS cii_contract_move_out_date,
163
+ ins.tdd_class AS cii_tdd_class,
164
+ ins.address_street AS cii_address_street,
165
+ ins.address_house_number AS cii_address_house_number,
166
+ ins.address_house_org_number AS cii_address_house_org_number,
167
+ ins.address_city AS cii_address_city,
168
+ ins.address_city_part AS cii_address_city_part,
169
+ ins.address_post_code AS cii_address_post_code,
170
+ ins.address_country AS cii_address_country,
171
+ ins.address_ruian_id AS cii_address_ruian_id
172
+ FROM enapo_ppas_commercial_invoice_installations ins
173
+ INNER JOIN enapo_ppas_commercial_invoice i
174
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
175
+ WHERE ins.eic = m.place_id
176
+ AND COALESCE(i.is_canceled, false) = false
177
+ ORDER BY i.facts_doc_date DESC
178
+ LIMIT 1
179
+ ) ci ON m.id_type = 'eic';
@@ -0,0 +1,132 @@
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
+ i.installations_billing_class AS di_installations_billing_class,
65
+ i.installations_measurement_type AS di_installations_measurement_type,
66
+ i.installations_contract_contract_id AS di_installations_contract_contract_id,
67
+ i.installations_contract_move_in_date AS di_installations_contract_move_in_date,
68
+ i.installations_contract_move_out_date AS di_installations_contract_move_out_date,
69
+ i.installations_tdd_class AS di_installations_tdd_class,
70
+ i.installations_address_street AS di_installations_address_street,
71
+ i.installations_address_house_number AS di_installations_address_house_number,
72
+ i.installations_address_house_org_number AS di_installations_address_house_org_number,
73
+ i.installations_address_city AS di_installations_address_city,
74
+ i.installations_address_city_part AS di_installations_address_city_part,
75
+ i.installations_address_post_code AS di_installations_address_post_code,
76
+ i.installations_address_country AS di_installations_address_country,
77
+ i.installations_address_ruian_id AS di_installations_address_ruian_id
78
+ FROM enapo_ppas_distribution_invoice i
79
+ WHERE i.eic = m.place_id
80
+ AND COALESCE(i.is_canceled, false) = false
81
+ ORDER BY i.facts_doc_date DESC
82
+ LIMIT 1
83
+ ) di ON m.id_type = 'eic'
84
+ LEFT JOIN LATERAL (
85
+ SELECT
86
+ i.id AS ci_id,
87
+ i.preceding_id AS ci_preceding_id,
88
+ i.customer_id AS ci_customer_id,
89
+ i.customer_company_id AS ci_customer_company_id,
90
+ i.customer_name AS ci_customer_name,
91
+ i.customer_contract_account_id AS ci_customer_contract_account_id,
92
+ i.customer_address_street AS ci_customer_address_street,
93
+ i.customer_address_house_number AS ci_customer_address_house_number,
94
+ i.customer_address_house_org_number AS ci_customer_address_house_org_number,
95
+ i.customer_address_city AS ci_customer_address_city,
96
+ i.customer_address_city_part AS ci_customer_address_city_part,
97
+ i.customer_address_post_code AS ci_customer_address_post_code,
98
+ i.customer_address_country AS ci_customer_address_country,
99
+ i.customer_address_ruian_id AS ci_customer_address_ruian_id,
100
+ i.facts_doc_date AS ci_facts_doc_date,
101
+ i.facts_net_date AS ci_facts_net_date,
102
+ i.facts_billing_transaction AS ci_facts_billing_transaction,
103
+ i.facts_to_pay_amount AS ci_facts_to_pay_amount,
104
+ i.facts_currency AS ci_facts_currency,
105
+ i.facts_price_brutto AS ci_facts_price_brutto,
106
+ i.is_canceled AS ci_is_canceled,
107
+ i.canceled_reason AS ci_canceled_reason,
108
+ ins.place_id AS cii_place_id,
109
+ ins.billing_class AS cii_billing_class,
110
+ ins.measurement_type AS cii_measurement_type,
111
+ ins.contract_contract_id AS cii_contract_contract_id,
112
+ ins.contract_move_in_date AS cii_contract_move_in_date,
113
+ ins.contract_move_out_date AS cii_contract_move_out_date,
114
+ ins.tdd_class AS cii_tdd_class,
115
+ ins.address_street AS cii_address_street,
116
+ ins.address_house_number AS cii_address_house_number,
117
+ ins.address_house_org_number AS cii_address_house_org_number,
118
+ ins.address_city AS cii_address_city,
119
+ ins.address_city_part AS cii_address_city_part,
120
+ ins.address_post_code AS cii_address_post_code,
121
+ ins.address_country AS cii_address_country,
122
+ ins.address_ruian_id AS cii_address_ruian_id
123
+ FROM enapo_ppas_commercial_invoice_installations ins
124
+ INNER JOIN enapo_ppas_commercial_invoice i
125
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
126
+ WHERE ins.eic = m.place_id
127
+ AND COALESCE(i.is_canceled, false) = false
128
+ ORDER BY i.facts_doc_date DESC
129
+ LIMIT 1
130
+ ) ci ON m.id_type = 'eic';
131
+
132
+ DROP VIEW IF EXISTS v_enapo_building_porsenna_devices;