Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SIRI-ET and GTFS-RT TripUpdates at the same time #6363

Open
wants to merge 21 commits into
base: dev-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ streetGraph.obj
graph.obj
# IntelliJ creates these pid files when you attach the debugger to tests
.attach_pid*

# draw.io backup files
*.svg.bkp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StopClusterMapperTest {
.siteRepositoryBuilder()
.withRegularStops(STOPS)
.build();
private static final TimetableRepository TRANSIT_MODEL = new TimetableRepository(
private static final TimetableRepository TIMETABLE_REPOSITORY = new TimetableRepository(
SITE_REPOSITORY,
new Deduplicator()
);
Expand All @@ -40,8 +40,8 @@ void clusterConsolidatedStops() {
var repo = new DefaultStopConsolidationRepository();
repo.addGroups(List.of(new ConsolidatedStopGroup(STOP_A.getId(), List.of(STOP_B.getId()))));

var service = new DefaultStopConsolidationService(repo, TRANSIT_MODEL);
var mapper = new StopClusterMapper(new DefaultTransitService(TRANSIT_MODEL), service);
var service = new DefaultStopConsolidationService(repo, TIMETABLE_REPOSITORY);
var mapper = new StopClusterMapper(new DefaultTransitService(TIMETABLE_REPOSITORY), service);

var clusters = mapper.generateStopClusters(LOCATIONS, List.of());

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.timetable.TripIdAndServiceDate;
import org.opentripplanner.transit.model.timetable.TripTimes;
import org.opentripplanner.transit.service.TransitEditorService;
import org.opentripplanner.transit.service.TimetableRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,7 +39,7 @@ public class TransitLayerUpdater {

private static final Logger LOG = LoggerFactory.getLogger(TransitLayerUpdater.class);

private final TransitEditorService transitService;
private final TimetableRepository timetableRepository;

/**
* Cache the TripPatternForDates indexed on the original TripPatterns in order to avoid this
Expand All @@ -55,27 +55,29 @@ public class TransitLayerUpdater {

private final Map<LocalDate, Set<TripPatternForDate>> tripPatternsRunningOnDateMapCache = new HashMap<>();

public TransitLayerUpdater(TransitEditorService transitService) {
this.transitService = transitService;
public TransitLayerUpdater(TimetableRepository timetableRepository) {
this.timetableRepository = timetableRepository;
}

public void update(
Collection<Timetable> updatedTimetables,
Map<TripPattern, SortedSet<Timetable>> timetables
) {
if (!transitService.hasRealtimeTransitLayer()) {
if (!timetableRepository.hasRealtimeTransitLayer()) {
return;
}

long startTime = System.currentTimeMillis();

// Make a shallow copy of the realtime transit layer. Only the objects that are copied will be
// changed during this update process.
TransitLayer realtimeTransitLayer = new TransitLayer(transitService.getRealtimeTransitLayer());
TransitLayer realtimeTransitLayer = new TransitLayer(
timetableRepository.getRealtimeTransitLayer()
);

// Instantiate a TripPatternForDateMapper with the new TripPattern mappings
TripPatternForDateMapper tripPatternForDateMapper = new TripPatternForDateMapper(
transitService.getServiceCodesRunningForDate()
timetableRepository.getServiceCodesRunningForDate()
);

Set<LocalDate> datesToBeUpdated = new HashSet<>();
Expand Down Expand Up @@ -222,7 +224,7 @@ public void update(

// Switch out the reference with the updated realtimeTransitLayer. This is synchronized to
// guarantee that the reference is set after all the fields have been updated.
transitService.setRealtimeTransitLayer(realtimeTransitLayer);
timetableRepository.setRealtimeTransitLayer(realtimeTransitLayer);

LOG.debug(
"UPDATING {} tripPatterns took {} ms",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.opentripplanner.routing.algorithm.raptoradapter.transit.TransitTuningParameters;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.TransitLayerMapper;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.TransitLayerUpdater;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
import org.opentripplanner.service.realtimevehicles.RealtimeVehicleRepository;
Expand All @@ -35,9 +34,9 @@
import org.opentripplanner.standalone.server.OTPWebApplication;
import org.opentripplanner.street.model.StreetLimitationParameters;
import org.opentripplanner.street.model.elevation.ElevationUtils;
import org.opentripplanner.transit.service.DefaultTransitService;
import org.opentripplanner.transit.service.TimetableRepository;
import org.opentripplanner.updater.configure.UpdaterConfigurator;
import org.opentripplanner.updater.trip.TimetableSnapshotManager;
import org.opentripplanner.utils.logging.ProgressTracker;
import org.opentripplanner.visualizer.GraphVisualizer;
import org.slf4j.Logger;
Expand Down Expand Up @@ -171,7 +170,7 @@ private void setupTransitRoutingServer() {
enableRequestTraceLogging();
createMetricsLogging();

creatTransitLayerForRaptor(timetableRepository(), routerConfig().transitTuningConfig());
createTransitLayerForRaptor(timetableRepository(), routerConfig().transitTuningConfig());

/* Create updater modules from JSON config. */
UpdaterConfigurator.configure(
Expand All @@ -180,6 +179,7 @@ private void setupTransitRoutingServer() {
vehicleRentalRepository(),
vehicleParkingRepository(),
timetableRepository(),
snapshotManager(),
routerConfig().updaterConfig()
);

Expand Down Expand Up @@ -217,7 +217,7 @@ private void initEllipsoidToGeoidDifference() {
/**
* Create transit layer for Raptor routing. Here we map the scheduled timetables.
*/
public static void creatTransitLayerForRaptor(
public static void createTransitLayerForRaptor(
TimetableRepository timetableRepository,
TransitTuningParameters tuningParameters
) {
Expand All @@ -233,9 +233,6 @@ public static void creatTransitLayerForRaptor(
timetableRepository.setRealtimeTransitLayer(
new TransitLayer(timetableRepository.getTransitLayer())
);
timetableRepository.setTransitLayerUpdater(
new TransitLayerUpdater(new DefaultTransitService(timetableRepository))
);
}

public static void initializeTransferCache(
Expand Down Expand Up @@ -287,6 +284,10 @@ public VehicleRentalRepository vehicleRentalRepository() {
return factory.vehicleRentalRepository();
}

private TimetableSnapshotManager snapshotManager() {
return factory.timetableSnapshotManager();
}

public VehicleParkingService vehicleParkingService() {
return factory.vehicleParkingService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.opentripplanner.transit.configure.TransitModule;
import org.opentripplanner.transit.service.TimetableRepository;
import org.opentripplanner.transit.service.TransitService;
import org.opentripplanner.updater.trip.TimetableSnapshotManager;
import org.opentripplanner.visualizer.GraphVisualizer;

/**
Expand Down Expand Up @@ -81,6 +82,7 @@ public interface ConstructApplicationFactory {
VehicleRentalService vehicleRentalService();
VehicleParkingRepository vehicleParkingRepository();
VehicleParkingService vehicleParkingService();
TimetableSnapshotManager timetableSnapshotManager();
DataImportIssueSummary dataImportIssueSummary();

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,55 @@

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import jakarta.inject.Singleton;
import java.time.LocalDate;
import java.time.ZoneId;
import org.opentripplanner.model.TimetableSnapshot;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.mappers.TransitLayerUpdater;
import org.opentripplanner.standalone.api.HttpRequestScoped;
import org.opentripplanner.standalone.config.ConfigModel;
import org.opentripplanner.transit.service.DefaultTransitService;
import org.opentripplanner.transit.service.TimetableRepository;
import org.opentripplanner.transit.service.TransitService;
import org.opentripplanner.updater.trip.TimetableSnapshotManager;

@Module
public abstract class TransitModule {

@Binds
@HttpRequestScoped
abstract TransitService bind(DefaultTransitService service);

@Provides
@Singleton
public static TimetableSnapshotManager timetableSnapshotManager(
TransitLayerUpdater transitLayerUpdater,
ConfigModel config,
TimetableRepository timetableRepository
) {
return new TimetableSnapshotManager(
transitLayerUpdater,
config.routerConfig().updaterConfig().timetableSnapshotParameters(),
() -> LocalDate.now(timetableRepository.getTimeZone())
);
}

/**
* Create a single instance of the transit layer updater which holds the incremental caches for
* the updates that need to applied to the {@link org.opentripplanner.routing.algorithm.raptoradapter.transit.TransitLayer}.
*/
@Provides
@Singleton
public static TransitLayerUpdater transitLayerUpdater(TimetableRepository timetableRepository) {
return new TransitLayerUpdater(timetableRepository);
}

/**
* Provides the currently published, immutable {@link TimetableSnapshot}.
*/
@Provides
public static TimetableSnapshot timetableSnapshot(TimetableSnapshotManager manager) {
return manager.getTimetableSnapshot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,23 @@ public class DefaultTransitService implements TransitEditorService {
/**
* This should only be accessed through the getTimetableSnapshot method.
*/
private TimetableSnapshot timetableSnapshot;
private final TimetableSnapshot timetableSnapshot;

@Inject
/**
* Create a service without a real-time snapshot (and therefore without any real-time data).
*/
public DefaultTransitService(TimetableRepository timetableRepository) {
this.timetableRepository = timetableRepository;
this.timetableRepositoryIndex = timetableRepository.getTimetableRepositoryIndex();
this(timetableRepository, null);
}

@Inject
public DefaultTransitService(
TimetableRepository timetableRepository,
TimetableSnapshot timetableSnapshotBuffer
@Nullable TimetableSnapshot timetableSnapshot
) {
this(timetableRepository);
this.timetableSnapshot = timetableSnapshotBuffer;
this.timetableRepository = timetableRepository;
this.timetableRepositoryIndex = timetableRepository.getTimetableRepositoryIndex();
this.timetableSnapshot = timetableSnapshot;
}

@Override
Expand Down Expand Up @@ -533,9 +536,6 @@ public boolean hasNewTripPatternsForModifiedTrips() {
*/
@Nullable
private TimetableSnapshot lazyGetTimeTableSnapShot() {
if (this.timetableSnapshot == null) {
timetableSnapshot = timetableRepository.getTimetableSnapshot();
}
return this.timetableSnapshot;
}

Expand Down Expand Up @@ -654,21 +654,6 @@ public TransitLayer getRealtimeTransitLayer() {
return this.timetableRepository.getRealtimeTransitLayer();
}

@Override
public void setTransitLayer(TransitLayer transitLayer) {
this.timetableRepository.setTransitLayer(transitLayer);
}

@Override
public void setRealtimeTransitLayer(TransitLayer realtimeTransitLayer) {
timetableRepository.setRealtimeTransitLayer(realtimeTransitLayer);
}

@Override
public boolean hasRealtimeTransitLayer() {
return timetableRepository.hasRealtimeTransitLayer();
}

@Override
public CalendarService getCalendarService() {
return this.timetableRepository.getCalendarService();
Expand Down
Loading
Loading