From 8ea9d93e3ca9d40a177cd0e08844d73cf01a440a Mon Sep 17 00:00:00 2001 From: lboyarsky <45011335+lboyarsky@users.noreply.github.com> Date: Fri, 12 Jul 2019 14:15:20 -0400 Subject: [PATCH] Alert blacklist for the trip planner (#20) * Update PLC list to match agenda doc * Blacklist for enhanced alerts feed --- docs/Governance.md | 4 ++-- .../updater/alerts/AlertsUpdateHandler.java | 4 ++-- .../GtfsEnhancedRealtimeAlertsUpdater.java | 19 ++++++++++++++++++- .../alerts/GtfsRealtimeAlertsUpdater.java | 2 +- .../java/org/opentripplanner/GtfsTest.java | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/Governance.md b/docs/Governance.md index b494e5e7f2d..685f6eec562 100644 --- a/docs/Governance.md +++ b/docs/Governance.md @@ -6,9 +6,9 @@ OpenTripPlanner is a member project of the [Software Freedom Conservancy](https: |-----|-------------| | Sean Barbeau | University of South Florida | | Sheldon Brown | Cambridge Systematics | -| Andrew Byrd | Plannerstack (Netherlands) | +| Andrew Byrd | Conveyal | | Drew Dara-Abrams | Interline | -| David Emory | Conveyal | +| David Emory | MARTA (Atlanta, Georgia, USA) | | Thomas Gran | Ruter & Entur (Norway) | | Tuukka Hastrup | Maanteeamet (Estonia) | | Frank Purcell | TriMet (Portland, Oregon) | diff --git a/src/main/java/org/opentripplanner/updater/alerts/AlertsUpdateHandler.java b/src/main/java/org/opentripplanner/updater/alerts/AlertsUpdateHandler.java index 342eea85f72..c22b8d82d9f 100644 --- a/src/main/java/org/opentripplanner/updater/alerts/AlertsUpdateHandler.java +++ b/src/main/java/org/opentripplanner/updater/alerts/AlertsUpdateHandler.java @@ -40,11 +40,11 @@ public class AlertsUpdateHandler { /** Set only if we should attempt to match the trip_id from other data in TripDescriptor */ private GtfsRealtimeFuzzyTripMatcher fuzzyTripMatcher; - public void update(FeedMessage message) { + public void update(List entities) { alertPatchService.expire(patchIds); patchIds.clear(); - for (FeedEntity entity : message.getEntityList()) { + for (FeedEntity entity : entities) { if (!entity.hasAlert()) { continue; } diff --git a/src/main/java/org/opentripplanner/updater/alerts/GtfsEnhancedRealtimeAlertsUpdater.java b/src/main/java/org/opentripplanner/updater/alerts/GtfsEnhancedRealtimeAlertsUpdater.java index af529851462..b0bfba386e2 100644 --- a/src/main/java/org/opentripplanner/updater/alerts/GtfsEnhancedRealtimeAlertsUpdater.java +++ b/src/main/java/org/opentripplanner/updater/alerts/GtfsEnhancedRealtimeAlertsUpdater.java @@ -3,6 +3,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -15,6 +16,7 @@ import org.opentripplanner.updater.GraphWriterRunnable; import org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher; import org.opentripplanner.updater.PollingGraphUpdater; +import org.opentripplanner.util.ArrayUtils; import org.opentripplanner.util.HttpUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +43,8 @@ public class GtfsEnhancedRealtimeAlertsUpdater extends PollingGraphUpdater { private AlertsUpdateHandler updateHandler = null; + private String[] blacklist = new String[0]; + @Override public void setGraphUpdaterManager(GraphUpdaterManager updaterManager) { this.updaterManager = updaterManager; @@ -61,6 +65,9 @@ protected void configurePolling(Graph graph, JsonNode config) throws Exception { if (config.path("fuzzyTripMatching").asBoolean(false)) { this.fuzzyTripMatcher = new GtfsRealtimeFuzzyTripMatcher(graph.index); } + if (config.path("blacklist") != null) { + this.blacklist = new ObjectMapper().convertValue(config.path("blacklist"), String[].class); + } LOG.info("Creating enhanced real-time alert (json) updater running every {} seconds : {}", pollingPeriodSeconds, url); } @@ -91,11 +98,17 @@ protected void runPolling() { return; } + List entities = feed + .getEntityList() + .stream() + .filter(e -> e.hasId() && !ArrayUtils.contains(blacklist, e.getId())) + .collect(Collectors.toList()); + // Handle update in graph writer runnable updaterManager.execute(new GraphWriterRunnable() { @Override public void run(Graph graph) { - updateHandler.update(feed); + updateHandler.update(entities); } }); @@ -144,6 +157,10 @@ private GtfsRealtime.FeedEntity parseEntity(JsonNode entity) { alert.setEffect(GtfsRealtime.Alert.Effect.valueOf(alertNode.get("effect").textValue())); } + if (alertNode.get("cause") != null) { + alert.setCause(GtfsRealtime.Alert.Cause.valueOf(alertNode.get("cause").textValue())); + } + if (alertNode.get("url") != null) { alert.setUrl(parseTranslatedString(alertNode.get("url"))); } diff --git a/src/main/java/org/opentripplanner/updater/alerts/GtfsRealtimeAlertsUpdater.java b/src/main/java/org/opentripplanner/updater/alerts/GtfsRealtimeAlertsUpdater.java index e5cd89d2d35..df37a856d27 100644 --- a/src/main/java/org/opentripplanner/updater/alerts/GtfsRealtimeAlertsUpdater.java +++ b/src/main/java/org/opentripplanner/updater/alerts/GtfsRealtimeAlertsUpdater.java @@ -102,7 +102,7 @@ protected void runPolling() { updaterManager.execute(new GraphWriterRunnable() { @Override public void run(Graph graph) { - updateHandler.update(feed); + updateHandler.update(feed.getEntityList()); } }); diff --git a/src/test/java/org/opentripplanner/GtfsTest.java b/src/test/java/org/opentripplanner/GtfsTest.java index 23edcaf2f32..4f31621e158 100644 --- a/src/test/java/org/opentripplanner/GtfsTest.java +++ b/src/test/java/org/opentripplanner/GtfsTest.java @@ -89,7 +89,7 @@ protected void setUp() { updates.add(feedEntity.getTripUpdate()); } timetableSnapshotSource.applyTripUpdates(graph, fullDataset, updates, feedId.getId()); - alertsUpdateHandler.update(feedMessage); + alertsUpdateHandler.update(feedMessage.getEntityList()); } catch (Exception exception) {} }