@golemio/pid 5.0.0-rc.2095893792 → 5.0.0-rc.2149588470

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 (106) hide show
  1. package/db/migrations/postgresql/20250930131408-event-deletedAt.js +53 -0
  2. package/db/migrations/postgresql/20251020110708-get-departures-add-aftertrack.js +53 -0
  3. package/db/migrations/postgresql/sqls/20250930131408-event-deletedAt-down.sql +3 -0
  4. package/db/migrations/postgresql/sqls/20250930131408-event-deletedAt-up.sql +2 -0
  5. package/db/migrations/postgresql/sqls/20251020110708-get-departures-add-aftertrack-down.sql +284 -0
  6. package/db/migrations/postgresql/sqls/20251020110708-get-departures-add-aftertrack-up.sql +289 -0
  7. package/dist/helpers/GtfsStopParser.d.ts +1 -0
  8. package/dist/helpers/GtfsStopParser.js +6 -1
  9. package/dist/helpers/GtfsStopParser.js.map +1 -1
  10. package/dist/integration-engine/data-retention/helpers/SelectRepositoryFactory.js +0 -2
  11. package/dist/integration-engine/data-retention/helpers/SelectRepositoryFactory.js.map +1 -1
  12. package/dist/integration-engine/data-retention/workers/constants/RepositoryTableNameEnum.d.ts +0 -1
  13. package/dist/integration-engine/data-retention/workers/constants/RepositoryTableNameEnum.js +0 -1
  14. package/dist/integration-engine/data-retention/workers/constants/RepositoryTableNameEnum.js.map +1 -1
  15. package/dist/integration-engine/jis/repositories/JISEventsRepository.js +9 -4
  16. package/dist/integration-engine/jis/repositories/JISEventsRepository.js.map +1 -1
  17. package/dist/integration-engine/jis/transformations/JISEventsTransformation.js +1 -0
  18. package/dist/integration-engine/jis/transformations/JISEventsTransformation.js.map +1 -1
  19. package/dist/integration-engine/jis/transformations/UpdateEventWebhookTransformation.d.ts +6 -2
  20. package/dist/integration-engine/jis/transformations/UpdateEventWebhookTransformation.js +1 -0
  21. package/dist/integration-engine/jis/transformations/UpdateEventWebhookTransformation.js.map +1 -1
  22. package/dist/integration-engine/jis/workers/tasks/RefreshJISEventsTask.js.map +1 -1
  23. package/dist/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.js +1 -0
  24. package/dist/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.js.map +1 -1
  25. package/dist/integration-engine/ropid-gtfs/interfaces/IPublicDepartureDto.d.ts +1 -0
  26. package/dist/integration-engine/ropid-gtfs/transformations/PublicDepartureCacheTransformation.js +1 -1
  27. package/dist/integration-engine/ropid-gtfs/transformations/PublicDepartureCacheTransformation.js.map +1 -1
  28. package/dist/integration-engine/vehicle-positions/workers/vehicle-descriptors/data-access/DescriptorRepository.d.ts +2 -2
  29. package/dist/integration-engine/vehicle-positions/workers/vehicle-descriptors/data-access/DescriptorRepository.js +4 -5
  30. package/dist/integration-engine/vehicle-positions/workers/vehicle-descriptors/data-access/DescriptorRepository.js.map +1 -1
  31. package/dist/integration-engine/vehicle-positions/workers/vehicle-descriptors/tasks/RefreshDescriptorsTask.js +1 -1
  32. package/dist/integration-engine/vehicle-positions/workers/vehicle-descriptors/tasks/RefreshDescriptorsTask.js.map +1 -1
  33. package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/helpers/DelayComputationManager.d.ts +6 -1
  34. package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/helpers/DelayComputationManager.js +288 -236
  35. package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/helpers/DelayComputationManager.js.map +1 -1
  36. package/dist/output-gateway/jis/controllers/v1/V1EventsController.js +3 -1
  37. package/dist/output-gateway/jis/controllers/v1/V1EventsController.js.map +1 -1
  38. package/dist/output-gateway/jis/data-access/JISEventsRepository.js +6 -4
  39. package/dist/output-gateway/jis/data-access/JISEventsRepository.js.map +1 -1
  40. package/dist/output-gateway/jis/data-access/RopidGTFSRoutesRepository.js +3 -1
  41. package/dist/output-gateway/jis/data-access/RopidGTFSRoutesRepository.js.map +1 -1
  42. package/dist/output-gateway/jis/routers/v1/V1JISRouter.js +1 -1
  43. package/dist/output-gateway/jis/routers/v1/V1JISRouter.js.map +1 -1
  44. package/dist/output-gateway/pid/controllers/v2/V2DepartureBoardsController.js +3 -1
  45. package/dist/output-gateway/pid/controllers/v2/V2DepartureBoardsController.js.map +1 -1
  46. package/dist/output-gateway/pid/controllers/v3/V3InfotextsController.js +5 -2
  47. package/dist/output-gateway/pid/controllers/v3/V3InfotextsController.js.map +1 -1
  48. package/dist/output-gateway/pid/controllers/v3/V3TransferBoardsController.js +6 -4
  49. package/dist/output-gateway/pid/controllers/v3/V3TransferBoardsController.js.map +1 -1
  50. package/dist/output-gateway/pid/controllers/v4/V4TransferBoardsController.d.ts +4 -1
  51. package/dist/output-gateway/pid/controllers/v4/V4TransferBoardsController.js +24 -7
  52. package/dist/output-gateway/pid/controllers/v4/V4TransferBoardsController.js.map +1 -1
  53. package/dist/output-gateway/pid/data-access/JISInfotextRepository.d.ts +4 -4
  54. package/dist/output-gateway/pid/data-access/JISInfotextRepository.js +12 -8
  55. package/dist/output-gateway/pid/data-access/JISInfotextRepository.js.map +1 -1
  56. package/dist/output-gateway/pid/helpers/TransferBoardFilter.d.ts +3 -0
  57. package/dist/output-gateway/pid/helpers/TransferBoardFilter.js +17 -0
  58. package/dist/output-gateway/pid/helpers/TransferBoardFilter.js.map +1 -1
  59. package/dist/output-gateway/pid/index.d.ts +8 -0
  60. package/dist/output-gateway/pid/index.js.map +1 -1
  61. package/dist/output-gateway/pid/models/helpers/SkipHelper.js +9 -2
  62. package/dist/output-gateway/pid/models/helpers/SkipHelper.js.map +1 -1
  63. package/dist/output-gateway/pid/routers/v2/V2PIDRouter.js +2 -2
  64. package/dist/output-gateway/pid/routers/v2/V2PIDRouter.js.map +1 -1
  65. package/dist/output-gateway/pid/routers/v3/V3PIDRouter.js +1 -1
  66. package/dist/output-gateway/pid/routers/v3/V3PIDRouter.js.map +1 -1
  67. package/dist/output-gateway/pid/service/facade/InfotextFacade.d.ts +1 -1
  68. package/dist/output-gateway/pid/service/facade/InfotextFacade.js +2 -2
  69. package/dist/output-gateway/pid/service/facade/InfotextFacade.js.map +1 -1
  70. package/dist/output-gateway/pid/service/facade/TransferFacade.d.ts +26 -4
  71. package/dist/output-gateway/pid/service/facade/TransferFacade.js +214 -0
  72. package/dist/output-gateway/pid/service/facade/TransferFacade.js.map +1 -1
  73. package/dist/output-gateway/public/controllers/v2/V2PublicDepartureBoardsController.js +5 -2
  74. package/dist/output-gateway/public/controllers/v2/V2PublicDepartureBoardsController.js.map +1 -1
  75. package/dist/output-gateway/public/controllers/v2/V2PublicGtfsController.js +5 -3
  76. package/dist/output-gateway/public/controllers/v2/V2PublicGtfsController.js.map +1 -1
  77. package/dist/output-gateway/public/controllers/v2/V2PublicVehiclePositionsController.js +7 -4
  78. package/dist/output-gateway/public/controllers/v2/V2PublicVehiclePositionsController.js.map +1 -1
  79. package/dist/output-gateway/public/controllers/v2/interfaces/PublicParamsInterfaces.d.ts +1 -0
  80. package/dist/output-gateway/public/data-access/redis/DelayComputationRepository.d.ts +2 -0
  81. package/dist/output-gateway/public/data-access/redis/DelayComputationRepository.js +44 -0
  82. package/dist/output-gateway/public/data-access/redis/DelayComputationRepository.js.map +1 -1
  83. package/dist/output-gateway/public/data-access/redis/PublicGtfsDepartureRepository.js +1 -1
  84. package/dist/output-gateway/public/data-access/redis/PublicGtfsDepartureRepository.js.map +1 -1
  85. package/dist/output-gateway/public/data-access/redis/PublicStopTimeRepository.d.ts +1 -1
  86. package/dist/output-gateway/public/data-access/redis/PublicStopTimeRepository.js +16 -20
  87. package/dist/output-gateway/public/data-access/redis/PublicStopTimeRepository.js.map +1 -1
  88. package/dist/output-gateway/public/routers/v2/V2PublicDeparturesRouter.js +1 -0
  89. package/dist/output-gateway/public/routers/v2/V2PublicDeparturesRouter.js.map +1 -1
  90. package/dist/output-gateway/public/service/facade/DepartureBoardFacade.d.ts +3 -1
  91. package/dist/output-gateway/public/service/facade/DepartureBoardFacade.js +8 -7
  92. package/dist/output-gateway/public/service/facade/DepartureBoardFacade.js.map +1 -1
  93. package/dist/output-gateway/ropid-gtfs/routers/v2/V2GTFSRouter.js +48 -39
  94. package/dist/output-gateway/ropid-gtfs/routers/v2/V2GTFSRouter.js.map +1 -1
  95. package/dist/output-gateway/vehicle-positions/routers/v2/V2VehiclePositionsRouter.js +16 -13
  96. package/dist/output-gateway/vehicle-positions/routers/v2/V2VehiclePositionsRouter.js.map +1 -1
  97. package/dist/schema-definitions/jis/datasources/JISEventsJsonSchema.js +6 -0
  98. package/dist/schema-definitions/jis/datasources/JISEventsJsonSchema.js.map +1 -1
  99. package/dist/schema-definitions/jis/datasources/interfaces/IJISEvent.d.ts +1 -0
  100. package/dist/schema-definitions/jis/models/JISEventsModel.d.ts +1 -0
  101. package/dist/schema-definitions/jis/models/JISEventsModel.js +10 -0
  102. package/dist/schema-definitions/jis/models/JISEventsModel.js.map +1 -1
  103. package/dist/schema-definitions/jis/models/interfaces/IJISEvent.d.ts +1 -0
  104. package/docs/implementation_documentation.md +2 -2
  105. package/docs/openapi-output.yaml +48 -10
  106. package/package.json +3 -3
@@ -37,14 +37,15 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
37
37
  var DescriptorRepository_1;
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.DescriptorRepository = void 0;
40
+ const RepositoryUtils_1 = require("../../../../shared/RepositoryUtils");
40
41
  const const_1 = require("../../../../../schema-definitions/const");
41
42
  const models_1 = require("../../../../../schema-definitions/vehicle-descriptors/models");
43
+ const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
42
44
  const models_2 = require("@golemio/core/dist/integration-engine/models");
43
45
  const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
44
46
  const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
45
47
  const sequelize_1 = __importStar(require("@golemio/core/dist/shared/sequelize"));
46
48
  const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
47
- const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
48
49
  let DescriptorRepository = exports.DescriptorRepository = DescriptorRepository_1 = class DescriptorRepository extends models_2.PostgresModel {
49
50
  constructor(logger) {
50
51
  super(DescriptorRepository_1.REPOSITORY_NAME, {
@@ -83,7 +84,7 @@ let DescriptorRepository = exports.DescriptorRepository = DescriptorRepository_1
83
84
  throw new golemio_errors_1.GeneralError("findAccessDescByRegistrationNumbers: failed to get descriptors", this.name, err);
84
85
  }
85
86
  }
86
- async saveData(descriptors) {
87
+ async refreshData(descriptors) {
87
88
  let transaction;
88
89
  try {
89
90
  await this.validate(descriptors);
@@ -97,10 +98,8 @@ let DescriptorRepository = exports.DescriptorRepository = DescriptorRepository_1
97
98
  await transaction?.commit();
98
99
  }
99
100
  catch (err) {
100
- const exception = new golemio_errors_1.GeneralError(`[${this.constructor.name}] Could not save data: ${err.message}`, this.constructor.name, err);
101
- this.logger.error(exception);
102
101
  await transaction?.rollback();
103
- throw exception;
102
+ RepositoryUtils_1.RepositoryUtils.mapSequelizeError(err, this.constructor.name, "refreshData");
104
103
  }
105
104
  }
106
105
  };
@@ -1 +1 @@
1
- {"version":3,"file":"DescriptorRepository.js","sourceRoot":"","sources":["../../../../../../src/integration-engine/vehicle-positions/workers/vehicle-descriptors/data-access/DescriptorRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mEAAuC;AACvC,yFAAkE;AAClE,yEAAqF;AACrF,6EAAwE;AACxE,mFAAkF;AAClF,iFAAiF;AACjF,iEAAwE;AAExE,wEAAqE;AAI9D,IAAM,oBAAoB,2DAA1B,MAAM,oBAAqB,SAAQ,sBAAa;IAGnD,YAAsC,MAAuB;QACzD,KAAK,CACD,sBAAoB,CAAC,eAAe,EACpC;YACI,WAAW,EAAE,wBAAe,CAAC,SAAS;YACtC,QAAQ,EAAE,iBAAS;YACnB,yBAAyB,EAAE,wBAAe,CAAC,cAAc;YACzD,UAAU,EAAE,gBAAgB;SAC/B,EACD,IAAI,uCAAmB,CAAC,sBAAoB,CAAC,eAAe,GAAG,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WAAW,EAAE,CAAC,CAAC;YAC9D,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAkB,WAAW,EAAE;gBAC/D,gBAAgB,EAAE,IAAI;gBACtB,SAAS,EAAE,KAAK;gBAChB,WAAW;aACd,CAAC,CAAC;YACH,MAAM,WAAW,EAAE,MAAM,EAAE,CAAC;SAC/B;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,SAAS,GAAG,IAAI,6BAAY,CAC9B,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,0BAA0B,GAAG,CAAC,OAAO,EAAE,EAChE,IAAI,CAAC,WAAW,CAAC,IAAI,EACrB,GAAG,CACN,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAC7B,MAAM,WAAW,EAAE,QAAQ,EAAE,CAAC;YAC9B,MAAM,SAAS,CAAC;SACnB;IACL,CAAC;;AAzDc,oCAAe,GAAG,wBAAwB,AAA3B,CAA4B;+BADjD,oBAAoB;IADhC,IAAA,qBAAU,GAAE;IAII,WAAA,IAAA,iBAAM,EAAC,qBAAS,CAAC,MAAM,CAAC,CAAA;;GAH5B,oBAAoB,CAyEhC"}
1
+ {"version":3,"file":"DescriptorRepository.js","sourceRoot":"","sources":["../../../../../../src/integration-engine/vehicle-positions/workers/vehicle-descriptors/data-access/DescriptorRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wEAA6D;AAC7D,mEAAuC;AACvC,yFAAkE;AAElE,wEAAqE;AAErE,yEAAqF;AACrF,6EAAwE;AACxE,mFAAkF;AAClF,iFAAiF;AACjF,iEAAwE;AAGjE,IAAM,oBAAoB,2DAA1B,MAAM,oBAAqB,SAAQ,sBAAa;IAGnD,YAAsC,MAAuB;QACzD,KAAK,CACD,sBAAoB,CAAC,eAAe,EACpC;YACI,WAAW,EAAE,wBAAe,CAAC,SAAS;YACtC,QAAQ,EAAE,iBAAS;YACnB,yBAAyB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C,SAAS,EAAE,WAAW,EAAE,CAAC;YACjE,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;YAC9D,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAkB,WAAW,EAAE;gBAC/D,gBAAgB,EAAE,IAAI;gBACtB,SAAS,EAAE,KAAK;gBAChB,WAAW;aACd,CAAC,CAAC;YACH,MAAM,WAAW,EAAE,MAAM,EAAE,CAAC;SAC/B;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,WAAW,EAAE,QAAQ,EAAE,CAAC;YAC9B,iCAAe,CAAC,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;SAChF;IACL,CAAC;;AAlDc,oCAAe,GAAG,wBAAwB,AAA3B,CAA4B;+BADjD,oBAAoB;IADhC,IAAA,qBAAU,GAAE;IAII,WAAA,IAAA,iBAAM,EAAC,qBAAS,CAAC,MAAM,CAAC,CAAA;;GAH5B,oBAAoB,CAkEhC"}
@@ -41,7 +41,7 @@ let RefreshDescriptorsTask = exports.RefreshDescriptorsTask = class RefreshDescr
41
41
  this.logger.warn(`${this.queueName}: no descriptors out of ${descriptorsResult.length} were transformed or were filtered out`);
42
42
  return;
43
43
  }
44
- await this.descriptorRepository.saveData(descriptorsFiltered);
44
+ await this.descriptorRepository.refreshData(descriptorsFiltered);
45
45
  this.logger.info(`${this.queueName}: ${descriptorsFiltered.length}/${descriptorsResult.length} vehicle descriptors were saved`);
46
46
  }
47
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RefreshDescriptorsTask.js","sourceRoot":"","sources":["../../../../../../src/integration-engine/vehicle-positions/workers/vehicle-descriptors/tasks/RefreshDescriptorsTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oEAA8E;AAG9E,8EAA0E;AAC1E,6FAA0F;AAC1F,iEAAwE;AACxE,4CA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K,mBAAmB,CAAC,MAAM,IAAI,iBAAiB,CAAC,MAAM,iCAAiC,CAChH,CAAC;IACN,CAAC;CACJ,CAAA;iCApCY,sBAAsB;IADlC,IAAA,qBAAU,GAAE;IAMJ,WAAA,IAAA,iBAAM,EAAC,mCAAgB,CAAC,2BAA2B,CAAC,CAAA;IAEpD,WAAA,IAAA,iBAAM,EAAC,mCAAgB,CAAC,gBAAgB,CAAC,CAAA;IAEzC,WAAA,IAAA,iBAAM,EAAC,mCAAgB,CAAC,oBAAoB,CAAC,CAAA;IAE7C,WAAA,IAAA,iBAAM,EAAC,mCAAgB,CAAC,wBAAwB,CAAC,CAAA;IAEjD,WAAA,IAAA,iBAAM,EAAC,+BAAc,CAAC,MAAM,CAAC,CAAA;qCAPH,yDAA2B,UAIxB,2CAAoB;QAEhB,mDAAwB;GAZrD,sBAAsB,CAoClC"}
1
+ {"version":3,"file":"RefreshDescriptorsTask.js","sourceRoot":"","sources":["../../../../../../src/integration-engine/vehicle-positions/workers/vehicle-descriptors/tasks/RefreshDescriptorsTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oEAA8E;AAE9E,8EAA0E;AAC1E,6FAA0F;AAC1F,iEAAwE;AACxE,4CAA2C;AAC3C,8EAA2E;AAC3E,4FAA6G;AAE7G,0FAAuF;AAGhF,IAAM,sBAAsB,oCAA5B,MAAM,sBAAuB,SAAQ,sCAAiB;IAIzD,YAEI,iBAAsD,EAEtD,gBAA2C,EAE3C,oBAAkD,EAElD,wBAA0D,EAC3B,MAAuB;QAEtD,KAAK,CAAC,uBAAW,CAAC,CAAC;QATX,sBAAiB,GAAjB,iBAAiB,CAA6B;QAE9C,qBAAgB,GAAhB,gBAAgB,CAAmB;QAEnC,yBAAoB,GAApB,oBAAoB,CAAsB;QAE1C,6BAAwB,GAAxB,wBAAwB,CAA0B;QACnB,WAAM,GAAN,MAAM,CAAS;QAZ1C,cAAS,GAAG,oBAAoB,CAAC;QACjC,aAAQ,GAAG,EAAE,G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AA2B,UAIxB,2CAAoB;QAEhB,mDAAwB;GAZrD,sBAAsB,CAoClC"}
@@ -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;