Skip to content

Commit f1df98b

Browse files
authored
Add prefix to gifs-realtime data (#184)
1 parent d78566c commit f1df98b

File tree

7 files changed

+23
-1
lines changed

7 files changed

+23
-1
lines changed

src/lib/import-gtfs-realtime.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface GtfsRealtimeTask {
3535
gtfsRealtimeExpirationSeconds: number;
3636
ignoreErrors: boolean;
3737
sqlitePath: string;
38+
prefix: string | undefined;
3839
currentTimestamp: number;
3940
log: (message: string, newLine?: boolean) => void;
4041
logWarning: (message: string) => void;
@@ -150,7 +151,11 @@ function prepareRealtimeFieldValue(
150151
return task.currentTimestamp + task.gtfsRealtimeExpirationSeconds;
151152
}
152153

153-
const value = getNestedProperty(entity, column.default, column.source);
154+
let value = getNestedProperty(entity, column.default, column.source);
155+
156+
if (column.prefix && task.prefix && value !== null) {
157+
value = `${task.prefix}${value}`;
158+
}
154159

155160
if (column.type === 'json') {
156161
return sqlString.escape(JSON.stringify(value));
@@ -390,6 +395,7 @@ export async function updateGtfsRealtime(initialConfig: Config) {
390395
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
391396
ignoreErrors: config.ignoreErrors,
392397
sqlitePath: config.sqlitePath,
398+
prefix: agency.prefix,
393399
currentTimestamp: Math.floor(Date.now() / 1000),
394400
log: log(config),
395401
logWarning: logWarning(config),

src/models/gtfs-realtime/service-alert-informed_entities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ export const serviceAlertInformedEntities = {
88
required: true,
99
primary: true,
1010
source: 'parent.id',
11+
prefix: true,
1112
},
1213
{
1314
name: 'stop_id',
1415
type: 'text',
1516
index: true,
1617
source: 'stopId',
1718
default: null,
19+
prefix: true,
1820
},
1921
{
2022
name: 'route_id',
2123
type: 'text',
2224
index: true,
2325
source: 'routeId',
2426
default: null,
27+
prefix: true,
2528
},
2629
{
2730
name: 'route_type',
@@ -36,6 +39,7 @@ export const serviceAlertInformedEntities = {
3639
index: true,
3740
source: 'trip.tripId',
3841
default: null,
42+
prefix: true,
3943
},
4044
{
4145
name: 'direction_id',

src/models/gtfs-realtime/service-alerts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const serviceAlerts = {
99
primary: true,
1010
index: true,
1111
source: 'id',
12+
prefix: true,
1213
},
1314
{
1415
name: 'active_period',

src/models/gtfs-realtime/stop-time-updates.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const stopTimeUpdates = {
88
index: true,
99
source: 'parent.tripUpdate.trip.tripId',
1010
default: null,
11+
prefix: true,
1112
},
1213
{
1314
name: 'trip_start_time',
@@ -27,13 +28,15 @@ export const stopTimeUpdates = {
2728
index: true,
2829
source: 'parent.tripUpdate.trip.routeId',
2930
default: null,
31+
prefix: true,
3032
},
3133
{
3234
name: 'stop_id',
3335
type: 'text',
3436
index: true,
3537
source: 'stopId',
3638
default: null,
39+
prefix: true,
3740
},
3841
{
3942
name: 'stop_sequence',

src/models/gtfs-realtime/trip-updates.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ export const tripUpdates = {
99
primary: true,
1010
index: true,
1111
source: 'id',
12+
prefix: true,
1213
},
1314
{
1415
name: 'vehicle_id',
1516
type: 'text',
1617
index: true,
1718
source: 'tripUpdate.vehicle.id',
1819
default: null,
20+
prefix: true,
1921
},
2022
{
2123
name: 'trip_id',
2224
type: 'text',
2325
index: true,
2426
source: 'tripUpdate.trip.tripId',
2527
default: null,
28+
prefix: true,
2629
},
2730
{
2831
name: 'trip_start_time',
@@ -42,6 +45,7 @@ export const tripUpdates = {
4245
index: true,
4346
source: 'tripUpdate.trip.routeId',
4447
default: null,
48+
prefix: true,
4549
},
4650
{
4751
name: 'start_date',

src/models/gtfs-realtime/vehicle-positions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const vehiclePositions = {
99
primary: true,
1010
index: true,
1111
source: 'id',
12+
prefix: true,
1213
},
1314
{
1415
name: 'bearing',
@@ -51,6 +52,7 @@ export const vehiclePositions = {
5152
index: true,
5253
source: 'vehicle.trip.tripId',
5354
default: null,
55+
prefix: true,
5456
},
5557
{
5658
name: 'trip_start_date',
@@ -96,6 +98,7 @@ export const vehiclePositions = {
9698
index: true,
9799
source: 'vehicle.vehicle.id',
98100
default: null,
101+
prefix: true,
99102
},
100103
{
101104
name: 'vehicle_label',

src/models/gtfs/stops.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const stops = {
5959
name: 'parent_station',
6060
type: 'text',
6161
index: true,
62+
prefix: true,
6263
},
6364
{
6465
name: 'stop_timezone',

0 commit comments

Comments
 (0)