@golemio/waze-tt 1.0.11-dev.747349989 → 1.1.0-dev.757321437
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', '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,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;
|