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-01-10
  • Loading branch information
leonardehrenfried committed Jan 13, 2025
2 parents 8e1da42 + 0312487 commit 53249fb
Show file tree
Hide file tree
Showing 7 changed files with 335 additions and 127 deletions.
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://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-02T15:56/assets/index-DODY0n0n.js"></script>
<link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-02T15:56/assets/index-BDL0-veX.css">
<script type="module" crossorigin src="https://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-11T19:23/assets/index-D--h-dOg.js"></script>
<link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/opentripplanner/debug-client-assets@main/2025/01/2025-01-11T19:23/assets/index-BDL0-veX.css">
</head>
<body>
<div id="root"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected ScheduledTransitLeg(ScheduledTransitLegBuilder<?> builder) {
getDistanceFromCoordinates(
List.of(transitLegCoordinates.getFirst(), transitLegCoordinates.getLast())
);
this.transitAlerts.addAll(builder.alerts());
}

public ZoneId getZoneId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Set;
import org.opentripplanner.model.transfer.ConstrainedTransfer;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.timetable.TripOnServiceDate;
import org.opentripplanner.transit.model.timetable.TripTimes;
Expand All @@ -23,6 +26,7 @@ public class ScheduledTransitLegBuilder<B extends ScheduledTransitLegBuilder<B>>
private ConstrainedTransfer transferToNextLeg;
private int generalizedCost;
private Float accessibilityScore;
private Set<TransitAlert> alerts = new HashSet<>();

public ScheduledTransitLegBuilder() {}

Expand All @@ -40,6 +44,7 @@ public ScheduledTransitLegBuilder(ScheduledTransitLeg original) {
generalizedCost = original.getGeneralizedCost();
accessibilityScore = original.accessibilityScore();
zoneId = original.getZoneId();
alerts = original.getTransitAlerts();
}

public B withTripTimes(TripTimes tripTimes) {
Expand Down Expand Up @@ -159,6 +164,10 @@ public Float accessibilityScore() {
return accessibilityScore;
}

public Set<TransitAlert> alerts() {
return alerts;
}

public ScheduledTransitLeg build() {
return new ScheduledTransitLeg(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package org.opentripplanner.model.plan;

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

import java.time.LocalDate;
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.routing.alertpatch.TransitAlert;
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
import org.opentripplanner.transit.model.basic.TransitMode;

class ScheduledTransitLegBuilderTest {

private static final TransitAlert ALERT = TransitAlert
.of(id("alert"))
.withDescriptionText(I18NString.of("alert"))
.build();

@Test
void transferZoneId() {
var pattern = TimetableRepositoryForTest.of().pattern(TransitMode.BUS).build();
Expand All @@ -28,4 +37,24 @@ void transferZoneId() {

assertEquals(ZoneIds.BERLIN, withScore.getZoneId());
}

@Test
void alerts() {
var pattern = TimetableRepositoryForTest.of().pattern(TransitMode.BUS).build();
var leg = new ScheduledTransitLegBuilder<>()
.withZoneId(ZoneIds.BERLIN)
.withServiceDate(LocalDate.of(2023, 11, 15))
.withTripPattern(pattern)
.withBoardStopIndexInPattern(0)
.withAlightStopIndexInPattern(1)
.build();

leg.addAlert(ALERT);

var newLeg = new ScheduledTransitLegBuilder<>(leg);

var withScore = newLeg.withAccessibilityScore(4f).build();

assertEquals(Set.of(ALERT), withScore.getTransitAlerts());
}
}
Loading

0 comments on commit 53249fb

Please sign in to comment.