use of org.opentripplanner.routing.alertpatch.Alert in project OpenTripPlanner by opentripplanner.
the class StreetNotesService method getNotes.
/**
* Return the set of notes applicable for this state / backedge pair.
*
* @param state
* @return The set of notes or null if empty.
*/
public Set<Alert> getNotes(State state) {
Edge edge = state.getBackEdge();
Set<MatcherAndAlert> maas = new HashSet<MatcherAndAlert>();
for (StreetNotesSource source : sources) {
Set<MatcherAndAlert> maas2 = source.getNotes(edge);
if (maas2 != null)
maas.addAll(maas2);
}
if (maas == null || maas.isEmpty()) {
return null;
}
Set<Alert> notes = new HashSet<Alert>(maas.size());
for (MatcherAndAlert maa : maas) {
if (maa.getMatcher().matches(state))
notes.add(maa.getNote());
}
if (notes.isEmpty())
return null;
return notes;
}
use of org.opentripplanner.routing.alertpatch.Alert in project OpenTripPlanner by opentripplanner.
the class WinkkiPollingGraphUpdater method getNote.
protected Alert getNote(SimpleFeature feature) {
Alert alert = Alert.createSimpleAlerts("winkki:" + feature.getAttribute("licence_type"));
alert.alertDescriptionText = feature.getAttribute("event_description") == null ? new NonLocalizedString("") : new NonLocalizedString(feature.getAttribute("event_description").toString());
alert.effectiveStartDate = feature.getAttribute("licence_startdate") == null ? (Date) feature.getAttribute("event_startdate") : (Date) feature.getAttribute("licence_startdate");
return alert;
}
use of org.opentripplanner.routing.alertpatch.Alert in project OpenTripPlanner by opentripplanner.
the class WFSNotePollingGraphUpdater method runPolling.
/**
* The function is run periodically by the update manager.
* The extending class should provide the getNote method. It is not implemented here
* as the requirements for different updaters can be vastly different dependent on the data source.
*/
@Override
protected void runPolling() throws IOException {
LOG.info("Run WFS polling updater with hashcode: {}", this.hashCode());
notesForEdge = HashMultimap.create();
uniqueMatchers = new HashMap<>();
FeatureIterator<SimpleFeature> features = featureSource.getFeatures(query).features();
while (features.hasNext()) {
SimpleFeature feature = features.next();
if (feature.getDefaultGeometry() == null)
continue;
Alert alert = getNote(feature);
if (alert == null)
continue;
Geometry geom = (Geometry) feature.getDefaultGeometry();
Geometry searchArea = geom.buffer(SEARCH_RADIUS_DEG);
Collection<Edge> edges = graph.streetIndex.getEdgesForEnvelope(searchArea.getEnvelopeInternal());
for (Edge edge : edges) {
if (edge instanceof StreetEdge && !searchArea.disjoint(edge.getGeometry())) {
addNote(edge, alert, NOTE_MATCHER);
}
}
}
updaterManager.execute(new WFSGraphWriter());
}
use of org.opentripplanner.routing.alertpatch.Alert in project OpenTripPlanner by opentripplanner.
the class WFSNotePollingGraphUpdater method buildMatcherAndAlert.
/**
* Create a MatcherAndAlert, interning it if the note and matcher pair is already created. Note:
* we use the default Object.equals() for matchers, as they are mostly already singleton
* instances.
*/
private MatcherAndAlert buildMatcherAndAlert(NoteMatcher noteMatcher, Alert note) {
T2<NoteMatcher, Alert> key = new T2<>(noteMatcher, note);
MatcherAndAlert interned = uniqueMatchers.get(key);
if (interned != null) {
return interned;
}
MatcherAndAlert ret = new MatcherAndAlert(noteMatcher, note);
uniqueMatchers.put(key, ret);
return ret;
}
use of org.opentripplanner.routing.alertpatch.Alert in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testStreetSplittingAlerts.
/**
* Test that alerts on split streets are preserved, i.e. if there are alerts on the street that is split the same alerts should be present on the
* new street.
*/
@Test
public void testStreetSplittingAlerts() {
HashSet<Edge> turns = new HashSet<Edge>();
turns.add(left);
turns.add(leftBack);
Alert alert = Alert.createSimpleAlerts("This is the alert");
Set<Alert> alerts = new HashSet<>();
alerts.add(alert);
graph.streetNotesService.addStaticNote(left, alert, StreetNotesService.ALWAYS_MATCHER);
graph.streetNotesService.addStaticNote(leftBack, alert, StreetNotesService.ALWAYS_MATCHER);
TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
// The alert should be preserved
// traverse the FreeEdge from the StreetLocation to the new IntersectionVertex
RoutingRequest req = new RoutingRequest();
req.setMaxWalkDistance(Double.MAX_VALUE);
State traversedOne = new State(start, req);
State currentState;
for (Edge e : start.getOutgoing()) {
currentState = e.traverse(traversedOne);
if (currentState != null) {
traversedOne = currentState;
break;
}
}
assertEquals(alerts, graph.streetNotesService.getNotes(traversedOne));
assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
// now, make sure wheelchair alerts are preserved
Alert wheelchairAlert = Alert.createSimpleAlerts("This is the wheelchair alert");
Set<Alert> wheelchairAlerts = new HashSet<>();
wheelchairAlerts.add(wheelchairAlert);
graph.streetNotesService.removeStaticNotes(left);
graph.streetNotesService.removeStaticNotes(leftBack);
graph.streetNotesService.addStaticNote(left, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
graph.streetNotesService.addStaticNote(leftBack, wheelchairAlert, StreetNotesService.WHEELCHAIR_MATCHER);
req.setWheelchairAccessible(true);
start.dispose();
start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
traversedOne = new State(start, req);
for (Edge e : start.getOutgoing()) {
currentState = e.traverse(traversedOne);
if (currentState != null) {
traversedOne = currentState;
break;
}
}
assertEquals(wheelchairAlerts, graph.streetNotesService.getNotes(traversedOne));
assertNotSame(left, traversedOne.getBackEdge().getFromVertex());
assertNotSame(leftBack, traversedOne.getBackEdge().getFromVertex());
start.dispose();
}
Aggregations