Skip to content

Commit 6b745da

Browse files
Merge pull request opentripplanner#7267 from entur/CarpoolingDepricatePolygon
Deprecated polygon, added centroid
2 parents 62750db + 77d3f20 commit 6b745da

23 files changed

+863
-347
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
package org.opentripplanner.ext.carpooling;
2+
3+
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_EAST;
4+
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTH;
5+
6+
import java.math.BigDecimal;
7+
import java.math.BigInteger;
8+
import java.time.ZonedDateTime;
9+
import java.util.Arrays;
10+
import net.opengis.gml._3.AbstractRingPropertyType;
11+
import net.opengis.gml._3.DirectPositionListType;
12+
import net.opengis.gml._3.LinearRingType;
13+
import net.opengis.gml._3.ObjectFactory;
14+
import net.opengis.gml._3.PolygonType;
15+
import org.opentripplanner.street.geometry.WgsCoordinate;
16+
import uk.org.siri.siri21.AimedFlexibleArea;
17+
import uk.org.siri.siri21.CircularAreaStructure;
18+
import uk.org.siri.siri21.EstimatedCall;
19+
import uk.org.siri.siri21.EstimatedVehicleJourney;
20+
import uk.org.siri.siri21.NaturalLanguageStringStructure;
21+
import uk.org.siri.siri21.OperatorRefStructure;
22+
import uk.org.siri.siri21.StopAssignmentStructure;
23+
24+
public class CarpoolEstimatedVehicleJourneyData {
25+
26+
private static final String FIRST_STOP_POLYGON =
27+
"10.813864907662264 59.904961620490184 10.818271230878196 59.903856857974404 10.818498026925795 59.90393809176436 10.818604482213118 59.9039055982723 10.818386943147004 59.90379187079944 10.818215688988204 59.90380579663352 10.81386953615231 59.90490591905822 10.813864907662264 59.904961620490184";
28+
private static final String LAST_STOP_POLYGON =
29+
"10.197976677739746 59.74492585818382 10.19775667855555 59.74465335895027 10.197230513839912 59.74475958772939 10.19714251416596 59.74464319791892 10.197628345697694 59.744487087140186 10.197844678229416 59.744667214897106 10.198856674477867 59.74438085749492 10.19892634088606 59.744463993767596 10.198640341946088 59.74453696877012 10.19883100790608 59.74475404536645 10.197976677739746 59.74492585818382";
30+
31+
public static EstimatedVehicleJourney arrivalIsAfterDepartureTime() {
32+
var journey = new EstimatedVehicleJourney();
33+
journey.setEstimatedCalls(new EstimatedVehicleJourney.EstimatedCalls());
34+
var first = new EstimatedCall();
35+
first.setAimedDepartureTime(ZonedDateTime.now().plusDays(1));
36+
var last = new EstimatedCall();
37+
last.setAimedArrivalTime(ZonedDateTime.now());
38+
journey.getEstimatedCalls().getEstimatedCalls().add(first);
39+
journey.getEstimatedCalls().getEstimatedCalls().add(last);
40+
41+
return journey;
42+
}
43+
44+
public static EstimatedVehicleJourney lessThanTwoStops() {
45+
var journey = new EstimatedVehicleJourney();
46+
journey.setEstimatedCalls(new EstimatedVehicleJourney.EstimatedCalls());
47+
journey.getEstimatedCalls().getEstimatedCalls().add(new EstimatedCall());
48+
49+
return journey;
50+
}
51+
52+
public static EstimatedVehicleJourney minimalCompleteJourney() {
53+
var journey = new EstimatedVehicleJourney();
54+
var operator = new OperatorRefStructure();
55+
operator.setValue("ENT");
56+
journey.setEstimatedVehicleJourneyCode("unittest");
57+
journey.setOperatorRef(operator);
58+
59+
var firstStop = forPoint(OSLO_EAST);
60+
firstStop.setAimedDepartureTime(ZonedDateTime.now());
61+
var firstName = new NaturalLanguageStringStructure();
62+
firstName.setValue("First stop");
63+
firstStop.getStopPointNames().add(firstName);
64+
var lastStop = forPoint(OSLO_NORTH);
65+
lastStop.setAimedDepartureTime(ZonedDateTime.now());
66+
var lastName = new NaturalLanguageStringStructure();
67+
lastName.setValue("Last stop");
68+
lastStop.getStopPointNames().add(lastName);
69+
lastStop.setAimedArrivalTime(ZonedDateTime.now().plusMinutes(45));
70+
71+
journey.setEstimatedCalls(new EstimatedVehicleJourney.EstimatedCalls());
72+
journey.getEstimatedCalls().getEstimatedCalls().add(firstStop);
73+
journey.getEstimatedCalls().getEstimatedCalls().add(lastStop);
74+
75+
return journey;
76+
}
77+
78+
public static EstimatedVehicleJourney minimalCompleteJourneyWithPolygon() {
79+
var journey = new EstimatedVehicleJourney();
80+
var operator = new OperatorRefStructure();
81+
operator.setValue("ENT");
82+
journey.setEstimatedVehicleJourneyCode("unittest");
83+
journey.setOperatorRef(operator);
84+
85+
var firstStop = forPolygon(FIRST_STOP_POLYGON);
86+
firstStop.setAimedDepartureTime(ZonedDateTime.now());
87+
var firstName = new NaturalLanguageStringStructure();
88+
firstName.setValue("First stop");
89+
firstStop.getStopPointNames().add(firstName);
90+
91+
var lastStop = forPolygon(LAST_STOP_POLYGON);
92+
lastStop.setAimedDepartureTime(ZonedDateTime.now());
93+
var lastName = new NaturalLanguageStringStructure();
94+
lastName.setValue("Last stop");
95+
lastStop.getStopPointNames().add(lastName);
96+
lastStop.setAimedArrivalTime(ZonedDateTime.now().plusMinutes(45));
97+
98+
journey.setEstimatedCalls(new EstimatedVehicleJourney.EstimatedCalls());
99+
journey.getEstimatedCalls().getEstimatedCalls().add(firstStop);
100+
journey.getEstimatedCalls().getEstimatedCalls().add(lastStop);
101+
102+
return journey;
103+
}
104+
105+
public static EstimatedVehicleJourney tripHasAimedTimesOnly() {
106+
var journey = minimalCompleteJourney();
107+
108+
var firstStop = journey.getEstimatedCalls().getEstimatedCalls().getFirst();
109+
var lastStop = journey.getEstimatedCalls().getEstimatedCalls().getLast();
110+
111+
firstStop.setAimedDepartureTime(ZonedDateTime.now());
112+
firstStop.setExpectedDepartureTime(null);
113+
lastStop.setAimedArrivalTime(ZonedDateTime.now().plusMinutes(45));
114+
lastStop.setExpectedArrivalTime(null);
115+
116+
return journey;
117+
}
118+
119+
public static EstimatedVehicleJourney tripHasExpectedTimesOnly() {
120+
var journey = minimalCompleteJourney();
121+
122+
var firstStop = journey.getEstimatedCalls().getEstimatedCalls().getFirst();
123+
var lastStop = journey.getEstimatedCalls().getEstimatedCalls().getLast();
124+
125+
firstStop.setAimedDepartureTime(null);
126+
firstStop.setExpectedDepartureTime(ZonedDateTime.now());
127+
lastStop.setAimedArrivalTime(null);
128+
lastStop.setExpectedArrivalTime(ZonedDateTime.now().plusMinutes(45));
129+
130+
return journey;
131+
}
132+
133+
public static EstimatedVehicleJourney stopTimesAreOutOfOrder() {
134+
var journey = new EstimatedVehicleJourney();
135+
journey.setEstimatedCalls(new EstimatedVehicleJourney.EstimatedCalls());
136+
var first = new EstimatedCall();
137+
first.setAimedDepartureTime(ZonedDateTime.now());
138+
var middle = new EstimatedCall();
139+
middle.setAimedArrivalTime(ZonedDateTime.now().plusDays(1));
140+
var last = new EstimatedCall();
141+
last.setAimedArrivalTime(ZonedDateTime.now());
142+
journey.getEstimatedCalls().getEstimatedCalls().add(first);
143+
journey.getEstimatedCalls().getEstimatedCalls().add(middle);
144+
journey.getEstimatedCalls().getEstimatedCalls().add(last);
145+
146+
return journey;
147+
}
148+
149+
static EstimatedCall forPoint(WgsCoordinate coordinate) {
150+
var call = new EstimatedCall();
151+
call.setAimedDepartureTime(ZonedDateTime.now());
152+
var circularArea = new CircularAreaStructure();
153+
circularArea.setLatitude(BigDecimal.valueOf(coordinate.latitude()));
154+
circularArea.setLongitude(BigDecimal.valueOf(coordinate.longitude()));
155+
circularArea.setRadius(BigInteger.valueOf(1));
156+
var stop = new StopAssignmentStructure();
157+
var flexibleArea = new AimedFlexibleArea();
158+
flexibleArea.setCircularArea(circularArea);
159+
stop.setExpectedFlexibleArea(flexibleArea);
160+
call.getDepartureStopAssignments().add(stop);
161+
162+
return call;
163+
}
164+
165+
static EstimatedCall forPolygon(String posList) {
166+
var call = new EstimatedCall();
167+
call.setAimedDepartureTime(ZonedDateTime.now());
168+
169+
var stop = new StopAssignmentStructure();
170+
var flexibleStop = poslistToAimedFlexibleArea(posList);
171+
stop.setExpectedFlexibleArea(flexibleStop);
172+
173+
call.getDepartureStopAssignments().add(stop);
174+
return call;
175+
}
176+
177+
static AimedFlexibleArea poslistToAimedFlexibleArea(String coordinates) {
178+
var gmlFactory = new ObjectFactory();
179+
180+
var poslist = Arrays.stream(coordinates.trim().split("\\s+")).map(Double::valueOf).toList();
181+
var polygon = new PolygonType().withExterior(
182+
new AbstractRingPropertyType().withAbstractRing(
183+
gmlFactory.createLinearRing(
184+
new LinearRingType().withPosList(new DirectPositionListType().withValue(poslist))
185+
)
186+
)
187+
);
188+
189+
var area = new AimedFlexibleArea();
190+
area.setPolygon(polygon);
191+
return area;
192+
}
193+
}

application/src/test/java/org/opentripplanner/ext/carpooling/CarpoolGraphPathBuilder.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/CarpoolGraphPathBuilder.java

File renamed without changes.

application/src/test/java/org/opentripplanner/ext/carpooling/CarpoolTestCoordinates.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/CarpoolTestCoordinates.java

File renamed without changes.

application/src/test/java/org/opentripplanner/ext/carpooling/TestCarpoolTripBuilder.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/CarpoolTripTestData.java

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
import org.opentripplanner.ext.carpooling.model.CarpoolStopType;
1111
import org.opentripplanner.ext.carpooling.model.CarpoolTrip;
1212
import org.opentripplanner.street.geometry.WgsCoordinate;
13-
import org.opentripplanner.transit.model.site.AreaStop;
1413

1514
/**
1615
* Builder utility for creating test CarpoolTrip instances without requiring full Graph infrastructure.
1716
*/
18-
public class TestCarpoolTripBuilder {
17+
public class CarpoolTripTestData {
1918

2019
private static final AtomicInteger ID_COUNTER = new AtomicInteger(0);
2120
private static final AtomicInteger AREA_STOP_COUNTER = new AtomicInteger(0);
@@ -62,16 +61,16 @@ public static CarpoolTrip createTripWithStops(
6261
for (int i = 0; i < intermediateStops.size(); i++) {
6362
CarpoolStop intermediate = intermediateStops.get(i);
6463
allStops.add(
65-
new CarpoolStop(
66-
intermediate.getAreaStop(),
67-
intermediate.getCarpoolStopType(),
68-
intermediate.getPassengerDelta(),
69-
i + 1,
70-
intermediate.getExpectedArrivalTime(),
71-
intermediate.getAimedArrivalTime(),
72-
intermediate.getExpectedDepartureTime(),
73-
intermediate.getAimedDepartureTime()
74-
)
64+
CarpoolStop.of(intermediate.getId(), () -> intermediate.getIndex() + 1)
65+
.withCoordinate(intermediate.getCoordinate())
66+
.withCarpoolStopType(intermediate.getCarpoolStopType())
67+
.withExpectedDepartureTime(intermediate.getExpectedDepartureTime())
68+
.withAimedArrivalTime(intermediate.getAimedArrivalTime())
69+
.withExpectedArrivalTime(intermediate.getExpectedArrivalTime())
70+
.withAimedArrivalTime(intermediate.getAimedDepartureTime())
71+
.withSequenceNumber(intermediate.getSequenceNumber() + 1)
72+
.withPassengerDelta(intermediate.getPassengerDelta())
73+
.build()
7574
);
7675
}
7776

@@ -155,16 +154,14 @@ public static CarpoolStop createStopAt(int sequence, WgsCoordinate location) {
155154
* Creates a CarpoolStop with all parameters.
156155
*/
157156
public static CarpoolStop createStopAt(int sequence, int passengerDelta, WgsCoordinate location) {
158-
return new CarpoolStop(
159-
createAreaStop(location),
160-
CarpoolStopType.PICKUP_AND_DROP_OFF,
161-
passengerDelta,
162-
sequence,
163-
null,
164-
null,
165-
null,
166-
null
167-
);
157+
return CarpoolStop.of(
158+
FeedScopedId.ofNullable("TEST", "area-" + AREA_STOP_COUNTER.incrementAndGet()),
159+
AREA_STOP_COUNTER::getAndIncrement
160+
)
161+
.withCoordinate(location)
162+
.withSequenceNumber(sequence)
163+
.withPassengerDelta(passengerDelta)
164+
.build();
168165
}
169166

170167
/**
@@ -182,16 +179,11 @@ public static CarpoolStop createOriginStopWithTime(
182179
ZonedDateTime expectedDepartureTime,
183180
ZonedDateTime aimedDepartureTime
184181
) {
185-
return new CarpoolStop(
186-
createAreaStop(location),
187-
CarpoolStopType.PICKUP_ONLY,
188-
0,
189-
0,
190-
null,
191-
null,
192-
expectedDepartureTime,
193-
aimedDepartureTime
194-
);
182+
return CarpoolStop.of(FeedScopedId.ofNullable("TEST", "area-0"), () -> 0)
183+
.withCoordinate(location)
184+
.withExpectedDepartureTime(expectedDepartureTime)
185+
.withAimedDepartureTime(aimedDepartureTime)
186+
.build();
195187
}
196188

197189
/**
@@ -210,33 +202,15 @@ public static CarpoolStop createDestinationStopWithTime(
210202
ZonedDateTime expectedArrivalTime,
211203
ZonedDateTime aimedArrivalTime
212204
) {
213-
return new CarpoolStop(
214-
createAreaStop(location),
215-
CarpoolStopType.DROP_OFF_ONLY,
216-
0,
217-
sequenceNumber,
218-
expectedArrivalTime,
219-
aimedArrivalTime,
220-
null,
221-
null
222-
);
223-
}
224-
225-
/**
226-
* Creates a minimal AreaStop for testing.
227-
*/
228-
private static AreaStop createAreaStop(WgsCoordinate coordinate) {
229-
// Create a simple point geometry at the coordinate
230-
var geometryFactory = new org.locationtech.jts.geom.GeometryFactory();
231-
var point = geometryFactory.createPoint(
232-
new org.locationtech.jts.geom.Coordinate(coordinate.longitude(), coordinate.latitude())
233-
);
234-
235-
return AreaStop.of(
205+
return CarpoolStop.of(
236206
FeedScopedId.ofNullable("TEST", "area-" + AREA_STOP_COUNTER.incrementAndGet()),
237207
AREA_STOP_COUNTER::getAndIncrement
238208
)
239-
.withGeometry(point)
209+
.withCoordinate(location)
210+
.withCarpoolStopType(CarpoolStopType.DROP_OFF_ONLY)
211+
.withSequenceNumber(sequenceNumber)
212+
.withExpectedArrivalTime(expectedArrivalTime)
213+
.withAimedArrivalTime(aimedArrivalTime)
240214
.build();
241215
}
242216
}

application/src/test/java/org/opentripplanner/ext/carpooling/constraints/PassengerDelayConstraintsTest.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/constraints/PassengerDelayConstraintsTest.java

File renamed without changes.

application/src/test/java/org/opentripplanner/ext/carpooling/filter/CapacityFilterTest.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/filter/CapacityFilterTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTH;
88
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_SOUTH;
99
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_WEST;
10-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createDestinationStop;
11-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createOriginStop;
12-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createStop;
13-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createTripWithCapacity;
14-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createTripWithStops;
10+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createDestinationStop;
11+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createOriginStop;
12+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createStop;
13+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createTripWithCapacity;
14+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createTripWithStops;
1515

1616
import java.util.List;
1717
import org.junit.jupiter.api.BeforeEach;

application/src/test/java/org/opentripplanner/ext/carpooling/filter/DirectionalCompatibilityFilterTest.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/filter/DirectionalCompatibilityFilterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_EAST;
1212
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTH;
1313
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTHEAST;
14-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createSimpleTrip;
15-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createStopAt;
16-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createTripWithStops;
14+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createSimpleTrip;
15+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createStopAt;
16+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createTripWithStops;
1717

1818
import java.util.List;
1919
import org.junit.jupiter.api.BeforeEach;

application/src/test/java/org/opentripplanner/ext/carpooling/filter/DistanceBasedFilterTest.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/filter/DistanceBasedFilterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.LAKE_WEST;
1010
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_CENTER;
1111
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTH;
12-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createSimpleTrip;
13-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createStopAt;
14-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createTripWithStops;
12+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createSimpleTrip;
13+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createStopAt;
14+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createTripWithStops;
1515

1616
import org.junit.jupiter.api.BeforeEach;
1717
import org.junit.jupiter.api.Test;

application/src/test/java/org/opentripplanner/ext/carpooling/filter/FilterChainTest.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/filter/FilterChainTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_EAST;
77
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTH;
88
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_WEST;
9-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createDestinationStop;
10-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createOriginStop;
11-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createSimpleTrip;
12-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createTripWithCapacity;
9+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createDestinationStop;
10+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createOriginStop;
11+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createSimpleTrip;
12+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createTripWithCapacity;
1313

1414
import java.util.List;
1515
import org.junit.jupiter.api.Test;

application/src/test/java/org/opentripplanner/ext/carpooling/filter/TimeBasedFilterTest.java renamed to application/src/ext-test/java/org/opentripplanner/ext/carpooling/filter/TimeBasedFilterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_EAST;
77
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTH;
88
import static org.opentripplanner.ext.carpooling.CarpoolTestCoordinates.OSLO_NORTHEAST;
9-
import static org.opentripplanner.ext.carpooling.TestCarpoolTripBuilder.createSimpleTripWithTime;
9+
import static org.opentripplanner.ext.carpooling.CarpoolTripTestData.createSimpleTripWithTime;
1010

1111
import java.time.Duration;
1212
import java.time.ZonedDateTime;

0 commit comments

Comments
 (0)