Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev-2.x' into stop-times-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Mar 5, 2025
2 parents 2dc7bab + a555e95 commit d048f93
Show file tree
Hide file tree
Showing 33 changed files with 291 additions and 264 deletions.
4 changes: 2 additions & 2 deletions application/src/client/classic-debug/js/otp/core/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ otp.core.Map = otp.Class({
//debug layers can be enabled in config.js or as URL query:
//?debug_layers=true
if (otp.config.debug_layers === true) {
var url = otp.config.hostname + '/' + otp.config.restService + '/inspector/layers';
var url = otp.config.hostname + '/otp/debugrastertiles/layers';
$.ajax(url, {
dataType: 'JSON',
success: function(data) {
var layers = {};
data.layers.map(function(layer) {
this.layer_control.addOverlay(new L.TileLayer(
otp.config.hostname + '/' + otp.config.restService + '/inspector/tile/' + layer.key + '/{z}/{x}/{y}.png',
otp.config.hostname + '/otp/debugrastertiles/' + layer.key + '/{z}/{x}/{y}.png',
{ maxZoom : 22}), layer.name);
}, this_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void shouldNotInterpolateFlexTimes() {

assertEquals(3, pattern.numberOfStops());

var tripTimes = pattern.getScheduledTimetable().getTripTimes(0);
var tripTimes = pattern.getScheduledTimetable().getTripTimes().getFirst();
var arrivalTime = tripTimes.getArrivalTime(1);

assertEquals(StopTime.MISSING_VALUE, arrivalTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ void testPopulateLegsWithRealtime() {
.asScheduledTransitLeg()
.getTripPattern()
.getScheduledTimetable()
.getTripTimes(0)
.getTripTimes()
.getFirst()
.getArrivalDelay(1);
assertEquals(123, leg1ArrivalDelay);
assertEquals(0, legs.get(0).getTransitAlerts().size());
Expand Down Expand Up @@ -128,7 +129,7 @@ void testPopulateLegsWithRealtimeKeepStaySeated() {
private static TripPattern delay(TripPattern pattern1, int seconds) {
var originalTimeTable = pattern1.getScheduledTimetable();

var delayedTripTimes = delay(originalTimeTable.getTripTimes(0), seconds);
var delayedTripTimes = delay(originalTimeTable.getTripTimes().getFirst(), seconds);
var delayedTimetable = Timetable.of()
.withTripPattern(pattern1)
.addTripTimes(delayedTripTimes)
Expand Down Expand Up @@ -166,7 +167,7 @@ private static TransitService makeTransitService(
patterns.forEach(pattern -> {
timetableRepository.addTripPattern(pattern.getId(), pattern);

var serviceCode = pattern.getScheduledTimetable().getTripTimes(0).getServiceCode();
var serviceCode = pattern.getScheduledTimetable().getTripTimes().getFirst().getServiceCode();
timetableRepository.getServiceCodes().put(pattern.getId(), serviceCode);

calendarServiceData.putServiceDatesForServiceId(pattern.getId(), List.of(serviceDate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public Optional<VertexVisualAttributes> renderVertex(Vertex v) {
}
return Optional.empty();
}

@Override
public String getName() {
return "Bike safety";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public void renderTile(TileRenderContext context) {
}
}

@Override
public String getName() {
return evRenderer.getName();
}

public interface EdgeVertexRenderer {
Comparator<Vertex> defaultVertexComparator = Comparator.comparing((Vertex v) ->
v instanceof StreetVertex
Expand All @@ -253,6 +258,13 @@ public interface EdgeVertexRenderer {
*/
Optional<VertexVisualAttributes> renderVertex(Vertex v);

/**
* Name of this tile Render which would be shown in frontend
*
* @return Name of tile render
*/
String getName();

default boolean hasEdgeSegments(Edge edge) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public Optional<VertexVisualAttributes> renderVertex(Vertex v) {
}
}

@Override
public String getName() {
return "Elevation";
}

@Override
public boolean hasEdgeSegments(Edge edge) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public Optional<EdgeVisualAttributes> renderEdge(Edge e) {
public Optional<VertexVisualAttributes> renderVertex(Vertex v) {
return Optional.empty();
}

@Override
public String getName() {
return "No thru traffic";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public interface TileRenderer {
/** Implementation of the tile rendering */
void renderTile(TileRenderContext context);

/** Gets descriptive name of this Tile Render */
String getName();

/**
* Context used for rendering a tile.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ public Envelope expandPixels(double marginXPixels, double marginYPixels) {
LOG.debug("Rendered tile at {} in {} ms", mapTile.bbox(), System.currentTimeMillis() - start);
return image;
}

/**
* Gets all renderers
* <p>
* Used to return list of renderers to client. Could be also used to show legend.
*/
public Map<String, TileRenderer> getRenderers() {
return renderers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public Optional<VertexVisualAttributes> renderVertex(Vertex v) {
return Optional.empty();
}

@Override
public String getName() {
return "Traversal permissions";
}

private Color getColor(StreetTraversalPermission permissions) {
/*
* We use the trick that there are 3 main traversal modes (WALK, BIKE and CAR) and 3 color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public Optional<VertexVisualAttributes> renderVertex(Vertex v) {
}
return Optional.empty();
}

@Override
public String getName() {
return "Walk safety";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public Optional<VertexVisualAttributes> renderVertex(Vertex v) {
}
return Optional.empty();
}

@Override
public String getName() {
return "Wheelchair access";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.opentripplanner.ext.debugrastertiles.api.resource;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.opentripplanner.ext.debugrastertiles.TileRenderer;

/**
* @author mabu
*/
public class DebugLayersList {

public List<DebugLayer> layers;

DebugLayersList(Map<String, TileRenderer> renderers) {
layers = new ArrayList<>(renderers.size());
for (Map.Entry<String, TileRenderer> layerInfo : renderers.entrySet()) {
String layer_key = layerInfo.getKey();
TileRenderer layer = layerInfo.getValue();
layers.add(new DebugLayer(layer_key, layer.getName()));
}
}

private static class DebugLayer {

public String key;
public String name;

private DebugLayer(String layer_key, String layer_name) {
this.key = layer_key;
this.name = layer_name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.CacheControl;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -68,4 +69,16 @@ public Response tileGet(
cc.setNoCache(false);
return Response.ok(baos.toByteArray()).type(format.toString()).cacheControl(cc).build();
}

/**
* Returns all layers.
* <p>
* Used in the classic debug client to create a layer menu.
*/
@GET
@Path("layers")
@Produces(MediaType.APPLICATION_JSON)
public DebugLayersList getLayers() {
return new DebugLayersList(tileRendererManager.getRenderers());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ModeInputType {
.name("accessMode")
.description(
"The mode used to get from the origin to the access stops in the transit " +
"network the transit network (first-mile). If the element is not present or null," +
"network (first-mile). If the element is not present or null," +
"only transit that can be immediately boarded from the origin will be used."
)
.type(EnumTypes.STREET_MODE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public class DebugStyleSpec {
};
private static final String EDGES_GROUP = "Edges";
private static final String ELEVATION_GROUP = "Elevation";
private static final String SAFETY_GROUP = "Safety";
private static final String WALK_SAFETY_GROUP = "Walk safety";
private static final String BICYCLE_SAFETY_GROUP = "Bicycle safety";
private static final String STOPS_GROUP = "Stops";
private static final String VERTICES_GROUP = "Vertices";
private static final String PERMISSIONS_GROUP = "Permissions";
Expand Down Expand Up @@ -134,7 +135,8 @@ static StyleSpec build(
backgroundLayers(extraRasterSources),
wheelchair(edges),
noThruTraffic(edges),
safety(edges),
bicycleSafety(edges),
walkSafety(edges),
traversalPermissions(edges),
edges(edges),
elevation(edges, vertices),
Expand Down Expand Up @@ -300,10 +302,10 @@ private static List<StyleBuilder> elevation(VectorSourceLayer edges, VectorSourc
);
}

private static List<StyleBuilder> safety(VectorSourceLayer edges) {
private static List<StyleBuilder> bicycleSafety(VectorSourceLayer edges) {
return List.of(
StyleBuilder.ofId("bicycle-safety")
.group(SAFETY_GROUP)
.group(BICYCLE_SAFETY_GROUP)
.typeLine()
.vectorSourceLayer(edges)
.log2LineColorFromProperty("bicycleSafetyFactor", 80)
Expand All @@ -313,8 +315,23 @@ private static List<StyleBuilder> safety(VectorSourceLayer edges) {
.minZoom(6)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder.ofId("bicycle-safety-text")
.vectorSourceLayer(edges)
.group(BICYCLE_SAFETY_GROUP)
.typeSymbol()
.lineText("bicycleSafetyFactor")
.textOffset(1)
.edgeFilter(EDGES_TO_DISPLAY)
.minZoom(17)
.maxZoom(MAX_ZOOM)
.intiallyHidden()
);
}

private static List<StyleBuilder> walkSafety(VectorSourceLayer edges) {
return List.of(
StyleBuilder.ofId("walk-safety")
.group(SAFETY_GROUP)
.group(WALK_SAFETY_GROUP)
.typeLine()
.vectorSourceLayer(edges)
.log2LineColorFromProperty("walkSafetyFactor", 80)
Expand All @@ -324,19 +341,9 @@ private static List<StyleBuilder> safety(VectorSourceLayer edges) {
.minZoom(6)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder.ofId("bicycle-safety-text")
.vectorSourceLayer(edges)
.group(SAFETY_GROUP)
.typeSymbol()
.lineText("bicycleSafetyFactor")
.textOffset(1)
.edgeFilter(EDGES_TO_DISPLAY)
.minZoom(17)
.maxZoom(MAX_ZOOM)
.intiallyHidden(),
StyleBuilder.ofId("walk-safety-text")
.vectorSourceLayer(edges)
.group(SAFETY_GROUP)
.group(WALK_SAFETY_GROUP)
.typeSymbol()
.lineText("walkSafetyFactor")
.textOffset(1)
Expand Down
33 changes: 0 additions & 33 deletions application/src/main/java/org/opentripplanner/model/Timetable.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,6 @@ public TimetableBuilder copyOf() {
return new TimetableBuilder(this);
}

/** @return the index of TripTimes for this trip ID in this particular Timetable */
public int getTripIndex(FeedScopedId tripId) {
int ret = 0;
for (TripTimes tt : tripTimes) {
// could replace linear search with indexing in stoptime updater, but not necessary
// at this point since the updater thread is far from pegged.
if (tt.getTrip().getId().equals(tripId)) {
return ret;
}
ret += 1;
}
return -1;
}

/**
* @return the index of TripTimes for this trip ID in this particular Timetable, ignoring
* AgencyIds.
*/
public int getTripIndex(String tripId) {
int ret = 0;
for (TripTimes tt : tripTimes) {
if (tt.getTrip().getId().getId().equals(tripId)) {
return ret;
}
ret += 1;
}
return -1;
}

public TripTimes getTripTimes(int tripIndex) {
return tripTimes.get(tripIndex);
}

@Nullable
public TripTimes getTripTimes(Trip trip) {
for (TripTimes tt : tripTimes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.opentripplanner.transit.model.timetable.Direction;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.transit.model.timetable.TripTimes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// TODO OTP2 instances of this class are still mutable after construction with a builder, this will be refactored in a subsequent step
/**
Expand Down Expand Up @@ -58,8 +56,6 @@ public final class TripPattern
extends AbstractTransitEntity<TripPattern, TripPatternBuilder>
implements Cloneable, LogInfo {

private static final Logger LOG = LoggerFactory.getLogger(TripPattern.class);

private final Route route;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
import org.opentripplanner.updater.GraphUpdaterStatus;
import org.opentripplanner.utils.collection.CollectionsView;
import org.opentripplanner.utils.time.ServiceDateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Default implementation of the Transit Service and Transit Editor Service.
Expand All @@ -80,7 +78,6 @@
*/
public class DefaultTransitService implements TransitEditorService {

private static final Logger LOG = LoggerFactory.getLogger(DefaultTransitService.class);
private final TimetableRepository timetableRepository;

private final TimetableRepositoryIndex timetableRepositoryIndex;
Expand Down
Loading

0 comments on commit d048f93

Please sign in to comment.