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
…024-03-04
  • Loading branch information
leonardehrenfried committed Mar 5, 2024
2 parents 401ab30 + 6fc4f60 commit f49d54b
Show file tree
Hide file tree
Showing 71 changed files with 1,850 additions and 742 deletions.
2 changes: 1 addition & 1 deletion docs/BuildConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Sections follow that describe particular settings in more depth.
| [readCachedElevations](#readCachedElevations) | `boolean` | Whether to read cached elevation data. | *Optional* | `true` | 2.0 |
| staticBikeParkAndRide | `boolean` | Whether we should create bike P+R stations from OSM data. | *Optional* | `false` | 1.5 |
| staticParkAndRide | `boolean` | Whether we should create car P+R stations from OSM data. | *Optional* | `true` | 1.5 |
| stopConsolidationFile | `string` | Name of the CSV-formatted file in the build directory which contains the configuration for stop consolidation. | *Optional* | | 2.5 |
| stopConsolidationFile | `uri` | Name of the CSV-formatted file in the build directory which contains the configuration for stop consolidation. | *Optional* | | 2.5 |
| [streetGraph](#streetGraph) | `uri` | URI to the street graph object file for reading and writing. | *Optional* | | 2.0 |
| [subwayAccessTime](#subwayAccessTime) | `double` | Minutes necessary to reach stops served by trips on routes of route_type=1 (subway) from the street. | *Optional* | `2.0` | 1.5 |
| [transitModelTimeZone](#transitModelTimeZone) | `time-zone` | Time zone for the graph. | *Optional* | | 2.2 |
Expand Down
2 changes: 2 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ based on merged pull requests. Search GitHub issues and pull requests for smalle
- Use NeTEx authority short name if name is not present [#5698](https://github.com/opentripplanner/OpenTripPlanner/pull/5698)
- Add Hamburg OSM mapper [#5701](https://github.com/opentripplanner/OpenTripPlanner/pull/5701)
- Remove configurable car speed and determine it in graph build [#5657](https://github.com/opentripplanner/OpenTripPlanner/pull/5657)
- Avoid cumulative real-time updates [#5705](https://github.com/opentripplanner/OpenTripPlanner/pull/5705)
- Fix time penalty [#5715](https://github.com/opentripplanner/OpenTripPlanner/pull/5715)
[](AUTOMATIC_CHANGELOG_PLACEHOLDER_DO_NOT_REMOVE)

## 2.4.0 (2023-09-13)
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@


<properties>
<otp.serialization.version.id>147</otp.serialization.version.id>
<otp.serialization.version.id>148</otp.serialization.version.id>
<!-- Lib versions - keep list sorted on property name -->
<geotools.version>30.2</geotools.version>
<google.dagger.version>2.51</google.dagger.version>
Expand All @@ -65,7 +65,7 @@
<junit.version>5.10.2</junit.version>
<micrometer.version>1.12.2</micrometer.version>
<netcdf4.version>5.5.3</netcdf4.version>
<logback.version>1.5.2</logback.version>
<logback.version>1.5.3</logback.version>
<lucene.version>9.9.1</lucene.version>
<slf4j.version>2.0.12</slf4j.version>
<netex-java-model.version>2.0.15</netex-java-model.version>
Expand Down Expand Up @@ -328,7 +328,7 @@
but we need the Maven project version as well, so we perform substitution. -->
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>7.0.0</version>
<version>8.0.0</version>
<executions>
<execution>
<goals>
Expand Down
28 changes: 14 additions & 14 deletions src/ext/java/org/opentripplanner/ext/siri/ModifiedTripBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ModifiedTripBuilder(
public Result<TripUpdate, UpdateError> build() {
RealTimeTripTimes newTimes = existingTripTimes.copyScheduledTimes();

StopPattern stopPattern = createStopPattern(pattern, calls, entityResolver);
var stopPattern = createStopPattern(pattern, calls, entityResolver);

if (cancellation || stopPattern.isAllStopsNonRoutable()) {
LOG.debug("Trip is cancelled");
Expand Down Expand Up @@ -220,15 +220,12 @@ static StopPattern createStopPattern(
EntityResolver entityResolver
) {
int numberOfStops = pattern.numberOfStops();
var builder = pattern.getStopPattern().mutate();
var builder = pattern.copyPlannedStopPattern();

Set<CallWrapper> alreadyVisited = new HashSet<>();
// modify updated stop-times
for (int i = 0; i < numberOfStops; i++) {
StopLocation stop = pattern.getStop(i);
builder.stops[i] = stop;
builder.dropoffs[i] = pattern.getAlightType(i);
builder.pickups[i] = pattern.getBoardType(i);
StopLocation stop = builder.stops.original(i);

for (CallWrapper call : calls) {
if (alreadyVisited.contains(call)) {
Expand All @@ -241,22 +238,25 @@ static StopPattern createStopPattern(
continue;
}

int stopIndex = i;
builder.stops[stopIndex] = callStop;
// Used in lambda
final int stopIndex = i;
builder.stops.with(stopIndex, callStop);

PickDropMapper
.mapPickUpType(call, builder.pickups[stopIndex])
.ifPresent(value -> builder.pickups[stopIndex] = value);
.mapPickUpType(call, builder.pickups.original(stopIndex))
.ifPresent(value -> builder.pickups.with(stopIndex, value));

PickDropMapper
.mapDropOffType(call, builder.dropoffs[stopIndex])
.ifPresent(value -> builder.dropoffs[stopIndex] = value);
.mapDropOffType(call, builder.dropoffs.original(stopIndex))
.ifPresent(value -> builder.dropoffs.with(stopIndex, value));

alreadyVisited.add(call);
break;
}
}

return builder.build();
var newStopPattern = builder.build();
return (pattern.isModified() && pattern.getStopPattern().equals(newStopPattern))
? pattern.getStopPattern()
: newStopPattern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class PickDropMapper {
* The Siri ArrivalBoardingActivity includes less information than the pick drop type, therefore is it only
* changed if routability has changed.
*
* @param currentValue The current pick drop value on a stopTime
* @param plannedValue The current pick drop value on a stopTime
* @param call The incoming call to be mapped
* @return Mapped PickDrop type, empty if routability is not changed.
*/
public static Optional<PickDrop> mapDropOffType(CallWrapper call, PickDrop currentValue) {
if (shouldBeCancelled(currentValue, call.isCancellation(), call.getArrivalStatus())) {
public static Optional<PickDrop> mapDropOffType(CallWrapper call, PickDrop plannedValue) {
if (shouldBeCancelled(plannedValue, call.isCancellation(), call.getArrivalStatus())) {
return Optional.of(CANCELLED);
}

Expand All @@ -33,7 +33,7 @@ public static Optional<PickDrop> mapDropOffType(CallWrapper call, PickDrop curre
}

return switch (arrivalBoardingActivityEnumeration) {
case ALIGHTING -> currentValue.isNotRoutable() ? Optional.of(SCHEDULED) : Optional.empty();
case ALIGHTING -> plannedValue.isNotRoutable() ? Optional.of(SCHEDULED) : Optional.empty();
case NO_ALIGHTING -> Optional.of(NONE);
case PASS_THRU -> Optional.of(CANCELLED);
};
Expand All @@ -45,12 +45,12 @@ public static Optional<PickDrop> mapDropOffType(CallWrapper call, PickDrop curre
* The Siri DepartureBoardingActivity includes less information than the planned data, therefore is it only
* changed if routability has changed.
*
* @param currentValue The current pick drop value on a stopTime
* @param plannedValue The current pick drop value on a stopTime
* @param call The incoming call to be mapped
* @return Mapped PickDrop type, empty if routability is not changed.
*/
public static Optional<PickDrop> mapPickUpType(CallWrapper call, PickDrop currentValue) {
if (shouldBeCancelled(currentValue, call.isCancellation(), call.getDepartureStatus())) {
public static Optional<PickDrop> mapPickUpType(CallWrapper call, PickDrop plannedValue) {
if (shouldBeCancelled(plannedValue, call.isCancellation(), call.getDepartureStatus())) {
return Optional.of(CANCELLED);
}

Expand All @@ -60,7 +60,7 @@ public static Optional<PickDrop> mapPickUpType(CallWrapper call, PickDrop curren
}

return switch (departureBoardingActivityEnumeration) {
case BOARDING -> currentValue.isNotRoutable() ? Optional.of(SCHEDULED) : Optional.empty();
case BOARDING -> plannedValue.isNotRoutable() ? Optional.of(SCHEDULED) : Optional.empty();
case NO_BOARDING -> Optional.of(NONE);
case PASS_THRU -> Optional.of(CANCELLED);
};
Expand All @@ -71,17 +71,16 @@ public static Optional<PickDrop> mapPickUpType(CallWrapper call, PickDrop curren
*
* If the existing PickDrop is non-routable, the value is not changed.
*
* @param currentValue The current pick drop value on a stopTime
* @param plannedValue The planned pick drop value on a stopTime
* @param isCallCancellation The incoming call cancellation-flag
* @param callStatus The incoming call arrival/departure status
* @return
*/
private static boolean shouldBeCancelled(
PickDrop currentValue,
PickDrop plannedValue,
Boolean isCallCancellation,
CallStatusEnumeration callStatus
) {
if (currentValue.isNotRoutable()) {
if (plannedValue.isNotRoutable()) {
return false;
}
return TRUE.equals(isCallCancellation) || callStatus == CallStatusEnumeration.CANCELLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void replaceConsolidatedStops(Itinerary i) {
if (leg instanceof ScheduledTransitLeg stl && needsToRenameStops(stl)) {
var agency = leg.getAgency();
// to show the name on the stop signage we use the primary stop's name
var from = service.primaryStop(stl.getFrom().stop.getId());
var from = service.primaryStop(stl.getFrom().stop.getId()).orElse(stl.getFrom().stop);
// to show the name that's on the display inside the vehicle we use the agency-specific name
var to = service.agencySpecificStop(stl.getTo().stop, agency);
return new ConsolidatedStopLeg(stl, from, to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private TripPattern modifyStopsInPattern(
TripPattern pattern,
List<StopReplacement> replacements
) {
var updatedStopPattern = pattern.getStopPattern().mutate();
var updatedStopPattern = pattern.copyPlannedStopPattern();
replacements.forEach(r -> updatedStopPattern.replaceStop(r.secondary(), r.primary()));
return pattern.copy().withStopPattern(updatedStopPattern.build()).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.ext.stopconsolidation;

import java.util.List;
import java.util.Optional;
import org.opentripplanner.ext.stopconsolidation.model.StopReplacement;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.organization.Agency;
Expand Down Expand Up @@ -41,5 +42,5 @@ public interface StopConsolidationService {
/**
* For a given stop id return the primary stop if it is part of a consolidated stop group.
*/
StopLocation primaryStop(FeedScopedId id);
Optional<StopLocation> primaryStop(FeedScopedId id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ private Optional<StopLocation> findAgencySpecificStop(StopLocation stop, Agency
}

@Override
public StopLocation primaryStop(FeedScopedId id) {
public Optional<StopLocation> primaryStop(FeedScopedId id) {
var primaryId = repo
.groups()
.stream()
.filter(g -> g.secondaries().contains(id))
.map(ConsolidatedStopGroup::primary)
.findAny()
.orElse(id);
return transitModel.getStopModel().getRegularStop(primaryId);
return Optional.ofNullable(transitModel.getStopModel().getRegularStop(primaryId));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.ext.stopconsolidation.model;

import java.util.Objects;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.ScheduledTransitLeg;
import org.opentripplanner.model.plan.ScheduledTransitLegBuilder;
Expand All @@ -12,8 +13,8 @@ public class ConsolidatedStopLeg extends ScheduledTransitLeg {

public ConsolidatedStopLeg(ScheduledTransitLeg original, StopLocation from, StopLocation to) {
super(new ScheduledTransitLegBuilder<>(original));
this.from = from;
this.to = to;
this.from = Objects.requireNonNull(from);
this.to = Objects.requireNonNull(to);
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/opentripplanner/datastore/OtpDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class OtpDataStore {
/* Named resources available for both reading and writing. */
private DataSource streetGraph;
private DataSource graph;
private DataSource stopConsolidation;
private CompositeDataSource buildReportDir;
private boolean opened = false;

Expand Down Expand Up @@ -104,6 +106,11 @@ public void open() {
graph = findSingleSource(config.graph(), GRAPH_FILENAME, GRAPH);
buildReportDir = findCompositeSource(config.reportDirectory(), BUILD_REPORT_DIR, REPORT);

if (config.stopConsolidation() != null) {
stopConsolidation =
findSourceUsingAllRepos(it -> it.findCompositeSource(config.stopConsolidation(), GTFS));
}

addAll(Arrays.asList(streetGraph, graph, buildReportDir));

// Also read in unknown sources in case the data input source is miss-spelled,
Expand Down Expand Up @@ -152,6 +159,10 @@ public CompositeDataSource getBuildReportDir() {
return buildReportDir;
}

public Optional<DataSource> stopConsolidation() {
return Optional.ofNullable(stopConsolidation);
}

/* private methods */
private void add(DataSource source) {
if (source != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opentripplanner.datastore.OtpDataStore;

/**
Expand Down Expand Up @@ -68,6 +69,12 @@ public interface OtpDataStoreConfig {
*/
URI streetGraph();

/**
* The URI to the stop consolidation data source.
*/
@Nullable
URI stopConsolidation();

/**
*
* A pattern to lookup local GTFS files
Expand Down
Loading

0 comments on commit f49d54b

Please sign in to comment.