use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSourceTest method testHandleDelayedTrip.
@Test
public void testHandleDelayedTrip() {
final FeedScopedId tripId = new FeedScopedId(feedId, "1.1");
final FeedScopedId tripId2 = new FeedScopedId(feedId, "1.2");
final Trip trip = graph.index.getTripForId().get(tripId);
final TripPattern pattern = graph.index.getPatternForTrip().get(trip);
final int tripIndex = pattern.scheduledTimetable.getTripIndex(tripId);
final int tripIndex2 = pattern.scheduledTimetable.getTripIndex(tripId2);
final TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED);
final TripUpdate.Builder tripUpdateBuilder = TripUpdate.newBuilder();
tripUpdateBuilder.setTrip(tripDescriptorBuilder);
final StopTimeUpdate.Builder stopTimeUpdateBuilder = tripUpdateBuilder.addStopTimeUpdateBuilder();
stopTimeUpdateBuilder.setScheduleRelationship(StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeUpdateBuilder.setStopSequence(2);
final StopTimeEvent.Builder arrivalBuilder = stopTimeUpdateBuilder.getArrivalBuilder();
final StopTimeEvent.Builder departureBuilder = stopTimeUpdateBuilder.getDepartureBuilder();
arrivalBuilder.setDelay(1);
departureBuilder.setDelay(1);
final TripUpdate tripUpdate = tripUpdateBuilder.build();
updater.applyTripUpdates(graph, fullDataset, Arrays.asList(tripUpdate), feedId);
final TimetableSnapshot snapshot = updater.getTimetableSnapshot();
final Timetable forToday = snapshot.resolve(pattern, serviceDate);
final Timetable schedule = snapshot.resolve(pattern, null);
assertNotSame(forToday, schedule);
assertNotSame(forToday.getTripTimes(tripIndex), schedule.getTripTimes(tripIndex));
assertSame(forToday.getTripTimes(tripIndex2), schedule.getTripTimes(tripIndex2));
assertEquals(1, forToday.getTripTimes(tripIndex).getArrivalDelay(1));
assertEquals(1, forToday.getTripTimes(tripIndex).getDepartureDelay(1));
assertEquals(RealTimeState.SCHEDULED, schedule.getTripTimes(tripIndex).getRealTimeState());
assertEquals(RealTimeState.UPDATED, forToday.getTripTimes(tripIndex).getRealTimeState());
assertEquals(RealTimeState.SCHEDULED, schedule.getTripTimes(tripIndex2).getRealTimeState());
assertEquals(RealTimeState.SCHEDULED, forToday.getTripTimes(tripIndex2).getRealTimeState());
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class RoutingRequest method preferencesPenaltyForRoute.
/**
* Check if route is preferred according to this request.
*/
public long preferencesPenaltyForRoute(Route route) {
long preferences_penalty = 0;
FeedScopedId agencyID = route.getAgency().getId();
if (!preferredRoutes.equals(RouteMatcher.emptyMatcher()) || !preferredAgencies.isEmpty()) {
boolean isPreferedRoute = preferredRoutes.matches(route);
boolean isPreferedAgency = preferredAgencies.contains(agencyID);
if (!isPreferedRoute && !isPreferedAgency) {
preferences_penalty += otherThanPreferredRoutesPenalty;
}
}
boolean isUnpreferedRoute = unpreferredRoutes.matches(route);
boolean isUnpreferedAgency = unpreferredAgencies.contains(agencyID);
if (isUnpreferedRoute || isUnpreferedAgency) {
preferences_penalty += useUnpreferredRoutesPenalty;
}
return preferences_penalty;
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class RouteMatcher method asString.
public String asString() {
StringBuilder builder = new StringBuilder();
for (FeedScopedId id : agencyAndRouteIds) {
builder.append(id.getFeedId() + "__" + id.getId());
builder.append(",");
}
for (T2<String, String> agencyIdAndRouteName : agencyIdAndRouteNames) {
builder.append(agencyIdAndRouteName.first + "_" + agencyIdAndRouteName.second);
builder.append(",");
}
for (String routeName : routeNames) {
builder.append("_" + routeName);
builder.append(",");
}
if (builder.length() > 0) {
builder.setLength(builder.length() - 1);
}
return builder.toString();
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class RouteMatcher method parse.
/**
* Build a new RouteMatcher from a string representation.
*
* @param routeSpecList A comma-separated list of route spec, each of the format
* [agencyId]_[routeName]_[routeId] Please note that this format is not really intuitive
* as it does not follow the OBA-gtfslib AgencyAndId standard ('agencyID_routeId'). This
* was kept for backward-compatibility purposes. If the original routeName contains some
* "_" each *must* be replaced by a space. If the agency or route ID contains a "_" they
* must be escaped using a backslash.
* TODO why do we want to accept route name strings when we have IDs? Break backward compatibility.
* FIXME this is the only place we are still using underscores as scope separators. Rethink this from scratch, see #1671.
* @return A RouteMatcher
* @throws IllegalArgumentException If the string representation is invalid.
*/
public static RouteMatcher parse(String routeSpecList) {
if (routeSpecList == null)
return emptyMatcher();
RouteMatcher retval = new RouteMatcher();
int n = 0;
for (String element : routeSpecList.split(",")) {
if (element.length() == 0)
continue;
n++;
// FIXME regexes with no comments
String[] routeSpec = element.split("(?<!\\\\)_", 3);
if (routeSpec.length != 2 && routeSpec.length != 3) {
throw new IllegalArgumentException("Wrong route spec format: " + element);
}
routeSpec[0] = routeSpec[0].replace("\\_", "_");
routeSpec[1] = routeSpec[1].replace("\\_", " ");
if (routeSpec.length >= 3)
routeSpec[2] = routeSpec[2].replace("\\_", "_");
String agencyId = routeSpec[0];
if (agencyId.length() == 0)
agencyId = null;
String routeName = routeSpec[1];
if (routeName.length() == 0)
routeName = null;
String routeId = routeSpec.length > 2 ? routeSpec[2] : null;
if (routeId != null && routeId.length() == 0)
routeId = null;
if (agencyId != null && routeId != null && routeName == null) {
// Case 1: specified agency ID and route ID but no route name
retval.agencyAndRouteIds.add(new FeedScopedId(agencyId, routeId));
} else if (agencyId != null && routeName != null && routeId == null) {
// Case 2: specified agency ID and route name but no route ID
retval.agencyIdAndRouteNames.add(new T2<String, String>(agencyId, routeName));
} else if (agencyId == null && routeName != null && routeId == null) {
// Case 3: specified route name only
retval.routeNames.add(routeName);
} else {
throw new IllegalArgumentException("Wrong route spec format: " + element);
}
}
if (n == 0)
return emptyMatcher();
return retval;
}
use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.
the class ServiceDay method init.
private void init(Map<FeedScopedId, Integer> serviceCodes, CalendarService cs, TimeZone timeZone) {
Date d = serviceDate.getAsDate(timeZone);
this.midnight = d.getTime() / 1000;
serviceIdsRunning = new BitSet(cs.getServiceIds().size());
for (FeedScopedId serviceId : cs.getServiceIdsOnDate(serviceDate)) {
int n = serviceCodes.get(serviceId);
if (n < 0)
continue;
serviceIdsRunning.set(n);
}
}
Aggregations