@golemio/pid 2.14.1-dev.1344898384 → 2.14.1-dev.1345502338

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', '20240612135256-fix-delay-in-view-future-stop-times-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', '20240612135256-fix-delay-in-view-future-stop-times-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,82 @@
1
+ -- v_public_vehiclepositions_future_stop_times source
2
+ CREATE OR REPLACE VIEW v_public_vehiclepositions_future_stop_times AS
3
+ WITH RECURSIVE stop_times AS (
4
+ SELECT
5
+ rst.trip_id,
6
+ vt.id AS trips_id,
7
+ vt.provider_source_type,
8
+ vp.delay,
9
+ COALESCE(vp.last_stop_sequence, 1) AS initial_stop_sequence,
10
+ vp.state_position,
11
+ rst.stop_id,
12
+ rst.stop_sequence,
13
+ rst.computed_dwell_time_seconds,
14
+ CASE WHEN vp.last_stop_sequence IS NULL THEN
15
+ vp.delay
16
+ ELSE
17
+ vp.delay_stop_arrival
18
+ END AS arrival_delay_seconds,
19
+ CASE WHEN vp.last_stop_sequence IS NULL THEN
20
+ predict_delay_seconds(vp.delay, rst.computed_dwell_time_seconds, vt.provider_source_type)
21
+ WHEN vp.state_position::text = 'at_stop'::text THEN
22
+ CASE WHEN vt.provider_source_type::text = '1'::text THEN
23
+ GREATEST(0, vp.delay)
24
+ ELSE
25
+ vp.delay
26
+ END
27
+ ELSE
28
+ vp.delay_stop_departure
29
+ END AS departure_delay_seconds
30
+ FROM
31
+ ropidgtfs_stop_times rst
32
+ JOIN vehiclepositions_trips vt ON vt.gtfs_trip_id::text = rst.trip_id::text
33
+ JOIN vehiclepositions_positions vp ON vp.id = vt.last_position_id
34
+ AND (vp.valid_to IS NULL
35
+ OR vp.valid_to >= now())
36
+ AND (vp.state_position::text = ANY (ARRAY['on_track'::character varying::text,
37
+ 'at_stop'::character varying::text,
38
+ 'before_track'::character varying::text,
39
+ 'before_track_delayed'::character varying::text]))
40
+ WHERE
41
+ vt.gtfs_trip_id IS NOT NULL
42
+ AND rst.stop_sequence = COALESCE(vp.last_stop_sequence, 1)
43
+ UNION ALL
44
+ SELECT
45
+ rst.trip_id,
46
+ previous_row.trips_id,
47
+ previous_row.provider_source_type,
48
+ previous_row.delay,
49
+ previous_row.initial_stop_sequence,
50
+ previous_row.state_position,
51
+ rst.stop_id,
52
+ rst.stop_sequence,
53
+ rst.computed_dwell_time_seconds,
54
+ CASE WHEN (rst.stop_sequence - previous_row.initial_stop_sequence) = 1
55
+ AND previous_row.state_position::text <> 'at_stop'::text THEN
56
+ previous_row.delay
57
+ ELSE
58
+ previous_row.departure_delay_seconds
59
+ END AS arrival_delay_seconds,
60
+ predict_delay_seconds(
61
+ CASE WHEN (rst.stop_sequence - previous_row.initial_stop_sequence) = 1
62
+ AND previous_row.state_position::text <> 'at_stop'::text THEN
63
+ previous_row.delay
64
+ ELSE
65
+ previous_row.departure_delay_seconds
66
+ END, rst.computed_dwell_time_seconds, previous_row.provider_source_type) AS departure_delay_seconds
67
+ FROM
68
+ stop_times previous_row
69
+ JOIN ropidgtfs_stop_times rst ON rst.trip_id::text = previous_row.trip_id::text
70
+ AND rst.stop_sequence =(previous_row.stop_sequence + 1))
71
+ SELECT
72
+ stop_times.trips_id AS rt_trip_id,
73
+ stop_times.stop_sequence,
74
+ COALESCE(stop_times.arrival_delay_seconds, 0) AS stop_arr_delay,
75
+ COALESCE(stop_times.departure_delay_seconds, 0) AS stop_dep_delay,
76
+ stop_times.stop_id
77
+ FROM
78
+ stop_times
79
+ ORDER BY
80
+ stop_times.trip_id,
81
+ stop_times.stop_sequence;
82
+
@@ -0,0 +1,93 @@
1
+ CREATE OR REPLACE VIEW v_public_vehiclepositions_future_stop_times AS
2
+ WITH RECURSIVE stop_times AS (
3
+ SELECT
4
+ rst.trip_id,
5
+ vt.id AS trips_id,
6
+ vt.provider_source_type,
7
+ coalesce(vp.delay, 0) AS delay,
8
+ coalesce(vp.last_stop_sequence, 1) AS initial_stop_sequence,
9
+ vp.state_position,
10
+ rst.stop_id,
11
+ rst.stop_sequence,
12
+ rst.computed_dwell_time_seconds,
13
+ rst.arrival_time,
14
+ rst.departure_time,
15
+ CASE WHEN vp.last_stop_sequence IS NULL THEN
16
+ coalesce(vp.delay, 0)
17
+ ELSE
18
+ coalesce(vp.delay_stop_arrival, 0)
19
+ END AS arrival_delay_seconds,
20
+ CASE WHEN vp.last_stop_sequence IS NULL THEN
21
+ predict_delay_seconds(vp.delay, rst.computed_dwell_time_seconds, vt.provider_source_type)
22
+ WHEN vp.state_position::text = 'at_stop'::text THEN
23
+ CASE WHEN vt.provider_source_type::text = '1'::text THEN
24
+ greatest(0, vp.delay)
25
+ ELSE
26
+ vp.delay
27
+ END
28
+ ELSE
29
+ vp.delay_stop_departure
30
+ END AS departure_delay_seconds
31
+ FROM
32
+ ropidgtfs_stop_times rst
33
+ JOIN vehiclepositions_trips vt ON vt.gtfs_trip_id::text = rst.trip_id::text
34
+ JOIN vehiclepositions_positions vp ON vp.id = vt.last_position_id
35
+ AND (vp.valid_to IS NULL
36
+ OR vp.valid_to >= now())
37
+ AND (vp.state_position::text = ANY (ARRAY['on_track'::character varying::text,
38
+ 'at_stop'::character varying::text,
39
+ 'before_track'::character varying::text,
40
+ 'before_track_delayed'::character varying::text]))
41
+ WHERE
42
+ vt.gtfs_trip_id IS NOT NULL
43
+ AND rst.stop_sequence = coalesce(vp.last_stop_sequence, 1)
44
+ UNION ALL
45
+ SELECT
46
+ rst.trip_id,
47
+ previous_row.trips_id,
48
+ previous_row.provider_source_type,
49
+ previous_row.delay,
50
+ previous_row.initial_stop_sequence,
51
+ previous_row.state_position,
52
+ rst.stop_id,
53
+ rst.stop_sequence,
54
+ rst.computed_dwell_time_seconds,
55
+ rst.arrival_time,
56
+ rst.departure_time,
57
+ CASE WHEN (rst.stop_sequence - previous_row.initial_stop_sequence) = 1
58
+ AND previous_row.state_position::text <> 'at_stop'::text THEN
59
+ CASE WHEN (rst.arrival_time::time +(interval '1 second' * previous_row.delay) < previous_row.departure_time::time +(interval '1 second' *(previous_row.departure_delay_seconds))) THEN
60
+ NULL
61
+ ELSE
62
+ previous_row.delay
63
+ END
64
+ ELSE
65
+ previous_row.departure_delay_seconds
66
+ END AS arrival_delay_seconds,
67
+ predict_delay_seconds(
68
+ CASE WHEN (rst.stop_sequence - previous_row.initial_stop_sequence) = 1
69
+ AND previous_row.state_position::text <> 'at_stop'::text THEN
70
+ previous_row.delay
71
+ ELSE
72
+ previous_row.departure_delay_seconds
73
+ END, rst.computed_dwell_time_seconds, previous_row.provider_source_type) AS departure_delay_seconds
74
+ FROM
75
+ stop_times previous_row
76
+ JOIN ropidgtfs_stop_times rst ON rst.trip_id::text = previous_row.trip_id::text
77
+ AND rst.stop_sequence =(previous_row.stop_sequence + 1))
78
+ SELECT
79
+ stop_times.trips_id AS rt_trip_id,
80
+ stop_times.stop_sequence,
81
+ stop_times.arrival_delay_seconds AS stop_arr_delay,
82
+ CASE WHEN (stop_times.arrival_time::time +(interval '1 second' * coalesce(stop_times.arrival_delay_seconds, 0))) >(stop_times.departure_time::time +(interval '1 second' * coalesce(stop_times.departure_delay_seconds, 0))) THEN
83
+ NULL
84
+ ELSE
85
+ stop_times.departure_delay_seconds
86
+ END AS stop_dep_delay,
87
+ stop_times.stop_id
88
+ FROM
89
+ stop_times
90
+ ORDER BY
91
+ stop_times.trip_id,
92
+ stop_times.stop_sequence;
93
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/pid",
3
- "version": "2.14.1-dev.1344898384",
3
+ "version": "2.14.1-dev.1345502338",
4
4
  "description": "Golemio PID Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",