Skip to content

Commit

Permalink
Complete mapping of SSP
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 17, 2025
1 parent d51c76a commit 6edb414
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.opentripplanner.ext.flex.trip.FlexTrip;
import org.opentripplanner.model.transfer.ConstrainedTransfer;
import org.opentripplanner.transit.model.basic.Notice;
Expand All @@ -15,6 +16,7 @@
import org.opentripplanner.transit.model.site.Entrance;
import org.opentripplanner.transit.model.site.Pathway;
import org.opentripplanner.transit.model.site.PathwayNode;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.transit.service.SiteRepository;

Expand Down Expand Up @@ -77,4 +79,9 @@ public interface OtpTransitService {
* transit services if they are outside the configured 'transitServiceStart' and 'transitServiceEnd'
*/
boolean hasActiveTransit();

/**
* @see org.opentripplanner.transit.service.TimetableRepository#findStopByScheduledStopPoint(FeedScopedId)
*/
Map<FeedScopedId, RegularStop> stopsByScheduledStopPoint();
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ public List<VehicleParking> vehicleParkings() {
return vehicleParkings;
}

/**
* @see org.opentripplanner.transit.service.TimetableRepository#findStopByScheduledStopPoint(FeedScopedId)
*/
public Map<FeedScopedId, RegularStop> stopsByScheduledStopPoints() {
return stopsByScheduledStopPoints;
}

public OtpTransitService build() {
return new OtpTransitServiceImpl(this);
}
Expand Down Expand Up @@ -319,10 +326,6 @@ public void limitServiceDays(ServiceDateInterval periodLimit) {
LOG.info("Limiting transit service days to time period complete.");
}

public Map<FeedScopedId, RegularStop> getStopsByScheduledStopPoints() {
return stopsByScheduledStopPoints;
}

/**
* Find all serviceIds in both CalendarServices and CalendarServiceDates.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.opentripplanner.transit.model.site.Entrance;
import org.opentripplanner.transit.model.site.Pathway;
import org.opentripplanner.transit.model.site.PathwayNode;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.transit.service.SiteRepository;

Expand Down Expand Up @@ -70,6 +71,7 @@ class OtpTransitServiceImpl implements OtpTransitService {
private final Collection<Trip> trips;

private final Collection<FlexTrip<?, ?>> flexTrips;
private final Map<FeedScopedId, RegularStop> stopsByScheduledStopPoint;

/**
* Create a read only version of the {@link OtpTransitService}.
Expand All @@ -91,6 +93,7 @@ class OtpTransitServiceImpl implements OtpTransitService {
this.tripPatterns = immutableList(builder.getTripPatterns().values());
this.trips = immutableList(builder.getTripsById().values());
this.flexTrips = immutableList(builder.getFlexTripsById().values());
this.stopsByScheduledStopPoint = Collections.unmodifiableMap(builder.stopsByScheduledStopPoints());
}

@Override
Expand Down Expand Up @@ -186,6 +189,14 @@ public boolean hasActiveTransit() {
return serviceIds.size() > 0;
}

/**
* @see org.opentripplanner.transit.service.TimetableRepository#findStopByScheduledStopPoint(FeedScopedId)
*/
@Override
public Map<FeedScopedId, RegularStop> stopsByScheduledStopPoint() {
return stopsByScheduledStopPoint;
}

/* Private Methods */

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void buildGraph() {
// - have operators and notice assignments.
timetableRepository.addOperators(otpService.getAllOperators());
timetableRepository.addNoticeAssignments(otpService.getNoticeAssignments());
timetableRepository.addScheduledStopPointMapping(otpService.stopsByScheduledStopPoint());

AddTransitEntitiesToGraph.addToGraph(
otpService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ private void mapScheduledStopPointsToQuays() {
var sspid = idFactory.createId(id);
var stopId = idFactory.createId(currentNetexIndex.getQuayIdByStopPointRef().lookup(id));
var stop = Objects.requireNonNull(transitBuilder.getStops().get(stopId));
transitBuilder.getStopsByScheduledStopPoints().put(sspid, stop);
System.out.printf("%s -> %s%n", sspid, stopId);
transitBuilder.stopsByScheduledStopPoints().put(sspid, stop);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,11 @@ public boolean containsTrip(FeedScopedId id) {
return this.timetableRepositoryIndex.containsTrip(id);
}

@Override
public Optional<RegularStop> findStopByScheduledStopPoint(FeedScopedId scheduledStopPoint) {
return timetableRepository.findStopByScheduledStopPoint(scheduledStopPoint);
}

/**
* Returns a list of Trips that match the filtering defined in the request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,26 @@ public void addTripPattern(FeedScopedId id, TripPattern tripPattern) {
tripPatternForId.put(id, tripPattern);
}

public void addScheduledStopPointMapping(FeedScopedId scheduledStopPointRef, FeedScopedId stopId) {
var stop = Objects.requireNonNull(siteRepository.getRegularStop(stopId));
stopsByScheduledStopPointRefs.put(scheduledStopPointRef, stop);
public void addScheduledStopPointMapping(Map<FeedScopedId, RegularStop> mapping) {
stopsByScheduledStopPointRefs.putAll(mapping);
}

/**
* Return the stop that is associated with the NeTEx concept of a scheduled stop point.
* <p>
* The scheduled stop point which is a "location-independent" stop that schedule systems provide
* which in turn can be later be resolved to an actual stop.
* <p>
* This way two schedule systems can use their own IDs for scheduled stop points but the stop (the
* actual physical infrastructure) is the same.
* <p>
* SIRI feeds are encouraged to refer to scheduled stop points in an EstimatedCall's stopPointRef
* but the specs are unclear and the reality on the ground very mixed.
*
* @link <a href="https://public.3.basecamp.com/p/TcEEP5WrNZJPBxrJU9GAjint">NeTEx Basecamp discussion</a>
*/
public Optional<RegularStop> findStopByScheduledStopPoint(FeedScopedId scheduledStopPoint) {
return Optional.ofNullable(stopsByScheduledStopPointRefs.get(scheduledStopPoint));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ List<TripTimeOnDate> findTripTimeOnDate(
*/
boolean containsTrip(FeedScopedId id);

/**
* @see TimetableRepository#findStopByScheduledStopPoint(FeedScopedId)
*/
Optional<RegularStop> findStopByScheduledStopPoint(FeedScopedId scheduledStopPoint);

/**
* Returns a list of {@link RegularStop}s that lay within a bounding box and match the other criteria
* in the request object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public TripOnServiceDate resolveTripOnServiceDate(

public TripOnServiceDate resolveTripOnServiceDate(
String serviceJourneyId,
LocalDate serviceDate
@Nullable LocalDate serviceDate
) {
if (serviceDate == null) {
return null;
Expand Down Expand Up @@ -157,11 +157,11 @@ public LocalDate resolveServiceDate(FramedVehicleJourneyRefStructure vehicleJour
* departure from the first stop, only the Date-part is actually used, and is defined to
* represent the actual serviceDate. The time and zone part is ignored.
*/
public LocalDate resolveServiceDate(ZonedDateTime originAimedDepartureTime) {
public LocalDate resolveServiceDate(@Nullable ZonedDateTime originAimedDepartureTime) {
if (originAimedDepartureTime == null) {
return null;
}
// This grab the local-date from timestamp passed into OTP ignoring the time and zone
// This grabs the local-date from timestamp passed into OTP ignoring the time and zone
// information. An alternative is to use the transit model zone:
// 'originAimedDepartureTime.withZoneSameInstant(transitService.getTimeZone())'

Expand All @@ -172,7 +172,7 @@ public LocalDate resolveServiceDate(ZonedDateTime originAimedDepartureTime) {
* Resolve a {@link Trip} by resolving a service journey id from FramedVehicleJourneyRef ->
* DatedVehicleJourneyRef.
*/
public Trip resolveTrip(FramedVehicleJourneyRefStructure journey) {
public Trip resolveTrip(@Nullable FramedVehicleJourneyRefStructure journey) {
if (journey != null) {
return resolveTrip(journey.getDatedVehicleJourneyRef());
}
Expand All @@ -184,10 +184,13 @@ public Trip resolveTrip(String serviceJourneyId) {
}

/**
* Resolve a {@link RegularStop} from a quay id.
* Resolve a {@link RegularStop} from a scheduled stop point or quay id.
*
* @see org.opentripplanner.transit.service.TimetableRepository#findStopByScheduledStopPoint(FeedScopedId)
*/
public RegularStop resolveQuay(String quayRef) {
return transitService.getRegularStop(resolveId(quayRef));
public RegularStop resolveQuay(String stopPointRef) {
var id = resolveId(stopPointRef);
return transitService.findStopByScheduledStopPoint(id).orElseGet(() -> transitService.getRegularStop(id));
}

/**
Expand Down

0 comments on commit 6edb414

Please sign in to comment.