Skip to content

Commit

Permalink
Fix indexing of pattern by stop
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Aug 20, 2024
1 parent 1a5c1d5 commit e176b0b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ void testCancelTrip() {
}

@Test
void testAddJourney() {
void testAddJourneyWithExistingRoute() {
var env = RealtimeTestEnvironment.siri();

Route route = env.getTransitService().getRouteForId(env.route1Id);
int numPatternForRoute = env.getTransitService().getPatternsForRoute(route).size();

String newJourneyId = "newJourney";
var updates = new SiriEtBuilder(env.getDateTimeHelper())
.withEstimatedVehicleJourneyCode(newJourneyId)
.withIsExtraJourney(true)
.withOperatorRef(env.operator1Id.getId())
.withLineRef(env.route1Id.getId())
.withLineRef(route.getId().getId())
.withRecordedCalls(builder -> builder.call(env.stopC1).departAimedActual("00:01", "00:02"))
.withEstimatedCalls(builder -> builder.call(env.stopD1).arriveAimedExpected("00:03", "00:04"))
.buildEstimatedTimetableDeliveries();
Expand All @@ -69,6 +72,11 @@ void testAddJourney() {
new TripIdAndServiceDate(tripId, SERVICE_DATE)
)
);
assertEquals(
numPatternForRoute + 1,
transitService.getPatternsForRoute(route).size(),
"The added trip should use a new pattern for this route"
);
}

@Test
Expand Down Expand Up @@ -99,7 +107,7 @@ void testAddJourneyWithNewRoute() {
FeedScopedId newRouteId = TransitModelForTest.id(newRouteRef);
Route newRoute = transitService.getRouteForId(newRouteId);
assertNotNull(newRoute);
assertNotNull(transitService.getPatternsForRoute(newRoute));
assertEquals(1, transitService.getPatternsForRoute(newRoute).size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public TripPattern getRealTimeAddedPatternForTrip(Trip trip) {
/**
* Return the trip patterns created by the updater for the given route.
*/
@Nullable
public Collection<TripPattern> getRealTimeAddedPatternForRoute(Route route) {
return realTimeAddedPatternsForRoute.get(route);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,17 @@ public TripPattern getPatternForTrip(Trip trip, LocalDate serviceDate) {
@Override
public Collection<TripPattern> getPatternsForRoute(Route route) {
OTPRequestTimeoutException.checkForTimeout();
Collection<TripPattern> tripPatterns = new HashSet<>(
transitModelIndex.getPatternsForRoute().get(route)
);
TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot();
if (currentSnapshot != null) {
Collection<TripPattern> tripPatterns = currentSnapshot.getRealTimeAddedPatternForRoute(route);
if (!tripPatterns.isEmpty()) {
return tripPatterns;
}
Collection<TripPattern> realTimeAddedPatternForRoute = currentSnapshot.getRealTimeAddedPatternForRoute(
route
);
tripPatterns.addAll(realTimeAddedPatternForRoute);
}
return this.transitModelIndex.getPatternsForRoute().get(route);
return tripPatterns;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public interface TransitService {

Collection<Notice> getNoticesByEntity(AbstractTransitEntity<?, ?> entity);

/**
* Return a trip pattern by id, not including patterns created by real-time updates.
*/
TripPattern getTripPatternForId(FeedScopedId id);

/**
Expand All @@ -97,8 +100,15 @@ public interface TransitService {

Agency getAgencyForId(FeedScopedId id);

/**
* Return a route for a given id, including routes created by real-time updates.
*
*/
Route getRouteForId(FeedScopedId id);

/**
* Return the routes using the given stop, not including real-time updates.
*/
Set<Route> getRoutesForStop(StopLocation stop);

/**
Expand Down Expand Up @@ -149,22 +159,31 @@ public interface TransitService {
@Nullable
Trip getScheduledTripForId(FeedScopedId id);

/**
* Return all trips, including those created by real-time updates.
*/
Collection<Trip> getAllTrips();

/**
* Return all routes, including those created by real-time updates.
*/
Collection<Route> getAllRoutes();

/**
* Return the scheduled trip pattern for a given trip (not taking into account real-time updates)
* Return the scheduled trip pattern for a given trip.
* If the trip is an added trip (extra journey), return the initial trip pattern for this trip.
*/
TripPattern getPatternForTrip(Trip trip);

/**
* Return the trip pattern for a given trip on a service date. The real-time updated version
* is returned if it exists, otherwise the scheduled trip pattern is returned.
*
*/
TripPattern getPatternForTrip(Trip trip, LocalDate serviceDate);

/**
* Return all the trip patterns used in the given route, including those added by real-time updates
*/
Collection<TripPattern> getPatternsForRoute(Route route);

MultiModalStation getMultiModalStationForStation(Station station);
Expand Down Expand Up @@ -208,12 +227,24 @@ List<TripTimeOnDate> stopTimesForPatternAtStop(
@Nullable
Timetable getTimetableForTripPattern(TripPattern tripPattern, LocalDate serviceDate);

/**
* Return the real-time added pattern for a given tripId and a given service date.
* Return null if the trip does not exist or if the trip has no real-time added pattern for
* this date (that is: it is still using its scheduled trip pattern for this date).
*/
@Nullable
TripPattern getRealtimeAddedTripPattern(FeedScopedId tripId, LocalDate serviceDate);

/**
* Return true if at least one trip pattern has been created by a real-time update.
*/
boolean hasRealtimeAddedTripPatterns();

TripOnServiceDate getTripOnServiceDateForTripAndDay(TripIdAndServiceDate tripIdAndServiceDate);

/**
* Return the TripOnServiceDate for a given id, including real-time updates.
*/
TripOnServiceDate getTripOnServiceDateById(FeedScopedId datedServiceJourneyId);

Collection<TripOnServiceDate> getAllTripOnServiceDates();
Expand Down

0 comments on commit e176b0b

Please sign in to comment.