@golemio/pid 2.12.10-dev.1265906013 → 2.12.10-dev.1266077057
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/20240424122841-delay-at-past-stops-release-part-1.js +53 -0
- package/db/migrations/postgresql/sqls/20240424122841-delay-at-past-stops-release-part-1-down.sql +1 -0
- package/db/migrations/postgresql/sqls/20240424122841-delay-at-past-stops-release-part-1-up.sql +98 -0
- package/package.json +1 -1
|
@@ -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', '20240424122841-delay-at-past-stops-release-part-1-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', '20240424122841-delay-at-past-stops-release-part-1-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
|
+
};
|
package/db/migrations/postgresql/sqls/20240424122841-delay-at-past-stops-release-part-1-down.sql
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
drop view v_vehiclepositions_stop_time_delay_prediction;
|
package/db/migrations/postgresql/sqls/20240424122841-delay-at-past-stops-release-part-1-up.sql
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
create view v_vehiclepositions_stop_time_delay_prediction as with recursive stop_times as (
|
|
2
|
+
select
|
|
3
|
+
vt.id,
|
|
4
|
+
rst.trip_id,
|
|
5
|
+
vt.provider_source_type,
|
|
6
|
+
vp.delay,
|
|
7
|
+
coalesce(vp.last_stop_sequence, 1) as initial_stop_sequence,
|
|
8
|
+
vp.state_position,
|
|
9
|
+
rst.stop_sequence,
|
|
10
|
+
rst.stop_id,
|
|
11
|
+
rs.platform_code,
|
|
12
|
+
vcs.cis_stop_platform_code,
|
|
13
|
+
rst.computed_dwell_time_seconds,
|
|
14
|
+
case
|
|
15
|
+
when vp.last_stop_sequence is null then vp.delay
|
|
16
|
+
else vp.delay_stop_arrival
|
|
17
|
+
end as arrival_delay_seconds,
|
|
18
|
+
case
|
|
19
|
+
when vp.last_stop_sequence is null then predict_delay_seconds(
|
|
20
|
+
vp.delay,
|
|
21
|
+
rst.computed_dwell_time_seconds,
|
|
22
|
+
vt.provider_source_type
|
|
23
|
+
)
|
|
24
|
+
when vp.state_position = 'at_stop' then case
|
|
25
|
+
when vt.provider_source_type = '1' then greatest(0, vp.delay)
|
|
26
|
+
else vp.delay
|
|
27
|
+
end
|
|
28
|
+
else vp.delay_stop_departure
|
|
29
|
+
end as departure_delay_seconds
|
|
30
|
+
from
|
|
31
|
+
ropidgtfs_stop_times rst
|
|
32
|
+
inner join vehiclepositions_trips vt on vt.gtfs_trip_id = rst.trip_id
|
|
33
|
+
inner join vehiclepositions_positions vp on vp.id = vt.last_position_id
|
|
34
|
+
and (
|
|
35
|
+
vp.valid_to is null
|
|
36
|
+
or vp.valid_to >= now()
|
|
37
|
+
)
|
|
38
|
+
left join ropidgtfs_stops rs on rs.stop_id = rst.stop_id
|
|
39
|
+
left join ropidgtfs_cis_stops rcs on rcs.id = rs.computed_cis_stop_id
|
|
40
|
+
left join vehiclepositions_cis_stops vcs on vcs.rt_trip_id = vt.id
|
|
41
|
+
and vcs.cis_stop_group_id = rcs.cis
|
|
42
|
+
where
|
|
43
|
+
vt.gtfs_trip_id is not null
|
|
44
|
+
and rst.stop_sequence = coalesce(vp.last_stop_sequence, 1)
|
|
45
|
+
union
|
|
46
|
+
all
|
|
47
|
+
select
|
|
48
|
+
previous_row.id,
|
|
49
|
+
rst.trip_id,
|
|
50
|
+
previous_row.provider_source_type,
|
|
51
|
+
previous_row.delay,
|
|
52
|
+
previous_row.initial_stop_sequence,
|
|
53
|
+
previous_row.state_position,
|
|
54
|
+
rst.stop_sequence,
|
|
55
|
+
rst.stop_id,
|
|
56
|
+
rs.platform_code,
|
|
57
|
+
vcs.cis_stop_platform_code,
|
|
58
|
+
rst.computed_dwell_time_seconds,
|
|
59
|
+
case
|
|
60
|
+
when rst.stop_sequence - previous_row.initial_stop_sequence = 1
|
|
61
|
+
and previous_row.state_position != 'at_stop' then previous_row.delay
|
|
62
|
+
else previous_row.departure_delay_seconds
|
|
63
|
+
end as arrival_delay_seconds,
|
|
64
|
+
predict_delay_seconds(
|
|
65
|
+
case
|
|
66
|
+
when rst.stop_sequence - previous_row.initial_stop_sequence = 1
|
|
67
|
+
and previous_row.state_position != 'at_stop' then previous_row.delay
|
|
68
|
+
else previous_row.departure_delay_seconds
|
|
69
|
+
end,
|
|
70
|
+
rst.computed_dwell_time_seconds,
|
|
71
|
+
previous_row.provider_source_type
|
|
72
|
+
) as departure_delay_seconds
|
|
73
|
+
from
|
|
74
|
+
stop_times previous_row
|
|
75
|
+
inner join ropidgtfs_stop_times rst on rst.trip_id = previous_row.trip_id
|
|
76
|
+
and rst.stop_sequence = previous_row.stop_sequence + 1
|
|
77
|
+
left join ropidgtfs_stops rs on rs.stop_id = rst.stop_id
|
|
78
|
+
left join ropidgtfs_cis_stops rcs on rcs.id = rs.computed_cis_stop_id
|
|
79
|
+
left join vehiclepositions_cis_stops vcs on vcs.rt_trip_id = previous_row.id
|
|
80
|
+
and vcs.cis_stop_group_id = rcs.cis
|
|
81
|
+
)
|
|
82
|
+
select
|
|
83
|
+
trip_id,
|
|
84
|
+
stop_sequence,
|
|
85
|
+
stop_id,
|
|
86
|
+
platform_code,
|
|
87
|
+
cis_stop_platform_code,
|
|
88
|
+
arrival_delay_seconds,
|
|
89
|
+
departure_delay_seconds
|
|
90
|
+
from
|
|
91
|
+
stop_times
|
|
92
|
+
order by
|
|
93
|
+
trip_id,
|
|
94
|
+
stop_sequence;
|
|
95
|
+
|
|
96
|
+
comment on view v_vehiclepositions_stop_time_delay_prediction is '
|
|
97
|
+
This view contains the predicted delay of a vehicle at each stop.
|
|
98
|
+
';
|