Skip to content

Commit 9be6f44

Browse files
committed
queryScheduleStopTimes(): warn against matching ambiguously without stop_{id,sequence}
1 parent 272c2aa commit 9be6f44

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

lib/match-alert.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const createMatchAlert = (cfg) => {
144144
// // todo: what if there are >1 matches? the match should be unambiguous, right?
145145
// const isMatch = scheduleStopTimes => scheduleStopTimes.length > 0
146146
// const scheduleStopTimes = await queryScheduleStopTimes({
147+
// logger,
147148
// route_id,
148149
// start_date,
149150
// trip_id: realtimeTripId,

lib/match-trip-update.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const createMatchTripUpdate = (cfg) => {
121121
// todo: use some StopTimeUpdate's stop_id/stop_sequence to unambiguously identify the trip "instance", then query all its stop_times
122122
const isMatch = scheduleStopTimes => scheduleStopTimes.length > 0
123123
const scheduleStopTimes = await queryScheduleStopTimes({
124+
logger,
124125
route_id,
125126
start_date: startDate,
126127
trip_id: realtimeTripId,

lib/match-vehicle-position.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const createMatchVehiclePosition = (cfg) => {
7272

7373
const isMatch = scheduleStopTimes => scheduleStopTimes.length === 1
7474
const scheduleStopTimes = await queryScheduleStopTimes({
75+
logger,
7576
route_id,
7677
start_date: startDate,
7778
trip_id: realtimeTripId,

lib/match.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {createMatchAlert} from './match-alert.js'
1212
import {createStoreAndRestoreStopTimeUpdatesFromDb} from './restore-stoptimeupdates.js'
1313
import {createApplyTripReplacementPeriods} from './apply-trip-replacement-periods.js'
1414

15-
const MATCHING_LOG_LEVEL = process.env.LOG_LEVEL_MATCHING || 'error'
15+
const MATCHING_LOG_LEVEL = process.env.LOG_LEVEL_MATCHING || 'warn'
1616

1717
const parseEncodedFeed = (feedEncoded) => {
1818
// decode feed, validate NyctFeedHeader

lib/query-schedule-stop-times.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const subdivisionsByRouteId = new Map([
6666
// todo: query & expose start_time?
6767
const queryScheduleStopTimes = async (cfg) => {
6868
const {
69+
logger,
6970
route_id,
7071
start_date,
7172
trip_id,
@@ -84,6 +85,26 @@ const queryScheduleStopTimes = async (cfg) => {
8485
ok(trip_id, 'missing/empty trip_id')
8586
strictEqual(typeof isMatch, 'function', 'isMatch must be a function')
8687

88+
// Without stop_id, it is not possible to unambiguously identify the targeted trip "instance", as there might be two trips with the same trip_id *suffix* running by the same stop one the same date.
89+
if (stop_id === null) {
90+
logger.warn({
91+
route_id,
92+
start_date,
93+
trip_id,
94+
stop_id,
95+
stop_sequence,
96+
}, 'matching without stop_id, risking incorrectly matched trip')
97+
// On top, with trips running loops (visiting a stop more than once), we need stop_sequence to uniquely identify which visit to match.
98+
} else if (stop_sequence === null) {
99+
logger.warn({
100+
route_id,
101+
start_date,
102+
trip_id,
103+
stop_id,
104+
stop_sequence,
105+
}, 'matching without stop_id, risking incorrectly matched stop_times row')
106+
}
107+
87108
const metricsCtx = {
88109
schedule_feed_digest: scheduleFeedDigestSlice,
89110
route_id,

0 commit comments

Comments
 (0)