@golemio/flow 1.0.10 → 1.0.11-dev.668805666

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', '20221017120142-flow_v_pedestrians_detections_api_join_condition-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', '20221017120142-flow_v_pedestrians_detections_api_join_condition-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,77 @@
1
+ CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_api
2
+ AS WITH wifi AS (
3
+ SELECT pedestrians_wifi.location_id,
4
+ pedestrians_wifi.direction_id,
5
+ 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,
6
+ 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,
7
+ sum(pedestrians_wifi.value) AS value,
8
+ count(pedestrians_wifi.value) AS count_n,
9
+ 3 AS quantity
10
+ FROM flow.pedestrians_wifi
11
+ 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)
12
+ ), pyro AS (
13
+ SELECT cd.locations_id AS location_id,
14
+ cd.directions_id AS direction_id,
15
+ to_timestamp((cd.measured_from / 1000)::double precision) AS measured_from,
16
+ to_timestamp((cd.measured_from / 1000)::double precision) + '00:15:00'::interval AS measured_to,
17
+ sum(cd.value) AS value,
18
+ count(cd.value) AS count_n,
19
+ 1 AS quantity
20
+ FROM flow.counters_detections cd
21
+ WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_directions_api.direction_id
22
+ FROM flow.pedestrians_directions_api))
23
+ 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)
24
+ ), flow AS (
25
+ SELECT flow_measurements.cube_id::character varying(50) AS location_id,
26
+ flow_measurements.sink_id::character varying(50) AS direction_id,
27
+ 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,
28
+ 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,
29
+ sum(flow_measurements.value) AS value,
30
+ count(flow_measurements.value) AS count_n,
31
+ 3 AS quantity
32
+ FROM flow.flow_measurements
33
+ 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,
34
+ pedestrians_directions_api.direction_id
35
+ FROM flow.pedestrians_directions_api)) AND flow_measurements.category::text = 'pedestrian'::text
36
+ 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)
37
+ 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))
38
+ ), measurements AS (
39
+ SELECT wifi.location_id,
40
+ wifi.direction_id,
41
+ wifi.measured_from,
42
+ wifi.measured_to,
43
+ wifi.value,
44
+ wifi.count_n,
45
+ wifi.quantity
46
+ FROM wifi
47
+ UNION ALL
48
+ SELECT pyro.location_id,
49
+ pyro.direction_id,
50
+ pyro.measured_from,
51
+ pyro.measured_to,
52
+ pyro.value,
53
+ pyro.count_n,
54
+ pyro.quantity
55
+ FROM pyro
56
+ UNION ALL
57
+ SELECT flow.location_id,
58
+ flow.direction_id,
59
+ flow.measured_from,
60
+ flow.measured_to,
61
+ flow.value,
62
+ flow.count_n,
63
+ flow.quantity
64
+ FROM flow
65
+ )
66
+ SELECT measurements.measured_from,
67
+ measurements.measured_to,
68
+ pda.location_id::character varying(50) AS location_id,
69
+ measurements.direction_id,
70
+ measurements.value,
71
+ CASE
72
+ WHEN (measurements.count_n::numeric / measurements.quantity::numeric) > 1::numeric THEN 1::numeric
73
+ ELSE measurements.count_n::numeric / measurements.quantity::numeric
74
+ END AS quality
75
+ FROM measurements
76
+ LEFT JOIN flow.pedestrians_directions_api pda ON measurements.direction_id::text = pda.direction_id::text;
77
+
@@ -0,0 +1,77 @@
1
+ CREATE OR REPLACE VIEW analytic.v_pedestrians_detections_api
2
+ AS WITH wifi AS (
3
+ SELECT pedestrians_wifi.location_id,
4
+ pedestrians_wifi.direction_id,
5
+ 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,
6
+ 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,
7
+ sum(pedestrians_wifi.value) AS value,
8
+ count(pedestrians_wifi.value) AS count_n,
9
+ 3 AS quantity
10
+ FROM flow.pedestrians_wifi
11
+ 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)
12
+ ), pyro AS (
13
+ SELECT cd.locations_id AS location_id,
14
+ cd.directions_id AS direction_id,
15
+ to_timestamp((cd.measured_from / 1000)::double precision) AS measured_from,
16
+ to_timestamp((cd.measured_from / 1000)::double precision) + '00:15:00'::interval AS measured_to,
17
+ sum(cd.value) AS value,
18
+ count(cd.value) AS count_n,
19
+ 1 AS quantity
20
+ FROM flow.counters_detections cd
21
+ WHERE cd.category::text = 'pedestrian'::text AND (cd.directions_id::text IN ( SELECT DISTINCT pedestrians_directions_api.direction_id
22
+ FROM flow.pedestrians_directions_api))
23
+ 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)
24
+ ), flow AS (
25
+ SELECT flow_measurements.cube_id::character varying(50) AS location_id,
26
+ flow_measurements.sink_id::character varying(50) AS direction_id,
27
+ 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,
28
+ 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,
29
+ sum(flow_measurements.value) AS value,
30
+ count(flow_measurements.value) AS count_n,
31
+ 3 AS quantity
32
+ FROM flow.flow_measurements
33
+ 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,
34
+ pedestrians_directions_api.direction_id
35
+ FROM flow.pedestrians_directions_api)) AND flow_measurements.category::text = 'pedestrian'::text
36
+ 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)
37
+ 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))
38
+ ), measurements AS (
39
+ SELECT wifi.location_id,
40
+ wifi.direction_id,
41
+ wifi.measured_from,
42
+ wifi.measured_to,
43
+ wifi.value,
44
+ wifi.count_n,
45
+ wifi.quantity
46
+ FROM wifi
47
+ UNION ALL
48
+ SELECT pyro.location_id,
49
+ pyro.direction_id,
50
+ pyro.measured_from,
51
+ pyro.measured_to,
52
+ pyro.value,
53
+ pyro.count_n,
54
+ pyro.quantity
55
+ FROM pyro
56
+ UNION ALL
57
+ SELECT flow.location_id,
58
+ flow.direction_id,
59
+ flow.measured_from,
60
+ flow.measured_to,
61
+ flow.value,
62
+ flow.count_n,
63
+ flow.quantity
64
+ FROM flow
65
+ )
66
+ SELECT measurements.measured_from,
67
+ measurements.measured_to,
68
+ pda.location_id::character varying(50) AS location_id,
69
+ measurements.direction_id,
70
+ measurements.value,
71
+ CASE
72
+ WHEN (measurements.count_n::numeric / measurements.quantity::numeric) > 1::numeric THEN 1::numeric
73
+ ELSE measurements.count_n::numeric / measurements.quantity::numeric
74
+ END AS quality
75
+ FROM measurements
76
+ LEFT JOIN flow.pedestrians_directions_api pda ON measurements.direction_id::text = pda.direction_id::text and measurements.location_id = pda.cube_id;
77
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/flow",
3
- "version": "1.0.10",
3
+ "version": "1.0.11-dev.668805666",
4
4
  "description": "Golemio Flow Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",