@golemio/flow 1.0.8-dev.568903441 → 1.0.8-dev.584979260

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 (39) hide show
  1. package/db/example/.config.json +3 -0
  2. package/db/example/00_truncate_tables.sql +10 -0
  3. package/db/example/01_wifiHistoricData.sql +49 -0
  4. package/db/example/02_countersData.sql +99 -0
  5. package/db/example/03_flowData.sql +343 -0
  6. package/db/example/99_runUpdateProcedure.sql +1 -0
  7. package/db/migrations/postgresql/.config.json +3 -0
  8. package/db/migrations/postgresql/20220616144407-flow.js +53 -0
  9. package/db/migrations/postgresql/20220711123652-analytic.js +53 -0
  10. package/db/migrations/postgresql/package.json +3 -0
  11. package/db/migrations/postgresql/sqls/20220616144407-flow-down.sql +15 -0
  12. package/db/migrations/postgresql/sqls/20220616144407-flow-up.sql +467 -0
  13. package/db/migrations/postgresql/sqls/20220711123652-analytic-down.sql +7 -0
  14. package/db/migrations/postgresql/sqls/20220711123652-analytic-up.sql +410 -0
  15. package/db/migrations/postgresql/sqls/package.json +3 -0
  16. package/dist/integration-engine/CountersWorker.d.ts +14 -0
  17. package/dist/integration-engine/CountersWorker.js +120 -0
  18. package/dist/integration-engine/CountersWorker.js.map +1 -0
  19. package/dist/integration-engine/FlowWorker.js +6 -2
  20. package/dist/integration-engine/FlowWorker.js.map +1 -1
  21. package/dist/integration-engine/queueDefinitions.js +27 -0
  22. package/dist/integration-engine/queueDefinitions.js.map +1 -1
  23. package/dist/integration-engine/transformations/EcoCounterMeasurementsTransformation.d.ts +6 -0
  24. package/dist/integration-engine/transformations/EcoCounterMeasurementsTransformation.js +42 -0
  25. package/dist/integration-engine/transformations/EcoCounterMeasurementsTransformation.js.map +1 -0
  26. package/dist/integration-engine/transformations/EcoCounterTransformation.d.ts +17 -0
  27. package/dist/integration-engine/transformations/EcoCounterTransformation.js +99 -0
  28. package/dist/integration-engine/transformations/EcoCounterTransformation.js.map +1 -0
  29. package/dist/output-gateway/models/PedestriansLocationsModel.js +4 -2
  30. package/dist/output-gateway/models/PedestriansLocationsModel.js.map +1 -1
  31. package/dist/output-gateway/models/PedestriansMeasurementsModel.js +4 -2
  32. package/dist/output-gateway/models/PedestriansMeasurementsModel.js.map +1 -1
  33. package/dist/schema-definitions/index.d.ts +185 -0
  34. package/dist/schema-definitions/index.js +197 -2
  35. package/dist/schema-definitions/index.js.map +1 -1
  36. package/docs/assets/flow_erd.png +0 -0
  37. package/docs/implementation_documentation_CZ.md +157 -0
  38. package/docs/implementation_documentation_Counters.md +166 -0
  39. package/package.json +9 -5
@@ -0,0 +1,410 @@
1
+ CREATE SCHEMA IF NOT EXISTS analytic;
2
+
3
+ CREATE TABLE analytic.pedestrians_locations_list (
4
+ id serial4 NOT NULL,
5
+ location_name_plain varchar(250) NULL,
6
+ location_name varchar(250) NULL,
7
+ lat numeric NULL,
8
+ lng numeric NULL,
9
+ address varchar(250) NULL,
10
+ city_district varchar(250) NULL,
11
+ tech varchar(250) NULL,
12
+ map_picture varchar(2500) NULL,
13
+ gate_picture varchar(2500) NULL,
14
+ measurement_start timestamptz NULL,
15
+ measurement_end timestamptz NULL,
16
+ id_equiptment varchar(250) NULL,
17
+ cube_id varchar(250) NULL,
18
+ lon varbit NULL,
19
+ map_image varchar(55) NULL,
20
+ place_image varchar(59) NULL,
21
+ "table" varchar(19) NULL,
22
+ CONSTRAINT equipment_list_pkey PRIMARY KEY (id)
23
+ );
24
+ COMMENT ON TABLE analytic.pedestrians_locations_list IS '-- tabulka lokací. obsahuje lokace různých druhů a hodně custom dat, takže ji tvoříme ručně. sporadicky probíhají aktualizace
25
+ -- tabulka se nachází na https://operator.sharepoint.com/:f:/s/Datova_Platforma/EsE5uSdyLzdImWgyrMY8nFcBzwtH7GOr6TXtzNBn3FLIJw?e=fOov5s a jmenuje se locations_list.csv';
26
+
27
+ INSERT INTO analytic.pedestrians_locations_list (location_name_plain,location_name,lat,lng,address,city_district,tech,map_picture,gate_picture,measurement_start,measurement_end,id_equiptment,cube_id,lon,map_image,place_image,"table") VALUES
28
+ ('Výstaviště - viadukt VO 2','107043 - Výstaviště - viadukt VO 2',50.1042106575078,14.431679367811926,'U Výstaviště (viadukt)','Praha 7','kamera',NULL,NULL,'2020-09-02 00:00:00+02',NULL,NULL,'0',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/1.png','https://storage.golemio.cz/intenzita-pesi-dopravy/1-map.png','flow_measurements'),
29
+ ('Rytířská 12','101336 - Rytířská 12',50.084781715549276,14.422412102465428,'Na Můstku 12','Praha 1','kamera',NULL,NULL,'2020-09-02 00:00:00+02',NULL,NULL,'1',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/2.png','https://storage.golemio.cz/intenzita-pesi-dopravy/2-map.png','flow_measurements'),
30
+ ('Výstaviště - viadukt','Výstaviště - viadukt',50.1042106575078,14.431679367811926,'U Výstaviště (viadukt)','Praha 7','pyro',NULL,NULL,'2020-07-23 00:00:00+02','2020-11-10 00:00:00+01',NULL,'ecoCounter-100061215',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/1.png','https://storage.golemio.cz/intenzita-pesi-dopravy/1-map.png','counters_detections'),
31
+ ('Stromovka - U Výstaviště','Stromovka - U Výstaviště',50.10489433551656,14.429609941952332,'U Výstaviště 67','Praha 7','wifi',NULL,NULL,'2020-11-24 00:00:00+01',NULL,NULL,'wifi1',NULL,NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/4-map.png','xyz'),
32
+ ('Stromovka - U Výstaviště','Stromovka - U Výstaviště',50.10489433551656,14.429609941952332,'U Výstaviště 67','Praha 7','pyro',NULL,NULL,'2020-11-11 00:00:00+01','2021-03-04 00:00:00+01',NULL,'ecoCounter-100065230',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/3.png','https://storage.golemio.cz/intenzita-pesi-dopravy/3-map.png','counters_detections'),
33
+ ('Stromovka - U Výstaviště','Stromovka - U Výstaviště',50.10489433551656,14.429609941952332,'U Výstaviště 67','Praha 7','kamera',NULL,NULL,'2020-12-17 00:00:00+01',NULL,NULL,'13',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/3.png','https://storage.golemio.cz/intenzita-pesi-dopravy/3-map.png','flow_measurements'),
34
+ ('Staroměstská věž pevná VI','101004 - Staroměstská věž pevná VI',50.08626,14.41301,'Karlův most','Praha 1','kamera',NULL,NULL,'2020-09-02 00:00:00+02',NULL,NULL,'9',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/5.png','https://storage.golemio.cz/intenzita-pesi-dopravy/5-map.png','flow_measurements'),
35
+ ('Železniční most - nápl. I (náplavka)','202049 - Železniční most - nápl. I (náplavka)',50.06739,14.41468,'Novoměstská náplavka','Praha 2','kamera',NULL,NULL,'2020-09-02 00:00:00+02',NULL,NULL,'10',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/6.png','https://storage.golemio.cz/intenzita-pesi-dopravy/6-map.png','flow_measurements'),
36
+ ('Železniční most - náplavka II','202050 - Železniční most - náplavka II',50.06693,14.41480,'Novoměstská náplavka','Praha 2','kamera',NULL,NULL,'2020-09-02 00:00:00+02',NULL,NULL,'11',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/7.png','https://storage.golemio.cz/intenzita-pesi-dopravy/7-map.png','flow_measurements'),
37
+ ('Železniční most - nápl. I (rampa)','202049 - Železniční most - nápl. I (rampa)',50.06739,14.41468,'Novoměstská náplavka','Praha 2','kamera',NULL,NULL,'2020-09-02 00:00:00+02',NULL,NULL,'10',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/6.png','https://storage.golemio.cz/intenzita-pesi-dopravy/6-map.png','flow_measurements');
38
+ INSERT INTO analytic.pedestrians_locations_list (location_name_plain,location_name,lat,lng,address,city_district,tech,map_picture,gate_picture,measurement_start,measurement_end,id_equiptment,cube_id,lon,map_image,place_image,"table") VALUES
39
+ ('Železniční most - nápl. I (plný profil)','202049 - Železniční most - nápl. I (plný profil)',50.06739,14.41468,'Novoměstská náplavka','Praha 2','kamera',NULL,NULL,'2020-09-02 00:00:00+02',NULL,NULL,'10',NULL,'https://storage.golemio.cz/intenzita-pesi-dopravy/6.png','https://storage.golemio.cz/intenzita-pesi-dopravy/6-map.png','flow_measurements');
40
+
41
+
42
+ CREATE TABLE analytic.pedestrians_locations_gates (
43
+ direction_id varchar(250) NOT NULL,
44
+ cube_id varchar(250) NOT NULL,
45
+ location_id int4 NOT NULL,
46
+ name varchar(250) NOT NULL,
47
+ direction_type varchar(250) NOT NULL,
48
+ CONSTRAINT equipment_gates_pkey PRIMARY KEY (direction_id, location_id)
49
+ );
50
+
51
+ INSERT INTO analytic.pedestrians_locations_gates (direction_id,cube_id,location_id,"name",direction_type) VALUES
52
+ ('4','0',1,'Směr pod viadukt','Směr 1'),
53
+ ('7','0',1,'Směr Výstaviště','Směr 2'),
54
+ ('2','1',2,'Směr Můstek','Směr 1'),
55
+ ('3','1',2,'Směr Rytířská','Směr 2'),
56
+ ('5','9',7,'Směr Malá strana','Směr 1'),
57
+ ('8','9',7,'Směr Staré město','Směr 2'),
58
+ ('6','10',8,'Náplavka, směr centrum','Směr 1'),
59
+ ('9','10',10,'Rampa, směr centrum','Směr 1'),
60
+ ('10','10',11,'Plný profil, směr centrum','Směr 1'),
61
+ ('11','10',8,'Náplavka, směr Vyšehrad','Směr 2');
62
+ INSERT INTO analytic.pedestrians_locations_gates (direction_id,cube_id,location_id,"name",direction_type) VALUES
63
+ ('13','10',10,'Rampa, směr Vyšehrad','Směr 2'),
64
+ ('15','10',11,'Plný profil, směr Vyšehrad','Směr 2'),
65
+ ('35','11',9,'Plný profil, směr centrum','Směr 1'),
66
+ ('29','11',9,'Plný profil, směr Vyšehrad','Směr 2'),
67
+ ('7','13',6,'Směr Planetarium','Směr 1'),
68
+ ('8','13',6,'Směr Holešovice','Směr 2'),
69
+ ('ecoCounter-103061215','ecoCounter-100061215',3,'Směr pod viadukt','Směr 1'),
70
+ ('ecoCounter-104061215','ecoCounter-100061215',3,'Směr Výstaviště','Směr 2'),
71
+ ('ecoCounter-353245241','ecoCounter-100065230',5,'Směr Planetarium','Směr 1'),
72
+ ('ecoCounter-102065230','ecoCounter-100065230',5,'Směr Planetarium','Směr 1');
73
+ INSERT INTO analytic.pedestrians_locations_gates (direction_id,cube_id,location_id,"name",direction_type) VALUES
74
+ ('ecoCounter-353240728','ecoCounter-100065230',5,'Směr Planetarium','Směr 1'),
75
+ ('ecoCounter-353235722','ecoCounter-100065230',5,'Směr Planetarium','Směr 1'),
76
+ ('ecoCounter-353231243','ecoCounter-100065230',5,'Směr Planetarium','Směr 1'),
77
+ ('ecoCounter-353245239','ecoCounter-100065230',5,'Směr Holešovice','Směr 2'),
78
+ ('ecoCounter-101065230','ecoCounter-100065230',5,'Směr Holešovice','Směr 2'),
79
+ ('ecoCounter-353240727','ecoCounter-100065230',5,'Směr Holešovice','Směr 2'),
80
+ ('ecoCounter-353235721','ecoCounter-100065230',5,'Směr Holešovice','Směr 2'),
81
+ ('ecoCounter-353231242','ecoCounter-100065230',5,'Směr Holešovice','Směr 2'),
82
+ ('dir1','wifi1',4,'Směr Holešovice','Směr 1'),
83
+ ('dir2','wifi1',4,'Směr Planetarium','Směr 2');
84
+
85
+ COMMENT ON TABLE analytic.pedestrians_locations_gates IS '-- tabulka směrů k jednotlivým lokacím, platí to samé co u lokations_list.
86
+ -- nachází se na https://operator.sharepoint.com/:f:/s/Datova_Platforma/EsE5uSdyLzdImWgyrMY8nFcBzwtH7GOr6TXtzNBn3FLIJw?e=fOov5s a jmenuje se directions_list.csv';
87
+
88
+ COMMENT ON TABLE pedestrians_wifi IS '-- tabulka na primární data wifi měření, jsou pouze jako csv na sharepointu https://operator.sharepoint.com/:f:/s/Datova_Platforma/EroMekiKaJdOtMPeF_Q8wPEBlZm5tLKHCgpK13H6hlc0Zg?e=4RbCkT';
89
+
90
+ -- analytic.v_pedestrians_detections_15min source
91
+
92
+ CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_15min
93
+ AS WITH wifi AS (
94
+ SELECT pedestrians_wifi.location_id AS locations_id,
95
+ pedestrians_wifi.direction_id AS directions_id,
96
+ date_trunc('hour'::text, pedestrians_wifi.measured_from) + (date_part('minute'::text, pedestrians_wifi.measured_from)::integer / 15)::double precision * '00:15:00'::interval AS measured_from,
97
+ sum(pedestrians_wifi.value) AS value,
98
+ count(pedestrians_wifi.value) AS count_n
99
+ FROM flow.pedestrians_wifi
100
+ GROUP BY pedestrians_wifi.location_id, pedestrians_wifi.direction_id, (date_trunc('hour'::text, pedestrians_wifi.measured_from) + (date_part('minute'::text, pedestrians_wifi.measured_from)::integer / 15)::double precision * '00:15:00'::interval)
101
+ ), pyro AS (
102
+ SELECT cd.locations_id,
103
+ lg.first_dir AS directions_id,
104
+ to_timestamp((cd.measured_from / 1000)::double precision) AS measured_from,
105
+ sum(cd.value) AS value,
106
+ count(cd.value) AS count_n
107
+ FROM flow.counters_detections cd
108
+ LEFT JOIN ( SELECT pedestrians_locations_gates.direction_id,
109
+ pedestrians_locations_gates.direction_type,
110
+ min(pedestrians_locations_gates.direction_id::text) OVER (PARTITION BY pedestrians_locations_gates.cube_id, pedestrians_locations_gates.direction_type) AS first_dir
111
+ FROM analytic.pedestrians_locations_gates) lg ON cd.directions_id::text = lg.direction_id::text
112
+ WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_locations_gates.direction_id
113
+ FROM analytic.pedestrians_locations_gates))
114
+ GROUP BY cd.locations_id, lg.first_dir, (to_timestamp((cd.measured_from / 1000)::double precision))
115
+ ), flow AS (
116
+ SELECT flow_measurements.cube_id::character varying(50) AS location_id,
117
+ flow_measurements.sink_id::character varying(50) AS direction_id,
118
+ date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval AS measured_from,
119
+ sum(flow_measurements.value) AS value,
120
+ count(flow_measurements.value) AS count_n
121
+ FROM flow.flow_measurements
122
+ WHERE ((flow_measurements.cube_id::character varying(50)::text, flow_measurements.sink_id::character varying(50)::text) IN ( SELECT DISTINCT pedestrians_locations_gates.cube_id AS location_id,
123
+ pedestrians_locations_gates.direction_id
124
+ FROM analytic.pedestrians_locations_gates)) AND flow_measurements.category::text = 'pedestrian'::text
125
+ GROUP BY (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50)), (date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval)
126
+ ORDER BY (date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval), (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50))
127
+ ), measurements AS (
128
+ SELECT wifi.locations_id,
129
+ wifi.directions_id,
130
+ wifi.measured_from,
131
+ wifi.value,
132
+ wifi.count_n
133
+ FROM wifi
134
+ UNION ALL
135
+ SELECT pyro.locations_id,
136
+ pyro.directions_id,
137
+ pyro.measured_from,
138
+ pyro.value,
139
+ pyro.count_n
140
+ FROM pyro
141
+ UNION ALL
142
+ SELECT flow.location_id,
143
+ flow.direction_id,
144
+ flow.measured_from,
145
+ flow.value,
146
+ flow.count_n
147
+ FROM flow
148
+ ), calendar AS (
149
+ SELECT generate_series(min(measurements.measured_from), max(measurements.measured_from), '00:15:00'::interval) AS calendar
150
+ FROM measurements
151
+ ), classes AS (
152
+ SELECT calendar.calendar,
153
+ m_1.location_id,
154
+ m_1.direction_id
155
+ FROM calendar
156
+ JOIN ( SELECT DISTINCT measurements.locations_id::character varying(50) AS location_id,
157
+ measurements.directions_id::character varying(50) AS direction_id
158
+ FROM measurements) m_1 ON true
159
+ )
160
+ SELECT c.calendar,
161
+ date_trunc('hour'::text, c.calendar) AS calendar_hour,
162
+ c.calendar::date AS calendar_date,
163
+ ll.measurement_start,
164
+ COALESCE(ll.measurement_end, now()::date::timestamp with time zone) AS measurement_end,
165
+ c.location_id,
166
+ c.direction_id,
167
+ concat(c.location_id, '-', c.direction_id) AS compound_id,
168
+ COALESCE(m.value, 0::bigint) AS value,
169
+ COALESCE(m.count_n, 0::bigint) AS count_n
170
+ FROM classes c
171
+ LEFT JOIN measurements m ON c.calendar = m.measured_from AND c.location_id::text = m.locations_id::text AND c.direction_id::text = m.directions_id::text
172
+ LEFT JOIN analytic.pedestrians_locations_list ll ON c.location_id::text = ll.cube_id::text
173
+ WHERE c.calendar >= ll.measurement_start AND c.calendar <= COALESCE(ll.measurement_end, now()::date::timestamp with time zone);
174
+
175
+
176
+ -- analytic.v_pedestrians_detections_api source
177
+
178
+ CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_api
179
+ AS WITH wifi AS (
180
+ SELECT pedestrians_wifi.location_id,
181
+ pedestrians_wifi.direction_id,
182
+ date_trunc('hour'::text, pedestrians_wifi.measured_from) + (date_part('minute'::text, pedestrians_wifi.measured_from)::integer / 15)::double precision * '00:15:00'::interval AS measured_from,
183
+ date_trunc('hour'::text, pedestrians_wifi.measured_from) + (date_part('minute'::text, pedestrians_wifi.measured_from)::integer / 15)::double precision * '00:15:00'::interval + '00:15:00'::interval AS measured_to,
184
+ sum(pedestrians_wifi.value) AS value,
185
+ count(pedestrians_wifi.value) AS count_n,
186
+ 3 AS quantity
187
+ FROM flow.pedestrians_wifi
188
+ GROUP BY pedestrians_wifi.location_id, pedestrians_wifi.direction_id, (date_trunc('hour'::text, pedestrians_wifi.measured_from) + (date_part('minute'::text, pedestrians_wifi.measured_from)::integer / 15)::double precision * '00:15:00'::interval), (date_trunc('hour'::text, pedestrians_wifi.measured_from) + (date_part('minute'::text, pedestrians_wifi.measured_from)::integer / 15)::double precision * '00:15:00'::interval + '00:15:00'::interval)
189
+ ), pyro AS (
190
+ SELECT cd.locations_id AS location_id,
191
+ cd.directions_id AS direction_id,
192
+ to_timestamp((cd.measured_from / 1000)::double precision) AS measured_from,
193
+ to_timestamp((cd.measured_from / 1000)::double precision) + '00:15:00'::interval AS measured_to,
194
+ sum(cd.value) AS value,
195
+ count(cd.value) AS count_n,
196
+ 1 AS quantity
197
+ FROM flow.counters_detections cd
198
+ WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_directions_api.direction_id
199
+ FROM flow.pedestrians_directions_api))
200
+ GROUP BY cd.locations_id, cd.directions_id, (to_timestamp((cd.measured_from / 1000)::double precision)), (to_timestamp((cd.measured_from / 1000)::double precision) + '00:15:00'::interval)
201
+ ), flow AS (
202
+ SELECT flow_measurements.cube_id::character varying(50) AS location_id,
203
+ flow_measurements.sink_id::character varying(50) AS direction_id,
204
+ date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval AS measured_from,
205
+ date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval + '00:15:00'::interval AS measured_to,
206
+ sum(flow_measurements.value) AS value,
207
+ count(flow_measurements.value) AS count_n,
208
+ 3 AS quantity
209
+ FROM flow.flow_measurements
210
+ WHERE ((flow_measurements.cube_id::character varying(50)::text, flow_measurements.sink_id::character varying(50)::text) IN ( SELECT DISTINCT pedestrians_directions_api.cube_id AS location_id,
211
+ pedestrians_directions_api.direction_id
212
+ FROM flow.pedestrians_directions_api)) AND flow_measurements.category::text = 'pedestrian'::text
213
+ GROUP BY (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50)), (date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval), (date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval + '00:15:00'::interval)
214
+ ORDER BY (date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) + (date_part('minute'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))::integer / 15)::double precision * '00:15:00'::interval), (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50))
215
+ ), measurements AS (
216
+ SELECT wifi.location_id,
217
+ wifi.direction_id,
218
+ wifi.measured_from,
219
+ wifi.measured_to,
220
+ wifi.value,
221
+ wifi.count_n,
222
+ wifi.quantity
223
+ FROM wifi
224
+ UNION ALL
225
+ SELECT pyro.location_id,
226
+ pyro.direction_id,
227
+ pyro.measured_from,
228
+ pyro.measured_to,
229
+ pyro.value,
230
+ pyro.count_n,
231
+ pyro.quantity
232
+ FROM pyro
233
+ UNION ALL
234
+ SELECT flow.location_id,
235
+ flow.direction_id,
236
+ flow.measured_from,
237
+ flow.measured_to,
238
+ flow.value,
239
+ flow.count_n,
240
+ flow.quantity
241
+ FROM flow
242
+ )
243
+ SELECT measurements.measured_from,
244
+ measurements.measured_to,
245
+ pda.location_id::character varying(50) AS location_id,
246
+ measurements.direction_id,
247
+ measurements.value,
248
+ CASE
249
+ WHEN (measurements.count_n::numeric / measurements.quantity::numeric) > 1::numeric THEN 1::numeric
250
+ ELSE measurements.count_n::numeric / measurements.quantity::numeric
251
+ END AS quality
252
+ FROM measurements
253
+ LEFT JOIN flow.pedestrians_directions_api pda ON measurements.direction_id::text = pda.direction_id::text;
254
+
255
+
256
+ -- analytic.v_pedestrians_detections_daily source
257
+
258
+ CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_daily
259
+ AS WITH wifi AS (
260
+ SELECT pedestrians_wifi.location_id AS locations_id,
261
+ pedestrians_wifi.direction_id AS directions_id,
262
+ pedestrians_wifi.measured_from::date AS measured_from,
263
+ sum(pedestrians_wifi.value) AS value,
264
+ count(pedestrians_wifi.value) AS count_n,
265
+ count(pedestrians_wifi.value)::numeric / 288::numeric AS quality_ratio
266
+ FROM flow.pedestrians_wifi
267
+ GROUP BY pedestrians_wifi.location_id, pedestrians_wifi.direction_id, (pedestrians_wifi.measured_from::date)
268
+ ), pyro AS (
269
+ SELECT cd.locations_id,
270
+ lg.first_dir AS directions_id,
271
+ to_timestamp((cd.measured_from / 1000)::double precision)::date AS measured_from,
272
+ sum(cd.value) AS value,
273
+ count(cd.value) / count(DISTINCT cd.directions_id) AS count_n,
274
+ count(cd.value)::numeric / 96::numeric / count(DISTINCT cd.directions_id)::numeric AS quality_ratio
275
+ FROM flow.counters_detections cd
276
+ LEFT JOIN ( SELECT pedestrians_locations_gates.direction_id,
277
+ pedestrians_locations_gates.direction_type,
278
+ min(pedestrians_locations_gates.direction_id::text) OVER (PARTITION BY pedestrians_locations_gates.cube_id, pedestrians_locations_gates.direction_type) AS first_dir
279
+ FROM analytic.pedestrians_locations_gates) lg ON cd.directions_id::text = lg.direction_id::text
280
+ WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_locations_gates.direction_id
281
+ FROM analytic.pedestrians_locations_gates))
282
+ GROUP BY cd.locations_id, lg.first_dir, (to_timestamp((cd.measured_from / 1000)::double precision)::date)
283
+ ), flow AS (
284
+ SELECT flow_measurements.cube_id::character varying(50) AS location_id,
285
+ flow_measurements.sink_id::character varying(50) AS direction_id,
286
+ to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)::date AS measured_from,
287
+ sum(flow_measurements.value) AS value,
288
+ count(flow_measurements.value) AS count_n,
289
+ count(flow_measurements.value)::numeric / 288::numeric AS quality_ratio
290
+ FROM flow.flow_measurements
291
+ WHERE ((flow_measurements.cube_id::character varying(50)::text, flow_measurements.sink_id::character varying(50)::text) IN ( SELECT DISTINCT pedestrians_locations_gates.cube_id AS location_id,
292
+ pedestrians_locations_gates.direction_id
293
+ FROM analytic.pedestrians_locations_gates)) AND flow_measurements.category::text = 'pedestrian'::text
294
+ GROUP BY (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50)), (to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)::date)
295
+ ORDER BY (to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)::date), (flow_measurements.cube_id::character varying(50)) DESC, (flow_measurements.sink_id::character varying(50))
296
+ ), measurements AS (
297
+ SELECT pyro.locations_id,
298
+ pyro.directions_id,
299
+ pyro.measured_from,
300
+ pyro.value,
301
+ pyro.count_n,
302
+ pyro.quality_ratio
303
+ FROM pyro
304
+ UNION ALL
305
+ SELECT flow.location_id,
306
+ flow.direction_id,
307
+ flow.measured_from,
308
+ flow.value,
309
+ flow.count_n,
310
+ flow.quality_ratio
311
+ FROM flow
312
+ UNION ALL
313
+ SELECT wifi.locations_id,
314
+ wifi.directions_id,
315
+ wifi.measured_from,
316
+ wifi.value,
317
+ wifi.count_n,
318
+ wifi.quality_ratio
319
+ FROM wifi
320
+ ), calendar AS (
321
+ SELECT generate_series(min(measurements.measured_from)::timestamp with time zone, max(measurements.measured_from)::timestamp with time zone, '1 day'::interval) AS calendar
322
+ FROM measurements
323
+ ), classes AS (
324
+ SELECT calendar.calendar,
325
+ m_1.location_id,
326
+ m_1.direction_id
327
+ FROM calendar
328
+ JOIN ( SELECT DISTINCT measurements.locations_id::character varying(50) AS location_id,
329
+ measurements.directions_id::character varying(50) AS direction_id
330
+ FROM measurements) m_1 ON true
331
+ )
332
+ SELECT c.calendar,
333
+ c.location_id,
334
+ c.direction_id,
335
+ concat(c.location_id, '-', c.direction_id) AS compound_id,
336
+ COALESCE(m.value, 0::bigint) AS value,
337
+ COALESCE(m.count_n, 0::bigint) AS count_n,
338
+ COALESCE(m.quality_ratio, 0::numeric) AS quality_ratio,
339
+ CASE
340
+ WHEN c.calendar < ll.measurement_start OR c.calendar > ll.measurement_end THEN 4
341
+ WHEN COALESCE(m.quality_ratio, 0::numeric) = 0::numeric THEN 3
342
+ WHEN COALESCE(m.quality_ratio, 0::numeric) < 0.9 THEN 2
343
+ WHEN COALESCE(m.quality_ratio, 0::numeric) > 0.9 AND COALESCE(m.quality_ratio, 0::numeric) < 1::numeric THEN 1
344
+ WHEN COALESCE(m.quality_ratio, 0::numeric) >= 1::numeric THEN 0
345
+ ELSE NULL::integer
346
+ END AS quality_code,
347
+ CASE
348
+ WHEN c.calendar < ll.measurement_start OR c.calendar > ll.measurement_end THEN 'Nenainstalovaná technologie'::text
349
+ WHEN COALESCE(m.quality_ratio, 0::numeric) = 0::numeric THEN 'Bez dat (0%)'::text
350
+ WHEN COALESCE(m.quality_ratio, 0::numeric) < 0.9 THEN 'Částečná data (<90%)'::text
351
+ WHEN COALESCE(m.quality_ratio, 0::numeric) > 0.9 AND COALESCE(m.quality_ratio, 0::numeric) < 1::numeric THEN 'Nekompletní data (>90%)'::text
352
+ WHEN COALESCE(m.quality_ratio, 0::numeric) >= 1::numeric THEN 'Kompletní data (100%)'::text
353
+ ELSE NULL::text
354
+ END AS quality_status
355
+ FROM classes c
356
+ LEFT JOIN measurements m ON c.calendar = m.measured_from AND c.location_id::text = m.locations_id::text AND c.direction_id::text = m.directions_id
357
+ LEFT JOIN analytic.pedestrians_locations_list ll ON c.location_id::text = ll.cube_id::text;
358
+
359
+
360
+ -- analytic.v_pedestrians_flow_quality source
361
+
362
+ CREATE OR REPLACE VIEW analytic.v_pedestrians_flow_quality
363
+ AS WITH timeline_category AS (
364
+ SELECT DISTINCT fs.cube_id,
365
+ fs.id AS sink_id,
366
+ timeline."timestamp"
367
+ FROM flow.flow_sinks fs
368
+ LEFT JOIN ( SELECT generate_series(date_trunc('month'::text, CURRENT_DATE - '180 days'::interval)::timestamp with time zone, date_trunc('hour'::text, CURRENT_DATE::timestamp with time zone), '01:00:00'::interval) AS "timestamp") timeline ON true
369
+ ), base_table AS (
370
+ SELECT date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision)) AS start_timestamp,
371
+ flow_measurements.cube_id,
372
+ flow_measurements.sink_id,
373
+ flow_measurements.category,
374
+ count(flow_measurements.cube_id) AS count
375
+ FROM flow.flow_measurements
376
+ WHERE flow_measurements.start_timestamp::double precision >= (1000::double precision * date_part('epoch'::text, CURRENT_DATE - '210 days'::interval))
377
+ GROUP BY (date_trunc('hour'::text, to_timestamp((flow_measurements.start_timestamp / 1000)::double precision))), flow_measurements.cube_id, flow_measurements.sink_id, flow_measurements.category
378
+ ), real_nrow AS (
379
+ SELECT base_table.start_timestamp,
380
+ base_table.cube_id,
381
+ base_table.sink_id,
382
+ sum(base_table.count) AS n_row,
383
+ sum(base_table.count) FILTER (WHERE base_table.category::text = 'pedestrian'::text) AS n_row_pedestrian
384
+ FROM base_table
385
+ GROUP BY base_table.start_timestamp, base_table.cube_id, base_table.sink_id
386
+ ), expected_nrow AS (
387
+ SELECT base_table.cube_id,
388
+ base_table.sink_id,
389
+ count(DISTINCT base_table.category) * 12 AS expected_nrow,
390
+ 12 AS expected_nrow_pedestrian
391
+ FROM base_table
392
+ WHERE base_table.start_timestamp >= (CURRENT_DATE - '30 days'::interval)
393
+ GROUP BY base_table.cube_id, base_table.sink_id
394
+ )
395
+ SELECT t."timestamp",
396
+ date_trunc('month'::text, t."timestamp")::date AS month,
397
+ t.cube_id,
398
+ t.sink_id,
399
+ concat(t.cube_id, ' - ', t.sink_id) AS cube_sink,
400
+ COALESCE(r.n_row, 0::bigint::numeric) AS n_row,
401
+ COALESCE(r.n_row_pedestrian, 0::bigint::numeric) AS n_row_pedestrian,
402
+ er.expected_nrow,
403
+ er.expected_nrow_pedestrian
404
+ FROM timeline_category t
405
+ LEFT JOIN real_nrow r ON t."timestamp" = r.start_timestamp AND t.cube_id = r.cube_id AND t.sink_id = r.sink_id
406
+ LEFT JOIN expected_nrow er ON t.cube_id = er.cube_id AND t.sink_id = er.sink_id;
407
+
408
+ -- analytic.v_flow_quality source
409
+
410
+ DROP VIEW IF EXISTS analytic.v_flow_quality
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseWorker } from "@golemio/core/dist/integration-engine/workers";
2
+ export declare class CountersWorker extends BaseWorker {
3
+ private dataSourceEcoCounter;
4
+ private dataSourceEcoCounterMeasurements;
5
+ private ecoCounterTransformation;
6
+ private ecoCounterMeasurementsTransformation;
7
+ private queuePrefix;
8
+ private countersLocationsModel;
9
+ private countersDirectionsModel;
10
+ private countersDetectionsModel;
11
+ constructor();
12
+ refreshEcoCounterDataInDB: (msg: any) => Promise<void>;
13
+ updateEcoCounter: (msg: any) => Promise<void>;
14
+ }
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CountersWorker = void 0;
16
+ const index_1 = require("../schema-definitions/index");
17
+ const config_1 = require("@golemio/core/dist/integration-engine/config");
18
+ const datasources_1 = require("@golemio/core/dist/integration-engine/datasources");
19
+ const models_1 = require("@golemio/core/dist/integration-engine/models");
20
+ const workers_1 = require("@golemio/core/dist/integration-engine/workers");
21
+ const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
22
+ const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
23
+ const EcoCounterMeasurementsTransformation_1 = require("./transformations/EcoCounterMeasurementsTransformation");
24
+ const EcoCounterTransformation_1 = require("./transformations/EcoCounterTransformation");
25
+ class CountersWorker extends workers_1.BaseWorker {
26
+ constructor() {
27
+ super();
28
+ this.refreshEcoCounterDataInDB = (msg) => __awaiter(this, void 0, void 0, function* () {
29
+ const data = yield this.dataSourceEcoCounter.getAll();
30
+ const transformedData = yield this.ecoCounterTransformation.transform(data);
31
+ yield this.countersLocationsModel.save(transformedData.locationsPedestrians);
32
+ yield this.countersDirectionsModel.save(transformedData.directionsPedestrians);
33
+ const promisesPeds = transformedData.directionsPedestrians.map((p) => {
34
+ this.sendMessageToExchange("workers." + this.queuePrefix + ".updateEcoCounter", JSON.stringify({
35
+ category: "pedestrian",
36
+ directions_id: p.id,
37
+ id: p.vendor_id,
38
+ locations_id: p.locations_id,
39
+ }));
40
+ });
41
+ yield Promise.all(promisesPeds);
42
+ });
43
+ this.updateEcoCounter = (msg) => __awaiter(this, void 0, void 0, function* () {
44
+ const inputData = JSON.parse(msg.content.toString());
45
+ const locationsId = inputData.locations_id;
46
+ const directionsId = inputData.directions_id;
47
+ const category = inputData.category;
48
+ const id = inputData.id;
49
+ // EcoCounter API is actually working with local Europe/Prague time, not ISO!!!
50
+ // so we have to send local time to request.
51
+ // Furthermore, the returned dates are START of the measurement interval, so if we want measurements
52
+ // from interval between 06:00 and 07:00 UTC (which is local 07:00 - 08:00), we have to send parameters
53
+ // from=07:00 and to=07:45, because it returns all the measurements where from and to parameters are INCLUDED.
54
+ const now = moment_timezone_1.default.utc().tz("Europe/Prague");
55
+ const step = 15;
56
+ const remainder = now.minute() % step;
57
+ // rounded to nearest next 15 minutes
58
+ const nowRounded = now.clone().subtract(remainder, "minutes").seconds(0).milliseconds(0);
59
+ const strTo = nowRounded.clone().subtract(step, "minutes").format("YYYY-MM-DDTHH:mm:ss");
60
+ const strFrom = nowRounded.clone().subtract(72, "hours").format("YYYY-MM-DDTHH:mm:ss");
61
+ let url = config_1.config.datasources.BicycleCountersEcoCounterMeasurements;
62
+ url = url.replace(":id", id);
63
+ url = url.replace(":from", strFrom);
64
+ url = url.replace(":to", strTo);
65
+ url = url.replace(":step", `${step}m`);
66
+ url = url.replace(":complete", "true");
67
+ this.dataSourceEcoCounterMeasurements.setProtocolStrategy(new datasources_1.HTTPProtocolStrategy({
68
+ headers: {
69
+ Authorization: `Bearer ${config_1.config.datasources.CountersEcoCounterTokens.OICT}`,
70
+ },
71
+ json: true,
72
+ method: "GET",
73
+ url,
74
+ }));
75
+ const data = yield this.dataSourceEcoCounterMeasurements.getAll();
76
+ // pedestrians
77
+ if (category === "pedestrian") {
78
+ yield this.countersDetectionsModel.saveBySqlFunction((yield this.ecoCounterMeasurementsTransformation.transform(data)).map((x) => {
79
+ x.directions_id = directionsId;
80
+ x.locations_id = locationsId;
81
+ x.category = "pedestrian";
82
+ return x;
83
+ }), ["locations_id", "directions_id", "measured_from", "category"]);
84
+ }
85
+ });
86
+ const parser = new datasources_1.JSONDataTypeStrategy({ resultsPath: "" });
87
+ parser.setFilter((item) => item.counter !== null);
88
+ this.dataSourceEcoCounter = new datasources_1.DataSource(index_1.Counters.ecoCounter.name + "DataSource", new datasources_1.HTTPProtocolStrategy({
89
+ headers: {
90
+ Authorization: `Bearer ${config_1.config.datasources.CountersEcoCounterTokens.OICT}`,
91
+ },
92
+ method: "GET",
93
+ url: config_1.config.datasources.BicycleCountersEcoCounter,
94
+ }), parser, new golemio_validator_1.JSONSchemaValidator(index_1.Counters.ecoCounter.name + "Validator", index_1.Counters.ecoCounter.datasourceJsonSchema));
95
+ this.dataSourceEcoCounterMeasurements = new datasources_1.DataSource(index_1.Counters.ecoCounter.name + "MeasurementsDataSource", undefined, new datasources_1.JSONDataTypeStrategy({ resultsPath: "" }), new golemio_validator_1.JSONSchemaValidator(index_1.Counters.ecoCounter.name + "MeasurementsDataSource", index_1.Counters.ecoCounter.measurementsDatasourceJsonSchema));
96
+ this.ecoCounterTransformation = new EcoCounterTransformation_1.EcoCounterTransformation();
97
+ this.ecoCounterMeasurementsTransformation = new EcoCounterMeasurementsTransformation_1.EcoCounterMeasurementsTransformation();
98
+ this.countersLocationsModel = new models_1.PostgresModel(index_1.Counters.locations.name + "Model", {
99
+ outputSequelizeAttributes: index_1.Counters.locations.outputSequelizeAttributes,
100
+ pgTableName: index_1.Counters.locations.pgTableName,
101
+ pgSchema: index_1.Counters.pgSchema,
102
+ savingType: "insertOrUpdate",
103
+ }, new golemio_validator_1.JSONSchemaValidator(index_1.Counters.locations.name + "ModelValidator", index_1.Counters.locations.outputJsonSchemaObject));
104
+ this.countersDirectionsModel = new models_1.PostgresModel(index_1.Counters.directions.name + "Model", {
105
+ outputSequelizeAttributes: index_1.Counters.directions.outputSequelizeAttributes,
106
+ pgTableName: index_1.Counters.directions.pgTableName,
107
+ pgSchema: index_1.Counters.pgSchema,
108
+ savingType: "insertOrUpdate",
109
+ }, new golemio_validator_1.JSONSchemaValidator(index_1.Counters.directions.name + "ModelValidator", index_1.Counters.directions.outputJsonSchemaObject));
110
+ this.countersDetectionsModel = new models_1.PostgresModel(index_1.Counters.detections.name + "Model", {
111
+ outputSequelizeAttributes: index_1.Counters.detections.outputSequelizeAttributes,
112
+ pgTableName: index_1.Counters.detections.pgTableName,
113
+ pgSchema: index_1.Counters.pgSchema,
114
+ savingType: "insertOrUpdate",
115
+ }, new golemio_validator_1.JSONSchemaValidator(index_1.Counters.detections.name + "ModelValidator", index_1.Counters.detections.outputJsonSchemaObject));
116
+ this.queuePrefix = config_1.config.RABBIT_EXCHANGE_NAME + "." + "counters";
117
+ }
118
+ }
119
+ exports.CountersWorker = CountersWorker;
120
+ //# sourceMappingURL=CountersWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CountersWorker.js","sourceRoot":"","sources":["../../src/integration-engine/CountersWorker.ts"],"names":[],"mapp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ClC;YACI,yBAAyB,EAAE,gBAAQ,CAAC,UAAU,CAAC,yBAAyB;YACxE,WAAW,EAAE,gBAAQ,CAAC,UAAU,CAAC,WAAW;YAC5C,QAAQ,EAAE,gBAAQ,CAAC,QAAQ;YAC3B,UAAU,EAAE,gBAAgB;SAC/B,EACD,IAAI,uCAAmB,CAAC,gBAAQ,CAAC,UAAU,CAAC,IAAI,GAAG,gBAAgB,EAAE,gBAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC,CACnH,CAAC;QACF,IAAI,CAAC,uBAAuB,GAAG,IAAI,sBAAa,CAC5C,gBAAQ,CAAC,UAAU,CAAC,IAAI,GAAG,OAAO,EAClC;YACI,yBAAyB,EAAE,gBAAQ,CAAC,UAAU,CAAC,yBAAyB;YACxE,WAAW,EAAE,gBAAQ,CAAC,UAAU,CAAC,WAAW;YAC5C,QAAQ,EAAE,gBAAQ,CAAC,QAAQ;YAC3B,UAAU,EAAE,gBAAgB;SAC/B,EACD,IAAI,uCAAmB,CAAC,gBAAQ,CAAC,UAAU,CAAC,IAAI,GAAG,gBAAgB,EAAE,gBAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC,CACnH,CAAC;QAEF,IAAI,CAAC,WAAW,GAAG,eAAM,CAAC,oBAAoB,GAAG,GAAG,GAAG,UAAU,CAAC;IACtE,CAAC;CA+EJ;AAzJD,wCAyJC"}
@@ -33,12 +33,12 @@ class FlowWorker extends workers_1.BaseWorker {
33
33
  this.refreshMatViewPedestriansDetectApi = () => __awaiter(this, void 0, void 0, function* () {
34
34
  try {
35
35
  const connection = connectors_1.PostgresConnector.getConnection();
36
- yield connection.query(`REFRESH MATERIALIZED VIEW "public"."mv_pedestrians_detections_api"`, {
36
+ yield connection.query(`CALL "${index_1.Flow.pgSchema}".update_detections_data()`, {
37
37
  type: sequelize_1.default.QueryTypes.SELECT,
38
38
  });
39
39
  }
40
40
  catch (err) {
41
- throw new golemio_errors_1.CustomError("Error while REFRESH MATERIALIZED VIEW.", true, this.constructor.name, 5050, err);
41
+ throw new golemio_errors_1.CustomError("Error while aggregating flow data.", true, this.constructor.name, 5050, err);
42
42
  }
43
43
  });
44
44
  this.getHistoryIntervalFromMsg = (msg) => {
@@ -399,21 +399,25 @@ class FlowWorker extends workers_1.BaseWorker {
399
399
  };
400
400
  this.flowMeasurementModel = new models_1.PostgresModel(index_1.Flow.detections.name + "Model", {
401
401
  outputSequelizeAttributes: index_1.Flow.detections.outputSequelizeAttributes,
402
+ pgSchema: index_1.Flow.pgSchema,
402
403
  pgTableName: index_1.Flow.detections.pgTableName,
403
404
  savingType: "insertOrUpdate",
404
405
  }, null);
405
406
  this.flowODMeasurementModel = new models_1.PostgresModel(index_1.Flow.detectionsOD.name + "Model", {
406
407
  outputSequelizeAttributes: index_1.Flow.detectionsOD.outputSequelizeAttributes,
408
+ pgSchema: index_1.Flow.pgSchema,
407
409
  pgTableName: index_1.Flow.detectionsOD.pgTableName,
408
410
  savingType: "insertOrUpdate",
409
411
  }, null);
410
412
  this.flowCubesModel = new models_1.PostgresModel(index_1.Flow.cubes.name + "Model", {
411
413
  outputSequelizeAttributes: index_1.Flow.cubes.outputSequelizeAttributes,
414
+ pgSchema: index_1.Flow.pgSchema,
412
415
  pgTableName: index_1.Flow.cubes.pgTableName,
413
416
  savingType: "insertOrUpdate",
414
417
  }, null);
415
418
  this.flowSinksModel = new models_1.PostgresModel(index_1.Flow.sinks.name + "Model", {
416
419
  outputSequelizeAttributes: index_1.Flow.sinks.outputSequelizeAttributes,
420
+ pgSchema: index_1.Flow.pgSchema,
417
421
  pgTableName: index_1.Flow.sinks.pgTableName,
418
422
  savingType: "insertOrUpdate",
419
423
  }, null);