Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev-2.x' into upstream-merge-2…
Browse files Browse the repository at this point in the history
…025-02-06
  • Loading branch information
leonardehrenfried committed Feb 6, 2025
2 parents 79e854a + f4b4df9 commit 9c83284
Show file tree
Hide file tree
Showing 88 changed files with 1,594 additions and 639 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/performance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ jobs:

# extended locations that are run only after merging to dev-2.x

- location: hamburg # German city
iterations: 1
jfr-delay: "50s"
profile: extended
# Hamburg is disabled because of https://github.com/opentripplanner/OpenTripPlanner/issues/6430
# - location: hamburg # German city
# iterations: 1
# jfr-delay: "50s"
# profile: extended

- location: baden-wuerttemberg # German state of Baden-Württemberg: https://en.wikipedia.org/wiki/Baden-W%C3%BCrttemberg
iterations: 1
Expand Down
2 changes: 1 addition & 1 deletion application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.4.1</version>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
4 changes: 2 additions & 2 deletions application/src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="/img/otp-logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OTP Debug</title>
<script type="module" crossorigin src="https://www.opentripplanner.org/debug-client-assets/2025/01/2025-01-28T11:22/assets/index-BHcP0Ndc.js"></script>
<link rel="stylesheet" crossorigin href="https://www.opentripplanner.org/debug-client-assets/2025/01/2025-01-28T11:22/assets/index-DjMJ6mws.css">
<script type="module" crossorigin src="https://www.opentripplanner.org/debug-client-assets/2025/02/2025-02-05T13:35/assets/index-Car595fu.js"></script>
<link rel="stylesheet" crossorigin href="https://www.opentripplanner.org/debug-client-assets/2025/02/2025-02-05T13:35/assets/index-CiWBeHPw.css">
</head>
<body>
<div id="root"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.opentripplanner.framework.model.Grams;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.LegConstructionSupport;
import org.opentripplanner.model.plan.ScheduledTransitLeg;
import org.opentripplanner.model.plan.ScheduledTransitLegBuilder;
import org.opentripplanner.model.plan.StreetLeg;
Expand Down Expand Up @@ -146,6 +147,7 @@ private ScheduledTransitLeg createTransitLeg(Route route) {
.withEndTime(TIME.plusMinutes(10))
.withServiceDate(TIME.toLocalDate())
.withZoneId(ZoneIds.BERLIN)
.withDistanceMeters(LegConstructionSupport.computeDistanceMeters(pattern, 0, 2))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.OTHER_FEED_AGENCY;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.util.List;
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.model.fare.FareProduct;
import org.opentripplanner.model.fare.FareProductUse;
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 @@ -82,6 +85,18 @@ public class FareModelForTest {
.setTransfers(1)
.setAgency(OTHER_FEED_AGENCY.getId())
.build();
public static final FareProduct FARE_PRODUCT = new FareProduct(
id("fp"),
"fare product",
Money.euros(10.00f),
null,
null,
null
);
public static final FareProductUse FARE_PRODUCT_USE = new FareProductUse(
"c1a04702-1fb6-32d4-ba02-483bf68111ed",
FARE_PRODUCT
);

// Fare rule sets
static FareRuleSet AIRPORT_TO_CITY_CENTER_SET = new FareRuleSet(TEN_DOLLARS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.opentripplanner.ext.flex;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opentripplanner.ext.fares.impl.FareModelForTest.FARE_PRODUCT_USE;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.time.Duration;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner.ext.flex.edgetype.FlexTripEdge;
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPath;
import org.opentripplanner.framework.geometry.GeometryUtils;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.street.model._data.StreetModelForTest;

class FlexibleTransitLegBuilderTest implements PlanTestConstants {

private static final FlexTripEdge EDGE = new FlexTripEdge(
StreetModelForTest.intersectionVertex(1, 1),
StreetModelForTest.intersectionVertex(2, 2),
A.stop,
B.stop,
null,
1,
2,
LocalDate.of(2025, 1, 15),
new FlexPath(1000, 600, () -> GeometryUtils.makeLineString(1, 1, 2, 2))
);
private static final TransitAlert ALERT = TransitAlert
.of(id("alert"))
.withHeaderText(I18NString.of("alert 1"))
.build();
private static final Duration TIME_SHIFT = Duration.ofHours(5);
private static final ZonedDateTime START_TIME = ZonedDateTime.parse("2025-01-14T14:01:21+01:00");
private static final ZonedDateTime END_TIME = START_TIME.plusHours(3);

@Test
void listsAreInitialized() {
var leg = new FlexibleTransitLegBuilder()
.withStartTime(START_TIME)
.withEndTime(END_TIME)
.withFlexTripEdge(EDGE)
.build();
assertNotNull(leg.fareProducts());
assertNotNull(leg.getTransitAlerts());
}

@Test
void everythingIsNonNull() {
var expectedType = RuntimeException.class;
assertThrows(expectedType, () -> new FlexibleTransitLegBuilder().withStartTime(null).build());
assertThrows(expectedType, () -> new FlexibleTransitLegBuilder().withEndTime(null).build());
assertThrows(
expectedType,
() -> new FlexibleTransitLegBuilder().withFlexTripEdge(null).build()
);
assertThrows(expectedType, () -> new FlexibleTransitLegBuilder().withAlerts(null).build());
assertThrows(
expectedType,
() -> new FlexibleTransitLegBuilder().withFareProducts(null).build()
);
}

@Test
void copy() {
var leg = new FlexibleTransitLegBuilder()
.withStartTime(START_TIME)
.withEndTime(END_TIME)
.withFlexTripEdge(EDGE)
.withFareProducts(List.of(FARE_PRODUCT_USE))
.withAlerts(Set.of(ALERT))
.build();

var copy = leg.copy().build();

assertEquals(copy.flexTripEdge(), EDGE);
assertEquals(copy.getStartTime(), START_TIME);
assertEquals(copy.getEndTime(), END_TIME);
assertEquals(copy.getTransitAlerts(), Set.of(ALERT));
assertEquals(copy.fareProducts(), List.of(FARE_PRODUCT_USE));
}

@Test
void timeShift() {
var leg = new FlexibleTransitLegBuilder()
.withStartTime(START_TIME)
.withEndTime(END_TIME)
.withFlexTripEdge(EDGE)
.withFareProducts(List.of(FARE_PRODUCT_USE))
.withAlerts(Set.of(ALERT))
.build();

var shifted = leg.withTimeShift(TIME_SHIFT);

assertEquals(START_TIME.plus(TIME_SHIFT), shifted.getStartTime());
assertEquals(END_TIME.plus(TIME_SHIFT), shifted.getEndTime());
assertEquals(List.of(FARE_PRODUCT_USE), shifted.fareProducts());
assertEquals(Set.of(ALERT), shifted.getTransitAlerts());
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
package org.opentripplanner.ext.stopconsolidation;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.ext.fares.impl.FareModelForTest.FARE_PRODUCT_USE;
import static org.opentripplanner.ext.stopconsolidation.TestStopConsolidationModel.STOP_C;
import static org.opentripplanner.ext.stopconsolidation.TestStopConsolidationModel.STOP_D;
import static org.opentripplanner.model.plan.PlanTestConstants.T11_05;
import static org.opentripplanner.model.plan.PlanTestConstants.T11_12;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.opentripplanner.ext.fares.impl.FareModelForTest;
import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationRepository;
import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationService;
import org.opentripplanner.ext.stopconsolidation.model.ConsolidatedStopGroup;
import org.opentripplanner.ext.stopconsolidation.model.ConsolidatedStopLeg;
import org.opentripplanner.model.fare.FareProduct;
import org.opentripplanner.model.fare.FareProductUse;
import org.opentripplanner.model.plan.Leg;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.model.plan.ScheduledTransitLeg;
import org.opentripplanner.model.plan.StreetLeg;
import org.opentripplanner.model.plan.TestItineraryBuilder;
import org.opentripplanner.transit.model.basic.Money;

class DecorateConsolidatedStopNamesTest {

private static final FareProduct fp = new FareProduct(
id("fp"),
"fare product",
Money.euros(10.00f),
null,
null,
null
);
private static final List<FareProductUse> fpu = List.of(
new FareProductUse("c1a04702-1fb6-32d4-ba02-483bf68111ed", fp)
);
private static final List<ConsolidatedStopGroup> GROUPS = List.of(
new ConsolidatedStopGroup(STOP_C.getId(), List.of(STOP_D.getId()))
);
Expand All @@ -52,7 +40,12 @@ void changeNames() {
.bus(1, T11_05, T11_12, PlanTestConstants.F)
.build();

itinerary.getLegs().getFirst().setFareProducts(fpu);
var first = (ScheduledTransitLeg) itinerary.getLegs().getFirst();
var withFp = first.copy().withFareProducts(List.of(FARE_PRODUCT_USE)).build();
var legs = new ArrayList<>(itinerary.getLegs());
legs.set(0, withFp);

itinerary.setLegs(legs);

filter.decorate(itinerary);

Expand All @@ -61,7 +54,7 @@ void changeNames() {
assertEquals(STOP_D.getName(), updatedLeg.getTo().name);

// Check that the fares were carried over
assertEquals(fpu, updatedLeg.fareProducts());
assertEquals(List.of(FARE_PRODUCT_USE), updatedLeg.fareProducts());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.opentripplanner.ext.stopconsolidation.model;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.ext.fares.impl.FareModelForTest.FARE_PRODUCT_USE;
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;

import java.time.LocalDate;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.opentripplanner._support.time.ZoneIds;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.model.fare.FareProductUse;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.model.plan.ScheduledTransitLeg;
import org.opentripplanner.model.plan.ScheduledTransitLegBuilder;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.network.TripPattern;

class ConsolidatedStopLegBuilderTest implements PlanTestConstants {

private static final Set<TransitAlert> ALERTS = Set.of(
TransitAlert.of(id("alert")).withDescriptionText(I18NString.of("alert")).build()
);
private static final TripPattern PATTERN = TimetableRepositoryForTest
.of()
.pattern(TransitMode.BUS)
.build();
private static final ScheduledTransitLeg SCHEDULED_TRANSIT_LEG = new ScheduledTransitLegBuilder<>()
.withZoneId(ZoneIds.BERLIN)
.withServiceDate(LocalDate.of(2025, 1, 15))
.withTripPattern(PATTERN)
.withBoardStopIndexInPattern(0)
.withDistanceMeters(1000)
.withAlightStopIndexInPattern(1)
.build();
private static final List<FareProductUse> FARES = List.of(FARE_PRODUCT_USE);

@Test
void build() {
var leg = new ConsolidatedStopLegBuilder(SCHEDULED_TRANSIT_LEG)
.withFrom(E.stop)
.withTo(F.stop)
.build();
assertEquals(E.stop, leg.getFrom().stop);
assertEquals(F.stop, leg.getTo().stop);
}

@Test
void copyAttributesFromConsolidatedStopLeg() {
var leg = new ConsolidatedStopLegBuilder(SCHEDULED_TRANSIT_LEG)
.withFrom(E.stop)
.withTo(F.stop)
.build();

var copy = leg
.copy()
.withAccessibilityScore(4f)
.withFareProducts(FARES)
.withAlerts(Set.of(ALERTS))
.build();

assertEquals(leg.getFrom().stop, copy.getFrom().stop);
assertEquals(leg.getTo().stop, copy.getTo().stop);
assertEquals(Set.of(ALERTS), copy.getTransitAlerts());
assertEquals(FARES, copy.fareProducts());
assertEquals(ZoneIds.BERLIN, copy.getZoneId());
}

@Test
void copyConsolidatedLeg() {
var leg = new ConsolidatedStopLegBuilder(SCHEDULED_TRANSIT_LEG)
.withFrom(E.stop)
.withTo(F.stop)
.withAlerts(ALERTS)
.build();

var copy = leg.copy().build();

assertEquals(E.stop, copy.getFrom().stop);
assertEquals(F.stop, copy.getTo().stop);
assertEquals(ALERTS, copy.getTransitAlerts());
}

@Test
void copyAttributesFromScheduledLeg() {
var leg = SCHEDULED_TRANSIT_LEG
.copy()
.withFareProducts(FARES)
.withAlerts(Set.of(ALERTS))
.build();

var copy = new ConsolidatedStopLegBuilder(leg).withFrom(C.stop).withTo(G.stop).build();

assertEquals(C.stop, copy.getFrom().stop);
assertEquals(G.stop, copy.getTo().stop);
assertEquals(Set.of(ALERTS), copy.getTransitAlerts());
assertEquals(FARES, copy.fareProducts());
assertEquals(ZoneIds.BERLIN, copy.getZoneId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private Itinerary addAccessibilityScore(Itinerary i) {
.stream()
.map(leg -> {
if (leg instanceof ScheduledTransitLeg transitLeg) {
return transitLeg.withAccessibilityScore(compute(transitLeg));
return transitLeg.copy().withAccessibilityScore(compute(transitLeg)).build();
} else if (leg instanceof StreetLeg streetLeg && leg.isWalkingLeg()) {
return streetLeg.withAccessibilityScore(compute(streetLeg));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.opentripplanner.model.fare.FareProductUse;
import org.opentripplanner.model.fare.ItineraryFares;
import org.opentripplanner.model.plan.FareProductAware;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.model.plan.TransitLeg;
import org.opentripplanner.utils.collection.ListUtils;

/**
Expand All @@ -22,8 +24,12 @@ public static void addFaresToLegs(ItineraryFares fares, Itinerary i) {

i.transformTransitLegs(leg -> {
var legUses = fares.getLegProducts().get(leg);
leg.setFareProducts(ListUtils.combine(itineraryFareUses, legUses));
return leg;
var allUses = ListUtils.combine(itineraryFareUses, legUses);
if (leg instanceof FareProductAware<TransitLeg> fpa) {
return fpa.decorateWithFareProducts(allUses);
} else {
return leg;
}
});
}
}
Loading

0 comments on commit 9c83284

Please sign in to comment.