use of org.onebusaway.gtfs.model.Trip in project onebusaway-application-modules by camsys.
the class StopTimeEntriesFactoryTest method testThreeInARowDuplicateRemoval.
@Test
public void testThreeInARowDuplicateRemoval() {
TransitGraphImpl graph = new TransitGraphImpl();
Stop stopA = new Stop();
stopA.setId(aid("stopA"));
graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
Stop stopB = new Stop();
stopB.setId(aid("stopB"));
graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
Stop stopC = new Stop();
stopC.setId(aid("stopC"));
graph.putStopEntry(stop("stopC", 47.66847942216854, -122.37545336180114));
Stop stopD = new Stop();
stopD.setId(aid("stopD"));
graph.putStopEntry(stop("stopD", 47.66947942216854, -122.37545336180114));
graph.refreshStopMapping();
Agency agency = new Agency();
agency.setId("1");
agency.setTimezone("America/Los_Angeles");
Route route = new Route();
route.setAgency(agency);
Trip trip = new Trip();
trip.setRoute(route);
trip.setServiceId(aid("serviceId"));
TripEntryImpl tripEntry = trip("trip");
StopTime stA = new StopTime();
stA.setId(100);
stA.setArrivalTime(time(9, 00));
stA.setDepartureTime(time(9, 05));
stA.setStopSequence(100);
stA.setStop(stopA);
stA.setTrip(trip);
StopTime stB = new StopTime();
stB.setId(101);
stB.setArrivalTime(time(9, 00));
stB.setDepartureTime(time(9, 05));
stB.setStopSequence(101);
stB.setStop(stopB);
stB.setTrip(trip);
StopTime stC = new StopTime();
stC.setId(102);
stC.setArrivalTime(time(9, 00));
stC.setDepartureTime(time(9, 05));
stC.setStopSequence(102);
stC.setStop(stopC);
stC.setTrip(trip);
StopTime stD = new StopTime();
stD.setId(103);
stD.setArrivalTime(time(11, 00));
stD.setDepartureTime(time(11, 05));
stD.setStopSequence(103);
stD.setStop(stopD);
stD.setTrip(trip);
StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
List<StopTime> stopTimes = Arrays.asList(stA, stB, stC, stD);
ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
shapePointsFactory.addPoint(47.66947942216854, -122.37545336180114);
ShapePoints shapePoints = shapePointsFactory.create();
List<StopTimeEntryImpl> entries = factory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
assertEquals(stopTimes.size(), entries.size());
StopTimeEntryImpl entry = entries.get(0);
assertEquals(0, entry.getAccumulatedSlackTime());
assertEquals(time(9, 00), entry.getArrivalTime());
assertEquals(time(9, 05), entry.getDepartureTime());
assertEquals(0, entry.getSequence());
assertEquals(181.5, entry.getShapeDistTraveled(), 0.1);
assertEquals(5 * 60, entry.getSlackTime());
entry = entries.get(1);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(9, 28, 45), entry.getArrivalTime());
assertEquals(time(9, 28, 45), entry.getDepartureTime());
assertEquals(1, entry.getSequence());
assertEquals(738.7, entry.getShapeDistTraveled(), 0.1);
assertEquals(0, entry.getSlackTime());
entry = entries.get(2);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(10, 00, 34), entry.getArrivalTime());
assertEquals(time(10, 00, 34), entry.getDepartureTime());
assertEquals(2, entry.getSequence());
assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
assertEquals(0, entry.getSlackTime());
entry = entries.get(3);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(11, 00), entry.getArrivalTime());
assertEquals(time(11, 05), entry.getDepartureTime());
assertEquals(3, entry.getSequence());
assertEquals(2877.69, entry.getShapeDistTraveled(), 0.1);
assertEquals(60 * 5, entry.getSlackTime());
}
use of org.onebusaway.gtfs.model.Trip in project onebusaway-application-modules by camsys.
the class TripEntriesFactoryTest method test.
@Test
public void test() {
GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
Agency agency = new Agency();
agency.setId("1");
agency.setTimezone("America/Los_Angeles");
// gtfsDao.saveEntity(agency);
Route route = new Route();
route.setId(new AgencyAndId("1", "routeA"));
route.setAgency(agency);
Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(route));
AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "tripA"));
trip.setRoute(route);
trip.setServiceId(new AgencyAndId("1", "serviceId"));
trip.setShapeId(shapeId);
Mockito.when(gtfsDao.getTripsForRoute(route)).thenReturn(Arrays.asList(trip));
Stop stopA = new Stop();
stopA.setId(aid("stopA"));
StopTime stA = new StopTime();
stA.setId(100);
stA.setArrivalTime(time(9, 00));
stA.setDepartureTime(time(9, 05));
stA.setStopSequence(100);
stA.setStop(stopA);
stA.setTrip(trip);
Stop stopB = new Stop();
stopB.setId(aid("stopB"));
StopTime stB = new StopTime();
stB.setId(101);
stB.setArrivalTime(time(10, 00));
stB.setDepartureTime(time(10, 05));
stB.setStopSequence(102);
stB.setStop(stopB);
stB.setTrip(trip);
Mockito.when(gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stA, stB));
TransitGraphImpl graph = new TransitGraphImpl();
graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
RouteEntryImpl routeEntry = route("routeA");
graph.putRouteEntry(routeEntry);
graph.initialize();
ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
ShapePoints shapePoints = shapePointsFactory.create();
ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeId)).thenReturn(shapePoints);
TripEntriesFactory factory = new TripEntriesFactory();
factory.setGtfsDao(gtfsDao);
factory.setShapePointHelper(shapePointHelper);
factory.setUniqueService(new UniqueServiceImpl());
StopTimeEntriesFactory stopTimeEntriesFactory = new StopTimeEntriesFactory();
stopTimeEntriesFactory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
factory.setStopTimeEntriesFactory(stopTimeEntriesFactory);
factory.processTrips(graph);
TripEntryImpl entry = graph.getTripEntryForId(trip.getId());
assertEquals(trip.getId(), entry.getId());
assertEquals(route.getId(), entry.getRoute().getId());
assertEquals(lsid("serviceId"), entry.getServiceId());
assertEquals(trip.getShapeId(), entry.getShapeId());
assertEquals(2177.1, entry.getTotalTripDistance(), 0.1);
List<StopTimeEntry> stopTimes = entry.getStopTimes();
assertEquals(2, stopTimes.size());
for (StopTimeEntry stopTime : stopTimes) {
assertSame(entry, stopTime.getTrip());
}
}
use of org.onebusaway.gtfs.model.Trip in project gtfs-realtime-validator by CUTR-at-USF.
the class TripDescriptorValidator method validate.
@Override
public List<ErrorListHelperModel> validate(long currentTimeMillis, GtfsDaoImpl gtfsData, GtfsMetadata gtfsMetadata, GtfsRealtime.FeedMessage feedMessage, GtfsRealtime.FeedMessage previousFeedMessage, GtfsRealtime.FeedMessage combinedFeedMessage) {
List<OccurrenceModel> errorListE003 = new ArrayList<>();
List<OccurrenceModel> errorListE004 = new ArrayList<>();
List<OccurrenceModel> errorListE016 = new ArrayList<>();
List<OccurrenceModel> errorListE020 = new ArrayList<>();
List<OccurrenceModel> errorListE021 = new ArrayList<>();
List<OccurrenceModel> errorListE023 = new ArrayList<>();
List<OccurrenceModel> errorListE024 = new ArrayList<>();
List<OccurrenceModel> errorListE030 = new ArrayList<>();
List<OccurrenceModel> errorListE031 = new ArrayList<>();
List<OccurrenceModel> errorListE032 = new ArrayList<>();
List<OccurrenceModel> errorListE033 = new ArrayList<>();
List<OccurrenceModel> errorListE034 = new ArrayList<>();
List<OccurrenceModel> errorListE035 = new ArrayList<>();
List<OccurrenceModel> errorListW006 = new ArrayList<>();
List<OccurrenceModel> errorListW009 = new ArrayList<>();
// Check the route_id values against the values from the GTFS feed
for (GtfsRealtime.FeedEntity entity : feedMessage.getEntityList()) {
if (entity.hasTripUpdate()) {
GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate();
if (!tripUpdate.getTrip().hasTripId()) {
checkW006(entity, tripUpdate.getTrip(), errorListW006);
} else {
String tripId = tripUpdate.getTrip().getTripId();
Trip trip = gtfsMetadata.getTrips().get(tripId);
if (trip == null) {
if (!GtfsUtils.isAddedTrip(tripUpdate.getTrip())) {
// Trip isn't in GTFS data and isn't an ADDED trip - E003
RuleUtils.addOccurrence(E003, GtfsUtils.getTripId(entity, tripUpdate), errorListE003, _log);
}
} else {
if (GtfsUtils.isAddedTrip(tripUpdate.getTrip())) {
// Trip is in GTFS data and is an ADDED trip - E016
RuleUtils.addOccurrence(E016, GtfsUtils.getTripId(entity, tripUpdate), errorListE016, _log);
}
if (tripUpdate.getTrip().hasStartTime()) {
checkE023(tripUpdate, tripUpdate.getTrip(), gtfsMetadata, errorListE023);
}
}
}
if (tripUpdate.getTrip().hasStartTime()) {
checkE020(tripUpdate, tripUpdate.getTrip(), errorListE020);
}
checkE021(tripUpdate, tripUpdate.getTrip(), errorListE021);
checkE004(tripUpdate, tripUpdate.getTrip(), gtfsMetadata, errorListE004);
checkE024(tripUpdate, tripUpdate.getTrip(), gtfsMetadata, errorListE024);
checkE035(entity, tripUpdate.getTrip(), gtfsMetadata, errorListE035);
boolean foundW009 = false;
List<GtfsRealtime.TripUpdate.StopTimeUpdate> stopTimeUpdateList = tripUpdate.getStopTimeUpdateList();
for (GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate : stopTimeUpdateList) {
// Only flag one occurrence of W009 for stop_time_update per trip to avoid flooding the database
if (!foundW009) {
checkW009(entity, stopTimeUpdate, errorListW009);
if (!errorListW009.isEmpty()) {
foundW009 = true;
}
}
}
if (tripUpdate.hasTrip()) {
checkW009(entity, tripUpdate.getTrip(), errorListW009);
}
}
if (entity.hasVehicle() && entity.getVehicle().hasTrip()) {
GtfsRealtime.TripDescriptor trip = entity.getVehicle().getTrip();
if (!trip.hasTripId()) {
checkW006(entity, trip, errorListW006);
} else {
String tripId = trip.getTripId();
if (!StringUtils.isEmpty(tripId)) {
Trip gtfsTrip = gtfsMetadata.getTrips().get(tripId);
if (gtfsTrip == null) {
if (!GtfsUtils.isAddedTrip(trip)) {
// E003 - Trip isn't in GTFS data and isn't an ADDED trip
RuleUtils.addOccurrence(E003, "vehicle_id " + entity.getVehicle().getVehicle().getId() + " trip_id " + tripId, errorListE003, _log);
}
} else {
if (GtfsUtils.isAddedTrip(trip)) {
// E016 - Trip is in GTFS data and is an ADDED trip
RuleUtils.addOccurrence(E016, "vehicle_id " + entity.getVehicle().getVehicle().getId() + " trip_id " + tripId, errorListE016, _log);
}
if (trip.hasStartTime()) {
checkE023(entity.getVehicle(), trip, gtfsMetadata, errorListE023);
}
}
}
}
if (trip.hasStartTime()) {
checkE020(entity.getVehicle(), trip, errorListE020);
}
checkE004(entity.getVehicle(), trip, gtfsMetadata, errorListE004);
checkE021(entity.getVehicle(), trip, errorListE021);
checkE024(entity.getVehicle(), trip, gtfsMetadata, errorListE024);
checkE035(entity, trip, gtfsMetadata, errorListE035);
checkW009(entity, trip, errorListW009);
}
if (entity.hasAlert()) {
GtfsRealtime.Alert alert = entity.getAlert();
List<GtfsRealtime.EntitySelector> entitySelectors = alert.getInformedEntityList();
if (entitySelectors != null && entitySelectors.size() > 0) {
for (GtfsRealtime.EntitySelector entitySelector : entitySelectors) {
checkE033(entity, entitySelector, errorListE033);
checkE034(entity, entitySelector, gtfsMetadata, errorListE034);
checkE035(entity, entitySelector.getTrip(), gtfsMetadata, errorListE035);
if (entitySelector.hasRouteId() && entitySelector.hasTrip()) {
checkE030(entity, entitySelector, gtfsMetadata, errorListE030);
checkE031(entity, entitySelector, errorListE031);
}
if (entitySelector.hasTrip()) {
checkW006(entity, entitySelector.getTrip(), errorListW006);
checkW009(entity, entitySelector.getTrip(), errorListW009);
}
}
} else {
// E032 - Alert does not have an informed_entity
RuleUtils.addOccurrence(E032, "alert ID " + entity.getId() + " does not have an informed_entity", errorListE032, _log);
}
}
}
List<ErrorListHelperModel> errors = new ArrayList<>();
if (!errorListE003.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E003), errorListE003));
}
if (!errorListE004.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E004), errorListE004));
}
if (!errorListE016.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E016), errorListE016));
}
if (!errorListE020.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E020), errorListE020));
}
if (!errorListE021.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E021), errorListE021));
}
if (!errorListE023.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E023), errorListE023));
}
if (!errorListE024.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E024), errorListE024));
}
if (!errorListE030.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E030), errorListE030));
}
if (!errorListE031.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E031), errorListE031));
}
if (!errorListE032.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E032), errorListE032));
}
if (!errorListE033.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E033), errorListE033));
}
if (!errorListE034.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E034), errorListE034));
}
if (!errorListE035.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(E035), errorListE035));
}
if (!errorListW006.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(W006), errorListW006));
}
if (!errorListW009.isEmpty()) {
errors.add(new ErrorListHelperModel(new MessageLogModel(W009), errorListW009));
}
return errors;
}
use of org.onebusaway.gtfs.model.Trip in project gtfs-realtime-validator by CUTR-at-USF.
the class TripDescriptorValidator method checkE024.
/**
* Checks rule E024 - "trip direction_id does not match GTFS data" and adds any errors that are found to the provided error list
*
* @param entity The VehiclePosition or TripUpdate that contains the data to be evaluated for rule E024
* @param trip The TripDescriptor be evaluated for rule E024
* @param gtfsMetadata metadata for the static GTFS data
* @param errors list to add any errors for E024 to
*/
private void checkE024(Object entity, GtfsRealtime.TripDescriptor trip, GtfsMetadata gtfsMetadata, List<OccurrenceModel> errors) {
if (trip.hasDirectionId()) {
int directionId = trip.getDirectionId();
Trip gtfsTrip = gtfsMetadata.getTrips().get(trip.getTripId());
if (gtfsTrip != null && (gtfsTrip.getDirectionId() == null || !gtfsTrip.getDirectionId().equals(String.valueOf(directionId)))) {
String prefix = "GTFS-rt " + GtfsUtils.getVehicleAndTripIdText(entity) + " trip.direction_id is " + directionId + " but GTFS trip.direction_id is " + gtfsTrip.getDirectionId();
RuleUtils.addOccurrence(E024, prefix, errors, _log);
}
}
}
use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.
the class TripPattern method dumpServices.
public void dumpServices() {
Set<AgencyAndId> services = Sets.newHashSet();
for (Trip trip : this.trips) {
services.add(trip.getServiceId());
}
LOG.info("route {} : {}", route, services);
}
Aggregations