Skip to content

Commit

Permalink
Alert blacklist for the trip planner (#20)
Browse files Browse the repository at this point in the history
* Update PLC list to match agenda doc

* Blacklist for enhanced alerts feed
  • Loading branch information
lboyarsky authored Jul 12, 2019
1 parent a17c0be commit 8ea9d93
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/Governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GtfsRealtime.FeedEntity> entities) {
alertPatchService.expire(patchIds);
patchIds.clear();

for (FeedEntity entity : message.getEntityList()) {
for (FeedEntity entity : entities) {
if (!entity.hasAlert()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -91,11 +98,17 @@ protected void runPolling() {
return;
}

List<GtfsRealtime.FeedEntity> 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);
}
});

Expand Down Expand Up @@ -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")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected void runPolling() {
updaterManager.execute(new GraphWriterRunnable() {
@Override
public void run(Graph graph) {
updateHandler.update(feed);
updateHandler.update(feed.getEntityList());
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/opentripplanner/GtfsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Expand Down

0 comments on commit 8ea9d93

Please sign in to comment.