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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5aa5a39
Allow SIRI and GTFS at the same time
leonardehrenfried Dec 22, 2024
7b75761
Fix cyclic dependency
leonardehrenfried Dec 23, 2024
e2c9a20
Fix some tests
leonardehrenfried Dec 23, 2024
dc8c8d0
Add diagram
leonardehrenfried Dec 23, 2024
bde1a38
Use easy instantiation of DefaultTransitService
leonardehrenfried Dec 23, 2024
1c2a269
Fix GraphQL test
leonardehrenfried Dec 23, 2024
0b1a994
Update diagram
leonardehrenfried Dec 23, 2024
0585926
Add javadoc
leonardehrenfried Dec 23, 2024
081bcbf
Fix some tests
leonardehrenfried Dec 24, 2024
228f8af
Allow running SIRI & GTFS-RT in tests
leonardehrenfried Dec 24, 2024
bca8739
Make integration tests pass
leonardehrenfried Dec 25, 2024
5308651
Move transit layer-related methods to TimetableRepository
leonardehrenfried Dec 25, 2024
bd38946
Fix remaining test
leonardehrenfried Dec 26, 2024
2aa87f3
Remove outdated comment
leonardehrenfried Dec 27, 2024
94ee02c
Polish documentation
leonardehrenfried Jan 2, 2025
fd156b7
Add method
leonardehrenfried Jan 2, 2025
5f8eb10
Rename 'diagrams' to 'design'
leonardehrenfried Jan 7, 2025
ff4b7ae
Use snapshot buffer
leonardehrenfried Jan 8, 2025
88d238e
Merge remote-tracking branch 'upstream/dev-2.x' into siri-gtfs
leonardehrenfried Jan 20, 2025
b9cba70
Update method name after merge
leonardehrenfried Jan 20, 2025
0723ab3
Merge remote-tracking branch 'upstream/dev-2.x' into siri-gtfs
leonardehrenfried Jan 24, 2025
706a2a7
Remove lazyGetTimeTableSnapShot()
leonardehrenfried Jan 27, 2025
ed0c782
Re-add log
leonardehrenfried Jan 27, 2025
a643e48
Clean up imports
leonardehrenfried Jan 27, 2025
c740b83
Remove 'this' from DefaultTransitService
leonardehrenfried Jan 29, 2025
d8991eb
Add Nullable annotation
leonardehrenfried Jan 29, 2025
b19e36e
Update Javadoc to reflect new reality
leonardehrenfried Jan 31, 2025
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();
}
}
Loading
Loading