@tmlmobilidade/import-gtfs 20251010.751.17 → 20251010.756.34
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/dist/index.d.ts +2 -19
- package/dist/index.js +2 -65
- package/dist/src/main.d.ts +9 -0
- package/dist/src/main.js +65 -0
- package/dist/src/processors/calendar.d.ts +1 -2
- package/dist/src/processors/calendar_dates.d.ts +1 -2
- package/dist/src/types.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Configuration options for importing GTFS data into a database.
|
|
5
|
-
*/
|
|
6
|
-
export interface ImportGtfsToDatabaseConfig {
|
|
7
|
-
date_range?: {
|
|
8
|
-
end: OperationalDate;
|
|
9
|
-
start: OperationalDate;
|
|
10
|
-
};
|
|
11
|
-
discrete_dates?: OperationalDate[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Imports GTFS data into the database for a given plan.
|
|
15
|
-
* @param plan The plan containing GTFS feed information.
|
|
16
|
-
* @param config Optional configuration for the import process.
|
|
17
|
-
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
18
|
-
*/
|
|
19
|
-
export declare function importGtfsToDatabase(plan: Plan, config?: ImportGtfsToDatabaseConfig): Promise<GtfsSQLTables>;
|
|
1
|
+
export * from './src/main.js';
|
|
2
|
+
export * from './src/types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { processCalendarDatesFile } from './src/processors/calendar_dates.js';
|
|
4
|
-
import { processRoutesFile } from './src/processors/routes.js';
|
|
5
|
-
import { processShapesFile } from './src/processors/shapes.js';
|
|
6
|
-
import { processStopTimesFile } from './src/processors/stop_times.js';
|
|
7
|
-
import { processStopsFile } from './src/processors/stops.js';
|
|
8
|
-
import { processTripsFile } from './src/processors/trips.js';
|
|
9
|
-
import { downloadAndExtractGtfs } from './src/utils/extract-file.js';
|
|
10
|
-
import { initGtfsSqlTables } from './src/utils/init-tables.js';
|
|
11
|
-
import TIMETRACKER from '@helperkits/timer';
|
|
12
|
-
import { Logs } from '@tmlmobilidade/utils';
|
|
13
|
-
/**
|
|
14
|
-
* Imports GTFS data into the database for a given plan.
|
|
15
|
-
* @param plan The plan containing GTFS feed information.
|
|
16
|
-
* @param config Optional configuration for the import process.
|
|
17
|
-
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
18
|
-
*/
|
|
19
|
-
export async function importGtfsToDatabase(plan, config = {}) {
|
|
20
|
-
try {
|
|
21
|
-
//
|
|
22
|
-
const globalTimer = new TIMETRACKER();
|
|
23
|
-
Logs.info(`Importing ${plan._id} GTFS to database...`);
|
|
24
|
-
//
|
|
25
|
-
// Initialize context for the current plan
|
|
26
|
-
const context = {
|
|
27
|
-
counters: {
|
|
28
|
-
calendar_dates: 0,
|
|
29
|
-
hashed_shapes: 0,
|
|
30
|
-
hashed_trips: 0,
|
|
31
|
-
shapes: 0,
|
|
32
|
-
stop_times: 0,
|
|
33
|
-
trips: 0,
|
|
34
|
-
},
|
|
35
|
-
gtfs: initGtfsSqlTables(),
|
|
36
|
-
plan: plan,
|
|
37
|
-
referenced_route_ids: new Set(),
|
|
38
|
-
referenced_shape_ids: new Set(),
|
|
39
|
-
workdir: await downloadAndExtractGtfs(plan),
|
|
40
|
-
};
|
|
41
|
-
//
|
|
42
|
-
// Validate GTFS feed info
|
|
43
|
-
if (!plan.gtfs_feed_info?.feed_start_date || !plan.gtfs_feed_info?.feed_end_date) {
|
|
44
|
-
throw new Error(`Plan "${plan._id}" is missing GTFS feed start and/or end date.`);
|
|
45
|
-
}
|
|
46
|
-
//
|
|
47
|
-
// Process GTFS files in the correct order
|
|
48
|
-
await processCalendarFile(context, config);
|
|
49
|
-
await processCalendarDatesFile(context, config);
|
|
50
|
-
await processTripsFile(context);
|
|
51
|
-
await processRoutesFile(context);
|
|
52
|
-
await processShapesFile(context);
|
|
53
|
-
await processStopsFile(context);
|
|
54
|
-
await processStopTimesFile(context);
|
|
55
|
-
Logs.success(`Finished importing GTFS to database for plan "${plan._id}" in ${globalTimer.get()}.`, 0);
|
|
56
|
-
Logs.divider();
|
|
57
|
-
Logs.terminate(`Finished importing GTFS to database in ${globalTimer.get()}.`);
|
|
58
|
-
return context.gtfs;
|
|
59
|
-
//
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
Logs.error('Error parsing plan.', error);
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
export * from './src/main.js';
|
|
2
|
+
export * from './src/types.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type GtfsSQLTables, type ImportGtfsToDatabaseConfig } from './types.js';
|
|
2
|
+
import { type Plan } from '@tmlmobilidade/types';
|
|
3
|
+
/**
|
|
4
|
+
* Imports GTFS data into the database for a given plan.
|
|
5
|
+
* @param plan The plan containing GTFS feed information.
|
|
6
|
+
* @param config Optional configuration for the import process.
|
|
7
|
+
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
8
|
+
*/
|
|
9
|
+
export declare function importGtfsToDatabase(plan: Plan, config?: ImportGtfsToDatabaseConfig): Promise<GtfsSQLTables>;
|
package/dist/src/main.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* * */
|
|
2
|
+
import { processCalendarFile } from './processors/calendar.js';
|
|
3
|
+
import { processCalendarDatesFile } from './processors/calendar_dates.js';
|
|
4
|
+
import { processRoutesFile } from './processors/routes.js';
|
|
5
|
+
import { processShapesFile } from './processors/shapes.js';
|
|
6
|
+
import { processStopTimesFile } from './processors/stop_times.js';
|
|
7
|
+
import { processStopsFile } from './processors/stops.js';
|
|
8
|
+
import { processTripsFile } from './processors/trips.js';
|
|
9
|
+
import { downloadAndExtractGtfs } from './utils/extract-file.js';
|
|
10
|
+
import { initGtfsSqlTables } from './utils/init-tables.js';
|
|
11
|
+
import TIMETRACKER from '@helperkits/timer';
|
|
12
|
+
import { Logs } from '@tmlmobilidade/utils';
|
|
13
|
+
/**
|
|
14
|
+
* Imports GTFS data into the database for a given plan.
|
|
15
|
+
* @param plan The plan containing GTFS feed information.
|
|
16
|
+
* @param config Optional configuration for the import process.
|
|
17
|
+
* @returns A promise that resolves to the imported GTFS SQL tables.
|
|
18
|
+
*/
|
|
19
|
+
export async function importGtfsToDatabase(plan, config = {}) {
|
|
20
|
+
try {
|
|
21
|
+
//
|
|
22
|
+
const globalTimer = new TIMETRACKER();
|
|
23
|
+
Logs.info(`Importing ${plan._id} GTFS to database...`);
|
|
24
|
+
//
|
|
25
|
+
// Initialize context for the current plan
|
|
26
|
+
const context = {
|
|
27
|
+
counters: {
|
|
28
|
+
calendar_dates: 0,
|
|
29
|
+
hashed_shapes: 0,
|
|
30
|
+
hashed_trips: 0,
|
|
31
|
+
shapes: 0,
|
|
32
|
+
stop_times: 0,
|
|
33
|
+
trips: 0,
|
|
34
|
+
},
|
|
35
|
+
gtfs: initGtfsSqlTables(),
|
|
36
|
+
plan: plan,
|
|
37
|
+
referenced_route_ids: new Set(),
|
|
38
|
+
referenced_shape_ids: new Set(),
|
|
39
|
+
workdir: await downloadAndExtractGtfs(plan),
|
|
40
|
+
};
|
|
41
|
+
//
|
|
42
|
+
// Validate GTFS feed info
|
|
43
|
+
if (!plan.gtfs_feed_info?.feed_start_date || !plan.gtfs_feed_info?.feed_end_date) {
|
|
44
|
+
throw new Error(`Plan "${plan._id}" is missing GTFS feed start and/or end date.`);
|
|
45
|
+
}
|
|
46
|
+
//
|
|
47
|
+
// Process GTFS files in the correct order
|
|
48
|
+
await processCalendarFile(context, config);
|
|
49
|
+
await processCalendarDatesFile(context, config);
|
|
50
|
+
await processTripsFile(context);
|
|
51
|
+
await processRoutesFile(context);
|
|
52
|
+
await processShapesFile(context);
|
|
53
|
+
await processStopsFile(context);
|
|
54
|
+
await processStopTimesFile(context);
|
|
55
|
+
Logs.success(`Finished importing GTFS to database for plan "${plan._id}" in ${globalTimer.get()}.`, 0);
|
|
56
|
+
Logs.divider();
|
|
57
|
+
Logs.terminate(`Finished importing GTFS to database in ${globalTimer.get()}.`);
|
|
58
|
+
return context.gtfs;
|
|
59
|
+
//
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
Logs.error('Error parsing plan.', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type ImportGtfsContext } from '../types.js';
|
|
2
|
-
import { type ImportGtfsToDatabaseConfig } from '../../index.js';
|
|
1
|
+
import { type ImportGtfsContext, type ImportGtfsToDatabaseConfig } from '../types.js';
|
|
3
2
|
/**
|
|
4
3
|
* Processes the calendar.txt file from the GTFS dataset.
|
|
5
4
|
* It extracts service_ids that are valid between the given start_date and end_date,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type ImportGtfsContext } from '../types.js';
|
|
2
|
-
import { type ImportGtfsToDatabaseConfig } from '../../index.js';
|
|
1
|
+
import { type ImportGtfsContext, type ImportGtfsToDatabaseConfig } from '../types.js';
|
|
3
2
|
/**
|
|
4
3
|
* Processes the calendar_dates.txt file from the GTFS dataset.
|
|
5
4
|
* It extracts service_ids that are valid between the given start_date and end_date,
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { SQLiteWriter } from '@tmlmobilidade/connectors';
|
|
2
2
|
import { type GTFS_Route_Extended, type GTFS_Shape, type GTFS_Stop_Extended, type GTFS_StopTime, type GTFS_Trip_Extended, type Plan } from '@tmlmobilidade/types';
|
|
3
3
|
import { type OperationalDate } from '@tmlmobilidade/types';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for importing GTFS data into a database.
|
|
6
|
+
*/
|
|
7
|
+
export interface ImportGtfsToDatabaseConfig {
|
|
8
|
+
date_range?: {
|
|
9
|
+
end: OperationalDate;
|
|
10
|
+
start: OperationalDate;
|
|
11
|
+
};
|
|
12
|
+
discrete_dates?: OperationalDate[];
|
|
13
|
+
}
|
|
4
14
|
/**
|
|
5
15
|
* Holds references to all GTFS-related SQL tables and writers.
|
|
6
16
|
* Each property corresponds to a specific GTFS entity and is associated
|
package/package.json
CHANGED