Search in sources :

Example 6 with Alert

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;
}
Also used : Alert(org.opentripplanner.routing.alertpatch.Alert) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 7 with Alert

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;
}
Also used : NonLocalizedString(org.opentripplanner.util.NonLocalizedString) Alert(org.opentripplanner.routing.alertpatch.Alert) Date(java.util.Date)

Example 8 with 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());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) MatcherAndAlert(org.opentripplanner.routing.services.notes.MatcherAndAlert) Alert(org.opentripplanner.routing.alertpatch.Alert) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 9 with Alert

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;
}
Also used : NoteMatcher(org.opentripplanner.routing.services.notes.NoteMatcher) MatcherAndAlert(org.opentripplanner.routing.services.notes.MatcherAndAlert) Alert(org.opentripplanner.routing.alertpatch.Alert) MatcherAndAlert(org.opentripplanner.routing.services.notes.MatcherAndAlert) T2(org.opentripplanner.common.model.T2)

Example 10 with Alert

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();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) Alert(org.opentripplanner.routing.alertpatch.Alert) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Alert (org.opentripplanner.routing.alertpatch.Alert)10 Edge (org.opentripplanner.routing.graph.Edge)4 HashSet (java.util.HashSet)3 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)3 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 T2 (org.opentripplanner.common.model.T2)2 AlertPatch (org.opentripplanner.routing.alertpatch.AlertPatch)2 MatcherAndAlert (org.opentripplanner.routing.services.notes.MatcherAndAlert)2 TranslatedString (org.opentripplanner.util.TranslatedString)2 EntitySelector (com.google.transit.realtime.GtfsRealtime.EntitySelector)1 TimeRange (com.google.transit.realtime.GtfsRealtime.TimeRange)1 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 LineString (com.vividsolutions.jts.geom.LineString)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 LinearLocation (com.vividsolutions.jts.linearref.LinearLocation)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1