@golemio/pid 4.2.0 → 4.2.1-dev.2113429421

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.
Files changed (27) hide show
  1. package/db/migrations/postgresql/20251020110708-get-departures-add-aftertrack.js +53 -0
  2. package/db/migrations/postgresql/sqls/20251020110708-get-departures-add-aftertrack-down.sql +284 -0
  3. package/db/migrations/postgresql/sqls/20251020110708-get-departures-add-aftertrack-up.sql +289 -0
  4. package/dist/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.js +1 -0
  5. package/dist/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.js.map +1 -1
  6. package/dist/integration-engine/ropid-gtfs/interfaces/IPublicDepartureDto.d.ts +1 -0
  7. package/dist/integration-engine/ropid-gtfs/transformations/PublicDepartureCacheTransformation.js +1 -1
  8. package/dist/integration-engine/ropid-gtfs/transformations/PublicDepartureCacheTransformation.js.map +1 -1
  9. package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/helpers/DelayComputationManager.d.ts +6 -1
  10. package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/helpers/DelayComputationManager.js +288 -236
  11. package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/helpers/DelayComputationManager.js.map +1 -1
  12. package/dist/output-gateway/pid/index.d.ts +1 -0
  13. package/dist/output-gateway/pid/index.js.map +1 -1
  14. package/dist/output-gateway/pid/models/helpers/SkipHelper.js +9 -2
  15. package/dist/output-gateway/pid/models/helpers/SkipHelper.js.map +1 -1
  16. package/dist/output-gateway/public/controllers/v2/V2PublicDepartureBoardsController.js +2 -1
  17. package/dist/output-gateway/public/controllers/v2/V2PublicDepartureBoardsController.js.map +1 -1
  18. package/dist/output-gateway/public/controllers/v2/interfaces/PublicParamsInterfaces.d.ts +1 -0
  19. package/dist/output-gateway/public/data-access/redis/PublicGtfsDepartureRepository.js +1 -1
  20. package/dist/output-gateway/public/data-access/redis/PublicGtfsDepartureRepository.js.map +1 -1
  21. package/dist/output-gateway/public/routers/v2/V2PublicDeparturesRouter.js +1 -0
  22. package/dist/output-gateway/public/routers/v2/V2PublicDeparturesRouter.js.map +1 -1
  23. package/dist/output-gateway/public/service/facade/DepartureBoardFacade.d.ts +1 -1
  24. package/dist/output-gateway/public/service/facade/DepartureBoardFacade.js +6 -7
  25. package/dist/output-gateway/public/service/facade/DepartureBoardFacade.js.map +1 -1
  26. package/docs/openapi-output.yaml +9 -0
  27. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"DeparturesRepository.js","sourceRoot":"","sources":["../../../../../src/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAA4D;AAG5D,gEAAuC;AACvC,8FAAqE;AAErE,wEAAqE;AAErE,yEAAqF;AACrF,6EAAwE;AACxE,mFAAkF;AAClF,mEAAiF;AACjF,iEAAwE;AACxE,+EAA4E;AAGrE,IAAM,oBAAoB,kCAA1B,MAAM,oBAAqB,SAAQ,sBAAa;IACnD,YACoC,MAA6B,EACnC,MAAuB;QAEjD,KAAK,CACD,sBAAsB,EACtB;YACI,WAAW,EAAE,6BAAe,CAAC,UAAU;YACvC,QAAQ,EAAE,iBAAS;YACnB,yBAAyB,EAAE,6BAAe,CAAC,cAAc;YACzD,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,CAAC;YACtD,UAAU,EAAE,YAAY;SAC3B,EACD,IAAI,uCAAmB,CAAC,sBAAsB,EAAE,6BAAe,CAAC,UAAU,CAAC,CAC9E,CAAC;QAbsC,WAAM,GAAN,MAAM,CAAe;QAC3B,WAAM,GAAN,MAAM,CAAS;QAe9C,sBAAiB,GAAG,KAAK,EAAE,iBAAwC,EAAiB,EAAE;YACzF,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;YACpE,MAAM,qBAAqB,GACvB,OAAO,KA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B,oBAAoB,CA0LhC"}
1
+ {"version":3,"file":"DeparturesRepository.js","sourceRoot":"","sources":["../../../../../src/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAA4D;AAG5D,gEAAuC;AACvC,8FAAqE;AAErE,wEAAqE;AAErE,yEAAqF;AACrF,6EAAwE;AACxE,mFAAkF;AAClF,mEAAiF;AACjF,iEAAwE;AACxE,+EAA4E;AAGrE,IAAM,oBAAoB,kCAA1B,MAAM,oBAAqB,SAAQ,sBAAa;IACnD,YACoC,MAA6B,EACnC,MAAuB;QAEjD,KAAK,CACD,sBAAsB,EACtB;YACI,WAAW,EAAE,6BAAe,CAAC,UAAU;YACvC,QAAQ,EAAE,iBAAS;YACnB,yBAAyB,EAAE,6BAAe,CAAC,cAAc;YACzD,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,CAAC;YACtD,UAAU,EAAE,YAAY;SAC3B,EACD,IAAI,uCAAmB,CAAC,sBAAsB,EAAE,6BAAe,CAAC,UAAU,CAAC,CAC9E,CAAC;QAbsC,WAAM,GAAN,MAAM,CAAe;QAC3B,WAAM,GAAN,MAAM,CAAS;QAe9C,sBAAiB,GAAG,KAAK,EAAE,iBAAwC,EAAiB,EAAE;YACzF,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;YACpE,MAAM,qBAAqB,GACvB,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,4EAA4E,CAAC,CAAC,CAAC,EAAE,CAAC;YAE3G,4BAA4B;YAC5B,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uCAiCmB,iBAAiB;2CACb,iBAAiB;2CACjB,iBAAiB;;;8CAGd,iBAAiB;4CACnB,iBAAiB;gDACb,iBAAiB;gDACjB,iBAAiB;;cAEnD,qBAAqB,EAAE,CAAC;YAC9B,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B,CAAC,GAAG,CAAC;gBAC3D,MAAM,aAAa,GAAG,SAAS,GAAG,6CAAqB,CAAC,IAAI,CAAC;gBAE7D,MAAM,IAAI,CAAC,cAAc,CAAC,SAAU,CAAC,KAAK,CACtC;2CAC2B,iBAAS;uBAC7B,SAAS;8BACF,SAAS,cAAc,aAAa;8BACpC,YAAY,cAAc,SAAS;6BACpC,aAAa,WAAW,EACrC,EAAE,WAAW,EAAE,CAClB,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACvB,MAAM,GAAG,CAAC;aACb;QACL,CAAC,CAAC;QAEK,YAAO,GAAG,KAAK,IAAmB,EAAE;YACvC,IAAI;gBACA,MAAM,IAAI,CAAC,cAAc,CAAC,SAAU,CAAC,KAAK,CACtC,WAAW,iBAAS,IAAI,6BAAe,CAAC,UAAU,GAAG,6CAAqB,CAAC,GAAG,GAAG,CACpF,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACvB,MAAM,GAAG,CAAC;aACb;QACL,CAAC,CAAC;IA1KF,CAAC;CA2KJ,CAAA;+BA3LY,oBAAoB;IADhC,IAAA,qBAAU,GAAE;IAGJ,WAAA,IAAA,iBAAM,EAAC,qBAAS,CAAC,YAAY,CAAC,CAAA;IAC9B,WAAA,IAAA,iBAAM,EAAC,qBAAS,CAAC,MAAM,CAAC,CAAA;;GAHpB,oBAAoB,CA2LhC"}
@@ -9,4 +9,5 @@ export interface IPublicDepartureDto {
9
9
  stop_sequence: number;
10
10
  platform_code: string | null;
11
11
  trip_headsign: string;
12
+ stop_headsign: string | null;
12
13
  }
@@ -23,7 +23,7 @@ let PublicDepartureCacheTransformation = exports.PublicDepartureCacheTransformat
23
23
  trip_id: inputDto.trip_id,
24
24
  stop_sequence: inputDto.stop_sequence,
25
25
  platform_code: inputDto.platform_code,
26
- trip_headsign: inputDto.trip_headsign,
26
+ trip_headsign: inputDto.stop_headsign ?? inputDto.trip_headsign,
27
27
  };
28
28
  return outputDto;
29
29
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PublicDepartureCacheTransformation.js","sourceRoot":"","sources":["../../../../src/integration-engine/ropid-gtfs/transformations/PublicDepartureCacheTransformation.ts"],"names":[],"mappings":";;;;;;;;;AACA,6GAA0G;AAC1G,iEAAgE;AAIzD,IAAM,kCAAkC,gDAAxC,MAAM,kCAAmC,SAAQ,+CAGvD;IAHM;;QAII,SAAI,GAAG,oCAAoC,CAAC;QAEzC,sBAAiB,GAAG,CAAC,QAA6B,EAAE,EAAE;YAC5D,MAAM,SAAS,GAAiC;gBAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,WAAW,EAAE;gBAC7D,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,EAAE,WAAW,EAAE,IAAI,IAAI;gBAClE,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;gBAC3C,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,aAAa,EAAE,QAAQ,CAAC,aAAa;gBACrC,aAAa,EAAE,QAAQ,CAAC,aAAa;gBACrC,aAAa,EAAE,QAAQ,CAAC,aAAa;aACxC,CAAC;YAEF,OAAO,SAAS,CAAC;QACrB,CAAC,CAAC;IACN,CAAC;CAAA,CAAA;6CArBY,kCAAkC;IAD9C,IAAA,qBAAU,GAAE;GACA,kCAAkC,CAqB9C"}
1
+ {"version":3,"file":"PublicDepartureCacheTransformation.js","sourceRoot":"","sources":["../../../../src/integration-engine/ropid-gtfs/transformations/PublicDepartureCacheTransformation.ts"],"names":[],"mappings":";;;;;;;;;AACA,6GAA0G;AAC1G,iEAAgE;AAIzD,IAAM,kCAAkC,gDAAxC,MAAM,kCAAmC,SAAQ,+CAGvD;IAHM;;QAII,SAAI,GAAG,oCAAoC,CAAC;QAEzC,sBAAiB,GAAG,CAAC,QAA6B,EAAE,EAAE;YAC5D,MAAM,SAAS,GAAiC;gBAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,WAAW,EAAE;gBAC7D,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB,EAAE,WAAW,EAAE,IAAI,IAAI;gBAClE,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;gBAC3C,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,aAAa,EAAE,QAAQ,CAAC,aAAa;gBACrC,aAAa,EAAE,QAAQ,CAAC,aAAa;gBACrC,aAAa,EAAE,QAAQ,CAAC,aAAa,IAAI,QAAQ,CAAC,aAAa;aAClE,CAAC;YAEF,OAAO,SAAS,CAAC;QACrB,CAAC,CAAC;IACN,CAAC;CAAA,CAAA;6CArBY,kCAAkC;IAD9C,IAAA,qBAAU,GAAE;GACA,kCAAkC,CAqB9C"}
@@ -12,7 +12,11 @@ export declare class DelayComputationManager {
12
12
  * @param {string} tripId - Internal DB trip id
13
13
  * @returns {IComputationTrip} - Result with shape anchor points
14
14
  */
15
- getComputationObject: (tripId: string) => Promise<IComputationTrip | null>;
15
+ getComputationObject(tripId: string): Promise<IComputationTrip | null>;
16
+ private roundToDecimals;
17
+ private shouldReadCoordsFromPrevPoint;
18
+ private setupBearingBetweenPoints;
19
+ private shapePointCompareDistance;
16
20
  /**
17
21
  * Return geometry of anchor points with distance from start along trip track shape
18
22
  *
@@ -22,6 +26,7 @@ export declare class DelayComputationManager {
22
26
  * @returns {IShapeGeometryAnchorPoint[]} - Result array of geometry points along trip track shape
23
27
  */
24
28
  private getShapesGeometryAnchorPoints;
29
+ private getAnchorPointProps;
25
30
  /**
26
31
  * Generate new shape points from segment of trip shape along original one
27
32
  * - preserving start and end shape points belonging to stops
@@ -34,257 +34,309 @@ class DelayComputationManager {
34
34
  constructor(gtfsTripsRepository) {
35
35
  this.gtfsTripsRepository = gtfsTripsRepository;
36
36
  this.METRO_TRIP_PREFIX_REGEX = /^(991|992|993)/;
37
- /**
38
- * Return shape anchor points along trip track shape with stop times parameters
39
- *
40
- * @param {string} tripId - Internal DB trip id
41
- * @returns {IComputationTrip} - Result with shape anchor points
42
- */
43
- this.getComputationObject = async (tripId) => {
44
- const gtfsTrip = await this.gtfsTripsRepository.findByIdForDelayComputation(tripId);
45
- if (!gtfsTrip) {
46
- helpers_1.log.info(`getComputationObject: GTFS trip ${tripId} was not found`);
47
- return null;
37
+ const simpleConfig = ioc_1.IntegrationEngineContainer.resolve(CoreToken_1.CoreToken.SimpleConfig);
38
+ this.stepBetweenPoints = config_1.config.vehiclePositions.stepBetweenPoints;
39
+ this.stepBetweenPointsforMetro = Number(simpleConfig.getValue("module.pid.vehicle-positions.shapes.metro.stepBetweenPointsForMetro", "0.05"));
40
+ }
41
+ /**
42
+ * Return shape anchor points along trip track shape with stop times parameters
43
+ *
44
+ * @param {string} tripId - Internal DB trip id
45
+ * @returns {IComputationTrip} - Result with shape anchor points
46
+ */
47
+ async getComputationObject(tripId) {
48
+ const gtfsTrip = await this.gtfsTripsRepository.findByIdForDelayComputation(tripId);
49
+ if (!gtfsTrip) {
50
+ helpers_1.log.info(`getComputationObject: GTFS trip ${tripId} was not found`);
51
+ return null;
52
+ }
53
+ const { shape_id, shapes, stop_times } = gtfsTrip;
54
+ if (!shapes?.length) {
55
+ throw new golemio_errors_1.GeneralError(`getComputationObject: GTFS trip ${tripId} has no shapes`, this.constructor.name);
56
+ }
57
+ else if (!stop_times?.length) {
58
+ throw new golemio_errors_1.GeneralError(`getComputationObject: GTFS trip ${tripId} has no stop_times`, this.constructor.name);
59
+ }
60
+ const isMetro = this.METRO_TRIP_PREFIX_REGEX.test(tripId);
61
+ const shapesGeometryAnchorPoints = this.getShapesGeometryAnchorPoints(shape_id, shapes, stop_times, isMetro);
62
+ // MAKING COPY
63
+ const shapePoints = [];
64
+ const lastPointIndex = shapesGeometryAnchorPoints.length - 1;
65
+ // const to determine shape points of stops (in meters)
66
+ const distanceBefore = 0.1;
67
+ const distanceAfter = 0.05;
68
+ for (let i = 0; i < shapesGeometryAnchorPoints.length; i++) {
69
+ const isLastPoint = i === lastPointIndex;
70
+ const bearing = this.setupBearingBetweenPoints(i, shapesGeometryAnchorPoints, shapePoints, isLastPoint);
71
+ // init values
72
+ let thisStopSequence = null;
73
+ let lastStopSequence = shapesGeometryAnchorPoints[i].last_stop_sequence;
74
+ let nextStopSequence = shapesGeometryAnchorPoints[i].next_stop_sequence;
75
+ // these are origin stop_times shape point fron shapes table, clearly at stops points
76
+ if (shapesGeometryAnchorPoints[i].this_stop_sequence) {
77
+ thisStopSequence = shapesGeometryAnchorPoints[i].this_stop_sequence;
48
78
  }
49
- const { shape_id, shapes, stop_times } = gtfsTrip;
50
- if (!shapes?.length) {
51
- throw new golemio_errors_1.GeneralError(`getComputationObject: GTFS trip ${tripId} has no shapes`, this.constructor.name);
79
+ // if is shape anchor point in close distance AFTER LAST stop, then set it also AT STOP
80
+ else if (i > 0 &&
81
+ shapesGeometryAnchorPoints[i].shape_dist_traveled -
82
+ stop_times[shapesGeometryAnchorPoints[i].last_stop_sequence - 1].shape_dist_traveled <=
83
+ distanceAfter) {
84
+ thisStopSequence = shapesGeometryAnchorPoints[i].last_stop_sequence;
52
85
  }
53
- else if (!stop_times?.length) {
54
- throw new golemio_errors_1.GeneralError(`getComputationObject: GTFS trip ${tripId} has no stop_times`, this.constructor.name);
86
+ // if is shape anchor point in close distance BEFORE NEXT stop, then set it also AT STOP
87
+ else if (i < shapesGeometryAnchorPoints.length - 1 &&
88
+ stop_times[shapesGeometryAnchorPoints[i].next_stop_sequence - 1].shape_dist_traveled -
89
+ shapesGeometryAnchorPoints[i].shape_dist_traveled <=
90
+ distanceBefore) {
91
+ thisStopSequence = shapesGeometryAnchorPoints[i].next_stop_sequence;
92
+ lastStopSequence = shapesGeometryAnchorPoints[i].next_stop_sequence;
93
+ nextStopSequence = Math.min(shapesGeometryAnchorPoints[i].next_stop_sequence + 1, stop_times.length);
55
94
  }
56
- const isMetro = this.METRO_TRIP_PREFIX_REGEX.test(tripId);
57
- const shapesGeometryAnchorPoints = this.getShapesGeometryAnchorPoints(shape_id, shapes, stop_times, isMetro);
58
- // MAKING COPY
59
- const shapePoints = [];
60
- // const to determine shape points of stops (in meters)
61
- const distanceBefore = 0.1;
62
- const distanceAfter = 0.05;
63
- for (let i = 0; i < shapesGeometryAnchorPoints.length; i++) {
64
- let bearing = 0;
65
- // add bearing from shape computed for previous shapePoint
66
- if (i > 0) {
67
- // compute bearing from two shape points
68
- let shapePointBearing = Math.round(turf.bearing(turf.point(shapesGeometryAnchorPoints[i - 1].coordinates), turf.point(shapesGeometryAnchorPoints[i].coordinates)));
69
- // turf.bearing returns -180 to 180, when 0 is north
70
- // we need 0 to 359, for negative value we substract from 360
71
- if (shapePointBearing < 0) {
72
- shapePointBearing = 360 - Math.abs(shapePointBearing);
73
- }
74
- // save bearing
75
- shapePoints[i - 1].bearing = shapePointBearing;
76
- // for the last shapePoint copy the bearing from last one
77
- if (shapesGeometryAnchorPoints.length - 1 === i) {
78
- bearing = shapePoints[i - 1].bearing;
79
- }
80
- }
81
- // init values
82
- let thisStopSequence = null;
83
- let lastStopSequence = shapesGeometryAnchorPoints[i].last_stop_sequence;
84
- let nextStopSequence = shapesGeometryAnchorPoints[i].next_stop_sequence;
85
- // these are origin stop_times shape point fron shapes table, clearly at stops points
86
- if (shapesGeometryAnchorPoints[i].this_stop_sequence) {
87
- thisStopSequence = shapesGeometryAnchorPoints[i].this_stop_sequence;
88
- }
89
- // if is shape anchor point in close distance AFTER LAST stop, then set it also AT STOP
90
- else if (i > 0 &&
91
- shapesGeometryAnchorPoints[i].shape_dist_traveled -
92
- stop_times[shapesGeometryAnchorPoints[i].last_stop_sequence - 1].shape_dist_traveled <=
93
- distanceAfter) {
94
- thisStopSequence = shapesGeometryAnchorPoints[i].last_stop_sequence;
95
- }
96
- // if is shape anchor point in close distance BEFORE NEXT stop, then set it also AT STOP
97
- else if (i < shapesGeometryAnchorPoints.length - 1 &&
98
- stop_times[shapesGeometryAnchorPoints[i].next_stop_sequence - 1].shape_dist_traveled -
99
- shapesGeometryAnchorPoints[i].shape_dist_traveled <=
100
- distanceBefore) {
101
- thisStopSequence = shapesGeometryAnchorPoints[i].next_stop_sequence;
102
- lastStopSequence = shapesGeometryAnchorPoints[i].next_stop_sequence;
103
- nextStopSequence = Math.min(shapesGeometryAnchorPoints[i].next_stop_sequence + 1, stop_times.length);
104
- }
105
- let shapeDistTraveled = shapesGeometryAnchorPoints[i].shape_dist_traveled;
106
- let distanceFromLastStop;
107
- // fallback to shape_dist_traveled from GTFS stop_times, if the vehicle is at stop
108
- // and set distance from last stop to 0 (the stop is literally at stop)
109
- if (thisStopSequence !== null) {
110
- shapeDistTraveled = stop_times[thisStopSequence - 1].shape_dist_traveled;
111
- distanceFromLastStop = 0;
112
- }
113
- else {
114
- distanceFromLastStop =
115
- Math.round((shapeDistTraveled - stop_times[lastStopSequence - 1].shape_dist_traveled) * 1000) / 1000;
116
- }
117
- // if is trip at stop than set departure by this stop
118
- // between stops do linear interpolation from departure from last stop and arrival of next stop
119
- const timeScheduledSeconds = thisStopSequence !== null
120
- ? stop_times[lastStopSequence - 1].arrival_time_seconds
121
- : stop_times[lastStopSequence - 1].departure_time_seconds +
122
- Math.round(((stop_times[nextStopSequence - 1].arrival_time_seconds -
123
- stop_times[lastStopSequence - 1].departure_time_seconds) *
124
- distanceFromLastStop) /
125
- (stop_times[nextStopSequence - 1].shape_dist_traveled -
126
- stop_times[lastStopSequence - 1].shape_dist_traveled));
127
- shapePoints.push({
128
- index: i,
129
- at_stop: thisStopSequence !== null,
130
- bearing,
131
- coordinates: shapesGeometryAnchorPoints[i].coordinates,
132
- distance_from_last_stop: distanceFromLastStop,
133
- last_stop_sequence: lastStopSequence,
134
- next_stop_sequence: nextStopSequence,
135
- shape_dist_traveled: shapeDistTraveled,
136
- this_stop_sequence: thisStopSequence,
137
- time_scheduled_seconds: timeScheduledSeconds,
138
- });
95
+ let shapeDistTraveled = shapesGeometryAnchorPoints[i].shape_dist_traveled;
96
+ let distanceFromLastStop;
97
+ // fallback to shape_dist_traveled from GTFS stop_times, if the vehicle is at stop
98
+ // and set distance from last stop to 0 (the stop is literally at stop)
99
+ if (thisStopSequence !== null) {
100
+ shapeDistTraveled = stop_times[thisStopSequence - 1].shape_dist_traveled;
101
+ distanceFromLastStop = 0;
139
102
  }
140
- return {
141
- trip_id: tripId,
142
- stop_times: stop_times,
143
- shapes_anchor_points: shapePoints,
144
- shapes: this.mapGtfsShapesToTripShapes(shapes),
145
- };
103
+ else {
104
+ distanceFromLastStop = this.roundToDecimals(shapeDistTraveled - stop_times[lastStopSequence - 1].shape_dist_traveled, 1000);
105
+ }
106
+ // if is trip at stop than set departure by this stop
107
+ // between stops do linear interpolation from departure from last stop and arrival of next stop
108
+ const timeScheduledSeconds = thisStopSequence !== null
109
+ ? stop_times[lastStopSequence - 1].arrival_time_seconds
110
+ : stop_times[lastStopSequence - 1].departure_time_seconds +
111
+ Math.round(((stop_times[nextStopSequence - 1].arrival_time_seconds -
112
+ stop_times[lastStopSequence - 1].departure_time_seconds) *
113
+ distanceFromLastStop) /
114
+ (stop_times[nextStopSequence - 1].shape_dist_traveled -
115
+ stop_times[lastStopSequence - 1].shape_dist_traveled));
116
+ shapePoints.push({
117
+ index: i,
118
+ at_stop: thisStopSequence !== null,
119
+ bearing,
120
+ coordinates: shapesGeometryAnchorPoints[i].coordinates,
121
+ distance_from_last_stop: distanceFromLastStop,
122
+ last_stop_sequence: lastStopSequence,
123
+ next_stop_sequence: nextStopSequence,
124
+ shape_dist_traveled: shapeDistTraveled,
125
+ this_stop_sequence: thisStopSequence,
126
+ time_scheduled_seconds: timeScheduledSeconds,
127
+ });
128
+ }
129
+ return {
130
+ trip_id: tripId,
131
+ stop_times: stop_times,
132
+ shapes_anchor_points: shapePoints,
133
+ shapes: this.mapGtfsShapesToTripShapes(shapes),
146
134
  };
147
- /**
148
- * Return geometry of anchor points with distance from start along trip track shape
149
- *
150
- * @param {string} shapeId - GTFS shape id
151
- * @param {ITransformedTripShape[]} shapes - GTFS shape points
152
- * @param {IStopTime[]} stops
153
- * @returns {IShapeGeometryAnchorPoint[]} - Result array of geometry points along trip track shape
154
- */
155
- this.getShapesGeometryAnchorPoints = (shapeId, shapes, stops, isMetro = false) => {
156
- try {
157
- let segmentShapes = [];
158
- // Splits shapes array to multiple arrays "delimited" by stops
159
- for (let st = 0; st < stops.length; st++) {
160
- let currentSegment = [];
161
- for (let sh = 0; sh < shapes.length; sh++) {
162
- let shapePoint = { ...shapes[sh], shape_at_stop: false };
163
- if (stops[st].shape_dist_traveled === shapes[sh].shape_dist_traveled) {
164
- shapePoint.shape_at_stop = true;
165
- }
166
- if (st < stops.length - 1 &&
167
- shapePoint.shape_dist_traveled >= stops[st].shape_dist_traveled &&
168
- shapePoint.shape_dist_traveled <= stops[st + 1].shape_dist_traveled) {
169
- currentSegment.push(shapePoint);
170
- }
135
+ }
136
+ roundToDecimals(n, fraction = 100000) {
137
+ return Math.round(n * fraction) / fraction;
138
+ }
139
+ shouldReadCoordsFromPrevPoint(points, i) {
140
+ if (i <= 1) {
141
+ return false;
142
+ }
143
+ return (points[i].coordinates[0] === points[i - 1].coordinates[0] && points[i].coordinates[1] === points[i - 1].coordinates[1]);
144
+ }
145
+ setupBearingBetweenPoints(index, source, target, isLast) {
146
+ // add bearing from shape computed for previous shapePoint
147
+ if (index === 0) {
148
+ return 0;
149
+ }
150
+ let bearing;
151
+ if (index > 1 && source[index - 1].this_stop_sequence && !source[index].this_stop_sequence) {
152
+ // Was the previous point at_stop? We'll ignore any bearing computation,
153
+ // it would point possibly to the after stop segment, usually behind a cross
154
+ // or after a curve. Thus we'll use the at_stop's incoming (prev point) bearing,
155
+ // because vehicle stays at_stop for some time, then it starts moving
156
+ // and we compute bearing in the 1st point after the stop in next iteration
157
+ return target[index - 1].bearing;
158
+ }
159
+ if (this.shouldReadCoordsFromPrevPoint(source, index)) {
160
+ // take bearing of the previous point (i - 1),
161
+ // as long as current point and prev. point have same coords
162
+ // ... to be saved into previous point (i - 1)
163
+ bearing = target[index - 1].bearing;
164
+ }
165
+ else {
166
+ // compute bearing from two shape points
167
+ bearing = turf.bearing(turf.point(source[index - 1].coordinates), turf.point(source[index].coordinates));
168
+ }
169
+ // turf.bearing returns -180 to 180, when 0 is north
170
+ // we need 0 to 359 => modulo 360
171
+ bearing = Math.round((360 + bearing) % 360);
172
+ // save bearing
173
+ target[index - 1].bearing = bearing;
174
+ // for the last shapePoint copy the bearing from last computed one
175
+ if (isLast) {
176
+ bearing = target[index - 1].bearing;
177
+ }
178
+ return bearing;
179
+ }
180
+ shapePointCompareDistance(point, currentStop, nextStop) {
181
+ if (currentStop.shape_dist_traveled === point.shape_dist_traveled) {
182
+ point.shape_at_stop = true;
183
+ }
184
+ if (nextStop) {
185
+ if (point.shape_dist_traveled >= currentStop.shape_dist_traveled &&
186
+ point.shape_dist_traveled <= nextStop.shape_dist_traveled) {
187
+ // current segment
188
+ return 0;
189
+ }
190
+ else if (point.shape_dist_traveled > nextStop.shape_dist_traveled) {
191
+ // future segment
192
+ return 1;
193
+ }
194
+ }
195
+ // previous stop segment OR missing nextStop (currentStop is last stop)
196
+ return -1;
197
+ }
198
+ /**
199
+ * Return geometry of anchor points with distance from start along trip track shape
200
+ *
201
+ * @param {string} shapeId - GTFS shape id
202
+ * @param {ITransformedTripShape[]} shapes - GTFS shape points
203
+ * @param {IStopTime[]} stops
204
+ * @returns {IShapeGeometryAnchorPoint[]} - Result array of geometry points along trip track shape
205
+ */
206
+ getShapesGeometryAnchorPoints(shapeId, shapes, stops, isMetro = false) {
207
+ try {
208
+ let segmentShapes = [];
209
+ // Splits shapes array to multiple arrays "delimited" by stops
210
+ let startShapeIndex = 0;
211
+ for (let st = 0; st < stops.length; st++) {
212
+ const currentSegment = [];
213
+ for (let sh = startShapeIndex; sh < shapes.length; sh++) {
214
+ const shapePoint = { ...shapes[sh], shape_at_stop: false };
215
+ const shapePointSituation = this.shapePointCompareDistance(shapePoint, stops[st], stops[st + 1]);
216
+ if (shapePointSituation === 0) {
217
+ // next stop iteration (outer for-cycle) can be shorter
218
+ startShapeIndex = sh;
219
+ // each segment starts with "at_stop=true" point
220
+ currentSegment.push(shapePoint);
171
221
  }
172
- if (currentSegment.length) {
173
- segmentShapes.push(currentSegment);
222
+ else if (shapePointSituation === 1) {
223
+ // no need to iterate over all future stops segments
224
+ break;
174
225
  }
175
226
  }
176
- let segmentArr = [];
177
- // concat arrays of stop divided segments with distributed shape points
178
- for (const segment of segmentShapes) {
179
- segmentArr = [
180
- ...segmentArr,
181
- ...this.divideSegmentLine(segment, isMetro ? this.stepBetweenPointsforMetro : this.stepBetweenPoints),
182
- ];
227
+ if (currentSegment.length) {
228
+ segmentShapes.push(currentSegment);
183
229
  }
184
- // Make initial shapesGeometryAnchorPoints
185
- let stopCounter = 0;
186
- const resultArr = segmentArr.map((segment, index) => {
187
- let this_stop_sequence;
188
- let last_stop_sequence;
189
- let next_stop_sequence;
190
- if (segment.shape_at_stop) {
191
- stopCounter++;
192
- this_stop_sequence = stopCounter;
193
- }
194
- else {
195
- this_stop_sequence = null;
196
- }
197
- last_stop_sequence = stopCounter;
198
- next_stop_sequence = stopCounter + 1;
199
- return {
200
- index,
201
- coordinates: [
202
- Math.round(segment.shape_pt_lon * 100000) / 100000,
203
- Math.round(segment.shape_pt_lat * 100000) / 100000,
204
- ],
205
- last_stop_sequence,
206
- next_stop_sequence,
207
- shape_dist_traveled: Math.round(segment.shape_dist_traveled * 1000) / 1000,
208
- this_stop_sequence,
209
- };
210
- });
211
- stopCounter++;
212
- // and lastly shape point for last stop as there is no segment for last stop
213
- resultArr.push({
214
- index: resultArr.length,
215
- coordinates: [
216
- Math.round(shapes[shapes.length - 1].shape_pt_lon * 100000) / 100000,
217
- Math.round(shapes[shapes.length - 1].shape_pt_lat * 100000) / 100000,
218
- ],
219
- last_stop_sequence: stopCounter,
220
- next_stop_sequence: stopCounter,
221
- shape_dist_traveled: Math.round(shapes[shapes.length - 1].shape_dist_traveled * 1000) / 1000,
222
- this_stop_sequence: stopCounter,
223
- });
224
- return resultArr;
225
230
  }
226
- catch (err) {
227
- helpers_1.log.error(err);
228
- helpers_1.log.error(shapeId);
229
- return [];
231
+ let segmentArr = [];
232
+ // concat arrays of stop divided segments with distributed shape points
233
+ for (const segment of segmentShapes) {
234
+ const line = this.divideSegmentLine(segment, isMetro ? this.stepBetweenPointsforMetro : this.stepBetweenPoints);
235
+ segmentArr.push(...line);
230
236
  }
231
- };
232
- /**
233
- * Generate new shape points from segment of trip shape along original one
234
- * - preserving start and end shape points belonging to stops
235
- * - creates new set of shape points between stops to get same point distance along original shape
236
- *
237
- * @param {ISegmentShape[]} segmentsArr - Original shape points segment between two stops
238
- * @param {number} distance - Minimal distance for two consequent shape points
239
- * @returns {ISegmentShape[]} - Result array of new shape points
240
- */
241
- this.divideSegmentLine = (segmentArr, distance = config_1.config.vehiclePositions.stepBetweenPoints) => {
242
- const shapeId = segmentArr[0].shape_id;
243
- const shapeCount = segmentArr.length;
244
- const startShapeDistTraveled = segmentArr[0].shape_dist_traveled;
245
- const endShapeDistTraveled = segmentArr[shapeCount - 1].shape_dist_traveled;
246
- const shapeDistLength = endShapeDistTraveled - startShapeDistTraveled;
247
- const segmentLine = turf.lineString(segmentArr.map((s) => {
248
- return [s.shape_pt_lon, s.shape_pt_lat];
249
- }));
250
- // because we dont believe source shape distances, rather compute length with turf.js
251
- const segmentLength = turf.length(segmentLine);
252
- const middlePointsCount = Math.floor(segmentLength / distance);
253
- const distanceOffset = (segmentLength - distance * middlePointsCount) / 2;
254
- // put first shape point
255
- const resultSegmentPoints = [
256
- {
257
- ...segmentArr[0],
258
- shape_pt_sequence: 1,
259
- },
260
- ];
261
- // for each middle point create acording shape point with interpolated origin shape dist traveled
262
- for (let i = 0; i < middlePointsCount; i++) {
263
- const currentDistance = i * distance + distanceOffset;
264
- const currentDistDistance = (shapeDistLength / segmentLength) * currentDistance;
265
- const newPoint = turf.along(segmentLine, i * distance + distanceOffset);
266
- resultSegmentPoints.push({
267
- shape_id: shapeId,
268
- shape_at_stop: false,
269
- shape_pt_sequence: resultSegmentPoints.length + 1,
270
- shape_pt_lat: newPoint.geometry.coordinates[1],
271
- shape_pt_lon: newPoint.geometry.coordinates[0],
272
- shape_dist_traveled: startShapeDistTraveled + currentDistDistance,
273
- });
274
- }
275
- return resultSegmentPoints;
276
- };
277
- this.mapGtfsShapesToTripShapes = (shapes) => {
278
- return shapes.map((shape) => {
237
+ // Make initial shapesGeometryAnchorPoints
238
+ let stopCounter = 0;
239
+ const resultArr = segmentArr.map((segment, index) => {
240
+ let this_stop_sequence;
241
+ if (segment.shape_at_stop) {
242
+ stopCounter++;
243
+ this_stop_sequence = stopCounter;
244
+ }
245
+ else {
246
+ this_stop_sequence = null;
247
+ }
279
248
  return {
280
- dist: shape.shape_dist_traveled,
281
- coords: [shape.shape_pt_lon, shape.shape_pt_lat],
249
+ index,
250
+ ...this.getAnchorPointProps(segment.shape_pt_lon, segment.shape_pt_lat, stopCounter, stopCounter + 1, segment.shape_dist_traveled),
251
+ this_stop_sequence,
282
252
  };
283
253
  });
254
+ stopCounter++;
255
+ // and lastly shape point for last stop as there is no segment for last stop
256
+ resultArr.push({
257
+ index: resultArr.length,
258
+ ...this.getAnchorPointProps(shapes[shapes.length - 1].shape_pt_lon, shapes[shapes.length - 1].shape_pt_lat, stopCounter, stopCounter, shapes[shapes.length - 1].shape_dist_traveled),
259
+ this_stop_sequence: stopCounter,
260
+ });
261
+ return resultArr;
262
+ }
263
+ catch (err) {
264
+ helpers_1.log.error(err);
265
+ helpers_1.log.error(shapeId);
266
+ return [];
267
+ }
268
+ }
269
+ getAnchorPointProps(lon, lat, last, next, dist) {
270
+ return {
271
+ coordinates: [this.roundToDecimals(lon), this.roundToDecimals(lat)],
272
+ last_stop_sequence: last,
273
+ next_stop_sequence: next,
274
+ shape_dist_traveled: this.roundToDecimals(dist, 1000),
284
275
  };
285
- const simpleConfig = ioc_1.IntegrationEngineContainer.resolve(CoreToken_1.CoreToken.SimpleConfig);
286
- this.stepBetweenPoints = config_1.config.vehiclePositions.stepBetweenPoints;
287
- this.stepBetweenPointsforMetro = Number(simpleConfig.getValue("module.pid.vehicle-positions.shapes.metro.stepBetweenPointsForMetro", "0.025"));
276
+ }
277
+ /**
278
+ * Generate new shape points from segment of trip shape along original one
279
+ * - preserving start and end shape points belonging to stops
280
+ * - creates new set of shape points between stops to get same point distance along original shape
281
+ *
282
+ * @param {ISegmentShape[]} segmentsArr - Original shape points segment between two stops
283
+ * @param {number} distance - Minimal distance for two consequent shape points
284
+ * @returns {ISegmentShape[]} - Result array of new shape points
285
+ */
286
+ divideSegmentLine(segmentArr, distance = config_1.config.vehiclePositions.stepBetweenPoints) {
287
+ const shapeId = segmentArr[0].shape_id;
288
+ const shapeCount = segmentArr.length;
289
+ const startShapeDistTraveled = segmentArr[0].shape_dist_traveled;
290
+ const endShapeDistTraveled = segmentArr[shapeCount - 1].shape_dist_traveled;
291
+ const shapeDistLength = endShapeDistTraveled - startShapeDistTraveled;
292
+ const segmentLine = turf.lineString(segmentArr.map((s) => {
293
+ return [s.shape_pt_lon, s.shape_pt_lat];
294
+ }));
295
+ // because we dont believe source shape distances, rather compute length with turf.js
296
+ const segmentLength = turf.length(segmentLine);
297
+ const middlePointsCount = Math.floor(segmentLength / distance);
298
+ const distanceOffset = (segmentLength - distance * middlePointsCount) / 2;
299
+ // put first shape point
300
+ const resultSegmentPoints = [
301
+ {
302
+ ...segmentArr[0],
303
+ shape_pt_sequence: 1,
304
+ },
305
+ ];
306
+ // for each middle point create acording shape point with interpolated origin shape dist traveled
307
+ for (let i = 0; i < middlePointsCount; i++) {
308
+ const currentDistance = i * distance + distanceOffset;
309
+ const currentDistDistance = (shapeDistLength / segmentLength) * currentDistance;
310
+ // There was an idea to skip possibly really small remaining shape distance
311
+ // to the first computed segment point... but it created possibly more issues
312
+ // with trams/buses having stops at crossings and having bearing into next point
313
+ // behind the crossing. Possibly investigate an option to compute points
314
+ // dynamically on a distance +- 50 meters apart between stops, not just shapes
315
+ // between stops (excluding next stop)
316
+ // const minimalDistanceLimit = distance / 10;
317
+ // if (currentDistDistance < minimalDistanceLimit) {
318
+ // // point would be too close, skip it
319
+ // // continue;
320
+ // }
321
+ const newPoint = turf.along(segmentLine, i * distance + distanceOffset);
322
+ resultSegmentPoints.push({
323
+ shape_id: shapeId,
324
+ shape_at_stop: false,
325
+ shape_pt_sequence: resultSegmentPoints.length + 1,
326
+ shape_pt_lat: this.roundToDecimals(newPoint.geometry.coordinates[1]),
327
+ shape_pt_lon: this.roundToDecimals(newPoint.geometry.coordinates[0]),
328
+ shape_dist_traveled: this.roundToDecimals(startShapeDistTraveled + currentDistDistance, 1000),
329
+ });
330
+ }
331
+ return resultSegmentPoints;
332
+ }
333
+ mapGtfsShapesToTripShapes(shapes) {
334
+ return shapes.map((shape) => {
335
+ return {
336
+ dist: shape.shape_dist_traveled,
337
+ coords: [shape.shape_pt_lon, shape.shape_pt_lat],
338
+ };
339
+ });
288
340
  }
289
341
  }
290
342
  exports.DelayComputationManager = DelayComputationManager;