Skip to content

Commit

Permalink
Take missing capacity into account
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jul 15, 2024
1 parent 506c90f commit ac046c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,15 @@ private void addEntriesToGroupMapperForPostProcessingLater() {
}

private void mapVehicleParkings() {
var mapper = new VehicleParkingMapper(idFactory);
var mapper = new VehicleParkingMapper(idFactory, issueStore);
currentNetexIndex
.getParkingsById()
.localKeys()
.forEach(id -> {
var parking = mapper.map(currentNetexIndex.getParkingsById().lookup(id));
transitBuilder.vehicleParkings().add(parking);
if (parking != null) {
transitBuilder.vehicleParkings().add(parking);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static org.rutebanken.netex.model.ParkingVehicleEnumeration.E_CYCLE;
import static org.rutebanken.netex.model.ParkingVehicleEnumeration.PEDAL_CYCLE;

import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.netex.mapping.support.FeedScopedIdFactory;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces;
Expand All @@ -26,16 +26,23 @@ class VehicleParkingMapper {
E_CYCLE,
CYCLE
);
private final DataImportIssueStore issueStore;

VehicleParkingMapper(FeedScopedIdFactory idFactory) {
VehicleParkingMapper(FeedScopedIdFactory idFactory, DataImportIssueStore issueStore) {
this.idFactory = idFactory;
this.issueStore = issueStore;
}

Collection<VehicleParking> map(Collection<Parking> parkings) {
return parkings.stream().map(this::map).collect(Collectors.toUnmodifiableSet());
}

@Nullable
VehicleParking map(Parking parking) {
if (parking.getTotalCapacity() == null) {
issueStore.add(
"MissingParkingCapacity",
"NeTEx Parking %s does not contain totalCapacity",
parking.getId()
);
return null;
}
return VehicleParking
.builder()
.id(idFactory.createId(parking.getId()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.netex.mapping;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.rutebanken.netex.model.ParkingVehicleEnumeration.AGRICULTURAL_VEHICLE;
import static org.rutebanken.netex.model.ParkingVehicleEnumeration.ALL_PASSENGER_VEHICLES;
Expand All @@ -13,9 +14,13 @@
import java.math.BigInteger;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.opentripplanner.framework.geometry.WgsCoordinate;
import org.opentripplanner.graph_builder.issue.api.DataImportIssue;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.issue.service.DefaultDataImportIssueStore;
import org.opentripplanner.netex.mapping.support.FeedScopedIdFactory;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces;
Expand All @@ -27,18 +32,14 @@

class VehicleParkingMapperTest {

private static final VehicleParkingMapper MAPPER = new VehicleParkingMapper(
new FeedScopedIdFactory("parking")
);

public static List<Set<ParkingVehicleEnumeration>> carCases() {
return List.of(Set.of(), Set.of(CAR, AGRICULTURAL_VEHICLE, ALL_PASSENGER_VEHICLES));
}

@ParameterizedTest
@MethodSource("carCases")
void mapCarLot(Set<ParkingVehicleEnumeration> vehicleTypes) {
var vp = MAPPER.map(parking(vehicleTypes));
var vp = mapper().map(parking(vehicleTypes));
assertCommonProperties(vp);
assertTrue(vp.hasAnyCarPlaces());
assertEquals(VehicleParkingSpaces.builder().carSpaces(10).build(), vp.getCapacity());
Expand All @@ -51,12 +52,33 @@ public static List<Set<ParkingVehicleEnumeration>> bicycleCases() {
@ParameterizedTest
@MethodSource("bicycleCases")
void mapBicycleLot(Set<ParkingVehicleEnumeration> vehicleTypes) {
var vp = MAPPER.map(parking(vehicleTypes));
var vp = mapper().map(parking(vehicleTypes));
assertCommonProperties(vp);
assertTrue(vp.hasBicyclePlaces());
assertEquals(VehicleParkingSpaces.builder().bicycleSpaces(10).build(), vp.getCapacity());
}

@Test
void dropEmptyCapacity() {
var parking = parking(Set.of(CAR));
parking.setTotalCapacity(null);
var issueStore = new DefaultDataImportIssueStore();
var vp = mapper(issueStore).map(parking);
assertNull(vp);
assertEquals(
List.of("MissingParkingCapacity"),
issueStore.listIssues().stream().map(DataImportIssue::getType).toList()
);
}

private VehicleParkingMapper mapper() {
return mapper(DataImportIssueStore.NOOP);
}

private static VehicleParkingMapper mapper(DataImportIssueStore issueStore) {
return new VehicleParkingMapper(new FeedScopedIdFactory("parking"), issueStore);
}

private static void assertCommonProperties(VehicleParking vp) {
assertEquals("A name", vp.getName().toString());
assertEquals(new WgsCoordinate(10, 20), vp.getCoordinate());
Expand Down

0 comments on commit ac046c6

Please sign in to comment.