Search in sources :

Example 51 with FeedScopedId

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());
}
Also used : Timetable(org.opentripplanner.model.Timetable) Trip(org.opentripplanner.model.Trip) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) TimetableSnapshot(org.opentripplanner.model.TimetableSnapshot) TripPattern(org.opentripplanner.model.TripPattern) StopTimeEvent(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) FeedScopedId(org.opentripplanner.model.FeedScopedId) StopTimeUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate) Test(org.junit.Test)

Example 52 with FeedScopedId

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;
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 53 with FeedScopedId

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();
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 54 with FeedScopedId

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;
}
Also used : FeedScopedId(org.opentripplanner.model.FeedScopedId) T2(org.opentripplanner.common.model.T2)

Example 55 with FeedScopedId

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);
    }
}
Also used : BitSet(java.util.BitSet) FeedScopedId(org.opentripplanner.model.FeedScopedId) Date(java.util.Date) ServiceDate(org.opentripplanner.model.calendar.ServiceDate)

Aggregations

FeedScopedId (org.opentripplanner.model.FeedScopedId)117 Trip (org.opentripplanner.model.Trip)32 Test (org.junit.Test)29 Stop (org.opentripplanner.model.Stop)25 TripPattern (org.opentripplanner.model.TripPattern)25 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)21 ArrayList (java.util.ArrayList)20 Route (org.opentripplanner.model.Route)15 HashSet (java.util.HashSet)11 List (java.util.List)11 Agency (org.opentripplanner.model.Agency)11 Collection (java.util.Collection)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 ZonedDateTime (java.time.ZonedDateTime)8 TransitEntity (org.opentripplanner.model.TransitEntity)8 RoutingService (org.opentripplanner.routing.RoutingService)8 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)8 Notice (org.opentripplanner.model.Notice)7 Station (org.opentripplanner.model.Station)7