@golemio/waze-tt 1.1.10 → 1.1.11-dev.1032945670
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', '20231011060636-uklid20231011-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', '20231011060636-uklid20231011-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,138 @@
|
|
|
1
|
+
-- analytic.lkpr_dashboard_route_names definition
|
|
2
|
+
|
|
3
|
+
CREATE TABLE analytic.lkpr_dashboard_route_names (
|
|
4
|
+
route_type text NULL,
|
|
5
|
+
route_num text NULL,
|
|
6
|
+
route_group_name text NULL,
|
|
7
|
+
order_idx int4 NULL
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
-- analytic.v_instatntomtom_days source
|
|
11
|
+
|
|
12
|
+
CREATE OR REPLACE VIEW analytic.v_instatntomtom_days
|
|
13
|
+
AS SELECT to_char(to_timestamp((wrl.update_time / 1000)::double precision), 'yyyy-mm-dd'::text) AS day_index,
|
|
14
|
+
wrl.route_id,
|
|
15
|
+
round(avg(wrl."time"::numeric / wrl.historic_time::numeric), 2) AS t_index_value,
|
|
16
|
+
count(*) AS t_index_count
|
|
17
|
+
FROM wazett.wazett_route_lives wrl
|
|
18
|
+
WHERE to_timestamp((wrl.update_time / 1000)::double precision)::time without time zone >= '05:00:00'::time without time zone AND to_timestamp((wrl.update_time / 1000)::double precision)::time without time zone <= '21:00:00'::time without time zone
|
|
19
|
+
GROUP BY (to_char(to_timestamp((wrl.update_time / 1000)::double precision), 'yyyy-mm-dd'::text)), wrl.route_id;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
-- analytic.v_lkpr_route_details source
|
|
23
|
+
|
|
24
|
+
CREATE OR REPLACE VIEW analytic.v_lkpr_route_details
|
|
25
|
+
AS SELECT re.id,
|
|
26
|
+
re.name,
|
|
27
|
+
re.route_code,
|
|
28
|
+
re.route_name,
|
|
29
|
+
re.from_name,
|
|
30
|
+
re.to_name,
|
|
31
|
+
re.route_type,
|
|
32
|
+
re.route_num,
|
|
33
|
+
re.route_variant,
|
|
34
|
+
CASE
|
|
35
|
+
WHEN re.route_variant = 'A1'::text THEN 'Na letiště'::text
|
|
36
|
+
WHEN re.route_variant = 'B1'::text THEN 'Z letiště'::text
|
|
37
|
+
ELSE 'Ostatní'::text
|
|
38
|
+
END AS direction,
|
|
39
|
+
drn.route_group_name,
|
|
40
|
+
drn.order_idx
|
|
41
|
+
FROM ( SELECT rc.id,
|
|
42
|
+
rc.name,
|
|
43
|
+
rc.route_code,
|
|
44
|
+
rc.route_name,
|
|
45
|
+
rc.from_name,
|
|
46
|
+
rc.to_name,
|
|
47
|
+
split_part(rc.route_code, '-'::text, 1) AS route_type,
|
|
48
|
+
split_part(rc.route_code, '-'::text, 2) AS route_num,
|
|
49
|
+
split_part(rc.route_code, '-'::text, 3) AS route_variant
|
|
50
|
+
FROM ( SELECT r.id,
|
|
51
|
+
r.name,
|
|
52
|
+
split_part(r.name, ' '::text, 1) AS route_code,
|
|
53
|
+
"substring"(r.name, "position"(r.name, ' '::text) + 1) AS route_name,
|
|
54
|
+
r.from_name,
|
|
55
|
+
r.to_name
|
|
56
|
+
FROM wazett.wazett_routes r
|
|
57
|
+
WHERE r.feed_id = 1) rc) re
|
|
58
|
+
LEFT JOIN analytic.lkpr_dashboard_route_names drn ON re.route_type = drn.route_type AND re.route_num = drn.route_num
|
|
59
|
+
ORDER BY drn.order_idx;
|
|
60
|
+
|
|
61
|
+
-- public.v_lkpr_export source
|
|
62
|
+
|
|
63
|
+
CREATE OR REPLACE VIEW public.v_lkpr_export
|
|
64
|
+
AS SELECT COALESCE(vrd.id, wrl.route_id) AS route_id,
|
|
65
|
+
vrd.name,
|
|
66
|
+
vrd.route_name,
|
|
67
|
+
vrd.from_name,
|
|
68
|
+
vrd.to_name,
|
|
69
|
+
vrd.route_num,
|
|
70
|
+
vrd.direction,
|
|
71
|
+
vrd.order_idx,
|
|
72
|
+
to_timestamp((wrl.update_time / 1000)::double precision) AS update_time,
|
|
73
|
+
wrl."time" AS actual_time,
|
|
74
|
+
round(wrl.length::numeric * 3.6 / wrl."time"::numeric) AS actual_speed,
|
|
75
|
+
wrl.historic_time,
|
|
76
|
+
round(wrl.length::numeric * 3.6 / wrl.historic_time::numeric) AS historic_speed,
|
|
77
|
+
wrl.length
|
|
78
|
+
FROM analytic.v_lkpr_route_details vrd
|
|
79
|
+
FULL JOIN wazett.wazett_route_lives wrl ON vrd.id = wrl.route_id
|
|
80
|
+
WHERE vrd.name ~~ 'TN-%'::text OR vrd.route_code ~~ 'TN-%'::text;
|
|
81
|
+
|
|
82
|
+
-- analytic.v_sck_route_details source
|
|
83
|
+
|
|
84
|
+
CREATE OR REPLACE VIEW analytic.v_sck_route_details
|
|
85
|
+
AS SELECT DISTINCT ON ((wazett_routes.name::json ->> 'project'::text), (wazett_routes.name::json ->> 'route number'::text), (wazett_routes.name::json ->> 'dir'::text)) wazett_routes.id,
|
|
86
|
+
concat(wazett_routes.name::json ->> 'route number'::text, ' ', wazett_routes.name::json ->> 'name'::text) AS name,
|
|
87
|
+
false AS section,
|
|
88
|
+
CASE
|
|
89
|
+
WHEN (wazett_routes.name::json ->> 'dir'::text) = 'Tam'::text THEN false
|
|
90
|
+
ELSE true
|
|
91
|
+
END AS reverse_direction,
|
|
92
|
+
wazett_routes.from_name,
|
|
93
|
+
wazett_routes.to_name,
|
|
94
|
+
wazett_routes.name::json ->> 'route number'::text AS poradi
|
|
95
|
+
FROM wazett.wazett_routes
|
|
96
|
+
WHERE wazett_routes.feed_id = 7 AND wazett_routes.name ~~ '{%'::text AND (wazett_routes.name::json ->> 'project'::text) = 'IPR SčK'::text
|
|
97
|
+
ORDER BY (wazett_routes.name::json ->> 'project'::text), (wazett_routes.name::json ->> 'route number'::text), (wazett_routes.name::json ->> 'dir'::text), wazett_routes.created_at DESC;
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
-- analytic.v_sck_route_live source
|
|
101
|
+
|
|
102
|
+
CREATE OR REPLACE VIEW analytic.v_sck_route_live
|
|
103
|
+
AS SELECT wrl.route_id,
|
|
104
|
+
wrl.update_time,
|
|
105
|
+
wrl."time",
|
|
106
|
+
wrl.length,
|
|
107
|
+
wrl.historic_time,
|
|
108
|
+
wrl.jam_level,
|
|
109
|
+
wrl.create_batch_id,
|
|
110
|
+
wrl.created_at,
|
|
111
|
+
wrl.created_by,
|
|
112
|
+
wrl.update_batch_id,
|
|
113
|
+
wrl.updated_at,
|
|
114
|
+
wrl.updated_by
|
|
115
|
+
FROM wazett.wazett_route_lives wrl
|
|
116
|
+
WHERE (wrl.route_id IN ( SELECT DISTINCT vsrd.id
|
|
117
|
+
FROM analytic.v_sck_route_details vsrd)) AND wrl.update_time >= 1675206000;
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
-- analytic.v_sck_last_update source
|
|
121
|
+
|
|
122
|
+
CREATE OR REPLACE VIEW analytic.v_sck_last_update
|
|
123
|
+
AS SELECT to_char(to_timestamp((vsrl.update_time / 1000)::double precision), 'dd.MM.yyyy hh24:mi:ss'::text) AS last_update
|
|
124
|
+
FROM analytic.v_sck_route_live vsrl
|
|
125
|
+
ORDER BY vsrl.update_time DESC
|
|
126
|
+
LIMIT 1;
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
-- analytic.v_wazett_routes_lines source
|
|
131
|
+
|
|
132
|
+
CREATE OR REPLACE VIEW analytic.v_wazett_routes_lines
|
|
133
|
+
AS SELECT wazett_routes.id,
|
|
134
|
+
wazett_routes.name,
|
|
135
|
+
st_astext(wazett_routes.line) AS line,
|
|
136
|
+
concat('#', "left"(lpad(to_hex((wazett_routes.id::double precision * character_length(wazett_routes.name)::double precision / (( SELECT min(wazett_routes_1.id * character_length(wazett_routes_1.name)) AS min
|
|
137
|
+
FROM wazett.wazett_routes wazett_routes_1))::double precision * 10000000::double precision)::bigint), 6, '0'::text), 6)) AS color
|
|
138
|
+
FROM wazett.wazett_routes;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
drop view analytic.v_wazett_routes_lines;
|
|
2
|
+
drop view analytic.v_sck_last_update;
|
|
3
|
+
drop view analytic.v_sck_route_live;
|
|
4
|
+
drop view analytic.v_sck_route_details;
|
|
5
|
+
|
|
6
|
+
drop view public.v_lkpr_export;
|
|
7
|
+
drop view analytic.v_lkpr_route_details;
|
|
8
|
+
drop view analytic.v_instatntomtom_days;
|
|
9
|
+
|
|
10
|
+
DROP TABLE analytic.lkpr_dashboard_route_names;
|