From bb40234b19f0c348798e10dfe38cc590f3a8109d Mon Sep 17 00:00:00 2001 From: haphut Date: Fri, 23 Mar 2018 07:36:40 +0200 Subject: [PATCH] Remove stop_sequence from output PubTrans has the equivalent of stop_sequence for via point stops, as well. The GTFS file released by HSL does not include via points so the stop_sequences did not match. Let's remove the incorrect stop_sequence. --- src/run.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/run.js b/src/run.js index f0aafc7..4749eea 100644 --- a/src/run.js +++ b/src/run.js @@ -6,6 +6,15 @@ const { createFeedBuilder, getFeedMessage } = require("./gtfsrt"); const { transformMonoMessage } = require("./mono"); const { startPublishing, startSubscription } = require("./mqtt"); +const removeStopSequence = feedEntity => { + const censored = _.cloneDeep(feedEntity); + censored.tripUpdate.stopTimeUpdate = _.map( + censored.tripUpdate.stopTimeUpdate, + stopTimeUpdate => _.omit(stopTimeUpdate, "stopSequence") + ); + return censored; +}; + const createMessageHandler = (log, cache, buildFeed, publish) => { const handleMessage = (topic, input) => { const feedEntityFragments = transformMonoMessage(log, input); @@ -20,6 +29,13 @@ const createMessageHandler = (log, cache, buildFeed, publish) => { * out nulls just in case. */ .filter() + /** + * As via points in PubTrans have their own stopSequence, stopSequence + * does not match the published GTFS. stopSequence should be removed only + * after updateCache where it is used for retaining order in + * stopTimeUpdate. + */ + .map(feedEntity => removeStopSequence(feedEntity)) // Publish each trip separately. .map(feedEntity => buildFeed([feedEntity])) .forEach(feed => publish(feed))