@golemio/waze-tt 1.1.0 → 1.1.1-dev.773639991
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.
- package/db/migrations/postgresql/20230125124017-pp20230125.js +53 -0
- package/db/migrations/postgresql/20230201102701-new_waze_routes.js +53 -0
- package/db/migrations/postgresql/20230207073127-malastrana20230207.js +53 -0
- package/db/migrations/postgresql/20230209091614-pp20230209.js +53 -0
- package/db/migrations/postgresql/sqls/20230125124017-pp20230125-down.sql +36 -0
- package/db/migrations/postgresql/sqls/20230125124017-pp20230125-up.sql +35 -0
- package/db/migrations/postgresql/sqls/20230201102701-new_waze_routes-down.sql +2 -0
- package/db/migrations/postgresql/sqls/20230201102701-new_waze_routes-up.sql +74 -0
- package/db/migrations/postgresql/sqls/20230207073127-malastrana20230207-down.sql +9 -0
- package/db/migrations/postgresql/sqls/20230207073127-malastrana20230207-up.sql +354 -0
- package/db/migrations/postgresql/sqls/20230209091614-pp20230209-down.sql +362 -0
- package/db/migrations/postgresql/sqls/20230209091614-pp20230209-up.sql +365 -0
- package/package.json +2 -2
|
@@ -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', '20230125124017-pp20230125-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', '20230125124017-pp20230125-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', '20230201102701-new_waze_routes-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', '20230201102701-new_waze_routes-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', '20230207073127-malastrana20230207-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', '20230207073127-malastrana20230207-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', '20230209091614-pp20230209-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', '20230209091614-pp20230209-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,36 @@
|
|
|
1
|
+
/* Replace with your SQL commands */
|
|
2
|
+
|
|
3
|
+
DROP VIEW if exists analytic.v_route_travel_times;
|
|
4
|
+
|
|
5
|
+
ALTER TABLE analytic.waze_dashboard_route_name
|
|
6
|
+
ALTER COLUMN route_id TYPE int;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
CREATE OR REPLACE VIEW analytic.v_route_travel_times
|
|
10
|
+
AS SELECT ts.route_id,
|
|
11
|
+
ts.year,
|
|
12
|
+
ts.month,
|
|
13
|
+
ts.day,
|
|
14
|
+
ts.dow,
|
|
15
|
+
ts.hour,
|
|
16
|
+
ts.quarter,
|
|
17
|
+
ts.hour + (ts.quarter::numeric / 60::numeric)::double precision AS hour_quarter,
|
|
18
|
+
((((((((ts.year || '-'::text) || ts.month) || '-'::text) || ts.day) || ' '::text) || ts.hour) || ':'::text) || ts.quarter)::timestamp without time zone AS date,
|
|
19
|
+
avg(ts.travel_time)::integer AS travel_time
|
|
20
|
+
FROM ( SELECT raw.route_id,
|
|
21
|
+
raw.update_time,
|
|
22
|
+
raw.travel_time,
|
|
23
|
+
date_part('year'::text, raw.update_time) AS year,
|
|
24
|
+
date_part('month'::text, raw.update_time) AS month,
|
|
25
|
+
date_part('day'::text, raw.update_time) AS day,
|
|
26
|
+
date_part('dow'::text, raw.update_time) AS dow,
|
|
27
|
+
date_part('hour'::text, raw.update_time) AS hour,
|
|
28
|
+
date_part('minute'::text, raw.update_time) AS minute,
|
|
29
|
+
date_part('minute'::text, raw.update_time)::integer / 15 * 15 AS quarter
|
|
30
|
+
FROM ( SELECT wazett_route_lives.route_id,
|
|
31
|
+
timezone('Europe/Prague'::text, to_timestamp((wazett_route_lives.update_time / 1000)::double precision)::timestamp without time zone) AS update_time,
|
|
32
|
+
wazett_route_lives."time" AS travel_time
|
|
33
|
+
FROM wazett.wazett_route_lives
|
|
34
|
+
JOIN analytic.waze_dashboard_route_name wdrn ON wdrn.route_id = wazett_route_lives.route_id) raw) ts
|
|
35
|
+
WHERE ts.year > 2000::double precision
|
|
36
|
+
GROUP BY ts.route_id, ts.year, ts.month, ts.day, ts.dow, ts.hour, ts.quarter;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* Replace with your SQL commands */
|
|
2
|
+
|
|
3
|
+
DROP VIEW if exists analytic.v_route_travel_times;
|
|
4
|
+
|
|
5
|
+
ALTER TABLE analytic.waze_dashboard_route_name
|
|
6
|
+
ALTER COLUMN route_id TYPE bigint;
|
|
7
|
+
|
|
8
|
+
CREATE OR REPLACE VIEW analytic.v_route_travel_times
|
|
9
|
+
AS SELECT ts.route_id,
|
|
10
|
+
ts.year,
|
|
11
|
+
ts.month,
|
|
12
|
+
ts.day,
|
|
13
|
+
ts.dow,
|
|
14
|
+
ts.hour,
|
|
15
|
+
ts.quarter,
|
|
16
|
+
ts.hour + (ts.quarter::numeric / 60::numeric)::double precision AS hour_quarter,
|
|
17
|
+
((((((((ts.year || '-'::text) || ts.month) || '-'::text) || ts.day) || ' '::text) || ts.hour) || ':'::text) || ts.quarter)::timestamp without time zone AS date,
|
|
18
|
+
avg(ts.travel_time)::integer AS travel_time
|
|
19
|
+
FROM ( SELECT raw.route_id,
|
|
20
|
+
raw.update_time,
|
|
21
|
+
raw.travel_time,
|
|
22
|
+
date_part('year'::text, raw.update_time) AS year,
|
|
23
|
+
date_part('month'::text, raw.update_time) AS month,
|
|
24
|
+
date_part('day'::text, raw.update_time) AS day,
|
|
25
|
+
date_part('dow'::text, raw.update_time) AS dow,
|
|
26
|
+
date_part('hour'::text, raw.update_time) AS hour,
|
|
27
|
+
date_part('minute'::text, raw.update_time) AS minute,
|
|
28
|
+
date_part('minute'::text, raw.update_time)::integer / 15 * 15 AS quarter
|
|
29
|
+
FROM ( SELECT wazett_route_lives.route_id,
|
|
30
|
+
timezone('Europe/Prague'::text, to_timestamp((wazett_route_lives.update_time / 1000)::double precision)::timestamp without time zone) AS update_time,
|
|
31
|
+
wazett_route_lives."time" AS travel_time
|
|
32
|
+
FROM wazett.wazett_route_lives
|
|
33
|
+
JOIN analytic.waze_dashboard_route_name wdrn ON wdrn.route_id = wazett_route_lives.route_id) raw) ts
|
|
34
|
+
WHERE ts.year > 2000::double precision
|
|
35
|
+
GROUP BY ts.route_id, ts.year, ts.month, ts.day, ts.dow, ts.hour, ts.quarter;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
-- create table for aggregated travel times from wazett data
|
|
2
|
+
CREATE TABLE IF NOT EXISTS analytic.waze_route_travel_times_agg (
|
|
3
|
+
route_id int8 NOT NULL,
|
|
4
|
+
"year" float8 NOT NULL,
|
|
5
|
+
"month" float8 NOT NULL,
|
|
6
|
+
"day" float8 NOT NULL,
|
|
7
|
+
dow float8 NOT NULL,
|
|
8
|
+
"hour" float8 NOT NULL,
|
|
9
|
+
quarter int4 NOT NULL,
|
|
10
|
+
hour_quarter float8 NOT NULL,
|
|
11
|
+
"date" timestamp NULL,
|
|
12
|
+
travel_time int4 NULL,
|
|
13
|
+
CONSTRAINT waze_route_travel_times_agg_pkey PRIMARY KEY (route_id, year, month, day, dow, hour, quarter, hour_quarter) INCLUDE (travel_time)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- this procedure is used to update the above table
|
|
17
|
+
CREATE OR REPLACE PROCEDURE analytic.update_waze()
|
|
18
|
+
LANGUAGE plpgsql
|
|
19
|
+
AS $procedure$
|
|
20
|
+
|
|
21
|
+
declare
|
|
22
|
+
lastupdatetimestamp timestamptz;
|
|
23
|
+
lastupdateunix bigint;
|
|
24
|
+
begin
|
|
25
|
+
select
|
|
26
|
+
case
|
|
27
|
+
when start_day is not null
|
|
28
|
+
then start_day
|
|
29
|
+
else '2021-01-01'
|
|
30
|
+
end as start_day_from into lastupdatetimestamp
|
|
31
|
+
from (select max(date)-interval '1 days' start_day from analytic.waze_route_travel_times_agg) wazemax;
|
|
32
|
+
|
|
33
|
+
lastupdateunix := extract ('epoch' from lastupdatetimestamp) * 1000;
|
|
34
|
+
-- inserting data is incremental, since the last timestamp already in the table
|
|
35
|
+
insert into analytic.waze_route_travel_times_agg
|
|
36
|
+
SELECT ts.route_id,
|
|
37
|
+
ts.year,
|
|
38
|
+
ts.month,
|
|
39
|
+
ts.day,
|
|
40
|
+
ts.dow,
|
|
41
|
+
ts.hour,
|
|
42
|
+
ts.quarter,
|
|
43
|
+
ts.hour + (ts.quarter::numeric / 60::numeric)::double precision AS hour_quarter,
|
|
44
|
+
((((((((ts.year || '-'::text) || ts.month) || '-'::text) || ts.day) || ' '::text) || ts.hour) || ':'::text) || ts.quarter)::timestamp without time zone AS date,
|
|
45
|
+
avg(ts.travel_time)::integer AS travel_time
|
|
46
|
+
FROM ( SELECT raw.route_id,
|
|
47
|
+
raw.update_time,
|
|
48
|
+
raw.travel_time,
|
|
49
|
+
date_part('year'::text, raw.update_time) AS year,
|
|
50
|
+
date_part('month'::text, raw.update_time) AS month,
|
|
51
|
+
date_part('day'::text, raw.update_time) AS day,
|
|
52
|
+
date_part('dow'::text, raw.update_time) AS dow,
|
|
53
|
+
date_part('hour'::text, raw.update_time) AS hour,
|
|
54
|
+
date_part('minute'::text, raw.update_time) AS minute,
|
|
55
|
+
date_part('minute'::text, raw.update_time)::integer / 15 * 15 AS quarter
|
|
56
|
+
FROM ( SELECT wazett_route_lives.route_id,
|
|
57
|
+
timezone('Europe/Prague'::text, to_timestamp((wazett_route_lives.update_time / 1000)::double precision)::timestamp without time zone) AS update_time,
|
|
58
|
+
wazett_route_lives."time" AS travel_time
|
|
59
|
+
FROM wazett_route_lives
|
|
60
|
+
JOIN analytic.waze_dashboard_route_name wdrn ON wdrn.route_id = wazett_route_lives.route_id
|
|
61
|
+
where wazett_route_lives.update_time > lastupdateunix -- this is the time condition for the increment
|
|
62
|
+
) raw
|
|
63
|
+
) ts
|
|
64
|
+
WHERE ts.year > 2000::double precision
|
|
65
|
+
GROUP BY ts.route_id, ts.year, ts.month, ts.day, ts.dow, ts.hour, ts.quarter
|
|
66
|
+
ON CONFLICT (route_id, year, month, day, dow, hour, quarter, hour_quarter)
|
|
67
|
+
DO update
|
|
68
|
+
SET
|
|
69
|
+
date = EXCLUDED.date,
|
|
70
|
+
travel_time = EXCLUDED.travel_time
|
|
71
|
+
;
|
|
72
|
+
end;
|
|
73
|
+
$procedure$
|
|
74
|
+
;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* Replace with your SQL commands */
|
|
2
|
+
DROP PROCEDURE analytic.update_mala_strana;
|
|
3
|
+
|
|
4
|
+
DROP MATERIALIZED VIEW analytic.mv_mala_strana_normal;
|
|
5
|
+
|
|
6
|
+
DROP VIEW analytic.v_mala_strana_route;
|
|
7
|
+
|
|
8
|
+
DROP TABLE analytic.mala_strana_route_hour_core;
|
|
9
|
+
DROP TABLE analytic.mala_strana_data_all;
|