Search in sources :

Example 11 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testZeroDelay.

@Test
public void testZeroDelay() {
    // NADAV stop
    final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
    // NANAA stop
    final double TO_LAT = 36.914944, TO_LON = -116.761472;
    Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
    // I want to go at 6:44
    ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 6, 44).atZone(zoneId).toInstant());
    ghRequest.setIgnoreTransfers(true);
    GHResponse responseWithoutRealtimeUpdate = graphHopperFactory.createWithoutRealtimeFeed().route(ghRequest);
    // The 6:00 departure of my line is going to be "late" by 0 minutes
    final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
    feedMessageBuilder.setHeader(header());
    feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("06:00:00")).addStopTimeUpdateBuilder().setStopSequence(5).setScheduleRelationship(SCHEDULED).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(0).build());
    GHResponse responseWithRealtimeUpdate = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(1, responseWithRealtimeUpdate.getAll().size());
    Trip.PtLeg responseWithRealtimeUpdateBest = (Trip.PtLeg) responseWithRealtimeUpdate.getBest().getLegs().get(0);
    Trip.PtLeg responseWithoutRealtimeUpdateBest = (Trip.PtLeg) responseWithoutRealtimeUpdate.getBest().getLegs().get(0);
    assertEquals(LocalDateTime.parse("2007-01-01T06:49:00").atZone(zoneId).toInstant(), responseWithRealtimeUpdateBest.stops.get(responseWithRealtimeUpdateBest.stops.size() - 1).plannedArrivalTime.toInstant(), "My planned arrival time is correct.");
    assertEquals(LocalDateTime.parse("2007-01-01T06:49:00").atZone(zoneId).toInstant(), responseWithRealtimeUpdateBest.stops.get(responseWithRealtimeUpdateBest.stops.size() - 1).predictedArrivalTime.toInstant(), "My expected arrival time is the same.");
    assertNull(responseWithoutRealtimeUpdateBest.stops.get(responseWithoutRealtimeUpdateBest.stops.size() - 1).predictedArrivalTime, "The trip without realtime update does not have an expected arrival time.");
// assertEquals(responseWithoutRealtimeUpdateBest.toString(), responseWithRealtimeUpdateBest.toString());
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 12 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testDelayFromBeginningWithoutTransfer.

@Test
public void testDelayFromBeginningWithoutTransfer() {
    // NADAV stop
    final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
    // NANAA stop
    final double TO_LAT = 36.914944, TO_LON = -116.761472;
    Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
    // I want to go at 6:44
    Instant initialTime = LocalDateTime.of(2007, 1, 1, 6, 44).atZone(zoneId).toInstant();
    ghRequest.setEarliestDepartureTime(initialTime);
    ghRequest.setIgnoreTransfers(true);
    // The 6:00 departure of my line is going to be "late" by 0 minutes
    final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
    feedMessageBuilder.setHeader(header());
    feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("06:00:00")).addStopTimeUpdateBuilder().setStopSequence(1).setScheduleRelationship(SCHEDULED).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(180).build());
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(1, response.getAll().size());
    Trip.PtLeg ptLeg = ((Trip.PtLeg) response.getBest().getLegs().get(0));
    assertEquals(LocalDateTime.parse("2007-01-01T06:52:00").atZone(zoneId).toInstant(), ptLeg.getArrivalTime().toInstant(), "My line run is 3 minutes late.");
    assertEquals(LocalDateTime.parse("2007-01-01T06:49:00").atZone(zoneId).toInstant(), ptLeg.stops.get(ptLeg.stops.size() - 1).plannedArrivalTime.toInstant(), "It is still reporting its original, scheduled time.");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 13 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testSkipArrivalStop.

@Test
public void testSkipArrivalStop() {
    // NADAV stop
    final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
    // NANAA stop
    final double TO_LAT = 36.914944, TO_LON = -116.761472;
    Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
    // I want to go at 6:44
    ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 6, 44).atZone(zoneId).toInstant());
    // But the 6:00 departure of my line is going to skip my arrival stop :-(
    final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
    feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("1").setTimestamp(ZonedDateTime.of(LocalDate.of(2007, 1, 1), LocalTime.of(0, 0), zoneId).toEpochSecond()));
    feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("06:00:00")).addStopTimeUpdateBuilder().setStopSequence(4).setScheduleRelationship(SKIPPED);
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(3, response.getAll().size());
    assertEquals(time(0, 21), response.getBest().getTime(), 0.1, "I have to continue to STAGECOACH and then go back one stop with the 07:00 bus.");
    ResponsePath impossibleAlternative = response.getAll().get(2);
    assertTrue(impossibleAlternative.isImpossible());
    assertTrue(((Trip.PtLeg) impossibleAlternative.getLegs().get(0)).stops.get(1).arrivalCancelled);
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 14 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testCanUseDelayedTripWhenIAmLateToo.

@Test
public void testCanUseDelayedTripWhenIAmLateToo() {
    // NADAV stop
    final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
    // NANAA stop
    final double TO_LAT = 36.914944, TO_LON = -116.761472;
    Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
    // I want to go at 6:44
    ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 6, 46).atZone(zoneId).toInstant());
    // But the 6:00 departure of my line is going to be super-late :-(
    final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
    feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("1").setTimestamp(ZonedDateTime.of(LocalDate.of(2007, 1, 1), LocalTime.of(0, 0), zoneId).toEpochSecond()));
    feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("06:00:00")).addStopTimeUpdateBuilder().setScheduleRelationship(SCHEDULED).setStopSequence(3).setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(120).build());
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    assertEquals(time(0, 5), response.getBest().getTime(), 0.1, "I am two minutes late for my bus, but the bus is two minutes late, too, so I catch it!");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Example 15 with Request

use of com.graphhopper.gtfs.Request in project graphhopper by graphhopper.

the class RealtimeIT method testMissedTransferButExtraTripOnFirstLeg.

@Test
public void testMissedTransferButExtraTripOnFirstLeg() {
    // NADAV stop
    final double FROM_LAT = 36.914893, FROM_LON = -116.76821;
    // BEATTY_AIRPORT stop
    final double TO_LAT = 36.868446, TO_LON = -116.784582;
    Request ghRequest = new Request(FROM_LAT, FROM_LON, TO_LAT, TO_LON);
    // I want to go at 6:44
    ghRequest.setEarliestDepartureTime(LocalDateTime.of(2007, 1, 1, 6, 44).atZone(zoneId).toInstant());
    // But the 6:00 departure of my line is going to be 5 minutes late at my transfer stop :-(
    final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
    feedMessageBuilder.setHeader(header());
    feedMessageBuilder.addEntityBuilder().setId("1").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("CITY2").setStartTime("06:00:00")).addStopTimeUpdateBuilder().setStopSequence(5).setScheduleRelationship(SCHEDULED).setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(300).build());
    final GtfsRealtime.TripUpdate.Builder extraTripUpdate = feedMessageBuilder.addEntityBuilder().setId("2").getTripUpdateBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setScheduleRelationship(ADDED).setTripId("EXTRA").setRouteId("CITY").setStartTime("06:45:00"));
    extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(1).setStopId("NADAV").setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 45).atZone(zoneId).toEpochSecond())).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 45).atZone(zoneId).toEpochSecond()));
    extraTripUpdate.addStopTimeUpdateBuilder().setStopSequence(2).setStopId("STAGECOACH").setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 46).atZone(zoneId).toEpochSecond())).setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(LocalDateTime.of(2007, 1, 1, 6, 46).atZone(zoneId).toEpochSecond()));
    GHResponse response = graphHopperFactory.createWith(feedMessageBuilder.build()).route(ghRequest);
    // assertEquals(2, response.getAll().size());
    assertEquals(time(0, 36), response.getBest().getTime(), 0.1, "The 6:44 bus will be late at STAGECOACH, but I won't be late because there's an extra trip.");
}
Also used : Request(com.graphhopper.gtfs.Request) Test(org.junit.jupiter.api.Test)

Aggregations

Request (com.graphhopper.gtfs.Request)19 Test (org.junit.jupiter.api.Test)18 PtRouter (com.graphhopper.gtfs.PtRouter)2 GHResponse (com.graphhopper.GHResponse)1 GHLocation (com.graphhopper.gtfs.GHLocation)1 StopWatch (com.graphhopper.util.StopWatch)1 Instant (java.time.Instant)1