|
| 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 | +} |
0 commit comments