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

Rename TransitModel to TransitRepository #6148

Merged
merged 4 commits into from
Oct 16, 2024
Merged
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 .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# reorder and reformat GTFS GraphQL API schema file with graphql-java
14051fab312a67cae9a460aaf0bbc77223bec624

# Make OTP a multi-module project
ead33ffe280dd7caf72cae5ff7a41542e8427636
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.opentripplanner.model.plan.Itinerary.createScheduledTransitItinerary;
import static org.opentripplanner.transit.model._data.TransitModelForTest.id;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
Expand All @@ -21,7 +21,7 @@
import org.opentripplanner.model.plan.ScheduledTransitLegBuilder;
import org.opentripplanner.model.plan.StreetLeg;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.opentripplanner.transit.model.framework.FeedScopedId;
Expand All @@ -46,9 +46,13 @@ class EmissionsTest {
.withEndTime(TIME.plusHours(1))
.build();

private static final Route ROUTE_WITH_EMISSIONS = TransitModelForTest.route(id("1")).build();
private static final Route ROUTE_WITH_ZERO_EMISSIONS = TransitModelForTest.route(id("2")).build();
private static final Route ROUTE_WITHOUT_EMISSIONS_CONFIGURED = TransitModelForTest
private static final Route ROUTE_WITH_EMISSIONS = TimetableRepositoryForTest
.route(id("1"))
.build();
private static final Route ROUTE_WITH_ZERO_EMISSIONS = TimetableRepositoryForTest
.route(id("2"))
.build();
private static final Route ROUTE_WITHOUT_EMISSIONS_CONFIGURED = TimetableRepositoryForTest
.route(id("3"))
.build();

Expand Down Expand Up @@ -119,12 +123,15 @@ private ScheduledTransitLeg createTransitLeg(Route route) {
var stoptime = new StopTime();
var stopTimes = new ArrayList<StopTime>();
stopTimes.add(stoptime);
var testModel = TransitModelForTest.of();
var testModel = TimetableRepositoryForTest.of();
var stopOne = testModel.stop("1:stop1", 60, 25).build();
var stopTwo = testModel.stop("1:stop1", 61, 25).build();
var stopThree = testModel.stop("1:stop1", 62, 25).build();
var stopPattern = TransitModelForTest.stopPattern(stopOne, stopTwo, stopThree);
var pattern = TransitModelForTest.tripPattern("1", route).withStopPattern(stopPattern).build();
var stopPattern = TimetableRepositoryForTest.stopPattern(stopOne, stopTwo, stopThree);
var pattern = TimetableRepositoryForTest
.tripPattern("1", route)
.withStopPattern(stopPattern)
.build();
var trip = Trip
.of(FeedScopedId.parse("FOO:BAR"))
.withMode(TransitMode.BUS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary;
import static org.opentripplanner.transit.model._data.TransitModelForTest.id;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.util.List;
import org.junit.jupiter.api.Test;
Expand All @@ -13,12 +13,12 @@
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.routing.fares.FareService;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.Money;

public class FaresFilterTest implements PlanTestConstants {

private final TransitModelForTest testModel = TransitModelForTest.of();
private final TimetableRepositoryForTest testModel = TimetableRepositoryForTest.of();

@Test
void shouldAddFare() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.routing.core.FareType;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.Money;
import org.opentripplanner.transit.model.network.Route;

class CombinedInterlinedLegsFareServiceTest implements PlanTestConstants {

static final Route route = TransitModelForTest.route("route-1").build();
static final Route route = TimetableRepositoryForTest.route("route-1").build();
static final Itinerary interlinedWithDifferentRoute = newItinerary(
Place.forStop(AIRPORT_STOP),
T11_00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.routing.core.FareType;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.Money;

class DefaultFareServiceTest implements PlanTestConstants {
Expand Down Expand Up @@ -116,7 +116,7 @@ void shouldNotCombineInterlinedLegs() {
var itin = newItinerary(Place.forStop(AIRPORT_STOP), T11_00)
.bus(1, T11_05, T11_12, Place.forStop(CITY_CENTER_A_STOP))
.staySeatedBus(
TransitModelForTest.route("123").build(),
TimetableRepositoryForTest.route("123").build(),
2,
T11_12,
T11_16,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.opentripplanner.ext.fares.impl;

import static org.opentripplanner.transit.model._data.TransitModelForTest.OTHER_FEED_AGENCY;
import static org.opentripplanner.transit.model._data.TransitModelForTest.id;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.OTHER_FEED_AGENCY;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import org.opentripplanner.ext.fares.model.FareAttribute;
import org.opentripplanner.ext.fares.model.FareRuleSet;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.transit.model.basic.Money;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.framework.FeedScopedId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.standalone.api.OtpServerRequestContext;
import org.opentripplanner.transit.model.basic.Money;
import org.opentripplanner.transit.service.TransitModel;
import org.opentripplanner.transit.service.TimetableRepository;

public class FaresIntegrationTest {

@Test
public void testBasic() {
TestOtpModel model = ConstantsForTests.buildGtfsGraph(ConstantsForTests.CALTRAIN_GTFS);
var graph = model.graph();
var transitModel = model.transitModel();
var timetableRepository = model.timetableRepository();

var feedId = transitModel.getFeedIds().iterator().next();
var feedId = timetableRepository.getFeedIds().iterator().next();

var serverContext = TestServerContext.createServerContext(graph, transitModel);
var serverContext = TestServerContext.createServerContext(graph, timetableRepository);

var start = LocalDateTime
.of(2009, Month.AUGUST, 7, 12, 0, 0)
Expand All @@ -53,10 +53,10 @@ public void testBasic() {
public void testPortland() {
TestOtpModel model = ConstantsForTests.getInstance().getCachedPortlandGraph();
Graph graph = model.graph();
TransitModel transitModel = model.transitModel();
var portlandId = transitModel.getFeedIds().iterator().next();
TimetableRepository timetableRepository = model.timetableRepository();
var portlandId = timetableRepository.getFeedIds().iterator().next();

var serverContext = TestServerContext.createServerContext(graph, transitModel);
var serverContext = TestServerContext.createServerContext(graph, timetableRepository);

// from zone 3 to zone 2
var from = GenericLocation.fromStopId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary;
import static org.opentripplanner.transit.model._data.TransitModelForTest.FEED_ID;
import static org.opentripplanner.transit.model._data.TransitModelForTest.id;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.FEED_ID;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import com.google.common.collect.Multimaps;
import java.time.Duration;
Expand All @@ -22,13 +22,13 @@
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.Money;
import org.opentripplanner.transit.model.framework.FeedScopedId;

class GtfsFaresV2ServiceTest implements PlanTestConstants {

private final TransitModelForTest testModel = TransitModelForTest.of();
private final TimetableRepositoryForTest testModel = TimetableRepositoryForTest.of();

FeedScopedId LEG_GROUP1 = id("leg-group1");
FeedScopedId LEG_GROUP2 = id("leg-group2");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.opentripplanner.ext.fares.impl;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary;
import static org.opentripplanner.transit.model._data.TransitModelForTest.FEED_ID;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.FEED_ID;
import static org.opentripplanner.transit.model.basic.Money.euros;

import java.util.LinkedList;
Expand All @@ -21,7 +20,7 @@
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.routing.core.FareType;
import org.opentripplanner.routing.fares.FareService;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.Money;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.framework.FeedScopedId;
Expand Down Expand Up @@ -76,7 +75,7 @@ private static List<Arguments> createTestCases() {
FareZone C = FareZone.of(new FeedScopedId(FEED_ID, "C")).build();
FareZone D = FareZone.of(new FeedScopedId(FEED_ID, "D")).build();

var testModel = TransitModelForTest.of();
var testModel = TimetableRepositoryForTest.of();
Place A1 = testModel.place("A1", sb -> sb.withCoordinate(10.0, 12.0).addFareZones(A));
Place A2 = testModel.place("A2", sb -> sb.withCoordinate(10.0, 12.0).addFareZones(A));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary;
import static org.opentripplanner.transit.model._data.TransitModelForTest.FEED_ID;
import static org.opentripplanner.transit.model._data.TransitModelForTest.id;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.FEED_ID;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.time.Duration;
import java.util.LinkedList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.street.model.StreetTraversalPermission;
import org.opentripplanner.street.model._data.StreetModelForTest;
import org.opentripplanner.transit.model._data.TransitModelForTest;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.opentripplanner.transit.model.site.AreaStop;
import org.opentripplanner.transit.service.StopModel;
import org.opentripplanner.transit.service.TransitModel;
import org.opentripplanner.transit.service.TimetableRepository;

class AreaStopsToVerticesMapperTest {

private static final TransitModelForTest TEST_MODEL = TransitModelForTest.of();
private static final TimetableRepositoryForTest TEST_MODEL = TimetableRepositoryForTest.of();

private static final AreaStop BERLIN_AREA_STOP = TEST_MODEL
.areaStop("berlin")
Expand All @@ -38,7 +38,10 @@ class AreaStopsToVerticesMapperTest {
.withAreaStop(AreaStopsToVerticesMapperTest.BERLIN_AREA_STOP)
.build();

public static final TransitModel TRANSIT_MODEL = new TransitModel(STOP_MODEL, new Deduplicator());
public static final TimetableRepository TRANSIT_MODEL = new TimetableRepository(
STOP_MODEL,
new Deduplicator()
);

static List<TestCase> testCases() {
return List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.opentripplanner.routing.api.request.framework.TimeAndCostPenalty;
import org.opentripplanner.routing.api.request.request.filter.AllowAllTransitFilter;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.transit.service.TransitModel;
import org.opentripplanner.transit.service.TimetableRepository;

/**
* This test checks the combination of transit and flex works.
Expand All @@ -48,7 +48,7 @@ public class FlexIntegrationTest {

static Graph graph;

static TransitModel transitModel;
static TimetableRepository timetableRepository;

static RoutingService service;

Expand All @@ -57,23 +57,23 @@ static void setup() {
OTPFeature.enableFeatures(Map.of(OTPFeature.FlexRouting, true));
TestOtpModel model = FlexIntegrationTestData.cobbOsm();
graph = model.graph();
transitModel = model.transitModel();
timetableRepository = model.timetableRepository();

addGtfsToGraph(
graph,
transitModel,
timetableRepository,
List.of(
FlexIntegrationTestData.COBB_BUS_30_GTFS,
FlexIntegrationTestData.MARTA_BUS_856_GTFS,
FlexIntegrationTestData.COBB_FLEX_GTFS
)
);
service = TestServerContext.createServerContext(graph, transitModel).routingService();
service = TestServerContext.createServerContext(graph, timetableRepository).routingService();
}

@Test
void addFlexTripsAndPatternsToGraph() {
assertFalse(transitModel.getAllTripPatterns().isEmpty());
assertFalse(timetableRepository.getAllTripPatterns().isEmpty());
}

@Test
Expand Down Expand Up @@ -176,38 +176,42 @@ static void teardown() {
OTPFeature.enableFeatures(Map.of(OTPFeature.FlexRouting, false));
}

private static void addGtfsToGraph(Graph graph, TransitModel transitModel, List<File> gtfsFiles) {
private static void addGtfsToGraph(
Graph graph,
TimetableRepository timetableRepository,
List<File> gtfsFiles
) {
// GTFS
var gtfsBundles = gtfsFiles.stream().map(GtfsBundle::new).toList();
GtfsModule gtfsModule = new GtfsModule(
gtfsBundles,
transitModel,
timetableRepository,
graph,
ServiceDateInterval.unbounded()
);
gtfsModule.buildGraph();

// link stations to streets
TestStreetLinkerModule.link(graph, transitModel);
TestStreetLinkerModule.link(graph, timetableRepository);

// link flex locations to streets
new AreaStopsToVerticesMapper(graph, transitModel).buildGraph();
new AreaStopsToVerticesMapper(graph, timetableRepository).buildGraph();

// generate direct transfers
var req = new RouteRequest();

// we don't have a complete coverage of the entire area so use straight lines for transfers
new DirectTransferGenerator(
graph,
transitModel,
timetableRepository,
DataImportIssueStore.NOOP,
Duration.ofMinutes(10),
List.of(req)
)
.buildGraph();

transitModel.index();
graph.index(transitModel.getStopModel());
timetableRepository.index();
graph.index(timetableRepository.getStopModel());
}

private Itinerary getItinerary(GenericLocation from, GenericLocation to, int index) {
Expand Down
Loading
Loading