From dbc00eecb4e86aa6c173d3a01298d505fd108bbd Mon Sep 17 00:00:00 2001 From: sharhio Date: Mon, 11 Mar 2024 15:09:33 +0200 Subject: [PATCH 01/17] Stop layer with alert information --- .../layers/stops/StopsLayerTest.java | 67 +++++++++++++- .../ext/vectortiles/VectorTilesResource.java | 4 +- ...DigitransitRealtimeStopPropertyMapper.java | 90 +++++++++++++++++++ .../stops/DigitransitStopPropertyMapper.java | 2 +- .../layers/stops/StopsBaseLayerBuilder.java | 30 +++++++ .../layers/stops/StopsLayerBuilder.java | 9 +- 6 files changed, 194 insertions(+), 8 deletions(-) create mode 100644 src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java create mode 100644 src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java diff --git a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java index 91d9009e2f0..ac05842a70d 100644 --- a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java @@ -1,15 +1,28 @@ package org.opentripplanner.ext.vectortiles.layers.stops; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.opentripplanner.framework.time.TimeUtils.time; +import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.opentripplanner.ext.realtimeresolver.RealtimeResolver; import org.opentripplanner.framework.i18n.TranslatedString; +import org.opentripplanner.model.plan.Place; +import org.opentripplanner.routing.alertpatch.AlertEffect; +import org.opentripplanner.routing.alertpatch.EntitySelector; +import org.opentripplanner.routing.alertpatch.TimePeriod; +import org.opentripplanner.routing.alertpatch.TransitAlert; +import org.opentripplanner.routing.impl.TransitAlertServiceImpl; +import org.opentripplanner.routing.services.TransitAlertService; +import org.opentripplanner.transit.model._data.TransitModelForTest; import org.opentripplanner.transit.model.framework.Deduplicator; import org.opentripplanner.transit.model.framework.FeedScopedId; +import org.opentripplanner.transit.model.network.Route; import org.opentripplanner.transit.model.site.RegularStop; import org.opentripplanner.transit.service.DefaultTransitService; import org.opentripplanner.transit.service.StopModel; @@ -18,9 +31,10 @@ public class StopsLayerTest { private RegularStop stop; + private RegularStop stop2; @BeforeEach - public void setUp() { + public final void setUp() { var nameTranslations = TranslatedString.getI18NString( new HashMap<>() { { @@ -49,6 +63,14 @@ public void setUp() { .withDescription(descTranslations) .withCoordinate(50, 10) .build(); + stop2 = + StopModel + .of() + .regularStop(new FeedScopedId("F", "name")) + .withName(nameTranslations) + .withDescription(descTranslations) + .withCoordinate(51, 10) + .build(); } @Test @@ -89,4 +111,47 @@ public void digitransitStopPropertyMapperTranslationTest() { assertEquals("nameDE", map.get("name")); assertEquals("descDE", map.get("desc")); } + + @Test + public void digitransitRealtimeStopPropertyMapperTest() { + var deduplicator = new Deduplicator(); + var transitModel = new TransitModel(new StopModel(), deduplicator); + transitModel.index(); + var alertService = new TransitAlertServiceImpl(transitModel); + var transitService = new DefaultTransitService(transitModel) { + @Override + public TransitAlertService getTransitAlertService() { + return alertService; + } + }; + + Route route = TransitModelForTest.route("route").build(); + var itinerary = newItinerary(Place.forStop(stop), time("11:00")) + .bus(route, 1, time("11:05"), time("11:20"), Place.forStop(stop2)) + .build(); + + var alert = TransitAlert + .of(stop.getId()) + .addEntity(new EntitySelector.Stop(stop.getId())) + .addTimePeriod(new TimePeriod(0, 0)) + .withEffect(AlertEffect.NO_SERVICE) + .build(); + transitService.getTransitAlertService().setAlerts(List.of(alert)); + + var itineraries = List.of(itinerary); + RealtimeResolver.populateLegsWithRealtime(itineraries, transitService); + + DigitransitRealtimeStopPropertyMapper mapper = DigitransitRealtimeStopPropertyMapper.create( + transitService, + new Locale("en-US") + ); + + Map map = new HashMap<>(); + mapper.map(stop).forEach(o -> map.put(o.key(), o.value())); + + assertEquals("F:name", map.get("gtfsId")); + assertEquals("name", map.get("name")); + assertEquals("desc", map.get("desc")); + assertEquals("[{\"alertEffect\":\"NO_SERVICE\"}]", map.get("alerts")); + } } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java b/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java index 29701ee2307..8622e96e2ff 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java @@ -20,7 +20,7 @@ import org.opentripplanner.apis.support.TileJson; import org.opentripplanner.ext.vectortiles.layers.areastops.AreaStopsLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.stations.StationsLayerBuilder; -import org.opentripplanner.ext.vectortiles.layers.stops.StopsLayerBuilder; +import org.opentripplanner.ext.vectortiles.layers.stops.StopsBaseLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.vehicleparkings.VehicleParkingGroupsLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.vehicleparkings.VehicleParkingsLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.vehiclerental.VehicleRentalPlacesLayerBuilder; @@ -122,7 +122,7 @@ private static LayerBuilder createLayerBuilder( OtpServerRequestContext context ) { return switch (layerParameters.type()) { - case Stop -> new StopsLayerBuilder(context.transitService(), layerParameters, locale); + case Stop -> new StopsBaseLayerBuilder(context.transitService(), layerParameters, locale); case Station -> new StationsLayerBuilder(context.transitService(), layerParameters, locale); case AreaStop -> new AreaStopsLayerBuilder(context.transitService(), layerParameters, locale); case VehicleRental -> new VehicleRentalPlacesLayerBuilder( diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java new file mode 100644 index 00000000000..a2b3c055552 --- /dev/null +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -0,0 +1,90 @@ +package org.opentripplanner.ext.vectortiles.layers.stops; + +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.opentripplanner.apis.support.mapping.PropertyMapper; +import org.opentripplanner.framework.i18n.I18NStringMapper; +import org.opentripplanner.inspector.vector.KeyValue; +import org.opentripplanner.transit.model.network.TripPattern; +import org.opentripplanner.transit.model.site.RegularStop; +import org.opentripplanner.transit.service.TransitService; + +public class DigitransitRealtimeStopPropertyMapper extends PropertyMapper { + + private final TransitService transitService; + private final I18NStringMapper i18NStringMapper; + + public DigitransitRealtimeStopPropertyMapper(TransitService transitService, Locale locale) { + this.transitService = transitService; + this.i18NStringMapper = new I18NStringMapper(locale); + } + + protected static DigitransitRealtimeStopPropertyMapper create( + TransitService transitService, + Locale locale + ) { + return new DigitransitRealtimeStopPropertyMapper(transitService, locale); + } + + @Override + protected Collection map(RegularStop stop) { + Collection patternsForStop = transitService.getPatternsForStop(stop); + + String type = patternsForStop + .stream() + .map(TripPattern::getMode) + .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())) + .entrySet() + .stream() + .max(Map.Entry.comparingByValue()) + .map(Map.Entry::getKey) + .map(Enum::name) + .orElse(null); + + String routes = JSONArray.toJSONString( + transitService + .getRoutesForStop(stop) + .stream() + .map(route -> { + JSONObject routeObject = new JSONObject(); + routeObject.put("gtfsType", route.getGtfsType()); + return routeObject; + }) + .toList() + ); + + String alerts = JSONArray.toJSONString( + transitService + .getTransitAlertService() + .getStopAlerts(stop.getId()) + .stream() + .map(alert -> { + JSONObject alertObject = new JSONObject(); + alertObject.put("alertEffect", alert.effect().toString()); + return alertObject; + }) + .toList() + ); + + return List.of( + new KeyValue("gtfsId", stop.getId().toString()), + new KeyValue("name", i18NStringMapper.mapNonnullToApi(stop.getName())), + new KeyValue("code", stop.getCode()), + new KeyValue("platform", stop.getPlatformCode()), + new KeyValue("desc", i18NStringMapper.mapToApi(stop.getDescription())), + new KeyValue( + "parentStation", + stop.getParentStation() != null ? stop.getParentStation().getId() : "null" + ), + new KeyValue("type", type), + new KeyValue("routes", routes), + new KeyValue("alerts", alerts) + ); + } +} diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index 2c5a4519e96..1634e6b0584 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -20,7 +20,7 @@ public class DigitransitStopPropertyMapper extends PropertyMapper { private final TransitService transitService; private final I18NStringMapper i18NStringMapper; - private DigitransitStopPropertyMapper(TransitService transitService, Locale locale) { + DigitransitStopPropertyMapper(TransitService transitService, Locale locale) { this.transitService = transitService; this.i18NStringMapper = new I18NStringMapper(locale); } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java new file mode 100644 index 00000000000..43dd499c9c0 --- /dev/null +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java @@ -0,0 +1,30 @@ +package org.opentripplanner.ext.vectortiles.layers.stops; + +import static java.util.Map.entry; + +import java.util.Locale; +import java.util.Map; +import org.opentripplanner.ext.vectortiles.VectorTilesResource; +import org.opentripplanner.inspector.vector.LayerParameters; +import org.opentripplanner.transit.service.TransitService; + +public class StopsBaseLayerBuilder extends StopsLayerBuilder { + + public StopsBaseLayerBuilder( + TransitService service, + LayerParameters layerParameters, + Locale locale + ) { + super( + service, + Map.ofEntries( + entry(MapperType.Digitransit, new DigitransitStopPropertyMapper(service, locale)), + entry( + MapperType.DigitransitRealtime, + new DigitransitRealtimeStopPropertyMapper(service, locale) + ) + ), + layerParameters + ); + } +} diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java index 2ad85587fe5..fa7036efd52 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java @@ -14,7 +14,7 @@ import org.opentripplanner.transit.model.site.RegularStop; import org.opentripplanner.transit.service.TransitService; -public class StopsLayerBuilder extends LayerBuilder { +public class StopsLayerBuilder extends LayerBuilder { static Map>> mappers = Map.of( MapperType.Digitransit, @@ -24,11 +24,11 @@ public class StopsLayerBuilder extends LayerBuilder { public StopsLayerBuilder( TransitService transitService, - LayerParameters layerParameters, - Locale locale + Map> mappers, + LayerParameters layerParameters ) { super( - mappers.get(MapperType.valueOf(layerParameters.mapper())).apply(transitService, locale), + mappers.get(MapperType.valueOf(layerParameters.mapper())), layerParameters.name(), layerParameters.expansionFactor() ); @@ -51,5 +51,6 @@ protected List getGeometries(Envelope query) { enum MapperType { Digitransit, + DigitransitRealtime, } } From c9774252f1ff1ccc6a24fa1daa66519f89cf8a44 Mon Sep 17 00:00:00 2001 From: sharhio Date: Tue, 12 Mar 2024 12:15:26 +0200 Subject: [PATCH 02/17] Repeated code cleaned up --- ...DigitransitRealtimeStopPropertyMapper.java | 36 ++---------- .../stops/DigitransitStopPropertyMapper.java | 57 ++++++++++--------- 2 files changed, 36 insertions(+), 57 deletions(-) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index a2b3c055552..08506f86975 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -1,17 +1,16 @@ package org.opentripplanner.ext.vectortiles.layers.stops; +import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getRoutes; +import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getType; + import java.util.Collection; import java.util.List; import java.util.Locale; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.opentripplanner.apis.support.mapping.PropertyMapper; import org.opentripplanner.framework.i18n.I18NStringMapper; import org.opentripplanner.inspector.vector.KeyValue; -import org.opentripplanner.transit.model.network.TripPattern; import org.opentripplanner.transit.model.site.RegularStop; import org.opentripplanner.transit.service.TransitService; @@ -34,31 +33,6 @@ protected static DigitransitRealtimeStopPropertyMapper create( @Override protected Collection map(RegularStop stop) { - Collection patternsForStop = transitService.getPatternsForStop(stop); - - String type = patternsForStop - .stream() - .map(TripPattern::getMode) - .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())) - .entrySet() - .stream() - .max(Map.Entry.comparingByValue()) - .map(Map.Entry::getKey) - .map(Enum::name) - .orElse(null); - - String routes = JSONArray.toJSONString( - transitService - .getRoutesForStop(stop) - .stream() - .map(route -> { - JSONObject routeObject = new JSONObject(); - routeObject.put("gtfsType", route.getGtfsType()); - return routeObject; - }) - .toList() - ); - String alerts = JSONArray.toJSONString( transitService .getTransitAlertService() @@ -82,8 +56,8 @@ protected Collection map(RegularStop stop) { "parentStation", stop.getParentStation() != null ? stop.getParentStation().getId() : "null" ), - new KeyValue("type", type), - new KeyValue("routes", routes), + new KeyValue("type", getType(transitService, stop)), + new KeyValue("routes", getRoutes(transitService, stop)), new KeyValue("alerts", alerts) ); } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index 1634e6b0584..2b6d7536f1c 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -34,30 +34,6 @@ protected static DigitransitStopPropertyMapper create( @Override protected Collection map(RegularStop stop) { - Collection patternsForStop = transitService.getPatternsForStop(stop); - - String type = patternsForStop - .stream() - .map(TripPattern::getMode) - .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())) - .entrySet() - .stream() - .max(Map.Entry.comparingByValue()) - .map(Map.Entry::getKey) - .map(Enum::name) - .orElse(null); - - String routes = JSONArray.toJSONString( - transitService - .getRoutesForStop(stop) - .stream() - .map(route -> { - JSONObject routeObject = new JSONObject(); - routeObject.put("gtfsType", route.getGtfsType()); - return routeObject; - }) - .toList() - ); return List.of( new KeyValue("gtfsId", stop.getId().toString()), new KeyValue("name", i18NStringMapper.mapNonnullToApi(stop.getName())), @@ -68,8 +44,37 @@ protected Collection map(RegularStop stop) { "parentStation", stop.getParentStation() != null ? stop.getParentStation().getId() : "null" ), - new KeyValue("type", type), - new KeyValue("routes", routes) + new KeyValue("type", getType(transitService, stop)), + new KeyValue("routes", getRoutes(transitService, stop)) ); } + + protected static String getRoutes(TransitService transitService, RegularStop stop) { + return JSONArray.toJSONString( + transitService + .getRoutesForStop(stop) + .stream() + .map(route -> { + JSONObject routeObject = new JSONObject(); + routeObject.put("gtfsType", route.getGtfsType()); + return routeObject; + }) + .toList() + ); + } + + protected static String getType(TransitService transitService, RegularStop stop) { + Collection patternsForStop = transitService.getPatternsForStop(stop); + + return patternsForStop + .stream() + .map(TripPattern::getMode) + .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())) + .entrySet() + .stream() + .max(Map.Entry.comparingByValue()) + .map(Map.Entry::getKey) + .map(Enum::name) + .orElse(null); + } } From 2e201f7cef0fa432401fe866ea03a7c4fb862e87 Mon Sep 17 00:00:00 2001 From: sharhio Date: Tue, 12 Mar 2024 16:08:15 +0200 Subject: [PATCH 03/17] added check for validityperiod, cleaned up unnecessary parts --- .../layers/stops/StopsLayerTest.java | 14 ++++++--- .../ext/vectortiles/VectorTilesResource.java | 4 +-- ...DigitransitRealtimeStopPropertyMapper.java | 23 +++++++++----- .../stops/DigitransitStopPropertyMapper.java | 2 +- .../layers/stops/StopsBaseLayerBuilder.java | 30 ------------------- .../layers/stops/StopsLayerBuilder.java | 16 ++++++++-- 6 files changed, 41 insertions(+), 48 deletions(-) delete mode 100644 src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java diff --git a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java index ac05842a70d..79a95d2883d 100644 --- a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java @@ -4,12 +4,16 @@ import static org.opentripplanner.framework.time.TimeUtils.time; import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZonedDateTime; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.opentripplanner._support.time.ZoneIds; import org.opentripplanner.ext.realtimeresolver.RealtimeResolver; import org.opentripplanner.framework.i18n.TranslatedString; import org.opentripplanner.model.plan.Place; @@ -34,7 +38,7 @@ public class StopsLayerTest { private RegularStop stop2; @BeforeEach - public final void setUp() { + public void setUp() { var nameTranslations = TranslatedString.getI18NString( new HashMap<>() { { @@ -116,6 +120,7 @@ public void digitransitStopPropertyMapperTranslationTest() { public void digitransitRealtimeStopPropertyMapperTest() { var deduplicator = new Deduplicator(); var transitModel = new TransitModel(new StopModel(), deduplicator); + transitModel.initTimeZone(ZoneIds.HELSINKI); transitModel.index(); var alertService = new TransitAlertServiceImpl(transitModel); var transitService = new DefaultTransitService(transitModel) { @@ -129,11 +134,12 @@ public TransitAlertService getTransitAlertService() { var itinerary = newItinerary(Place.forStop(stop), time("11:00")) .bus(route, 1, time("11:05"), time("11:20"), Place.forStop(stop2)) .build(); - + var startDate = ZonedDateTime.now(ZoneIds.HELSINKI).minusDays(1).toEpochSecond(); + var endDate = ZonedDateTime.now(ZoneIds.HELSINKI).plusDays(1).toEpochSecond(); var alert = TransitAlert .of(stop.getId()) .addEntity(new EntitySelector.Stop(stop.getId())) - .addTimePeriod(new TimePeriod(0, 0)) + .addTimePeriod(new TimePeriod(startDate, endDate)) .withEffect(AlertEffect.NO_SERVICE) .build(); transitService.getTransitAlertService().setAlerts(List.of(alert)); @@ -141,7 +147,7 @@ public TransitAlertService getTransitAlertService() { var itineraries = List.of(itinerary); RealtimeResolver.populateLegsWithRealtime(itineraries, transitService); - DigitransitRealtimeStopPropertyMapper mapper = DigitransitRealtimeStopPropertyMapper.create( + DigitransitRealtimeStopPropertyMapper mapper = new DigitransitRealtimeStopPropertyMapper( transitService, new Locale("en-US") ); diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java b/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java index 8622e96e2ff..29701ee2307 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/VectorTilesResource.java @@ -20,7 +20,7 @@ import org.opentripplanner.apis.support.TileJson; import org.opentripplanner.ext.vectortiles.layers.areastops.AreaStopsLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.stations.StationsLayerBuilder; -import org.opentripplanner.ext.vectortiles.layers.stops.StopsBaseLayerBuilder; +import org.opentripplanner.ext.vectortiles.layers.stops.StopsLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.vehicleparkings.VehicleParkingGroupsLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.vehicleparkings.VehicleParkingsLayerBuilder; import org.opentripplanner.ext.vectortiles.layers.vehiclerental.VehicleRentalPlacesLayerBuilder; @@ -122,7 +122,7 @@ private static LayerBuilder createLayerBuilder( OtpServerRequestContext context ) { return switch (layerParameters.type()) { - case Stop -> new StopsBaseLayerBuilder(context.transitService(), layerParameters, locale); + case Stop -> new StopsLayerBuilder(context.transitService(), layerParameters, locale); case Station -> new StationsLayerBuilder(context.transitService(), layerParameters, locale); case AreaStop -> new AreaStopsLayerBuilder(context.transitService(), layerParameters, locale); case VehicleRental -> new VehicleRentalPlacesLayerBuilder( diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 08506f86975..2bae5074a78 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -3,6 +3,8 @@ import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getRoutes; import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getType; +import java.time.Instant; +import java.time.ZonedDateTime; import java.util.Collection; import java.util.List; import java.util.Locale; @@ -24,13 +26,6 @@ public DigitransitRealtimeStopPropertyMapper(TransitService transitService, Loca this.i18NStringMapper = new I18NStringMapper(locale); } - protected static DigitransitRealtimeStopPropertyMapper create( - TransitService transitService, - Locale locale - ) { - return new DigitransitRealtimeStopPropertyMapper(transitService, locale); - } - @Override protected Collection map(RegularStop stop) { String alerts = JSONArray.toJSONString( @@ -40,7 +35,19 @@ protected Collection map(RegularStop stop) { .stream() .map(alert -> { JSONObject alertObject = new JSONObject(); - alertObject.put("alertEffect", alert.effect().toString()); + Instant currentTime = ZonedDateTime.now(transitService.getTimeZone()).toInstant(); + if ( + ( + alert.getEffectiveStartDate() != null && + alert.getEffectiveStartDate().isBefore(currentTime) + ) && + ( + alert.getEffectiveEndDate() != null && + alert.getEffectiveEndDate().isAfter(currentTime) + ) + ) { + alertObject.put("alertEffect", alert.effect().toString()); + } return alertObject; }) .toList() diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index 2b6d7536f1c..8f9c427468e 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -42,7 +42,7 @@ protected Collection map(RegularStop stop) { new KeyValue("desc", i18NStringMapper.mapToApi(stop.getDescription())), new KeyValue( "parentStation", - stop.getParentStation() != null ? stop.getParentStation().getId() : "null" + stop.getParentStation() != null ? stop.getParentStation().getId() : null ), new KeyValue("type", getType(transitService, stop)), new KeyValue("routes", getRoutes(transitService, stop)) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java deleted file mode 100644 index 43dd499c9c0..00000000000 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsBaseLayerBuilder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.opentripplanner.ext.vectortiles.layers.stops; - -import static java.util.Map.entry; - -import java.util.Locale; -import java.util.Map; -import org.opentripplanner.ext.vectortiles.VectorTilesResource; -import org.opentripplanner.inspector.vector.LayerParameters; -import org.opentripplanner.transit.service.TransitService; - -public class StopsBaseLayerBuilder extends StopsLayerBuilder { - - public StopsBaseLayerBuilder( - TransitService service, - LayerParameters layerParameters, - Locale locale - ) { - super( - service, - Map.ofEntries( - entry(MapperType.Digitransit, new DigitransitStopPropertyMapper(service, locale)), - entry( - MapperType.DigitransitRealtime, - new DigitransitRealtimeStopPropertyMapper(service, locale) - ) - ), - layerParameters - ); - } -} diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java index fa7036efd52..aa664497728 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java @@ -1,5 +1,7 @@ package org.opentripplanner.ext.vectortiles.layers.stops; +import static java.util.Map.entry; + import java.util.List; import java.util.Locale; import java.util.Map; @@ -24,11 +26,19 @@ public class StopsLayerBuilder extends LayerBuilder { public StopsLayerBuilder( TransitService transitService, - Map> mappers, - LayerParameters layerParameters + LayerParameters layerParameters, + Locale locale ) { super( - mappers.get(MapperType.valueOf(layerParameters.mapper())), + (PropertyMapper) Map + .ofEntries( + entry(MapperType.Digitransit, new DigitransitStopPropertyMapper(transitService, locale)), + entry( + MapperType.DigitransitRealtime, + new DigitransitRealtimeStopPropertyMapper(transitService, locale) + ) + ) + .get(MapperType.valueOf(layerParameters.mapper())), layerParameters.name(), layerParameters.expansionFactor() ); From c38e648486382999a6f7f0ab665908632b632d4b Mon Sep 17 00:00:00 2001 From: sharhio Date: Wed, 13 Mar 2024 09:55:58 +0200 Subject: [PATCH 04/17] Show stop status instead of alerts --- .../layers/stops/StopsLayerTest.java | 2 +- ...DigitransitRealtimeStopPropertyMapper.java | 50 +++++++++---------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java index 79a95d2883d..d2b604e0705 100644 --- a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java @@ -158,6 +158,6 @@ public TransitAlertService getTransitAlertService() { assertEquals("F:name", map.get("gtfsId")); assertEquals("name", map.get("name")); assertEquals("desc", map.get("desc")); - assertEquals("[{\"alertEffect\":\"NO_SERVICE\"}]", map.get("alerts")); + assertEquals("OUT_OF_SERVICE", map.get("state")); } } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 2bae5074a78..9581731a1ca 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -8,11 +8,10 @@ import java.util.Collection; import java.util.List; import java.util.Locale; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; import org.opentripplanner.apis.support.mapping.PropertyMapper; import org.opentripplanner.framework.i18n.I18NStringMapper; import org.opentripplanner.inspector.vector.KeyValue; +import org.opentripplanner.routing.alertpatch.AlertEffect; import org.opentripplanner.transit.model.site.RegularStop; import org.opentripplanner.transit.service.TransitService; @@ -28,30 +27,19 @@ public DigitransitRealtimeStopPropertyMapper(TransitService transitService, Loca @Override protected Collection map(RegularStop stop) { - String alerts = JSONArray.toJSONString( - transitService - .getTransitAlertService() - .getStopAlerts(stop.getId()) - .stream() - .map(alert -> { - JSONObject alertObject = new JSONObject(); - Instant currentTime = ZonedDateTime.now(transitService.getTimeZone()).toInstant(); - if ( - ( - alert.getEffectiveStartDate() != null && - alert.getEffectiveStartDate().isBefore(currentTime) - ) && - ( - alert.getEffectiveEndDate() != null && - alert.getEffectiveEndDate().isAfter(currentTime) - ) - ) { - alertObject.put("alertEffect", alert.effect().toString()); - } - return alertObject; - }) - .toList() - ); + Instant currentTime = ZonedDateTime.now(transitService.getTimeZone()).toInstant(); + boolean noService = transitService + .getTransitAlertService() + .getStopAlerts(stop.getId()) + .stream() + .anyMatch(alert -> + alert.effect().equals(AlertEffect.NO_SERVICE) && + ( + alert.getEffectiveStartDate() != null && + alert.getEffectiveStartDate().isBefore(currentTime) + ) && + (alert.getEffectiveEndDate() != null && alert.getEffectiveEndDate().isAfter(currentTime)) + ); return List.of( new KeyValue("gtfsId", stop.getId().toString()), @@ -65,7 +53,15 @@ protected Collection map(RegularStop stop) { ), new KeyValue("type", getType(transitService, stop)), new KeyValue("routes", getRoutes(transitService, stop)), - new KeyValue("alerts", alerts) + new KeyValue( + "state", + noService ? StopState.OUT_OF_SERVICE.toString() : StopState.OPERATIONAL.toString() + ) ); } + + enum StopState { + OPERATIONAL, + OUT_OF_SERVICE, + } } From f80544b9eb21564575eaa37cda51118f9c3dde76 Mon Sep 17 00:00:00 2001 From: sharhio Date: Wed, 13 Mar 2024 10:16:27 +0200 Subject: [PATCH 05/17] Show if there is a no service alert --- .../ext/vectortiles/layers/stops/StopsLayerTest.java | 2 +- .../stops/DigitransitRealtimeStopPropertyMapper.java | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java index d2b604e0705..dcb7f0db31a 100644 --- a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java @@ -158,6 +158,6 @@ public TransitAlertService getTransitAlertService() { assertEquals("F:name", map.get("gtfsId")); assertEquals("name", map.get("name")); assertEquals("desc", map.get("desc")); - assertEquals("OUT_OF_SERVICE", map.get("state")); + assertEquals(true, map.get("noServiceAlert")); } } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 9581731a1ca..543246acac9 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -28,7 +28,7 @@ public DigitransitRealtimeStopPropertyMapper(TransitService transitService, Loca @Override protected Collection map(RegularStop stop) { Instant currentTime = ZonedDateTime.now(transitService.getTimeZone()).toInstant(); - boolean noService = transitService + boolean noServiceAlert = transitService .getTransitAlertService() .getStopAlerts(stop.getId()) .stream() @@ -53,15 +53,7 @@ protected Collection map(RegularStop stop) { ), new KeyValue("type", getType(transitService, stop)), new KeyValue("routes", getRoutes(transitService, stop)), - new KeyValue( - "state", - noService ? StopState.OUT_OF_SERVICE.toString() : StopState.OPERATIONAL.toString() - ) + new KeyValue("noServiceAlert", noServiceAlert) ); } - - enum StopState { - OPERATIONAL, - OUT_OF_SERVICE, - } } From dd4db6078ba45e4df29504e6bee21c45b7111f7f Mon Sep 17 00:00:00 2001 From: sharhio Date: Wed, 13 Mar 2024 13:46:50 +0200 Subject: [PATCH 06/17] refactoring, validity logic fixed --- .../layers/stops/StopsLayerTest.java | 2 +- ...DigitransitRealtimeStopPropertyMapper.java | 39 +++++++------------ .../stops/DigitransitStopPropertyMapper.java | 24 ++++++++++-- .../routing/alertpatch/TransitAlert.java | 13 +++++++ 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java index dcb7f0db31a..a914cf9db6c 100644 --- a/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java +++ b/src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerTest.java @@ -158,6 +158,6 @@ public TransitAlertService getTransitAlertService() { assertEquals("F:name", map.get("gtfsId")); assertEquals("name", map.get("name")); assertEquals("desc", map.get("desc")); - assertEquals(true, map.get("noServiceAlert")); + assertEquals(true, map.get("closedByServiceAlert")); } } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 543246acac9..5c4f774bb20 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -1,17 +1,17 @@ package org.opentripplanner.ext.vectortiles.layers.stops; +import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getKeyValues; import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getRoutes; import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getType; import java.time.Instant; -import java.time.ZonedDateTime; import java.util.Collection; import java.util.List; import java.util.Locale; import org.opentripplanner.apis.support.mapping.PropertyMapper; +import org.opentripplanner.framework.collection.ListUtils; import org.opentripplanner.framework.i18n.I18NStringMapper; import org.opentripplanner.inspector.vector.KeyValue; -import org.opentripplanner.routing.alertpatch.AlertEffect; import org.opentripplanner.transit.model.site.RegularStop; import org.opentripplanner.transit.service.TransitService; @@ -27,33 +27,24 @@ public DigitransitRealtimeStopPropertyMapper(TransitService transitService, Loca @Override protected Collection map(RegularStop stop) { - Instant currentTime = ZonedDateTime.now(transitService.getTimeZone()).toInstant(); + Instant currentTime = Instant.now(); boolean noServiceAlert = transitService .getTransitAlertService() .getStopAlerts(stop.getId()) .stream() - .anyMatch(alert -> - alert.effect().equals(AlertEffect.NO_SERVICE) && - ( - alert.getEffectiveStartDate() != null && - alert.getEffectiveStartDate().isBefore(currentTime) - ) && - (alert.getEffectiveEndDate() != null && alert.getEffectiveEndDate().isAfter(currentTime)) - ); + .anyMatch(alert -> alert.noServiceOn(currentTime)); - return List.of( - new KeyValue("gtfsId", stop.getId().toString()), - new KeyValue("name", i18NStringMapper.mapNonnullToApi(stop.getName())), - new KeyValue("code", stop.getCode()), - new KeyValue("platform", stop.getPlatformCode()), - new KeyValue("desc", i18NStringMapper.mapToApi(stop.getDescription())), - new KeyValue( - "parentStation", - stop.getParentStation() != null ? stop.getParentStation().getId() : "null" - ), - new KeyValue("type", getType(transitService, stop)), - new KeyValue("routes", getRoutes(transitService, stop)), - new KeyValue("noServiceAlert", noServiceAlert) + Collection sharedKeyValues = getKeyValues( + stop, + i18NStringMapper.mapNonnullToApi(stop.getName()), + i18NStringMapper.mapToApi(stop.getDescription()), + getType(transitService, stop), + getRoutes(transitService, stop) ); + Collection keyValues = ListUtils.combine( + sharedKeyValues, + List.of(new KeyValue("closedByServiceAlert", noServiceAlert)) + ); + return keyValues; } } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index 8f9c427468e..998e125ce9d 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -34,18 +34,34 @@ protected static DigitransitStopPropertyMapper create( @Override protected Collection map(RegularStop stop) { + return getKeyValues( + stop, + i18NStringMapper.mapNonnullToApi(stop.getName()), + i18NStringMapper.mapToApi(stop.getDescription()), + getType(transitService, stop), + getRoutes(transitService, stop) + ); + } + + protected static Collection getKeyValues( + RegularStop stop, + String name, + String description, + String type, + String routes + ) { return List.of( new KeyValue("gtfsId", stop.getId().toString()), - new KeyValue("name", i18NStringMapper.mapNonnullToApi(stop.getName())), + new KeyValue("name", name), new KeyValue("code", stop.getCode()), new KeyValue("platform", stop.getPlatformCode()), - new KeyValue("desc", i18NStringMapper.mapToApi(stop.getDescription())), + new KeyValue("desc", description), new KeyValue( "parentStation", stop.getParentStation() != null ? stop.getParentStation().getId() : null ), - new KeyValue("type", getType(transitService, stop)), - new KeyValue("routes", getRoutes(transitService, stop)) + new KeyValue("type", type), + new KeyValue("routes", routes) ); } diff --git a/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java b/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java index d5d260a8218..ac278a44a5c 100644 --- a/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java +++ b/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java @@ -191,6 +191,19 @@ public Instant getEffectiveEndDate() { .orElse(null); } + /** + * Checks if the alert has a NO_SERVICE alert active at the requested time. + * @param instant + * @return + */ + public boolean noServiceOn(Instant instant) { + return ( + effect.equals(AlertEffect.NO_SERVICE) && + (getEffectiveStartDate() != null && getEffectiveStartDate().isBefore(instant)) && + (getEffectiveEndDate() == null || getEffectiveEndDate().isAfter(instant)) + ); + } + @Override public boolean sameAs(@Nonnull TransitAlert other) { return ( From 816fba9aef50c2f1fe8bdb06c9264cbf2f25c8aa Mon Sep 17 00:00:00 2001 From: sharhio Date: Thu, 14 Mar 2024 08:25:11 +0200 Subject: [PATCH 07/17] refactoring --- ...DigitransitRealtimeStopPropertyMapper.java | 12 ++-------- .../stops/DigitransitStopPropertyMapper.java | 22 ++++++------------- .../routing/alertpatch/TransitAlert.java | 2 +- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 5c4f774bb20..0cce00bb385 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -1,8 +1,6 @@ package org.opentripplanner.ext.vectortiles.layers.stops; import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getKeyValues; -import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getRoutes; -import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getType; import java.time.Instant; import java.util.Collection; @@ -32,15 +30,9 @@ protected Collection map(RegularStop stop) { .getTransitAlertService() .getStopAlerts(stop.getId()) .stream() - .anyMatch(alert -> alert.noServiceOn(currentTime)); + .anyMatch(alert -> alert.noServiceAt(currentTime)); - Collection sharedKeyValues = getKeyValues( - stop, - i18NStringMapper.mapNonnullToApi(stop.getName()), - i18NStringMapper.mapToApi(stop.getDescription()), - getType(transitService, stop), - getRoutes(transitService, stop) - ); + Collection sharedKeyValues = getKeyValues(stop, i18NStringMapper, transitService); Collection keyValues = ListUtils.combine( sharedKeyValues, List.of(new KeyValue("closedByServiceAlert", noServiceAlert)) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index 998e125ce9d..94569de1ce5 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -34,34 +34,26 @@ protected static DigitransitStopPropertyMapper create( @Override protected Collection map(RegularStop stop) { - return getKeyValues( - stop, - i18NStringMapper.mapNonnullToApi(stop.getName()), - i18NStringMapper.mapToApi(stop.getDescription()), - getType(transitService, stop), - getRoutes(transitService, stop) - ); + return getKeyValues(stop, i18NStringMapper, transitService); } protected static Collection getKeyValues( RegularStop stop, - String name, - String description, - String type, - String routes + I18NStringMapper i18NStringMapper, + TransitService transitService ) { return List.of( new KeyValue("gtfsId", stop.getId().toString()), - new KeyValue("name", name), + new KeyValue("name", i18NStringMapper.mapNonnullToApi(stop.getName())), new KeyValue("code", stop.getCode()), new KeyValue("platform", stop.getPlatformCode()), - new KeyValue("desc", description), + new KeyValue("desc", i18NStringMapper.mapToApi(stop.getDescription())), new KeyValue( "parentStation", stop.getParentStation() != null ? stop.getParentStation().getId() : null ), - new KeyValue("type", type), - new KeyValue("routes", routes) + new KeyValue("type", getType(transitService, stop)), + new KeyValue("routes", getRoutes(transitService, stop)) ); } diff --git a/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java b/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java index ac278a44a5c..17a307ed205 100644 --- a/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java +++ b/src/main/java/org/opentripplanner/routing/alertpatch/TransitAlert.java @@ -196,7 +196,7 @@ public Instant getEffectiveEndDate() { * @param instant * @return */ - public boolean noServiceOn(Instant instant) { + public boolean noServiceAt(Instant instant) { return ( effect.equals(AlertEffect.NO_SERVICE) && (getEffectiveStartDate() != null && getEffectiveStartDate().isBefore(instant)) && From c148dafc8f292138d6bbf458b9b3980544dc0a6e Mon Sep 17 00:00:00 2001 From: sharhio <113033056+sharhio@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:53:03 +0200 Subject: [PATCH 08/17] Update src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java Co-authored-by: Leonard Ehrenfried --- .../layers/stops/DigitransitRealtimeStopPropertyMapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 0cce00bb385..ad31855d501 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -33,10 +33,9 @@ protected Collection map(RegularStop stop) { .anyMatch(alert -> alert.noServiceAt(currentTime)); Collection sharedKeyValues = getKeyValues(stop, i18NStringMapper, transitService); - Collection keyValues = ListUtils.combine( + return ListUtils.combine( sharedKeyValues, List.of(new KeyValue("closedByServiceAlert", noServiceAlert)) ); - return keyValues; } } From 796d542109b10ca1fc703da04f1d204cebc1ca2d Mon Sep 17 00:00:00 2001 From: sharhio Date: Mon, 18 Mar 2024 13:11:07 +0200 Subject: [PATCH 09/17] naming --- .../layers/stops/DigitransitRealtimeStopPropertyMapper.java | 4 ++-- .../layers/stops/DigitransitStopPropertyMapper.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index ad31855d501..55d67d28d71 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -1,6 +1,6 @@ package org.opentripplanner.ext.vectortiles.layers.stops; -import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getKeyValues; +import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getBaseKeyValues; import java.time.Instant; import java.util.Collection; @@ -32,7 +32,7 @@ protected Collection map(RegularStop stop) { .stream() .anyMatch(alert -> alert.noServiceAt(currentTime)); - Collection sharedKeyValues = getKeyValues(stop, i18NStringMapper, transitService); + Collection sharedKeyValues = getBaseKeyValues(stop, i18NStringMapper, transitService); return ListUtils.combine( sharedKeyValues, List.of(new KeyValue("closedByServiceAlert", noServiceAlert)) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index 94569de1ce5..2568f1fbc9b 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -34,10 +34,10 @@ protected static DigitransitStopPropertyMapper create( @Override protected Collection map(RegularStop stop) { - return getKeyValues(stop, i18NStringMapper, transitService); + return getBaseKeyValues(stop, i18NStringMapper, transitService); } - protected static Collection getKeyValues( + protected static Collection getBaseKeyValues( RegularStop stop, I18NStringMapper i18NStringMapper, TransitService transitService From 5120e12483b8acc2b0509af41e7a9036386e2b8a Mon Sep 17 00:00:00 2001 From: sharhio Date: Mon, 18 Mar 2024 13:18:33 +0200 Subject: [PATCH 10/17] documentation --- docs/sandbox/MapboxVectorTilesApi.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/sandbox/MapboxVectorTilesApi.md b/docs/sandbox/MapboxVectorTilesApi.md index 45feec03d47..11a09176d3b 100644 --- a/docs/sandbox/MapboxVectorTilesApi.md +++ b/docs/sandbox/MapboxVectorTilesApi.md @@ -103,6 +103,15 @@ The feature must be configured in `router-config.json` as follows "minZoom": 14, "cacheMaxSeconds": 60 }, + // Contains just stops and real-time information for them + { + "name": "realtimeStops", + "type": "Stop", + "mapper": "DigitransitRealtime", + "maxZoom": 20, + "minZoom": 14, + "cacheMaxSeconds": 600 + }, // This exists for backwards compatibility. At some point, we might want // to add a new real-time parking mapper with better translation support // and less unnecessary fields. From 89e82e96567f2a72531f75e74a03a0bde845b239 Mon Sep 17 00:00:00 2001 From: sharhio Date: Mon, 18 Mar 2024 13:47:22 +0200 Subject: [PATCH 11/17] docs generation --- docs/sandbox/MapboxVectorTilesApi.md | 9 --------- .../gtfs/generated/GraphQLDataFetchers.java | 18 +++++++++++++++++- .../apis/gtfs/generated/GraphQLTypes.java | 1 + 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/sandbox/MapboxVectorTilesApi.md b/docs/sandbox/MapboxVectorTilesApi.md index 11a09176d3b..45feec03d47 100644 --- a/docs/sandbox/MapboxVectorTilesApi.md +++ b/docs/sandbox/MapboxVectorTilesApi.md @@ -103,15 +103,6 @@ The feature must be configured in `router-config.json` as follows "minZoom": 14, "cacheMaxSeconds": 60 }, - // Contains just stops and real-time information for them - { - "name": "realtimeStops", - "type": "Stop", - "mapper": "DigitransitRealtime", - "maxZoom": 20, - "minZoom": 14, - "cacheMaxSeconds": 600 - }, // This exists for backwards compatibility. At some point, we might want // to add a new real-time parking mapper with better translation support // and less unnecessary fields. diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 2f39f7f4030..8bc83ce1108 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -2,6 +2,8 @@ package org.opentripplanner.apis.gtfs.generated; import graphql.relay.Connection; +import graphql.relay.Connection; +import graphql.relay.Edge; import graphql.relay.Edge; import graphql.schema.DataFetcher; import graphql.schema.TypeResolver; @@ -21,8 +23,12 @@ import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRoutingErrorCode; import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLTransitMode; import org.opentripplanner.apis.gtfs.model.RideHailingProvider; +import org.opentripplanner.apis.gtfs.model.RouteTypeModel; +import org.opentripplanner.apis.gtfs.model.StopOnRouteModel; +import org.opentripplanner.apis.gtfs.model.StopOnTripModel; import org.opentripplanner.apis.gtfs.model.StopPosition; import org.opentripplanner.apis.gtfs.model.TripOccupancy; +import org.opentripplanner.apis.gtfs.model.UnknownModel; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.ext.ridehailing.model.RideEstimate; import org.opentripplanner.model.StopTimesInPattern; @@ -44,6 +50,8 @@ import org.opentripplanner.routing.graphfinder.PatternAtStop; import org.opentripplanner.routing.graphfinder.PlaceAtDistance; import org.opentripplanner.routing.vehicle_parking.VehicleParking; +import org.opentripplanner.routing.vehicle_parking.VehicleParking; +import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; import org.opentripplanner.routing.vehicle_parking.VehicleParkingState; import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle; @@ -54,6 +62,7 @@ import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; +import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle; import org.opentripplanner.transit.model.basic.Money; import org.opentripplanner.transit.model.network.Route; @@ -1235,6 +1244,10 @@ public interface GraphQLElevationProfileComponent { public DataFetcher elevation(); } + /** + * This type is only here for backwards-compatibility and this API will never return it anymore. + * Please use the leg's `fareProducts` instead. + */ public interface GraphQLFare { public DataFetcher cents(); @@ -1245,7 +1258,10 @@ public interface GraphQLFare { public DataFetcher type(); } - /** Component of the fare (i.e. ticket) for a part of the itinerary */ + /** + * This type is only here for backwards-compatibility and this API will never return it anymore. + * Please use the leg's `fareProducts` instead. + */ public interface GraphQLFareComponent { public DataFetcher cents(); diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java index ecc038fec18..ffe37e77284 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java @@ -1,6 +1,7 @@ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; From d75df7fb6ba3c0cf7c554f2a78eb2bd0a8f6907d Mon Sep 17 00:00:00 2001 From: sharhio Date: Tue, 19 Mar 2024 09:20:41 +0200 Subject: [PATCH 12/17] documentation --- doc-templates/sandbox/MapboxVectorTilesApi.md | 9 +++++++++ docs/sandbox/MapboxVectorTilesApi.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/doc-templates/sandbox/MapboxVectorTilesApi.md b/doc-templates/sandbox/MapboxVectorTilesApi.md index 35211eff00b..9fd3b9e4ba2 100644 --- a/doc-templates/sandbox/MapboxVectorTilesApi.md +++ b/doc-templates/sandbox/MapboxVectorTilesApi.md @@ -103,6 +103,15 @@ The feature must be configured in `router-config.json` as follows "minZoom": 14, "cacheMaxSeconds": 60 }, + // Contains just stops and real-time information for them + { + "name": "realtimeStops", + "type": "Stop", + "mapper": "DigitransitRealtime", + "maxZoom": 20, + "minZoom": 14, + "cacheMaxSeconds": 600 + }, // This exists for backwards compatibility. At some point, we might want // to add a new real-time parking mapper with better translation support // and less unnecessary fields. diff --git a/docs/sandbox/MapboxVectorTilesApi.md b/docs/sandbox/MapboxVectorTilesApi.md index 45feec03d47..11a09176d3b 100644 --- a/docs/sandbox/MapboxVectorTilesApi.md +++ b/docs/sandbox/MapboxVectorTilesApi.md @@ -103,6 +103,15 @@ The feature must be configured in `router-config.json` as follows "minZoom": 14, "cacheMaxSeconds": 60 }, + // Contains just stops and real-time information for them + { + "name": "realtimeStops", + "type": "Stop", + "mapper": "DigitransitRealtime", + "maxZoom": 20, + "minZoom": 14, + "cacheMaxSeconds": 600 + }, // This exists for backwards compatibility. At some point, we might want // to add a new real-time parking mapper with better translation support // and less unnecessary fields. From 5132bf2be807378306ec41499b825abaae90f954 Mon Sep 17 00:00:00 2001 From: sharhio Date: Thu, 21 Mar 2024 14:10:20 +0200 Subject: [PATCH 13/17] config doc fix, parentstation not shared --- doc-templates/sandbox/MapboxVectorTilesApi.md | 2 +- .../DigitransitRealtimeStopPropertyMapper.java | 8 +++++++- .../stops/DigitransitStopPropertyMapper.java | 16 +++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/doc-templates/sandbox/MapboxVectorTilesApi.md b/doc-templates/sandbox/MapboxVectorTilesApi.md index 9fd3b9e4ba2..d64d9700da4 100644 --- a/doc-templates/sandbox/MapboxVectorTilesApi.md +++ b/doc-templates/sandbox/MapboxVectorTilesApi.md @@ -110,7 +110,7 @@ The feature must be configured in `router-config.json` as follows "mapper": "DigitransitRealtime", "maxZoom": 20, "minZoom": 14, - "cacheMaxSeconds": 600 + "cacheMaxSeconds": 60 }, // This exists for backwards compatibility. At some point, we might want // to add a new real-time parking mapper with better translation support diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 55d67d28d71..47cf7210274 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -35,7 +35,13 @@ protected Collection map(RegularStop stop) { Collection sharedKeyValues = getBaseKeyValues(stop, i18NStringMapper, transitService); return ListUtils.combine( sharedKeyValues, - List.of(new KeyValue("closedByServiceAlert", noServiceAlert)) + List.of( + new KeyValue("closedByServiceAlert", noServiceAlert), + new KeyValue( + "parentStation", + stop.getParentStation() != null ? stop.getParentStation().getId() : null + ) + ) ); } } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index 2568f1fbc9b..e9c40e43ba8 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -9,6 +9,7 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.opentripplanner.apis.support.mapping.PropertyMapper; +import org.opentripplanner.framework.collection.ListUtils; import org.opentripplanner.framework.i18n.I18NStringMapper; import org.opentripplanner.inspector.vector.KeyValue; import org.opentripplanner.transit.model.network.TripPattern; @@ -34,7 +35,16 @@ protected static DigitransitStopPropertyMapper create( @Override protected Collection map(RegularStop stop) { - return getBaseKeyValues(stop, i18NStringMapper, transitService); + Collection sharedKeyValues = getBaseKeyValues(stop, i18NStringMapper, transitService); + return ListUtils.combine( + sharedKeyValues, + List.of( + new KeyValue( + "parentStation", + stop.getParentStation() != null ? stop.getParentStation().getId() : "null" + ) + ) + ); } protected static Collection getBaseKeyValues( @@ -48,10 +58,6 @@ protected static Collection getBaseKeyValues( new KeyValue("code", stop.getCode()), new KeyValue("platform", stop.getPlatformCode()), new KeyValue("desc", i18NStringMapper.mapToApi(stop.getDescription())), - new KeyValue( - "parentStation", - stop.getParentStation() != null ? stop.getParentStation().getId() : null - ), new KeyValue("type", getType(transitService, stop)), new KeyValue("routes", getRoutes(transitService, stop)) ); From a408f01d4c8b935ad65bc6f89fd1ef0acea2fd5e Mon Sep 17 00:00:00 2001 From: sharhio Date: Thu, 21 Mar 2024 14:10:56 +0200 Subject: [PATCH 14/17] Revert "docs generation" This reverts commit 89e82e96567f2a72531f75e74a03a0bde845b239. --- .../gtfs/generated/GraphQLDataFetchers.java | 18 +----------------- .../apis/gtfs/generated/GraphQLTypes.java | 1 - 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 8bc83ce1108..2f39f7f4030 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -2,8 +2,6 @@ package org.opentripplanner.apis.gtfs.generated; import graphql.relay.Connection; -import graphql.relay.Connection; -import graphql.relay.Edge; import graphql.relay.Edge; import graphql.schema.DataFetcher; import graphql.schema.TypeResolver; @@ -23,12 +21,8 @@ import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRoutingErrorCode; import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLTransitMode; import org.opentripplanner.apis.gtfs.model.RideHailingProvider; -import org.opentripplanner.apis.gtfs.model.RouteTypeModel; -import org.opentripplanner.apis.gtfs.model.StopOnRouteModel; -import org.opentripplanner.apis.gtfs.model.StopOnTripModel; import org.opentripplanner.apis.gtfs.model.StopPosition; import org.opentripplanner.apis.gtfs.model.TripOccupancy; -import org.opentripplanner.apis.gtfs.model.UnknownModel; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.ext.ridehailing.model.RideEstimate; import org.opentripplanner.model.StopTimesInPattern; @@ -50,8 +44,6 @@ import org.opentripplanner.routing.graphfinder.PatternAtStop; import org.opentripplanner.routing.graphfinder.PlaceAtDistance; import org.opentripplanner.routing.vehicle_parking.VehicleParking; -import org.opentripplanner.routing.vehicle_parking.VehicleParking; -import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; import org.opentripplanner.routing.vehicle_parking.VehicleParkingState; import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle; @@ -62,7 +54,6 @@ import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; -import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle; import org.opentripplanner.transit.model.basic.Money; import org.opentripplanner.transit.model.network.Route; @@ -1244,10 +1235,6 @@ public interface GraphQLElevationProfileComponent { public DataFetcher elevation(); } - /** - * This type is only here for backwards-compatibility and this API will never return it anymore. - * Please use the leg's `fareProducts` instead. - */ public interface GraphQLFare { public DataFetcher cents(); @@ -1258,10 +1245,7 @@ public interface GraphQLFare { public DataFetcher type(); } - /** - * This type is only here for backwards-compatibility and this API will never return it anymore. - * Please use the leg's `fareProducts` instead. - */ + /** Component of the fare (i.e. ticket) for a part of the itinerary */ public interface GraphQLFareComponent { public DataFetcher cents(); diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java index ffe37e77284..ecc038fec18 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java @@ -1,7 +1,6 @@ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; From e8f94883577d846917911698c36e406a53d9b023 Mon Sep 17 00:00:00 2001 From: sharhio Date: Thu, 21 Mar 2024 14:20:16 +0200 Subject: [PATCH 15/17] docs generation --- docs/sandbox/MapboxVectorTilesApi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sandbox/MapboxVectorTilesApi.md b/docs/sandbox/MapboxVectorTilesApi.md index 11a09176d3b..a78b47e92ae 100644 --- a/docs/sandbox/MapboxVectorTilesApi.md +++ b/docs/sandbox/MapboxVectorTilesApi.md @@ -110,7 +110,7 @@ The feature must be configured in `router-config.json` as follows "mapper": "DigitransitRealtime", "maxZoom": 20, "minZoom": 14, - "cacheMaxSeconds": 600 + "cacheMaxSeconds": 60 }, // This exists for backwards compatibility. At some point, we might want // to add a new real-time parking mapper with better translation support From b4a0f8ec4d0b9421d8bbcaabe3d89f6c37ca7b66 Mon Sep 17 00:00:00 2001 From: sharhio Date: Mon, 25 Mar 2024 10:01:53 +0200 Subject: [PATCH 16/17] changelog entry --- doc-templates/sandbox/MapboxVectorTilesApi.md | 1 + docs/sandbox/MapboxVectorTilesApi.md | 1 + 2 files changed, 2 insertions(+) diff --git a/doc-templates/sandbox/MapboxVectorTilesApi.md b/doc-templates/sandbox/MapboxVectorTilesApi.md index d64d9700da4..6468f56db32 100644 --- a/doc-templates/sandbox/MapboxVectorTilesApi.md +++ b/doc-templates/sandbox/MapboxVectorTilesApi.md @@ -212,3 +212,4 @@ key, and a function to create the mapper, with a `Graph` object as a parameter, * Added a new Digitransit vehicle parking mapper with no real-time information and less fields - 2024-01-22: Make `basePath` configurable [#5627](https://github.com/opentripplanner/OpenTripPlanner/pull/5627) - 2024-02-27: Add layer for flex zones [#5704](https://github.com/opentripplanner/OpenTripPlanner/pull/5704) +- 2024-03-25: Add layer for realtime stops [#5743](https://github.com/opentripplanner/OpenTripPlanner/pull/5743) diff --git a/docs/sandbox/MapboxVectorTilesApi.md b/docs/sandbox/MapboxVectorTilesApi.md index a78b47e92ae..62f3bd36c38 100644 --- a/docs/sandbox/MapboxVectorTilesApi.md +++ b/docs/sandbox/MapboxVectorTilesApi.md @@ -307,3 +307,4 @@ key, and a function to create the mapper, with a `Graph` object as a parameter, * Added a new Digitransit vehicle parking mapper with no real-time information and less fields - 2024-01-22: Make `basePath` configurable [#5627](https://github.com/opentripplanner/OpenTripPlanner/pull/5627) - 2024-02-27: Add layer for flex zones [#5704](https://github.com/opentripplanner/OpenTripPlanner/pull/5704) +- 2024-03-25: Add layer for realtime stops [#5743](https://github.com/opentripplanner/OpenTripPlanner/pull/5743) From e6c31e63e8ce73eb1dc628e62cc46bd00aec9bfe Mon Sep 17 00:00:00 2001 From: sharhio Date: Mon, 25 Mar 2024 13:25:58 +0200 Subject: [PATCH 17/17] removed old string return value --- .../DigitransitRealtimeStopPropertyMapper.java | 8 +------- .../stops/DigitransitStopPropertyMapper.java | 17 ++++++----------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java index 47cf7210274..55d67d28d71 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java @@ -35,13 +35,7 @@ protected Collection map(RegularStop stop) { Collection sharedKeyValues = getBaseKeyValues(stop, i18NStringMapper, transitService); return ListUtils.combine( sharedKeyValues, - List.of( - new KeyValue("closedByServiceAlert", noServiceAlert), - new KeyValue( - "parentStation", - stop.getParentStation() != null ? stop.getParentStation().getId() : null - ) - ) + List.of(new KeyValue("closedByServiceAlert", noServiceAlert)) ); } } diff --git a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java index e9c40e43ba8..643ed63b7f8 100644 --- a/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java +++ b/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitStopPropertyMapper.java @@ -35,16 +35,7 @@ protected static DigitransitStopPropertyMapper create( @Override protected Collection map(RegularStop stop) { - Collection sharedKeyValues = getBaseKeyValues(stop, i18NStringMapper, transitService); - return ListUtils.combine( - sharedKeyValues, - List.of( - new KeyValue( - "parentStation", - stop.getParentStation() != null ? stop.getParentStation().getId() : "null" - ) - ) - ); + return getBaseKeyValues(stop, i18NStringMapper, transitService); } protected static Collection getBaseKeyValues( @@ -59,7 +50,11 @@ protected static Collection getBaseKeyValues( new KeyValue("platform", stop.getPlatformCode()), new KeyValue("desc", i18NStringMapper.mapToApi(stop.getDescription())), new KeyValue("type", getType(transitService, stop)), - new KeyValue("routes", getRoutes(transitService, stop)) + new KeyValue("routes", getRoutes(transitService, stop)), + new KeyValue( + "parentStation", + stop.getParentStation() != null ? stop.getParentStation().getId() : null + ) ); }