@golemio/flow 1.2.8-dev.1018144829 → 1.2.8-dev.1030067355
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dbm;
|
|
4
|
+
var type;
|
|
5
|
+
var seed;
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var path = require('path');
|
|
8
|
+
var Promise;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* We receive the dbmigrate dependency from dbmigrate initially.
|
|
12
|
+
* This enables us to not have to rely on NODE_PATH.
|
|
13
|
+
*/
|
|
14
|
+
exports.setup = function(options, seedLink) {
|
|
15
|
+
dbm = options.dbmigrate;
|
|
16
|
+
type = dbm.dataType;
|
|
17
|
+
seed = seedLink;
|
|
18
|
+
Promise = options.Promise;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.up = function(db) {
|
|
22
|
+
var filePath = path.join(__dirname, 'sqls', '20231008165359-uklid20231008-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', '20231008165359-uklid20231008-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,296 @@
|
|
|
1
|
+
-- analytic.v_pedestrians_detections_api source
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_api
|
|
4
|
+
AS WITH wifi AS (
|
|
5
|
+
SELECT pedestrians_wifi.location_id,
|
|
6
|
+
pedestrians_wifi.direction_id,
|
|
7
|
+
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,
|
|
8
|
+
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,
|
|
9
|
+
sum(pedestrians_wifi.value) AS value,
|
|
10
|
+
count(pedestrians_wifi.value) AS count_n,
|
|
11
|
+
3 AS quantity
|
|
12
|
+
FROM flow.pedestrians_wifi
|
|
13
|
+
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)
|
|
14
|
+
), pyro AS (
|
|
15
|
+
SELECT cd.locations_id AS location_id,
|
|
16
|
+
cd.directions_id AS direction_id,
|
|
17
|
+
cd.measured_from,
|
|
18
|
+
cd.measured_from + '00:15:00'::interval AS measured_to,
|
|
19
|
+
sum(cd.value) AS value,
|
|
20
|
+
count(cd.value) AS count_n,
|
|
21
|
+
1 AS quantity
|
|
22
|
+
FROM flow.counters_detections cd
|
|
23
|
+
WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_directions_api.direction_id
|
|
24
|
+
FROM flow.pedestrians_directions_api))
|
|
25
|
+
GROUP BY cd.locations_id, cd.directions_id, cd.measured_from, (cd.measured_from + '00:15:00'::interval)
|
|
26
|
+
), flow AS (
|
|
27
|
+
SELECT flow_measurements.cube_id::character varying(50) AS location_id,
|
|
28
|
+
flow_measurements.sink_id::character varying(50) AS direction_id,
|
|
29
|
+
date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval AS measured_from,
|
|
30
|
+
date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval + '00:15:00'::interval AS measured_to,
|
|
31
|
+
sum(flow_measurements.value) AS value,
|
|
32
|
+
count(flow_measurements.value) AS count_n,
|
|
33
|
+
3 AS quantity
|
|
34
|
+
FROM flow.flow_measurements
|
|
35
|
+
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,
|
|
36
|
+
pedestrians_directions_api.direction_id
|
|
37
|
+
FROM flow.pedestrians_directions_api)) AND flow_measurements.category::text = 'pedestrian'::text
|
|
38
|
+
GROUP BY (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50)), (date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval), (date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval + '00:15:00'::interval)
|
|
39
|
+
ORDER BY (date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval), (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50))
|
|
40
|
+
), measurements AS (
|
|
41
|
+
SELECT wifi.location_id,
|
|
42
|
+
wifi.direction_id,
|
|
43
|
+
wifi.measured_from,
|
|
44
|
+
wifi.measured_to,
|
|
45
|
+
wifi.value,
|
|
46
|
+
wifi.count_n,
|
|
47
|
+
wifi.quantity
|
|
48
|
+
FROM wifi
|
|
49
|
+
UNION ALL
|
|
50
|
+
SELECT pyro.location_id,
|
|
51
|
+
pyro.direction_id,
|
|
52
|
+
pyro.measured_from,
|
|
53
|
+
pyro.measured_to,
|
|
54
|
+
pyro.value,
|
|
55
|
+
pyro.count_n,
|
|
56
|
+
pyro.quantity
|
|
57
|
+
FROM pyro
|
|
58
|
+
UNION ALL
|
|
59
|
+
SELECT flow.location_id,
|
|
60
|
+
flow.direction_id,
|
|
61
|
+
flow.measured_from,
|
|
62
|
+
flow.measured_to,
|
|
63
|
+
flow.value,
|
|
64
|
+
flow.count_n,
|
|
65
|
+
flow.quantity
|
|
66
|
+
FROM flow
|
|
67
|
+
)
|
|
68
|
+
SELECT measurements.measured_from,
|
|
69
|
+
measurements.measured_to,
|
|
70
|
+
pda.location_id::character varying(50) AS location_id,
|
|
71
|
+
measurements.direction_id,
|
|
72
|
+
measurements.value,
|
|
73
|
+
CASE
|
|
74
|
+
WHEN (measurements.count_n::numeric / measurements.quantity::numeric) > 1::numeric THEN 1::numeric
|
|
75
|
+
ELSE measurements.count_n::numeric / measurements.quantity::numeric
|
|
76
|
+
END AS quality
|
|
77
|
+
FROM measurements
|
|
78
|
+
LEFT JOIN flow.pedestrians_directions_api pda ON measurements.direction_id::text = pda.direction_id::text AND measurements.location_id::text = pda.cube_id::text;
|
|
79
|
+
-- analytic.v_pedestrians_flow_quality source
|
|
80
|
+
|
|
81
|
+
CREATE OR REPLACE VIEW analytic.v_pedestrians_flow_quality
|
|
82
|
+
AS WITH timeline_category AS (
|
|
83
|
+
SELECT DISTINCT fs.cube_id,
|
|
84
|
+
fs.id AS sink_id,
|
|
85
|
+
timeline."timestamp"
|
|
86
|
+
FROM flow.flow_sinks fs
|
|
87
|
+
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
|
|
88
|
+
), real_nrow AS (
|
|
89
|
+
SELECT date_trunc('hour'::text, flow_measurements.start_timestamp) AS start_timestamp,
|
|
90
|
+
flow_measurements.cube_id,
|
|
91
|
+
flow_measurements.sink_id,
|
|
92
|
+
count(*) AS n_row,
|
|
93
|
+
count(*) FILTER (WHERE flow_measurements.category::text = 'pedestrian'::text) AS n_row_pedestrian
|
|
94
|
+
FROM flow.flow_measurements
|
|
95
|
+
WHERE EXTRACT(epoch FROM flow_measurements.start_timestamp)::double precision >= (1000::double precision * date_part('epoch'::text, CURRENT_DATE - '210 days'::interval))
|
|
96
|
+
GROUP BY (date_trunc('hour'::text, flow_measurements.start_timestamp)), flow_measurements.cube_id, flow_measurements.sink_id
|
|
97
|
+
)
|
|
98
|
+
SELECT t."timestamp",
|
|
99
|
+
date_trunc('month'::text, t."timestamp")::date AS month,
|
|
100
|
+
t.cube_id,
|
|
101
|
+
t.sink_id,
|
|
102
|
+
concat(t.cube_id, ' - ', t.sink_id) AS cube_sink,
|
|
103
|
+
COALESCE(r.n_row::numeric, 0::bigint::numeric) AS n_row,
|
|
104
|
+
COALESCE(r.n_row_pedestrian::numeric, 0::bigint::numeric) AS n_row_pedestrian,
|
|
105
|
+
108::bigint AS expected_nrow,
|
|
106
|
+
12 AS expected_nrow_pedestrian
|
|
107
|
+
FROM timeline_category t
|
|
108
|
+
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;
|
|
109
|
+
|
|
110
|
+
-- analytic.v_pedestrians_detections_daily source
|
|
111
|
+
|
|
112
|
+
CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_daily
|
|
113
|
+
AS WITH wifi AS (
|
|
114
|
+
SELECT pedestrians_wifi.location_id AS locations_id,
|
|
115
|
+
pedestrians_wifi.direction_id AS directions_id,
|
|
116
|
+
pedestrians_wifi.measured_from::date AS measured_from,
|
|
117
|
+
sum(pedestrians_wifi.value) AS value,
|
|
118
|
+
count(pedestrians_wifi.value) AS count_n,
|
|
119
|
+
count(pedestrians_wifi.value)::numeric / 288::numeric AS quality_ratio
|
|
120
|
+
FROM flow.pedestrians_wifi
|
|
121
|
+
GROUP BY pedestrians_wifi.location_id, pedestrians_wifi.direction_id, (pedestrians_wifi.measured_from::date)
|
|
122
|
+
), pyro AS (
|
|
123
|
+
SELECT cd.locations_id,
|
|
124
|
+
lg.first_dir AS directions_id,
|
|
125
|
+
cd.measured_from::date AS measured_from,
|
|
126
|
+
sum(cd.value) AS value,
|
|
127
|
+
count(cd.value) / count(DISTINCT cd.directions_id) AS count_n,
|
|
128
|
+
count(cd.value)::numeric / 96::numeric / count(DISTINCT cd.directions_id)::numeric AS quality_ratio
|
|
129
|
+
FROM flow.counters_detections cd
|
|
130
|
+
LEFT JOIN ( SELECT pedestrians_locations_gates.direction_id,
|
|
131
|
+
pedestrians_locations_gates.direction_type,
|
|
132
|
+
min(pedestrians_locations_gates.direction_id::text) OVER (PARTITION BY pedestrians_locations_gates.cube_id, pedestrians_locations_gates.direction_type) AS first_dir
|
|
133
|
+
FROM analytic.pedestrians_locations_gates) lg ON cd.directions_id::text = lg.direction_id::text
|
|
134
|
+
WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_locations_gates.direction_id
|
|
135
|
+
FROM analytic.pedestrians_locations_gates))
|
|
136
|
+
GROUP BY cd.locations_id, lg.first_dir, (cd.measured_from::date)
|
|
137
|
+
), flow AS (
|
|
138
|
+
SELECT flow_measurements.cube_id::character varying(50) AS location_id,
|
|
139
|
+
flow_measurements.sink_id::character varying(50) AS direction_id,
|
|
140
|
+
flow_measurements.start_timestamp::date AS measured_from,
|
|
141
|
+
sum(flow_measurements.value) AS value,
|
|
142
|
+
count(flow_measurements.value) AS count_n,
|
|
143
|
+
count(flow_measurements.value)::numeric / 288::numeric AS quality_ratio
|
|
144
|
+
FROM flow.flow_measurements
|
|
145
|
+
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,
|
|
146
|
+
pedestrians_locations_gates.direction_id
|
|
147
|
+
FROM analytic.pedestrians_locations_gates)) AND flow_measurements.category::text = 'pedestrian'::text
|
|
148
|
+
GROUP BY (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50)), (flow_measurements.start_timestamp::date)
|
|
149
|
+
ORDER BY (flow_measurements.start_timestamp::date), (flow_measurements.cube_id::character varying(50)) DESC, (flow_measurements.sink_id::character varying(50))
|
|
150
|
+
), measurements AS (
|
|
151
|
+
SELECT pyro.locations_id,
|
|
152
|
+
pyro.directions_id,
|
|
153
|
+
pyro.measured_from,
|
|
154
|
+
pyro.value,
|
|
155
|
+
pyro.count_n,
|
|
156
|
+
pyro.quality_ratio
|
|
157
|
+
FROM pyro
|
|
158
|
+
UNION ALL
|
|
159
|
+
SELECT flow.location_id,
|
|
160
|
+
flow.direction_id,
|
|
161
|
+
flow.measured_from,
|
|
162
|
+
flow.value,
|
|
163
|
+
flow.count_n,
|
|
164
|
+
flow.quality_ratio
|
|
165
|
+
FROM flow
|
|
166
|
+
UNION ALL
|
|
167
|
+
SELECT wifi.locations_id,
|
|
168
|
+
wifi.directions_id,
|
|
169
|
+
wifi.measured_from,
|
|
170
|
+
wifi.value,
|
|
171
|
+
wifi.count_n,
|
|
172
|
+
wifi.quality_ratio
|
|
173
|
+
FROM wifi
|
|
174
|
+
), calendar AS (
|
|
175
|
+
SELECT generate_series(min(measurements.measured_from)::timestamp with time zone, max(measurements.measured_from)::timestamp with time zone, '1 day'::interval) AS calendar
|
|
176
|
+
FROM measurements
|
|
177
|
+
), classes AS (
|
|
178
|
+
SELECT calendar.calendar,
|
|
179
|
+
m_1.location_id,
|
|
180
|
+
m_1.direction_id
|
|
181
|
+
FROM calendar
|
|
182
|
+
JOIN ( SELECT DISTINCT measurements.locations_id::character varying(50) AS location_id,
|
|
183
|
+
measurements.directions_id::character varying(50) AS direction_id
|
|
184
|
+
FROM measurements) m_1 ON true
|
|
185
|
+
)
|
|
186
|
+
SELECT c.calendar,
|
|
187
|
+
c.location_id,
|
|
188
|
+
c.direction_id,
|
|
189
|
+
concat(c.location_id, '-', c.direction_id) AS compound_id,
|
|
190
|
+
COALESCE(m.value, 0::bigint) AS value,
|
|
191
|
+
COALESCE(m.count_n, 0::bigint) AS count_n,
|
|
192
|
+
COALESCE(m.quality_ratio, 0::numeric) AS quality_ratio,
|
|
193
|
+
CASE
|
|
194
|
+
WHEN c.calendar < ll.measurement_start OR c.calendar > ll.measurement_end THEN 4
|
|
195
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) = 0::numeric THEN 3
|
|
196
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) < 0.9 THEN 2
|
|
197
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) > 0.9 AND COALESCE(m.quality_ratio, 0::numeric) < 1::numeric THEN 1
|
|
198
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) >= 1::numeric THEN 0
|
|
199
|
+
ELSE NULL::integer
|
|
200
|
+
END AS quality_code,
|
|
201
|
+
CASE
|
|
202
|
+
WHEN c.calendar < ll.measurement_start OR c.calendar > ll.measurement_end THEN 'Nenainstalovaná technologie'::text
|
|
203
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) = 0::numeric THEN 'Bez dat (0%)'::text
|
|
204
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) < 0.9 THEN 'Částečná data (<90%)'::text
|
|
205
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) > 0.9 AND COALESCE(m.quality_ratio, 0::numeric) < 1::numeric THEN 'Nekompletní data (>90%)'::text
|
|
206
|
+
WHEN COALESCE(m.quality_ratio, 0::numeric) >= 1::numeric THEN 'Kompletní data (100%)'::text
|
|
207
|
+
ELSE NULL::text
|
|
208
|
+
END AS quality_status
|
|
209
|
+
FROM classes c
|
|
210
|
+
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
|
|
211
|
+
LEFT JOIN analytic.pedestrians_locations_list ll ON c.location_id::text = ll.cube_id::text;
|
|
212
|
+
|
|
213
|
+
-- analytic.v_pedestrians_detections_15min source
|
|
214
|
+
|
|
215
|
+
CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_15min
|
|
216
|
+
AS WITH wifi AS (
|
|
217
|
+
SELECT pedestrians_wifi.location_id AS locations_id,
|
|
218
|
+
pedestrians_wifi.direction_id AS directions_id,
|
|
219
|
+
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,
|
|
220
|
+
sum(pedestrians_wifi.value) AS value,
|
|
221
|
+
count(pedestrians_wifi.value) AS count_n
|
|
222
|
+
FROM flow.pedestrians_wifi
|
|
223
|
+
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)
|
|
224
|
+
), pyro AS (
|
|
225
|
+
SELECT cd.locations_id,
|
|
226
|
+
lg.first_dir AS directions_id,
|
|
227
|
+
cd.measured_from,
|
|
228
|
+
sum(cd.value) AS value,
|
|
229
|
+
count(cd.value) AS count_n
|
|
230
|
+
FROM flow.counters_detections cd
|
|
231
|
+
LEFT JOIN ( SELECT pedestrians_locations_gates.direction_id,
|
|
232
|
+
pedestrians_locations_gates.direction_type,
|
|
233
|
+
min(pedestrians_locations_gates.direction_id::text) OVER (PARTITION BY pedestrians_locations_gates.cube_id, pedestrians_locations_gates.direction_type) AS first_dir
|
|
234
|
+
FROM analytic.pedestrians_locations_gates) lg ON cd.directions_id::text = lg.direction_id::text
|
|
235
|
+
WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_locations_gates.direction_id
|
|
236
|
+
FROM analytic.pedestrians_locations_gates))
|
|
237
|
+
GROUP BY cd.locations_id, lg.first_dir, cd.measured_from
|
|
238
|
+
), flow AS (
|
|
239
|
+
SELECT flow_measurements.cube_id::character varying(50) AS location_id,
|
|
240
|
+
flow_measurements.sink_id::character varying(50) AS direction_id,
|
|
241
|
+
date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval AS measured_from,
|
|
242
|
+
sum(flow_measurements.value) AS value,
|
|
243
|
+
count(flow_measurements.value) AS count_n
|
|
244
|
+
FROM flow.flow_measurements
|
|
245
|
+
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,
|
|
246
|
+
pedestrians_locations_gates.direction_id
|
|
247
|
+
FROM analytic.pedestrians_locations_gates)) AND flow_measurements.category::text = 'pedestrian'::text
|
|
248
|
+
GROUP BY (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50)), (date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval)
|
|
249
|
+
ORDER BY (date_trunc('hour'::text, flow_measurements.start_timestamp) + (date_part('minute'::text, flow_measurements.start_timestamp)::integer / 15)::double precision * '00:15:00'::interval), (flow_measurements.cube_id::character varying(50)), (flow_measurements.sink_id::character varying(50))
|
|
250
|
+
), measurements AS (
|
|
251
|
+
SELECT wifi.locations_id,
|
|
252
|
+
wifi.directions_id,
|
|
253
|
+
wifi.measured_from,
|
|
254
|
+
wifi.value,
|
|
255
|
+
wifi.count_n
|
|
256
|
+
FROM wifi
|
|
257
|
+
UNION ALL
|
|
258
|
+
SELECT pyro.locations_id,
|
|
259
|
+
pyro.directions_id,
|
|
260
|
+
pyro.measured_from,
|
|
261
|
+
pyro.value,
|
|
262
|
+
pyro.count_n
|
|
263
|
+
FROM pyro
|
|
264
|
+
UNION ALL
|
|
265
|
+
SELECT flow.location_id,
|
|
266
|
+
flow.direction_id,
|
|
267
|
+
flow.measured_from,
|
|
268
|
+
flow.value,
|
|
269
|
+
flow.count_n
|
|
270
|
+
FROM flow
|
|
271
|
+
), calendar AS (
|
|
272
|
+
SELECT generate_series(min(measurements.measured_from), max(measurements.measured_from), '00:15:00'::interval) AS calendar
|
|
273
|
+
FROM measurements
|
|
274
|
+
), classes AS (
|
|
275
|
+
SELECT calendar.calendar,
|
|
276
|
+
m_1.location_id,
|
|
277
|
+
m_1.direction_id
|
|
278
|
+
FROM calendar
|
|
279
|
+
JOIN ( SELECT DISTINCT measurements.locations_id::character varying(50) AS location_id,
|
|
280
|
+
measurements.directions_id::character varying(50) AS direction_id
|
|
281
|
+
FROM measurements) m_1 ON true
|
|
282
|
+
)
|
|
283
|
+
SELECT c.calendar,
|
|
284
|
+
date_trunc('hour'::text, c.calendar) AS calendar_hour,
|
|
285
|
+
c.calendar::date AS calendar_date,
|
|
286
|
+
ll.measurement_start,
|
|
287
|
+
COALESCE(ll.measurement_end, now()::date::timestamp with time zone) AS measurement_end,
|
|
288
|
+
c.location_id,
|
|
289
|
+
c.direction_id,
|
|
290
|
+
concat(c.location_id, '-', c.direction_id) AS compound_id,
|
|
291
|
+
COALESCE(m.value, 0::bigint) AS value,
|
|
292
|
+
COALESCE(m.count_n, 0::bigint) AS count_n
|
|
293
|
+
FROM classes c
|
|
294
|
+
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
|
|
295
|
+
LEFT JOIN analytic.pedestrians_locations_list ll ON c.location_id::text = ll.cube_id::text
|
|
296
|
+
WHERE c.calendar >= ll.measurement_start AND c.calendar <= COALESCE(ll.measurement_end, now()::date::timestamp with time zone);
|