use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.
the class StopTimesMapperTest method testMapStopTimes.
@Test
public void testMapStopTimes() {
NetexTestDataSample sample = new NetexTestDataSample();
StopTimesMapper stopTimesMapper = new StopTimesMapper(MappingSupport.ID_FACTORY, sample.getStopsById(), sample.getDestinationDisplayById(), sample.getQuayIdByStopPointRef());
StopTimesMapper.MappedStopTimes result = stopTimesMapper.mapToStopTimes(sample.getJourneyPattern(), new Trip(), sample.getTimetabledPassingTimes());
List<StopTime> stopTimes = result.stopTimes;
assertEquals(4, stopTimes.size());
assertStop(stopTimes.get(0), "NSR:Quay:1", 18000, "Bergen");
assertStop(stopTimes.get(1), "NSR:Quay:2", 18240, "Bergen");
assertStop(stopTimes.get(2), "NSR:Quay:3", 18600, "Stavanger");
assertStop(stopTimes.get(3), "NSR:Quay:4", 18900, "Stavanger");
Map<String, StopTime> map = result.stopTimeByNetexId;
assertEquals(stopTimes.get(0), map.get("TTPT-1"));
assertEquals(stopTimes.get(1), map.get("TTPT-2"));
assertEquals(stopTimes.get(2), map.get("TTPT-3"));
assertEquals(stopTimes.get(3), map.get("TTPT-4"));
}
use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.
the class JourneyWhiteListed method isTripTimeShortAcceptable.
private static boolean isTripTimeShortAcceptable(TripTimeShort tts, Collection<FeedScopedId> authorityIds, Collection<FeedScopedId> lineIds, RoutingService routingService) {
Trip trip = routingService.getTripForId().get(tts.tripId);
if (trip == null || trip.getRoute() == null) {
return true;
}
Route route = trip.getRoute();
boolean okForAuthority = authorityIds.contains(route.getAgency().getId());
boolean okForLine = lineIds.contains(route.getId());
return okForAuthority || okForLine;
}
use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.
the class EstimatedCallType method getAllRelevantAlerts.
/**
* Resolves all AlertPatches that are relevant for the supplied TripTimeShort.
*/
private static Collection<TransitAlert> getAllRelevantAlerts(TripTimeShort tripTimeShort, RoutingService routingService) {
FeedScopedId tripId = tripTimeShort.tripId;
Trip trip = routingService.getTripForId().get(tripId);
FeedScopedId routeId = trip.getRoute().getId();
FeedScopedId stopId = tripTimeShort.stopId;
Stop stop = routingService.getStopForId(stopId);
FeedScopedId parentStopId = stop.getParentStation().getId();
Collection<TransitAlert> allAlerts = new HashSet<>();
TransitAlertService alertPatchService = routingService.getTransitAlertService();
// Quay
allAlerts.addAll(alertPatchService.getStopAlerts(stopId));
allAlerts.addAll(alertPatchService.getStopAndTripAlerts(stopId, tripId));
allAlerts.addAll(alertPatchService.getStopAndRouteAlerts(stopId, routeId));
// StopPlace
allAlerts.addAll(alertPatchService.getStopAlerts(parentStopId));
allAlerts.addAll(alertPatchService.getStopAndTripAlerts(parentStopId, tripId));
allAlerts.addAll(alertPatchService.getStopAndRouteAlerts(parentStopId, routeId));
// Trip
allAlerts.addAll(alertPatchService.getTripAlerts(tripId));
// Route
allAlerts.addAll(alertPatchService.getRouteAlerts(routeId));
// Agency
// TODO OTP2 This should probably have a FeedScopeId argument instead of string
allAlerts.addAll(alertPatchService.getAgencyAlerts(trip.getRoute().getAgency().getId()));
// TripPattern
allAlerts.addAll(alertPatchService.getTripPatternAlerts(routingService.getPatternForTrip().get(trip).getId()));
long serviceDayMillis = 1000 * tripTimeShort.serviceDay;
long arrivalMillis = 1000 * tripTimeShort.realtimeArrival;
long departureMillis = 1000 * tripTimeShort.realtimeDeparture;
filterSituationsByDateAndStopConditions(allAlerts, new Date(serviceDayMillis + arrivalMillis), new Date(serviceDayMillis + departureMillis), Arrays.asList(StopCondition.STOP, StopCondition.START_POINT, StopCondition.EXCEPTIONAL_STOP));
return allAlerts;
}
use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.
the class TripPatternMapper method mapTripPattern.
Result mapTripPattern(JourneyPattern journeyPattern) {
// Make sure the result is clean, by creating a new object.
result = new Result();
Collection<ServiceJourney> serviceJourneys = serviceJourneyByPatternId.lookup(journeyPattern.getId());
if (serviceJourneys == null || serviceJourneys.isEmpty()) {
LOG.warn("ServiceJourneyPattern " + journeyPattern.getId() + " does not contain any serviceJourneys.");
return null;
}
List<Trip> trips = new ArrayList<>();
for (ServiceJourney serviceJourney : serviceJourneys) {
Trip trip = tripMapper.mapServiceJourney(serviceJourney);
// Unable to map ServiceJourney, problem logged by the mapper above
if (trip == null)
continue;
StopTimesMapper.MappedStopTimes stopTimes = stopTimesMapper.mapToStopTimes(journeyPattern, trip, serviceJourney.getPassingTimes().getTimetabledPassingTime());
// Unable to map StopTimes, problem logged by the mapper above
if (stopTimes == null)
continue;
result.tripStopTimes.put(trip, stopTimes.stopTimes);
result.stopTimeByNetexId.putAll(stopTimes.stopTimeByNetexId);
trip.setTripHeadsign(getHeadsign(stopTimes.stopTimes));
trips.add(trip);
}
// No trips successfully mapped
if (trips.isEmpty())
return result;
// Create StopPattern from any trip (since they are part of the same JourneyPattern)
StopPattern stopPattern = new StopPattern(result.tripStopTimes.get(trips.get(0)));
TripPattern tripPattern = new TripPattern(lookupRoute(journeyPattern), stopPattern);
tripPattern.setId(idFactory.createId(journeyPattern.getId()));
tripPattern.name = journeyPattern.getName() == null ? "" : journeyPattern.getName().getValue();
createTripTimes(trips, tripPattern);
result.tripPatterns.add(tripPattern);
return result;
}
use of org.opentripplanner.model.Trip in project OpenTripPlanner by opentripplanner.
the class SeattleFareServiceFactory method processGtfs.
@Override
public void processGtfs(OtpTransitService transitService) {
// Add custom extension: trips may have a fare ID specified in KCM GTFS.
// Need to ensure that we are scoped to feed when adding trips to FareRuleSet,
// since fare IDs may not be unique across feeds and trip agency IDsqq
// may not match fare attribute agency IDs (which are feed IDs).
Map<FeedScopedId, FareRuleSet> feedFareRules = new HashMap<>();
fillFareRules(transitService.getAllFareAttributes(), transitService.getAllFareRules(), feedFareRules);
regularFareRules.putAll(feedFareRules);
Map<String, FareRuleSet> feedFareRulesById = new HashMap<>();
for (FareRuleSet rule : regularFareRules.values()) {
String id = rule.getFareAttribute().getId().getId();
feedFareRulesById.put(id, rule);
}
for (Trip trip : transitService.getAllTrips()) {
String fareId = trip.getFareId();
FareRuleSet rule = feedFareRulesById.get(fareId);
if (rule != null)
rule.addTrip(trip.getId());
}
}
Aggregations