use of uk.org.siri.siri20.NaturalLanguageStringStructure in project onebusaway-application-modules by camsys.
the class StopPointsActionTest method initialize.
@Before
public void initialize() throws Exception {
// Agencies
Map<String, List<CoordinateBounds>> agencies = new HashMap<String, List<CoordinateBounds>>();
agencies.put("1", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.410813, -122.038662, 47.810813, -122.638662))));
agencies.put("3", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(0.0, 0.0, 0.0, 0.0))));
agencies.put("40", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.510813, -122.138662, 47.710813, -122.538662))));
// Route Bean
Builder routeBuilder = RouteBean.builder();
routeBuilder.setAgency(new AgencyBean());
routeBuilder.setId("1_100194");
routeBean = routeBuilder.create();
// Route Bean List
routes = new ArrayList<RouteBean>(1);
routes.add(routeBean);
// Stop Bean
stopBean = new StopBean();
stopBean.setId("1_430");
stopBean.setName("3rd Ave & Pine St");
stopBean.setLon(-122.338662);
stopBean.setLat(47.610813);
stopBean.setRoutes(routes);
// Stop Bean List
stops = new ArrayList<StopBean>(1);
stops.add(stopBean);
// Stop Group
stopIds = new ArrayList<String>(1);
stopIds.add(stopBean.getId());
stopGroupName = new NameBean("destination", "Destination");
stopGroup = new StopGroupBean();
stopGroup.setId("0");
stopGroup.setStopIds(stopIds);
stopGroup.setName(stopGroupName);
// Stop Group List
stopGroups = new ArrayList<StopGroupBean>(1);
stopGroups.add(stopGroup);
// Stop Grouping
stopGrouping = new StopGroupingBean();
stopGrouping.setStopGroups(stopGroups);
// Stop Grouping List
List<StopGroupingBean> stopGroupings = new ArrayList<StopGroupingBean>(1);
stopGroupings.add(stopGrouping);
// Stops For Route
stopsForRouteBean = new StopsForRouteBean();
stopsForRouteBean.setRoute(routeBean);
stopsForRouteBean.setStopGroupings(stopGroupings);
stopsForRouteBean.setStops(stops);
// LineDirectionStructure
LineDirectionStructure lds = new LineDirectionStructure();
DirectionRefStructure drs = new DirectionRefStructure();
LineRefStructure lrs = new LineRefStructure();
lds.setDirectionRef(drs);
lds.setLineRef(lrs);
drs.setValue("0");
lrs.setValue("1_100194");
// Location Structure
LocationStructure ls = new LocationStructure();
BigDecimal lat = new BigDecimal(47.610813);
BigDecimal lon = new BigDecimal(-122.338662);
ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
// StopNames
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue("3rd Ave & Pine St");
List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
stopNames.add(stopName);
// StopPointRef
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue("1_430");
// Monitored
Boolean monitored = true;
// AnnotatedStopPointStructure
AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
mockStopPoint.setLocation(ls);
mockStopPoint.getStopName().add(stopName);
mockStopPoint.setStopPointRef(stopPointRef);
mockStopPoint.setMonitored(monitored);
List<AnnotatedStopPointStructure> mockStopPoints = new ArrayList<AnnotatedStopPointStructure>(1);
mockStopPoints.add(mockStopPoint);
Map<Boolean, List<AnnotatedStopPointStructure>> annotatedStopPointMap = new HashMap<Boolean, List<AnnotatedStopPointStructure>>();
annotatedStopPointMap.put(true, mockStopPoints);
when(realtimeService.getAnnotatedStopPointStructures(anyListOf(String.class), anyListOf(AgencyAndId.class), any(DetailLevel.class), anyLong(), anyMapOf(Filters.class, String.class))).thenReturn(annotatedStopPointMap);
// XML Serializer
SiriXmlSerializerV2 serializer = new SiriXmlSerializerV2();
when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
when(transitDataService.getRouteForId("1_430")).thenReturn(routeBean);
lenient().when(transitDataService.getStopsForRoute("1_430")).thenReturn(stopsForRouteBean);
lenient().when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
lenient().when(transitDataService.getAgencyIdsWithCoverageArea()).thenReturn(agencies);
}
use of uk.org.siri.siri20.NaturalLanguageStringStructure in project OpenTripPlanner by opentripplanner.
the class SiriTimetableSnapshotSource method applyVehicleMonitoring.
/**
* Method to apply a trip update list to the most recent version of the timetable snapshot.
*
* @param graph graph to update (needed for adding/changing stop patterns)
* @param fullDataset true iff the list with updates represent all updates that are active right
* now, i.e. all previous updates should be disregarded
* @param updates SIRI VehicleMonitoringDeliveries that should be applied atomically
*/
public void applyVehicleMonitoring(final Graph graph, final String feedId, final boolean fullDataset, final List<VehicleMonitoringDeliveryStructure> updates) {
if (updates == null) {
LOG.warn("updates is null");
return;
}
// Acquire lock on buffer
bufferLock.lock();
try {
if (fullDataset) {
// Remove all updates from the buffer
buffer.clear(feedId);
}
for (VehicleMonitoringDeliveryStructure vmDelivery : updates) {
ServiceDate serviceDate = new ServiceDate();
List<VehicleActivityStructure> activities = vmDelivery.getVehicleActivities();
if (activities != null) {
// Handle activities
LOG.info("Handling {} VM-activities.", activities.size());
int handledCounter = 0;
int skippedCounter = 0;
for (VehicleActivityStructure activity : activities) {
boolean handled = handleModifiedTrip(graph, feedId, activity, serviceDate);
if (handled) {
handledCounter++;
} else {
skippedCounter++;
}
}
LOG.info("Applied {} VM-activities, skipped {}.", handledCounter, skippedCounter);
}
List<VehicleActivityCancellationStructure> cancellations = vmDelivery.getVehicleActivityCancellations();
if (cancellations != null && !cancellations.isEmpty()) {
// Handle cancellations
LOG.info("TODO: Handle {} cancellations.", cancellations.size());
}
List<NaturalLanguageStringStructure> notes = vmDelivery.getVehicleActivityNotes();
if (notes != null && !notes.isEmpty()) {
// Handle notes
LOG.info("TODO: Handle {} notes.", notes.size());
}
}
// Make sure that the public (locking) getTimetableSnapshot function is not called.
if (purgeExpiredData) {
final boolean modified = purgeExpiredData();
getTimetableSnapshot(modified);
} else {
getTimetableSnapshot(false);
}
} finally {
// Always release lock
bufferLock.unlock();
if (keepLogging) {
LOG.info("Reducing SIRI-VM logging until restart");
keepLogging = false;
}
}
}
use of uk.org.siri.siri20.NaturalLanguageStringStructure in project onebusaway-application-modules by camsys.
the class SiriSupportV2 method fillAnnotatedLineStructure.
public static boolean fillAnnotatedLineStructure(AnnotatedLineStructure annotatedLineStructure, RouteResult routeResult, Map<Filters, String> filters, DetailLevel detailLevel, long currentTime) {
Directions directions = new Directions();
// Set Line Value
LineRefStructure line = new LineRefStructure();
line.setValue(routeResult.getId());
NaturalLanguageStringStructure lineName = new NaturalLanguageStringStructure();
lineName.setValue(routeResult.getShortName());
// DETAIL - minimum: Return only the name and identifier of stops
// ideally, this would return only stops with scheduled service
annotatedLineStructure.setLineRef(line);
annotatedLineStructure.getLineName().add(lineName);
annotatedLineStructure.setDirections(directions);
annotatedLineStructure.setMonitored(true);
// Loop through Direction Ids
for (RouteDirection direction : routeResult.getDirections()) {
// Check for existing stops in direction
if (direction == null | direction.getStops().size() == 0)
continue;
String directionId = direction.getDirectionId();
// Journey patterns - holds stop points for direction
JourneyPattern pattern = new JourneyPattern();
JourneyPatterns patterns = new JourneyPatterns();
// Directions
DirectionRefStructure dirRefStructure = new DirectionRefStructure();
dirRefStructure.setValue(directionId);
RouteDirectionStructure routeDirectionStructure = new RouteDirectionStructure();
NaturalLanguageStringStructure directionName = new NaturalLanguageStringStructure();
directionName.setValue(direction.getDestination());
routeDirectionStructure.getDirectionName().add(directionName);
directions.getDirection().add(routeDirectionStructure);
// Destination
Destinations destinations = new Destinations();
AnnotatedDestinationStructure annotatedDest = new AnnotatedDestinationStructure();
DestinationRefStructure destRef = new DestinationRefStructure();
destRef.setValue(direction.getDestination());
annotatedDest.setDestinationRef(destRef);
destinations.getDestination().add(annotatedDest);
// Stops
StopsInPattern stopsInPattern = new StopsInPattern();
List<StopOnRoute> scheduledStops = new ArrayList<StopOnRoute>();
List<StopOnRoute> allStops = new ArrayList<StopOnRoute>();
// Categorize by Scheduled and Unscheduled Stops
for (StopOnRoute stop : direction.getStops()) {
if (stop.getHasUpcomingScheduledStop() != null && stop.getHasUpcomingScheduledStop())
scheduledStops.add(stop);
allStops.add(stop);
}
if (detailLevel.equals(DetailLevel.NORMAL)) {
for (int i = 0; i < scheduledStops.size(); i++) {
StopOnRoute stop = direction.getStops().get(i);
BigDecimal stopLat = new BigDecimal(stop.getLatitude());
BigDecimal stopLon = new BigDecimal(stop.getLongitude());
LocationStructure location = new LocationStructure();
location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
pointInPattern.setLocation(location);
pointInPattern.setOrder(BigInteger.valueOf(i));
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue(stop.getName());
pointInPattern.getStopName().add(stopName);
StopPointRefStructure spr = new StopPointRefStructure();
spr.setValue(stop.getId());
stopsInPattern.getStopPointInPattern().add(pointInPattern);
}
}
if (detailLevel.equals(DetailLevel.STOPS) || detailLevel.equals(DetailLevel.FULL)) {
for (int i = 0; i < allStops.size(); i++) {
StopOnRoute stop = direction.getStops().get(i);
Boolean hasUpcomingScheduledService = stop.getHasUpcomingScheduledStop();
BigDecimal stopLat = new BigDecimal(stop.getLatitude());
BigDecimal stopLon = new BigDecimal(stop.getLongitude());
LocationStructure location = new LocationStructure();
location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
StopPointRefStructure spr = new StopPointRefStructure();
spr.setValue(stop.getId());
StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
pointInPattern.setLocation(location);
pointInPattern.setOrder(BigInteger.valueOf(i));
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue(stop.getName());
pointInPattern.getStopName().add(stopName);
pointInPattern.setStopPointRef(spr);
stopsInPattern.getStopPointInPattern().add(pointInPattern);
// HasUpcomingService Extension
SiriUpcomingServiceExtension upcomingService = new SiriUpcomingServiceExtension();
upcomingService.setUpcomingScheduledService(hasUpcomingScheduledService);
ExtensionsStructure upcomingServiceExtensions = new ExtensionsStructure();
upcomingServiceExtensions.setAny(upcomingService);
pointInPattern.setExtensions(upcomingServiceExtensions);
}
}
String includePolylineFilter = filters.get(Filters.INCLUDE_POLYLINES);
if (includePolylineFilter != null && passFilter("true", includePolylineFilter)) {
// Polyline Extension
SiriPolyLinesExtension polylines = new SiriPolyLinesExtension();
for (String polyline : direction.getPolylines()) {
polylines.getPolylines().add(polyline);
}
ExtensionsStructure PolylineExtension = new ExtensionsStructure();
PolylineExtension.setAny(polylines);
routeDirectionStructure.setExtensions(PolylineExtension);
}
routeDirectionStructure.setJourneyPatterns(patterns);
pattern.setStopsInPattern(stopsInPattern);
patterns.getJourneyPattern().add(pattern);
routeDirectionStructure.setDirectionRef(dirRefStructure);
}
return true;
}
use of uk.org.siri.siri20.NaturalLanguageStringStructure in project onebusaway-application-modules by camsys.
the class SiriSupportV2 method fillAnnotatedStopPointStructure.
public static boolean fillAnnotatedStopPointStructure(AnnotatedStopPointStructure annotatedStopPoint, StopRouteDirection stopRouteDirection, Map<Filters, String> filters, DetailLevel detailLevel, long currentTime) {
StopBean stopBean = stopRouteDirection.getStop();
List<RouteForDirection> routeDirections = stopRouteDirection.getRouteDirections();
// Set Stop Name
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue(stopBean.getName());
// Set Route and Direction
Lines lines = new Lines();
for (RouteForDirection routeDirection : routeDirections) {
String directionId = routeDirection.getDirectionId();
String routeId = routeDirection.getRouteId();
LineRefStructure line = new LineRefStructure();
line.setValue(routeId);
DirectionRefStructure direction = new DirectionRefStructure();
direction.setValue(directionId);
LineDirectionStructure lineDirection = new LineDirectionStructure();
lineDirection.setDirectionRef(direction);
lineDirection.setLineRef(line);
lines.getLineRefOrLineDirection().add(lineDirection);
}
// Set Lat and Lon
BigDecimal stopLat = new BigDecimal(stopBean.getLat());
BigDecimal stopLon = new BigDecimal(stopBean.getLon());
LocationStructure location = new LocationStructure();
location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
// Set StopId
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue(stopBean.getId());
// Details -- minimum
annotatedStopPoint.getStopName().add(stopName);
// Details -- normal
if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.FULL)) {
annotatedStopPoint.setLocation(location);
annotatedStopPoint.setLines(lines);
annotatedStopPoint.setMonitored(true);
}
annotatedStopPoint.setStopPointRef(stopPointRef);
return true;
}
use of uk.org.siri.siri20.NaturalLanguageStringStructure in project onebusaway-application-modules by camsys.
the class SiriSupportV2 method getOnwardCallStructure.
private static OnwardCallStructure getOnwardCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, long responseTimestamp) {
OnwardCallStructure onwardCallStructure = new OnwardCallStructure();
onwardCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber));
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue(stopBean.getId());
onwardCallStructure.setStopPointRef(stopPointRef);
NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure();
stopPoint.setValue(stopBean.getName());
onwardCallStructure.getStopPointName().add(stopPoint);
if (prediction != null) {
if (prediction.getScheduleRelationship() != null && prediction.isSkipped()) {
_log.info("SKIPPED STOP: " + stopBean.getId());
return null;
}
if (prediction.getTimepointPredictedArrivalTime() < responseTimestamp) {
// TODO - LCARABALLO - should this be setExpectedArrivalTime?
onwardCallStructure.setExpectedArrivalTime(DateUtil.toXmlGregorianCalendar(responseTimestamp));
onwardCallStructure.setExpectedDepartureTime(DateUtil.toXmlGregorianCalendar(responseTimestamp));
} else {
onwardCallStructure.setExpectedArrivalTime(DateUtil.toXmlGregorianCalendar(prediction.getTimepointPredictedArrivalTime()));
onwardCallStructure.setExpectedDepartureTime(DateUtil.toXmlGregorianCalendar(prediction.getTimepointPredictedArrivalTime()));
}
}
// Distances
NaturalLanguageStringStructure presentableDistance = new NaturalLanguageStringStructure();
presentableDistance.setValue(presentationService.getPresentableDistance(distanceOfVehicleFromCall, index));
onwardCallStructure.setNumberOfStopsAway(BigInteger.valueOf(index));
onwardCallStructure.setDistanceFromStop(new BigDecimal(distanceOfVehicleFromCall).toBigInteger());
onwardCallStructure.setArrivalProximityText(presentableDistance);
return onwardCallStructure;
}
Aggregations