Search in sources :

Example 1 with AlertPatchServiceImpl

use of org.opentripplanner.routing.impl.AlertPatchServiceImpl in project OpenTripPlanner by opentripplanner.

the class GtfsTest method setUp.

protected void setUp() {
    File gtfs = new File("src/test/resources/" + getFeedName());
    File gtfsRealTime = new File("src/test/resources/" + getFeedName() + ".pb");
    GtfsBundle gtfsBundle = new GtfsBundle(gtfs);
    feedId = new GtfsFeedId.Builder().id("FEED").build();
    gtfsBundle.setFeedId(feedId);
    List<GtfsBundle> gtfsBundleList = Collections.singletonList(gtfsBundle);
    GtfsModule gtfsGraphBuilderImpl = new GtfsModule(gtfsBundleList);
    alertsUpdateHandler = new AlertsUpdateHandler();
    graph = new Graph();
    router = new Router("TEST", graph);
    gtfsBundle.setTransfersTxtDefinesStationPaths(true);
    gtfsGraphBuilderImpl.buildGraph(graph, null);
    // Set the agency ID to be used for tests to the first one in the feed.
    agencyId = graph.getAgencies(feedId.getId()).iterator().next().getId();
    System.out.printf("Set the agency ID for this test to %s\n", agencyId);
    graph.index(new DefaultStreetVertexIndexFactory());
    timetableSnapshotSource = new TimetableSnapshotSource(graph);
    timetableSnapshotSource.purgeExpiredData = (false);
    graph.timetableSnapshotSource = (timetableSnapshotSource);
    alertPatchServiceImpl = new AlertPatchServiceImpl(graph);
    alertsUpdateHandler.setAlertPatchService(alertPatchServiceImpl);
    alertsUpdateHandler.setFeedId(feedId.getId());
    try {
        final boolean fullDataset = false;
        InputStream inputStream = new FileInputStream(gtfsRealTime);
        FeedMessage feedMessage = FeedMessage.PARSER.parseFrom(inputStream);
        List<FeedEntity> feedEntityList = feedMessage.getEntityList();
        List<TripUpdate> updates = new ArrayList<TripUpdate>(feedEntityList.size());
        for (FeedEntity feedEntity : feedEntityList) {
            updates.add(feedEntity.getTripUpdate());
        }
        timetableSnapshotSource.applyTripUpdates(graph, fullDataset, updates, feedId.getId());
        alertsUpdateHandler.update(feedMessage);
    } catch (Exception exception) {
    }
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Router(org.opentripplanner.standalone.Router) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) AlertPatchServiceImpl(org.opentripplanner.routing.impl.AlertPatchServiceImpl) FileInputStream(java.io.FileInputStream) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) GtfsModule(org.opentripplanner.graph_builder.module.GtfsModule) Graph(org.opentripplanner.routing.graph.Graph) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) File(java.io.File) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource) AlertsUpdateHandler(org.opentripplanner.updater.alerts.AlertsUpdateHandler)

Example 2 with AlertPatchServiceImpl

use of org.opentripplanner.routing.impl.AlertPatchServiceImpl in project OpenTripPlanner by opentripplanner.

the class GtfsRealtimeAlertsUpdater method configurePolling.

@Override
protected void configurePolling(Graph graph, JsonNode config) throws Exception {
    // TODO: add options to choose different patch services
    AlertPatchService alertPatchService = new AlertPatchServiceImpl(graph);
    this.alertPatchService = alertPatchService;
    String url = config.path("url").asText();
    if (url == null) {
        throw new IllegalArgumentException("Missing mandatory 'url' parameter");
    }
    this.url = url;
    this.earlyStart = config.path("earlyStartSec").asInt(0);
    this.feedId = config.path("feedId").asText();
    if (config.path("fuzzyTripMatching").asBoolean(false)) {
        this.fuzzyTripMatcher = new GtfsRealtimeFuzzyTripMatcher(graph.index);
    }
    LOG.info("Creating real-time alert updater running every {} seconds : {}", frequencySec, url);
}
Also used : GtfsRealtimeFuzzyTripMatcher(org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher) AlertPatchService(org.opentripplanner.routing.services.AlertPatchService) AlertPatchServiceImpl(org.opentripplanner.routing.impl.AlertPatchServiceImpl)

Aggregations

AlertPatchServiceImpl (org.opentripplanner.routing.impl.AlertPatchServiceImpl)2 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)1 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)1 GtfsFeedId (org.opentripplanner.graph_builder.module.GtfsFeedId)1 GtfsModule (org.opentripplanner.graph_builder.module.GtfsModule)1 Graph (org.opentripplanner.routing.graph.Graph)1 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)1 AlertPatchService (org.opentripplanner.routing.services.AlertPatchService)1 Router (org.opentripplanner.standalone.Router)1 GtfsRealtimeFuzzyTripMatcher (org.opentripplanner.updater.GtfsRealtimeFuzzyTripMatcher)1 AlertsUpdateHandler (org.opentripplanner.updater.alerts.AlertsUpdateHandler)1 TimetableSnapshotSource (org.opentripplanner.updater.stoptime.TimetableSnapshotSource)1