@golemio/pid 2.6.5-dev.834035052 → 2.6.6
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/example/00_clear_test_data.sql +4 -4
- package/db/example/03_ropidgtfs_dump.sql +1 -10
- package/db/example/14_nightDelays.sql +8 -16
- package/db/example/99_precomputed_tables.sql +169 -0
- package/db/migrations/postgresql/sqls/20220915123941-partitioned-departures-down.sql +0 -2
- package/db/migrations/postgresql/sqls/20230307124639-positions-internal-down.sql +1 -1
- package/dist/integration-engine/queueDefinitions.js +0 -10
- package/dist/integration-engine/queueDefinitions.js.map +1 -1
- package/dist/integration-engine/ropid-gtfs/RopidGTFSMetadataModel.d.ts +7 -13
- package/dist/integration-engine/ropid-gtfs/RopidGTFSMetadataModel.js +45 -50
- package/dist/integration-engine/ropid-gtfs/RopidGTFSMetadataModel.js.map +1 -1
- package/dist/integration-engine/ropid-gtfs/RopidGTFSMinMaxSequencesModel.d.ts +19 -0
- package/dist/integration-engine/ropid-gtfs/{data-access/precomputed/MinMaxStopSequencesRepository.js → RopidGTFSMinMaxSequencesModel.js} +33 -34
- package/dist/integration-engine/ropid-gtfs/RopidGTFSMinMaxSequencesModel.js.map +1 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSScheduledTripsModel.d.ts +21 -0
- package/dist/integration-engine/ropid-gtfs/{data-access/precomputed/TripScheduleRepository.js → RopidGTFSScheduledTripsModel.js} +26 -27
- package/dist/integration-engine/ropid-gtfs/RopidGTFSScheduledTripsModel.js.map +1 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSServicesFirst14daysModel.d.ts +19 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSServicesFirst14daysModel.js +142 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSServicesFirst14daysModel.js.map +1 -0
- package/dist/integration-engine/ropid-gtfs/RopidGTFSWorker.d.ts +3 -4
- package/dist/integration-engine/ropid-gtfs/RopidGTFSWorker.js +18 -50
- package/dist/integration-engine/ropid-gtfs/RopidGTFSWorker.js.map +1 -1
- package/dist/integration-engine/ropid-gtfs/data-access/{precomputed/DeparturesRepository.d.ts → DeparturesRepository.d.ts} +1 -2
- package/dist/integration-engine/ropid-gtfs/data-access/DeparturesRepository.js +162 -0
- package/dist/integration-engine/ropid-gtfs/data-access/DeparturesRepository.js.map +1 -0
- package/dist/integration-engine/ropid-gtfs/data-access/index.d.ts +1 -0
- package/dist/integration-engine/ropid-gtfs/data-access/{precomputed/index.js → index.js} +0 -3
- package/dist/integration-engine/ropid-gtfs/data-access/index.js.map +1 -0
- package/dist/integration-engine/ropid-gtfs/index.d.ts +3 -0
- package/dist/integration-engine/ropid-gtfs/index.js +3 -0
- package/dist/integration-engine/ropid-gtfs/index.js.map +1 -1
- package/dist/integration-engine/ropid-gtfs/utils.js +4 -5
- package/dist/integration-engine/ropid-gtfs/utils.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/workers/runs/data-access/CommonRunsRepository.d.ts +1 -1
- package/dist/integration-engine/vehicle-positions/workers/runs/data-access/CommonRunsRepository.js +3 -3
- package/dist/integration-engine/vehicle-positions/workers/runs/data-access/CommonRunsRepository.js.map +1 -1
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/TripsRepository.js +18 -18
- package/dist/integration-engine/vehicle-positions/workers/vehicle-positions/data-access/TripsRepository.js.map +1 -1
- package/dist/output-gateway/departure-boards/DepartureBoardsRouter.js +1 -1
- package/dist/output-gateway/pid/data-access/DeparturesRepository.js +6 -0
- package/dist/output-gateway/pid/data-access/DeparturesRepository.js.map +1 -1
- package/dist/output-gateway/pid/middleware/checkTimeFromMiddleware.js +2 -2
- package/dist/schema-definitions/ropid-gtfs/RopidGTFSPrecomputed.d.ts +3 -3
- package/dist/schema-definitions/ropid-gtfs/RopidGTFSPrecomputed.js +15 -15
- package/dist/schema-definitions/ropid-gtfs/RopidGTFSPrecomputed.js.map +1 -1
- package/dist/schema-definitions/ropid-gtfs/models/precomputed/DeparturesModel.d.ts +1 -0
- package/dist/schema-definitions/ropid-gtfs/models/precomputed/DeparturesModel.js +18 -5
- package/dist/schema-definitions/ropid-gtfs/models/precomputed/DeparturesModel.js.map +1 -1
- package/dist/schema-definitions/ropid-gtfs/models/precomputed/interfaces/IDeparturesModel.d.ts +1 -0
- package/docs/implementation_documentation.md +10 -30
- package/docs/openapi-output.yaml +1 -1
- package/package.json +3 -4
- package/db/migrations/postgresql/20230327121511-departure-view.js +0 -53
- package/db/migrations/postgresql/sqls/20230327121511-departure-view-down.sql +0 -81
- package/db/migrations/postgresql/sqls/20230327121511-departure-view-up.sql +0 -37
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.js +0 -132
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/DeparturesRepository.js.map +0 -1
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/MinMaxStopSequencesRepository.d.ts +0 -9
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/MinMaxStopSequencesRepository.js.map +0 -1
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/ServicesCalendarRepository.d.ts +0 -9
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/ServicesCalendarRepository.js +0 -135
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/ServicesCalendarRepository.js.map +0 -1
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/TripScheduleRepository.d.ts +0 -11
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/TripScheduleRepository.js.map +0 -1
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/index.d.ts +0 -4
- package/dist/integration-engine/ropid-gtfs/data-access/precomputed/index.js.map +0 -1
- package/dist/integration-engine/ropid-gtfs/helpers/SourceTableSuffixEnum.d.ts +0 -5
- package/dist/integration-engine/ropid-gtfs/helpers/SourceTableSuffixEnum.js +0 -10
- package/dist/integration-engine/ropid-gtfs/helpers/SourceTableSuffixEnum.js.map +0 -1
|
@@ -9,44 +9,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const
|
|
14
|
-
const ropid_gtfs_1 = require("../../../../schema-definitions/ropid-gtfs");
|
|
12
|
+
exports.RopidGTFSMinMaxSequencesModel = void 0;
|
|
13
|
+
const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
|
|
15
14
|
const helpers_1 = require("@golemio/core/dist/integration-engine/helpers");
|
|
15
|
+
const ropid_gtfs_1 = require("../../schema-definitions/ropid-gtfs");
|
|
16
16
|
const models_1 = require("@golemio/core/dist/integration-engine/models");
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
class MinMaxStopSequencesRepository extends models_1.PostgresModel {
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
class RopidGTFSMinMaxSequencesModel extends models_1.PostgresModel {
|
|
20
19
|
constructor() {
|
|
21
|
-
super("
|
|
22
|
-
outputSequelizeAttributes: ropid_gtfs_1.RopidGTFS.
|
|
23
|
-
pgTableName: ropid_gtfs_1.RopidGTFS.
|
|
20
|
+
super(ropid_gtfs_1.RopidGTFS.minMaxSequences.name + "Model", {
|
|
21
|
+
outputSequelizeAttributes: ropid_gtfs_1.RopidGTFS.minMaxSequences.outputSequelizeAttributes,
|
|
22
|
+
pgTableName: ropid_gtfs_1.RopidGTFS.minMaxSequences.pgTableName,
|
|
24
23
|
pgSchema: ropid_gtfs_1.RopidGTFS.pgSchema,
|
|
25
24
|
savingType: "insertOnly",
|
|
26
25
|
attributesToRemove: ["id", "created_at", "updated_at"],
|
|
27
|
-
}, new golemio_validator_1.JSONSchemaValidator("
|
|
28
|
-
this.
|
|
26
|
+
}, new golemio_validator_1.JSONSchemaValidator(ropid_gtfs_1.RopidGTFS.minMaxSequences.name + "ModelValidator", ropid_gtfs_1.RopidGTFS.minMaxSequences.outputJsonSchema));
|
|
27
|
+
this.createAndPopulateFromTmp = () => __awaiter(this, void 0, void 0, function* () {
|
|
29
28
|
const sql = `
|
|
30
29
|
SELECT
|
|
31
|
-
trip_id,
|
|
32
|
-
max(stop_sequence) AS max_stop_sequence,
|
|
33
|
-
min(stop_sequence) AS min_stop_sequence,
|
|
34
|
-
GREATEST(
|
|
35
|
-
max(arrival_time::interval),
|
|
36
|
-
max(departure_time::interval)
|
|
37
|
-
) AS max_stop_time,
|
|
38
|
-
LEAST(
|
|
39
|
-
min(arrival_time::interval),
|
|
40
|
-
min(departure_time::interval)
|
|
41
|
-
) AS min_stop_time
|
|
42
|
-
FROM "${ropid_gtfs_1.RopidGTFS.pgSchema}".
|
|
43
|
-
GROUP BY trip_id
|
|
30
|
+
ropidgtfs_stop_times_tmp.trip_id,
|
|
31
|
+
max(ropidgtfs_stop_times_tmp.stop_sequence) AS max_stop_sequence,
|
|
32
|
+
min(ropidgtfs_stop_times_tmp.stop_sequence) AS min_stop_sequence,
|
|
33
|
+
(GREATEST(
|
|
34
|
+
max((ropidgtfs_stop_times_tmp.arrival_time)::interval),
|
|
35
|
+
max((ropidgtfs_stop_times_tmp.departure_time)::interval)
|
|
36
|
+
))::text AS max_stop_time,
|
|
37
|
+
(LEAST(
|
|
38
|
+
min((ropidgtfs_stop_times_tmp.arrival_time)::interval),
|
|
39
|
+
min((ropidgtfs_stop_times_tmp.departure_time)::interval)
|
|
40
|
+
))::text AS min_stop_time
|
|
41
|
+
FROM "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_stop_times_tmp
|
|
42
|
+
GROUP BY ropidgtfs_stop_times_tmp.trip_id
|
|
44
43
|
`;
|
|
45
44
|
try {
|
|
46
|
-
const tmpTable = ropid_gtfs_1.RopidGTFS.
|
|
45
|
+
const tmpTable = ropid_gtfs_1.RopidGTFS.minMaxSequences.pgTableName + "_tmp";
|
|
47
46
|
yield this.sequelizeModel.sequelize.query(`DROP TABLE IF EXISTS "${ropid_gtfs_1.RopidGTFS.pgSchema}"."${tmpTable}";
|
|
48
47
|
CREATE TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}"."${tmpTable}" (
|
|
49
|
-
LIKE "${ropid_gtfs_1.RopidGTFS.pgSchema}"."${ropid_gtfs_1.RopidGTFS.
|
|
48
|
+
LIKE "${ropid_gtfs_1.RopidGTFS.pgSchema}"."${ropid_gtfs_1.RopidGTFS.minMaxSequences.pgTableName}"
|
|
50
49
|
);
|
|
51
50
|
INSERT INTO "${ropid_gtfs_1.RopidGTFS.pgSchema}"."${tmpTable}" ${sql};`);
|
|
52
51
|
}
|
|
@@ -57,10 +56,10 @@ class MinMaxStopSequencesRepository extends models_1.PostgresModel {
|
|
|
57
56
|
});
|
|
58
57
|
this.replaceByTmp = (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
59
58
|
try {
|
|
60
|
-
const pgTableName = ropid_gtfs_1.RopidGTFS.
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const indexQuery = (0, utils_1.buildAlterIndexQuery)(ropid_gtfs_1.RopidGTFS.
|
|
59
|
+
const pgTableName = ropid_gtfs_1.RopidGTFS.minMaxSequences.pgTableName;
|
|
60
|
+
const tableNameActual = pgTableName + "_actual";
|
|
61
|
+
const tableNameTmp = pgTableName + "_tmp";
|
|
62
|
+
const indexQuery = (0, utils_1.buildAlterIndexQuery)(ropid_gtfs_1.RopidGTFS.minMaxSequences.modelIndexOptions);
|
|
64
63
|
yield this.sequelizeModel.sequelize.query(`
|
|
65
64
|
LOCK "${ropid_gtfs_1.RopidGTFS.pgSchema}".${pgTableName} IN EXCLUSIVE MODE;
|
|
66
65
|
ALTER TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tableNameActual} NO INHERIT "${ropid_gtfs_1.RopidGTFS.pgSchema}".${pgTableName};
|
|
@@ -77,8 +76,8 @@ class MinMaxStopSequencesRepository extends models_1.PostgresModel {
|
|
|
77
76
|
});
|
|
78
77
|
this.createIndexes = () => __awaiter(this, void 0, void 0, function* () {
|
|
79
78
|
try {
|
|
80
|
-
const indexes = ropid_gtfs_1.RopidGTFS.
|
|
81
|
-
const indexQuery = (0, utils_1.buildCreateIndexQuery)(ropid_gtfs_1.RopidGTFS.
|
|
79
|
+
const indexes = ropid_gtfs_1.RopidGTFS.minMaxSequences.modelIndexOptions;
|
|
80
|
+
const indexQuery = (0, utils_1.buildCreateIndexQuery)(ropid_gtfs_1.RopidGTFS.minMaxSequences.pgTableName, indexes);
|
|
82
81
|
yield this.sequelizeModel.sequelize.query(indexQuery);
|
|
83
82
|
}
|
|
84
83
|
catch (err) {
|
|
@@ -88,5 +87,5 @@ class MinMaxStopSequencesRepository extends models_1.PostgresModel {
|
|
|
88
87
|
});
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
|
-
exports.
|
|
92
|
-
//# sourceMappingURL=
|
|
90
|
+
exports.RopidGTFSMinMaxSequencesModel = RopidGTFSMinMaxSequencesModel;
|
|
91
|
+
//# sourceMappingURL=RopidGTFSMinMaxSequencesModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RopidGTFSMinMaxSequencesModel.js","sourceRoot":"","sources":["../../../src/integration-engine/ropid-gtfs/RopidGTFSMinMaxSequencesModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mFAAkF;AAElF,2EAAoE;AACpE,oEAA4C;AAC5C,yEAAqF;AACrF,mCAAmF;AAEnF,MAAa,6BAA8B,SAAQ,sBAAa;IAY5D;QACI,KAAK,CACD,sBAAS,CAAC,eAAe,CAAC,IAAI,GAAG,OAAO,EACxC;YACI,yBAAyB,EAAE,sBAAS,CAAC,eAAe,CAAC,yBAAyB;YAC9E,WAAW,EAAE,sBAAS,CAAC,eAAe,CAAC,WAAW;YAClD,QAAQ,EAAE,sBAAS,CAAC,QAAQ;YAC5B,UAAU,EAAE,YAAY;YACxB,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,CAAC;SACzD,EACD,IAAI,uCA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sBAAS,CAAC,QAAQ,MAAM,eAAe;kBAC7D,UAAU;+BACG,sBAAS,CAAC,QAAQ,MAAM,YAAY,eAAe,eAAe;+BAClE,sBAAS,CAAC,QAAQ,MAAM,eAAe,cAAc,sBAAS,CAAC,QAAQ,MAAM,WAAW;iBACtG,EACD,EAAE,WAAW,EAAE,CAClB,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,aAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM,GAAG,CAAC;aACb;QACL,CAAC,CAAA,CAAC;QAEK,kBAAa,GAAG,GAAwB,EAAE;YAC7C,IAAI;gBACA,MAAM,OAAO,GAAG,sBAAS,CAAC,eAAe,CAAC,iBAAiB,CAAC;gBAE5D,MAAM,UAAU,GAAG,IAAA,6BAAqB,EAAC,sBAAS,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBAEzF,MAAM,IAAI,CAAC,cAAc,CAAC,SAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;aAC1D;YAAC,OAAO,GAAG,EAAE;gBACV,aAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM,GAAG,CAAC;aACb;QACL,CAAC,CAAA,CAAC;IAxEF,CAAC;CAyEJ;AAjGD,sEAiGC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IModel, PostgresModel } from "@golemio/core/dist/integration-engine/models";
|
|
2
|
+
import { JSONSchemaValidator } from "@golemio/core/dist/shared/golemio-validator";
|
|
3
|
+
import Sequelize, { FindOptions, Transaction } from "@golemio/core/dist/shared/sequelize";
|
|
4
|
+
import { IGtfsRunTripCache } from "./interfaces/IGtfsRunTripCache";
|
|
5
|
+
export declare class RopidGTFSScheduledTripsModel extends PostgresModel implements IModel {
|
|
6
|
+
/** Model name */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The Sequelize Model */
|
|
9
|
+
sequelizeModel: Sequelize.ModelCtor<any>;
|
|
10
|
+
/** The Sequelize Model for temporary table */
|
|
11
|
+
protected tmpSequelizeModel: Sequelize.ModelCtor<any> | null;
|
|
12
|
+
/** Validation helper */
|
|
13
|
+
protected validator: JSONSchemaValidator;
|
|
14
|
+
/** Type/Strategy of saving the data */
|
|
15
|
+
protected savingType: "insertOnly" | "insertOrUpdate";
|
|
16
|
+
constructor();
|
|
17
|
+
findAll: (options: FindOptions) => Promise<IGtfsRunTripCache[]>;
|
|
18
|
+
createAndPopulateFromTmp: () => Promise<void>;
|
|
19
|
+
replaceByTmp: (transaction: Transaction) => Promise<void>;
|
|
20
|
+
createIndexes: () => Promise<void>;
|
|
21
|
+
}
|
|
@@ -9,26 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
const utils_1 = require("
|
|
14
|
-
const ropid_gtfs_1 = require("
|
|
12
|
+
exports.RopidGTFSScheduledTripsModel = void 0;
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const ropid_gtfs_1 = require("../../schema-definitions/ropid-gtfs");
|
|
15
15
|
const helpers_1 = require("@golemio/core/dist/integration-engine/helpers");
|
|
16
16
|
const models_1 = require("@golemio/core/dist/integration-engine/models");
|
|
17
17
|
const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
|
|
18
|
-
|
|
19
|
-
class TripScheduleRepository extends models_1.PostgresModel {
|
|
18
|
+
class RopidGTFSScheduledTripsModel extends models_1.PostgresModel {
|
|
20
19
|
constructor() {
|
|
21
|
-
super("
|
|
22
|
-
outputSequelizeAttributes: ropid_gtfs_1.RopidGTFS.
|
|
23
|
-
pgTableName: ropid_gtfs_1.RopidGTFS.
|
|
20
|
+
super(ropid_gtfs_1.RopidGTFS.scheduledTrips.name + "Model", {
|
|
21
|
+
outputSequelizeAttributes: ropid_gtfs_1.RopidGTFS.scheduledTrips.outputSequelizeAttributes,
|
|
22
|
+
pgTableName: ropid_gtfs_1.RopidGTFS.scheduledTrips.pgTableName,
|
|
24
23
|
pgSchema: ropid_gtfs_1.RopidGTFS.pgSchema,
|
|
25
24
|
savingType: "insertOnly",
|
|
26
25
|
attributesToRemove: ["id", "created_at", "updated_at"],
|
|
27
|
-
}, new golemio_validator_1.JSONSchemaValidator("
|
|
26
|
+
}, new golemio_validator_1.JSONSchemaValidator(ropid_gtfs_1.RopidGTFS.scheduledTrips.name + "ModelValidator", ropid_gtfs_1.RopidGTFS.scheduledTrips.outputJsonSchema));
|
|
28
27
|
this.findAll = (options) => {
|
|
29
28
|
return this.sequelizeModel.findAll(Object.assign({ raw: true }, options));
|
|
30
29
|
};
|
|
31
|
-
this.
|
|
30
|
+
this.createAndPopulateFromTmp = () => __awaiter(this, void 0, void 0, function* () {
|
|
32
31
|
/* eslint-disable max-len */
|
|
33
32
|
const sql = `
|
|
34
33
|
SELECT
|
|
@@ -115,21 +114,21 @@ class TripScheduleRepository extends models_1.PostgresModel {
|
|
|
115
114
|
GREATEST(t6.arrival_time::INTERVAL, t6.departure_time::INTERVAL) AS max_stop_time,
|
|
116
115
|
t5.stop_id AS first_stop_id,
|
|
117
116
|
t6.stop_id AS last_stop_id
|
|
118
|
-
FROM "${ropid_gtfs_1.RopidGTFS.pgSchema}".
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".
|
|
122
|
-
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".
|
|
123
|
-
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".
|
|
124
|
-
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".
|
|
117
|
+
FROM "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_run_numbers_tmp t1
|
|
118
|
+
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_services_first14days_tmp t3 ON t1.service_id = t3.service_id
|
|
119
|
+
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_trips_minmaxsequences_tmp t4 ON t1.trip_id = t4.trip_id
|
|
120
|
+
LEFT OUTER JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_stop_times_tmp t5 ON t1.trip_id = t5.trip_id AND t5.stop_sequence = t4.min_stop_sequence
|
|
121
|
+
LEFT OUTER JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_stop_times_tmp t6 ON t1.trip_id = t6.trip_id AND t6.stop_sequence = t4.max_stop_sequence
|
|
122
|
+
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_trips_tmp t8 ON t1.trip_id = t8.trip_id
|
|
123
|
+
LEFT JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_routes_tmp t7 ON t8.route_id = t7.route_id
|
|
125
124
|
) t0;
|
|
126
125
|
`;
|
|
127
126
|
/* eslint-enable max-len */
|
|
128
127
|
try {
|
|
129
|
-
const tmpTable = ropid_gtfs_1.RopidGTFS.
|
|
128
|
+
const tmpTable = ropid_gtfs_1.RopidGTFS.scheduledTrips.pgTableName + "_tmp";
|
|
130
129
|
yield this.sequelizeModel.sequelize.query(`DROP TABLE IF EXISTS "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tmpTable};
|
|
131
130
|
CREATE TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tmpTable} (
|
|
132
|
-
LIKE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${ropid_gtfs_1.RopidGTFS.
|
|
131
|
+
LIKE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${ropid_gtfs_1.RopidGTFS.scheduledTrips.pgTableName}
|
|
133
132
|
);
|
|
134
133
|
INSERT INTO "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tmpTable} ${sql};`);
|
|
135
134
|
}
|
|
@@ -140,10 +139,10 @@ class TripScheduleRepository extends models_1.PostgresModel {
|
|
|
140
139
|
});
|
|
141
140
|
this.replaceByTmp = (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
142
141
|
try {
|
|
143
|
-
const pgTableName = ropid_gtfs_1.RopidGTFS.
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const indexQuery = (0, utils_1.buildAlterIndexQuery)(ropid_gtfs_1.RopidGTFS.
|
|
142
|
+
const pgTableName = ropid_gtfs_1.RopidGTFS.scheduledTrips.pgTableName;
|
|
143
|
+
const tableNameActual = pgTableName + "_actual";
|
|
144
|
+
const tableNameTmp = pgTableName + "_tmp";
|
|
145
|
+
const indexQuery = (0, utils_1.buildAlterIndexQuery)(ropid_gtfs_1.RopidGTFS.scheduledTrips.modelIndexOptions);
|
|
147
146
|
yield this.sequelizeModel.sequelize.query(`
|
|
148
147
|
LOCK "${ropid_gtfs_1.RopidGTFS.pgSchema}".${pgTableName} IN EXCLUSIVE MODE;
|
|
149
148
|
ALTER TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tableNameActual} NO INHERIT "${ropid_gtfs_1.RopidGTFS.pgSchema}".${pgTableName};
|
|
@@ -160,8 +159,8 @@ class TripScheduleRepository extends models_1.PostgresModel {
|
|
|
160
159
|
});
|
|
161
160
|
this.createIndexes = () => __awaiter(this, void 0, void 0, function* () {
|
|
162
161
|
try {
|
|
163
|
-
const indexes = ropid_gtfs_1.RopidGTFS.
|
|
164
|
-
const indexQuery = (0, utils_1.buildCreateIndexQuery)(ropid_gtfs_1.RopidGTFS.
|
|
162
|
+
const indexes = ropid_gtfs_1.RopidGTFS.scheduledTrips.modelIndexOptions;
|
|
163
|
+
const indexQuery = (0, utils_1.buildCreateIndexQuery)(ropid_gtfs_1.RopidGTFS.scheduledTrips.pgTableName, indexes);
|
|
165
164
|
yield this.sequelizeModel.sequelize.query(indexQuery);
|
|
166
165
|
}
|
|
167
166
|
catch (err) {
|
|
@@ -171,5 +170,5 @@ class TripScheduleRepository extends models_1.PostgresModel {
|
|
|
171
170
|
});
|
|
172
171
|
}
|
|
173
172
|
}
|
|
174
|
-
exports.
|
|
175
|
-
//# sourceMappingURL=
|
|
173
|
+
exports.RopidGTFSScheduledTripsModel = RopidGTFSScheduledTripsModel;
|
|
174
|
+
//# sourceMappingURL=RopidGTFSScheduledTripsModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RopidGTFSScheduledTripsModel.js","sourceRoot":"","sources":["../../../src/integration-engine/ropid-gtfs/RopidGTFSScheduledTripsModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAmF;AACnF,oEAA4C;AAC5C,2EAAoE;AACpE,yEAAqF;AACrF,mFAAkF;AAIlF,MAAa,4BAA6B,SAAQ,sBAAa;IAY3D;QACI,KAAK,CACD,sBAAS,CAAC,cAAc,CAAC,IAAI,GAAG,OAAO,EACvC;YACI,yBAAyB,EAAE,sBAAS,CAAC,cAAc,CAAC,yBAAyB;YAC7E,WAAW,EAAE,sBAAS,CAAC,cAAc,CAAC,WAAW;YACjD,QAAQ,EAAE,sBAAS,CAAC,QAAQ;YAC5B,UAAU,EAAE,YAAY;YACxB,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,CAAC;SACzD,EACD,IAAI,uCAAmB,CAAC,sBAAS,CAAC,cAAc,CAAC,IAAI,GAAG,gBAAgB,EAAE,sBAAS,CAAC,cAAc,CAAC,gBAAgB,CAAC,CACvH,CAAC;QAGC,YAAO,GAAG,CAAC,OAAoB,EAAgC,EAAE;YACpE,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,iBAAG,GAAG,EAAE,IAAI,IAAK,OAAO,EAAG,CAAC;QAClE,CAAC,CAAC;QAEK,6BAAwB,GAAG,GAAwB,EAAE;YACxD,4BAA4B;YAC5B,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAW;wCAC/E,sBAAS,CAAC,QAAQ,KAAK,eAAe;kBAC5D,UAAU;+BACG,sBAAS,CAAC,QAAQ,KAAK,YAAY,cAAc,eAAe;+BAChE,sBAAS,CAAC,QAAQ,KAAK,eAAe,aAAa,sBAAS,CAAC,QAAQ,KAAK,WAAW;iBACnG,EACD,EAAE,WAAW,EAAE,CAClB,CAAC;aACL;YAAC,OAAO,GAAG,EAAE;gBACV,aAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM,GAAG,CAAC;aACb;QACL,CAAC,CAAA,CAAC;QAEK,kBAAa,GAAG,GAAwB,EAAE;YAC7C,IAAI;gBACA,MAAM,OAAO,GAAG,sBAAS,CAAC,cAAc,CAAC,iBAAiB,CAAC;gBAE3D,MAAM,UAAU,GAAG,IAAA,6BAAqB,EAAC,sBAAS,CAAC,cAAc,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBAExF,MAAM,IAAI,CAAC,cAAc,CAAC,SAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;aAC1D;YAAC,OAAO,GAAG,EAAE;gBACV,aAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM,GAAG,CAAC;aACb;QACL,CAAC,CAAA,CAAC;IA5JF,CAAC;CA6JJ;AArLD,oEAqLC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JSONSchemaValidator } from "@golemio/core/dist/shared/golemio-validator";
|
|
2
|
+
import Sequelize, { Transaction } from "@golemio/core/dist/shared/sequelize";
|
|
3
|
+
import { IModel, PostgresModel } from "@golemio/core/dist/integration-engine/models";
|
|
4
|
+
export declare class RopidGTFSServicesFirst14daysModel extends PostgresModel implements IModel {
|
|
5
|
+
/** Model name */
|
|
6
|
+
name: string;
|
|
7
|
+
/** The Sequelize Model */
|
|
8
|
+
sequelizeModel: Sequelize.ModelCtor<any>;
|
|
9
|
+
/** The Sequelize Model for temporary table */
|
|
10
|
+
protected tmpSequelizeModel: Sequelize.ModelCtor<any> | null;
|
|
11
|
+
/** Validation helper */
|
|
12
|
+
protected validator: JSONSchemaValidator;
|
|
13
|
+
/** Type/Strategy of saving the data */
|
|
14
|
+
protected savingType: "insertOnly" | "insertOrUpdate";
|
|
15
|
+
constructor();
|
|
16
|
+
createAndPopulateFromTmp: () => Promise<void>;
|
|
17
|
+
replaceByTmp: (transaction: Transaction) => Promise<void>;
|
|
18
|
+
createIndexes: () => Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RopidGTFSServicesFirst14daysModel = void 0;
|
|
13
|
+
const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
|
|
14
|
+
const helpers_1 = require("@golemio/core/dist/integration-engine/helpers");
|
|
15
|
+
const models_1 = require("@golemio/core/dist/integration-engine/models");
|
|
16
|
+
const ropid_gtfs_1 = require("../../schema-definitions/ropid-gtfs");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
class RopidGTFSServicesFirst14daysModel extends models_1.PostgresModel {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(ropid_gtfs_1.RopidGTFS.services_first14days.name + "Model", {
|
|
21
|
+
outputSequelizeAttributes: ropid_gtfs_1.RopidGTFS.services_first14days.outputSequelizeAttributes,
|
|
22
|
+
pgTableName: ropid_gtfs_1.RopidGTFS.services_first14days.pgTableName,
|
|
23
|
+
pgSchema: ropid_gtfs_1.RopidGTFS.pgSchema,
|
|
24
|
+
savingType: "insertOnly",
|
|
25
|
+
attributesToRemove: ["id", "created_at", "updated_at"],
|
|
26
|
+
}, new golemio_validator_1.JSONSchemaValidator(ropid_gtfs_1.RopidGTFS.services_first14days.name + "ModelValidator", ropid_gtfs_1.RopidGTFS.services_first14days.outputJsonSchema));
|
|
27
|
+
this.createAndPopulateFromTmp = () => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const sql = `
|
|
29
|
+
SELECT
|
|
30
|
+
dates.date,
|
|
31
|
+
(
|
|
32
|
+
date_part('day'::text, ((dates.date)::timestamp without time zone - (
|
|
33
|
+
to_char(timezone('Europe/Prague'::text, now()), 'YYYY-MM-DD'::text)
|
|
34
|
+
)::timestamp without time zone))
|
|
35
|
+
)::integer AS day_diff,
|
|
36
|
+
ropidgtfs_calendar_tmp.service_id
|
|
37
|
+
FROM (
|
|
38
|
+
(
|
|
39
|
+
SELECT
|
|
40
|
+
(date_trunc('day'::text, dd.dd))::date AS date
|
|
41
|
+
FROM generate_series(
|
|
42
|
+
((( SELECT (CURRENT_TIMESTAMP - '1 day'::interval)))::date)::timestamp with time zone,
|
|
43
|
+
((( SELECT (CURRENT_TIMESTAMP + '12 days'::interval)))::date)::timestamp with time zone,
|
|
44
|
+
'1 day'::interval
|
|
45
|
+
) dd(dd)
|
|
46
|
+
) dates
|
|
47
|
+
JOIN "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_calendar_tmp ON ((1 = 1))
|
|
48
|
+
)
|
|
49
|
+
WHERE (
|
|
50
|
+
(
|
|
51
|
+
(dates.date >= (ropidgtfs_calendar_tmp.start_date)::date)
|
|
52
|
+
AND (dates.date <= (ropidgtfs_calendar_tmp.end_date)::date)
|
|
53
|
+
AND (
|
|
54
|
+
(
|
|
55
|
+
(btrim(to_char((dates.date)::timestamp with time zone, 'day'::text)) = 'monday'::text)
|
|
56
|
+
AND (ropidgtfs_calendar_tmp.monday = 1)
|
|
57
|
+
) OR (
|
|
58
|
+
(btrim(to_char((dates.date)::timestamp with time zone, 'day'::text)) = 'tuesday'::text)
|
|
59
|
+
AND (ropidgtfs_calendar_tmp.tuesday = 1)
|
|
60
|
+
) OR (
|
|
61
|
+
(btrim(to_char((dates.date)::timestamp with time zone, 'day'::text)) = 'wednesday'::text)
|
|
62
|
+
AND (ropidgtfs_calendar_tmp.wednesday = 1)
|
|
63
|
+
) OR (
|
|
64
|
+
(btrim(to_char((dates.date)::timestamp with time zone, 'day'::text)) = 'thursday'::text)
|
|
65
|
+
AND (ropidgtfs_calendar_tmp.thursday = 1)
|
|
66
|
+
) OR (
|
|
67
|
+
(btrim(to_char((dates.date)::timestamp with time zone, 'day'::text)) = 'friday'::text)
|
|
68
|
+
AND (ropidgtfs_calendar_tmp.friday = 1)
|
|
69
|
+
) OR (
|
|
70
|
+
(btrim(to_char((dates.date)::timestamp with time zone, 'day'::text)) = 'saturday'::text)
|
|
71
|
+
AND (ropidgtfs_calendar_tmp.saturday = 1)
|
|
72
|
+
) OR (
|
|
73
|
+
(btrim(to_char((dates.date)::timestamp with time zone, 'day'::text)) = 'sunday'::text)
|
|
74
|
+
AND (ropidgtfs_calendar_tmp.sunday = 1)
|
|
75
|
+
)
|
|
76
|
+
) AND (
|
|
77
|
+
NOT ((ropidgtfs_calendar_tmp.service_id)::text IN (
|
|
78
|
+
SELECT ropidgtfs_calendar_dates_tmp.service_id
|
|
79
|
+
FROM "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_calendar_dates_tmp
|
|
80
|
+
WHERE (
|
|
81
|
+
(ropidgtfs_calendar_dates_tmp.exception_type = 2)
|
|
82
|
+
AND (dates.date = (ropidgtfs_calendar_dates_tmp.date)::date)
|
|
83
|
+
)
|
|
84
|
+
))
|
|
85
|
+
)) OR ((ropidgtfs_calendar_tmp.service_id)::text IN (
|
|
86
|
+
SELECT ropidgtfs_calendar_dates_tmp.service_id
|
|
87
|
+
FROM "${ropid_gtfs_1.RopidGTFS.pgSchema}".ropidgtfs_calendar_dates_tmp
|
|
88
|
+
WHERE (
|
|
89
|
+
(ropidgtfs_calendar_dates_tmp.exception_type = 1)
|
|
90
|
+
AND (dates.date = (ropidgtfs_calendar_dates_tmp.date)::date)
|
|
91
|
+
))
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
ORDER BY dates.date
|
|
95
|
+
`;
|
|
96
|
+
try {
|
|
97
|
+
const tmpTable = ropid_gtfs_1.RopidGTFS.services_first14days.pgTableName + "_tmp";
|
|
98
|
+
yield this.sequelizeModel.sequelize.query(`DROP TABLE IF EXISTS "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tmpTable};
|
|
99
|
+
CREATE TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tmpTable} (
|
|
100
|
+
LIKE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${ropid_gtfs_1.RopidGTFS.services_first14days.pgTableName}
|
|
101
|
+
);
|
|
102
|
+
INSERT INTO "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tmpTable} ${sql};`);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
helpers_1.log.error(err);
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
this.replaceByTmp = (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
try {
|
|
111
|
+
const pgTableName = ropid_gtfs_1.RopidGTFS.services_first14days.pgTableName;
|
|
112
|
+
const tableNameActual = pgTableName + "_actual";
|
|
113
|
+
const tableNameTmp = pgTableName + "_tmp";
|
|
114
|
+
const indexQuery = (0, utils_1.buildAlterIndexQuery)(ropid_gtfs_1.RopidGTFS.services_first14days.modelIndexOptions);
|
|
115
|
+
yield this.sequelizeModel.sequelize.query(`
|
|
116
|
+
LOCK "${ropid_gtfs_1.RopidGTFS.pgSchema}".${pgTableName} IN EXCLUSIVE MODE;
|
|
117
|
+
ALTER TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tableNameActual} NO INHERIT "${ropid_gtfs_1.RopidGTFS.pgSchema}".${pgTableName};
|
|
118
|
+
DROP TABLE IF EXISTS "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tableNameActual};
|
|
119
|
+
${indexQuery}
|
|
120
|
+
ALTER TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tableNameTmp} RENAME TO ${tableNameActual};
|
|
121
|
+
ALTER TABLE "${ropid_gtfs_1.RopidGTFS.pgSchema}".${tableNameActual} INHERIT "${ropid_gtfs_1.RopidGTFS.pgSchema}".${pgTableName};
|
|
122
|
+
`, { transaction });
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
helpers_1.log.error(err);
|
|
126
|
+
throw err;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
this.createIndexes = () => __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
try {
|
|
131
|
+
const indexQuery = (0, utils_1.buildCreateIndexQuery)(ropid_gtfs_1.RopidGTFS.services_first14days.pgTableName, ropid_gtfs_1.RopidGTFS.services_first14days.modelIndexOptions);
|
|
132
|
+
yield this.sequelizeModel.sequelize.query(indexQuery);
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
helpers_1.log.error(err);
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.RopidGTFSServicesFirst14daysModel = RopidGTFSServicesFirst14daysModel;
|
|
142
|
+
//# sourceMappingURL=RopidGTFSServicesFirst14daysModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RopidGTFSServicesFirst14daysModel.js","sourceRoot":"","sources":["../../../src/integration-engine/ropid-gtfs/RopidGTFSServicesFirst14daysModel.ts"],"names":[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BACV,aAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM,GAAG,CAAC;aACb;QACL,CAAC,CAAA,CAAC;IA5HF,CAAC;CA6HJ;AAxJD,8EAwJC"}
|
|
@@ -21,9 +21,9 @@ export declare class RopidGTFSWorker extends BaseWorker {
|
|
|
21
21
|
private transformationDeparturesPresets;
|
|
22
22
|
/** Precomputed data repositories */
|
|
23
23
|
private departuresRepository;
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
24
|
+
private ropidGTFSMinMaxSequencesModel;
|
|
25
|
+
private ropidGTFSScheduledTripsModel;
|
|
26
|
+
private ropidGTFSServicesFirst14daysModel;
|
|
27
27
|
private metaModel;
|
|
28
28
|
private redisModel;
|
|
29
29
|
private departuresPresetsModel;
|
|
@@ -58,7 +58,6 @@ export declare class RopidGTFSWorker extends BaseWorker {
|
|
|
58
58
|
* Queue listener method - verify tmp tables and replace public
|
|
59
59
|
*/
|
|
60
60
|
checkSavedRowsAndReplaceTables: (msg: AMQPMessage) => Promise<boolean>;
|
|
61
|
-
refreshPrecomputedTables: () => Promise<void>;
|
|
62
61
|
/**
|
|
63
62
|
* Queue listener method - triggers processing of DEPARTURES_PRESETS dataset
|
|
64
63
|
*/
|
|
@@ -41,8 +41,7 @@ const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator
|
|
|
41
41
|
const os_1 = __importDefault(require("os"));
|
|
42
42
|
const pg_copy_streams_1 = require("pg-copy-streams");
|
|
43
43
|
const _1 = require("./");
|
|
44
|
-
const
|
|
45
|
-
const SourceTableSuffixEnum_1 = require("./helpers/SourceTableSuffixEnum");
|
|
44
|
+
const data_access_1 = require("./data-access");
|
|
46
45
|
var CacheContentType;
|
|
47
46
|
(function (CacheContentType) {
|
|
48
47
|
CacheContentType["CSV"] = "CSV";
|
|
@@ -328,7 +327,7 @@ class RopidGTFSWorker extends workers_1.BaseWorker {
|
|
|
328
327
|
yield Promise.all(datasetDeployInfo.map((el) => __awaiter(this, void 0, void 0, function* () {
|
|
329
328
|
yield this.metaModel.checkSavedTmpTables(el.dataset, el.lastModified.version);
|
|
330
329
|
})));
|
|
331
|
-
yield this.createAndPopulatePrecomputedTmpTables(
|
|
330
|
+
yield this.createAndPopulatePrecomputedTmpTables();
|
|
332
331
|
yield this.metaModel.replaceTables(notDeployedVersions);
|
|
333
332
|
// this flushes all models on current db
|
|
334
333
|
yield this.redisModel.flush();
|
|
@@ -350,33 +349,11 @@ class RopidGTFSWorker extends workers_1.BaseWorker {
|
|
|
350
349
|
return true;
|
|
351
350
|
}
|
|
352
351
|
else {
|
|
353
|
-
//
|
|
354
|
-
yield this.sendMessageToExchange("workers." + this.queuePrefix + ".refreshPrecomputedTables", "");
|
|
352
|
+
// finish with error
|
|
355
353
|
throw new golemio_errors_1.CustomError("Error while checking RopidGTFS saved rows.", true, this.constructor.name, 5004, err);
|
|
356
354
|
}
|
|
357
355
|
}
|
|
358
356
|
});
|
|
359
|
-
this.refreshPrecomputedTables = () => __awaiter(this, void 0, void 0, function* () {
|
|
360
|
-
try {
|
|
361
|
-
yield this.createAndPopulatePrecomputedTmpTables(SourceTableSuffixEnum_1.SourceTableSuffixEnum.Actual);
|
|
362
|
-
}
|
|
363
|
-
catch (err) {
|
|
364
|
-
helpers_1.log.error(err);
|
|
365
|
-
throw new golemio_errors_1.CustomError("Error while creating RopidGTFS precomputed tables", true, this.constructor.name);
|
|
366
|
-
}
|
|
367
|
-
const connection = connectors_1.PostgresConnector.getConnection();
|
|
368
|
-
const transaction = yield connection.transaction();
|
|
369
|
-
try {
|
|
370
|
-
yield this.metaModel.replacePrecomputedTables(transaction);
|
|
371
|
-
yield transaction.commit();
|
|
372
|
-
}
|
|
373
|
-
catch (err) {
|
|
374
|
-
yield transaction.rollback();
|
|
375
|
-
helpers_1.log.error(err);
|
|
376
|
-
throw new golemio_errors_1.CustomError("Error while replacing RopidGTFS precomputed tables", true, this.constructor.name);
|
|
377
|
-
}
|
|
378
|
-
yield this.redisModel.flush();
|
|
379
|
-
});
|
|
380
357
|
/**
|
|
381
358
|
* Queue listener method - triggers processing of DEPARTURES_PRESETS dataset
|
|
382
359
|
*/
|
|
@@ -446,7 +423,7 @@ class RopidGTFSWorker extends workers_1.BaseWorker {
|
|
|
446
423
|
// get connection and db client
|
|
447
424
|
const connection = connectors_1.PostgresConnector.getConnection();
|
|
448
425
|
const client = (yield connection.connectionManager.getConnection({ type: "write" }));
|
|
449
|
-
const tmpTableName = ropid_gtfs_1.RopidGTFS[modelName].pgTableName +
|
|
426
|
+
const tmpTableName = ropid_gtfs_1.RopidGTFS[modelName].pgTableName + "_tmp";
|
|
450
427
|
// copy transformed data to tmp table by stream
|
|
451
428
|
yield new Promise((resolve, reject) => {
|
|
452
429
|
const stream = client
|
|
@@ -473,12 +450,12 @@ class RopidGTFSWorker extends workers_1.BaseWorker {
|
|
|
473
450
|
hasTmpTable: false,
|
|
474
451
|
outputSequelizeAttributes: modelDef.outputSequelizeAttributes,
|
|
475
452
|
pgSchema: ropid_gtfs_1.RopidGTFS.pgSchema,
|
|
476
|
-
pgTableName: modelDef.pgTableName +
|
|
453
|
+
pgTableName: modelDef.pgTableName + "_tmp",
|
|
477
454
|
savingType: "insertOnly",
|
|
478
455
|
sequelizeAdditionalSettings: Object.assign({ timestamps: false }, (modelDef.modelIndexOptions &&
|
|
479
456
|
modelDef.modelIndexOptions.length && {
|
|
480
457
|
indexes: modelDef.modelIndexOptions.map((indexDef) => {
|
|
481
|
-
return Object.assign(Object.assign({}, indexDef), { name: indexDef.name +
|
|
458
|
+
return Object.assign(Object.assign({}, indexDef), { name: indexDef.name + "_tmp" });
|
|
482
459
|
}),
|
|
483
460
|
})),
|
|
484
461
|
}, new golemio_validator_1.JSONSchemaValidator(modelDef.name + "Tmp" + "ModelValidator", modelDef.outputMongooseSchemaObject));
|
|
@@ -492,24 +469,15 @@ class RopidGTFSWorker extends workers_1.BaseWorker {
|
|
|
492
469
|
yield model.sync({ force: true, schema: ropid_gtfs_1.RopidGTFS.pgSchema });
|
|
493
470
|
return model;
|
|
494
471
|
});
|
|
495
|
-
this.createAndPopulatePrecomputedTmpTables = (
|
|
496
|
-
|
|
497
|
-
yield this.
|
|
498
|
-
|
|
499
|
-
yield this.
|
|
500
|
-
|
|
501
|
-
yield this.
|
|
502
|
-
|
|
503
|
-
yield this.minMaxStopSequencesRepository.createIndexes();
|
|
504
|
-
helpers_1.log.info(`Datasets: creating temp table ${this.tripScheduleRepository["tableName"]}${SourceTableSuffixEnum_1.SourceTableSuffixEnum.Tmp}`);
|
|
505
|
-
yield this.tripScheduleRepository.createAndPopulate(sourceTableSuffix);
|
|
506
|
-
helpers_1.log.info(`Datasets: creating indexes on ${this.tripScheduleRepository["tableName"]}${SourceTableSuffixEnum_1.SourceTableSuffixEnum.Tmp}`);
|
|
507
|
-
yield this.tripScheduleRepository.createIndexes();
|
|
508
|
-
helpers_1.log.info(`Datasets: creating temp table ${this.departuresRepository["tableName"]}${SourceTableSuffixEnum_1.SourceTableSuffixEnum.Tmp}`);
|
|
509
|
-
yield this.departuresRepository.createAndPopulate(sourceTableSuffix);
|
|
510
|
-
helpers_1.log.info(`Datasets: creating indexes on ${this.departuresRepository["tableName"]}${SourceTableSuffixEnum_1.SourceTableSuffixEnum.Tmp}`);
|
|
472
|
+
this.createAndPopulatePrecomputedTmpTables = () => __awaiter(this, void 0, void 0, function* () {
|
|
473
|
+
yield this.ropidGTFSServicesFirst14daysModel.createAndPopulateFromTmp();
|
|
474
|
+
yield this.ropidGTFSServicesFirst14daysModel.createIndexes();
|
|
475
|
+
yield this.ropidGTFSMinMaxSequencesModel.createAndPopulateFromTmp();
|
|
476
|
+
yield this.ropidGTFSMinMaxSequencesModel.createIndexes();
|
|
477
|
+
yield this.ropidGTFSScheduledTripsModel.createAndPopulateFromTmp();
|
|
478
|
+
yield this.ropidGTFSScheduledTripsModel.createIndexes();
|
|
479
|
+
yield this.departuresRepository.createAndPopulateFromTmp();
|
|
511
480
|
yield this.departuresRepository.createIndexes();
|
|
512
|
-
helpers_1.log.info(`Datasets: running analyze on ${this.departuresRepository["tableName"]}${SourceTableSuffixEnum_1.SourceTableSuffixEnum.Tmp}`);
|
|
513
481
|
yield this.departuresRepository.analyze();
|
|
514
482
|
});
|
|
515
483
|
// Redis Models
|
|
@@ -606,10 +574,10 @@ class RopidGTFSWorker extends workers_1.BaseWorker {
|
|
|
606
574
|
},
|
|
607
575
|
};
|
|
608
576
|
/** Precomputed data repositories */
|
|
609
|
-
this.departuresRepository = new
|
|
610
|
-
this.
|
|
611
|
-
this.
|
|
612
|
-
this.
|
|
577
|
+
this.departuresRepository = new data_access_1.DeparturesRepository();
|
|
578
|
+
this.ropidGTFSMinMaxSequencesModel = new _1.RopidGTFSMinMaxSequencesModel();
|
|
579
|
+
this.ropidGTFSScheduledTripsModel = new _1.RopidGTFSScheduledTripsModel();
|
|
580
|
+
this.ropidGTFSServicesFirst14daysModel = new _1.RopidGTFSServicesFirst14daysModel();
|
|
613
581
|
this.queuePrefix = config_1.config.RABBIT_EXCHANGE_NAME + "." + ropid_gtfs_1.RopidGTFS.name.toLowerCase();
|
|
614
582
|
}
|
|
615
583
|
}
|