Search in sources :

Example 1 with StopWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesForStopAction method show.

public DefaultHttpHeaders show() throws ServiceException {
    if (hasErrors())
        return setValidationErrorsResponse();
    if (_query.getTime() == 0)
        _query.setTime(SystemTime.currentTimeMillis());
    StopWithArrivalsAndDeparturesBean result = _service.getStopWithArrivalsAndDepartures(_id, _query);
    if (result == null)
        return setResourceNotFoundResponse();
    if (isVersion(V1)) {
        // Convert data to v1 form
        List<ArrivalAndDepartureBeanV1> arrivals = getArrivalsAsV1(result);
        StopWithArrivalsAndDeparturesBeanV1 v1 = new StopWithArrivalsAndDeparturesBeanV1(result.getStop(), arrivals, result.getNearbyStops());
        return setOkResponse(v1);
    } else if (isVersion(V2)) {
        BeanFactoryV2 factory = getBeanFactoryV2();
        return setOkResponse(factory.getResponse(result));
    } else {
        return setUnknownVersionResponse();
    }
}
Also used : StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) ArrivalAndDepartureBeanV1(org.onebusaway.api.model.where.ArrivalAndDepartureBeanV1) StopWithArrivalsAndDeparturesBeanV1(org.onebusaway.api.model.where.StopWithArrivalsAndDeparturesBeanV1) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Example 2 with StopWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class SiriSupport method fillOnwardCalls.

private static void fillOnwardCalls(MonitoredVehicleJourneyStructure monitoredVehicleJourney, BlockInstanceBean blockInstance, TripBean framedJourneyTripBean, TripStatusBean currentVehicleTripStatus, OnwardCallsMode onwardCallsMode, PresentationService presentationService, TransitDataService transitDataService, Map<String, TimepointPredictionRecord> stopLevelPredictions, int maximumOnwardCalls, boolean hasRealtimeData, long responseTimestamp) {
    String tripIdOfMonitoredCall = framedJourneyTripBean.getId();
    monitoredVehicleJourney.setOnwardCalls(new OnwardCallsStructure());
    // no need to go further if this is the case!
    if (maximumOnwardCalls == 0) {
        return;
    }
    List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips();
    double distanceOfVehicleAlongBlock = 0;
    int blockTripStopsAfterTheVehicle = 0;
    int onwardCallsAdded = 0;
    boolean foundActiveTrip = false;
    for (int i = 0; i < blockTrips.size(); i++) {
        BlockTripBean blockTrip = blockTrips.get(i);
        if (!foundActiveTrip) {
            if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
                distanceOfVehicleAlongBlock += currentVehicleTripStatus.getDistanceAlongTrip();
                foundActiveTrip = true;
            } else {
                // so to get the size of this one, we have to look at the next.
                if (i + 1 < blockTrips.size()) {
                    distanceOfVehicleAlongBlock = blockTrips.get(i + 1).getDistanceAlongBlock();
                }
                // bus has already served this trip, so no need to go further
                continue;
            }
        }
        if (onwardCallsMode == OnwardCallsMode.STOP_MONITORING) {
            // always include onward calls for the trip the monitored call is on ONLY.
            if (!blockTrip.getTrip().getId().equals(tripIdOfMonitoredCall)) {
                continue;
            }
        }
        boolean foundMatch = false;
        HashMap<String, Integer> visitNumberForStopMap = new HashMap<String, Integer>();
        for (BlockStopTimeBean stopTime : blockTrip.getBlockStopTimes()) {
            int visitNumber = getVisitNumber(visitNumberForStopMap, stopTime.getStopTime().getStop());
            StopBean stop = stopTime.getStopTime().getStop();
            double distanceOfCallAlongTrip = stopTime.getDistanceAlongBlock() - blockTrip.getDistanceAlongBlock();
            double distanceOfVehicleFromCall = stopTime.getDistanceAlongBlock() - distanceOfVehicleAlongBlock;
            // on future trips, count always.
            if (currentVehicleTripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
                if (!hasRealtimeData) {
                    if (stop.getId().equals(currentVehicleTripStatus.getNextStop().getId()))
                        foundMatch = true;
                    if (foundMatch) {
                        blockTripStopsAfterTheVehicle++;
                        ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
                        StopWithArrivalsAndDeparturesBean result = transitDataService.getStopWithArrivalsAndDepartures(stop.getId(), query);
                        // We can't assume the first result is the correct result
                        Collections.sort(result.getArrivalsAndDepartures(), new SortByTime());
                        if (result.getArrivalsAndDepartures().isEmpty()) {
                            // bad data?  abort!
                            continue;
                        }
                        ArrivalAndDepartureBean arrivalAndDeparture = result.getArrivalsAndDepartures().get(0);
                        distanceOfVehicleFromCall = arrivalAndDeparture.getDistanceFromStop();
                    // responseTimestamp = arrivalAndDeparture.getScheduledArrivalTime();
                    } else
                        continue;
                } else if (stopTime.getDistanceAlongBlock() >= distanceOfVehicleAlongBlock) {
                    blockTripStopsAfterTheVehicle++;
                } else {
                    // stop is behind the bus--no need to go further
                    continue;
                }
            // future trip--bus hasn't reached this trip yet, so count all stops
            } else {
                blockTripStopsAfterTheVehicle++;
            }
            monitoredVehicleJourney.getOnwardCalls().getOnwardCall().add(getOnwardCallStructure(stop, presentationService, distanceOfCallAlongTrip, distanceOfVehicleFromCall, visitNumber, blockTripStopsAfterTheVehicle - 1, stopLevelPredictions.get(stopTime.getStopTime().getStop().getId()), hasRealtimeData, responseTimestamp, (currentVehicleTripStatus.getServiceDate() + stopTime.getStopTime().getArrivalTime() * 1000)));
            onwardCallsAdded++;
            if (onwardCallsAdded >= maximumOnwardCalls) {
                return;
            }
        }
        // if we get here, we added our stops
        return;
    }
    return;
}
Also used : BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) HashMap(java.util.HashMap) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean) BlockStopTimeBean(org.onebusaway.transit_data.model.blocks.BlockStopTimeBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) BigInteger(java.math.BigInteger) OnwardCallsStructure(uk.org.siri.siri.OnwardCallsStructure) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 3 with StopWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceImpl method getArrivalsAndDeparturesForStop.

private List<ArrivalAndDepartureBean> getArrivalsAndDeparturesForStop(String stopId, long currentTime) {
    ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
    query.setTime(currentTime);
    query.setMinutesBefore(5);
    query.setMinutesAfter(65);
    StopWithArrivalsAndDeparturesBean stopWithArrivalsAndDepartures = _transitDataService.getStopWithArrivalsAndDepartures(stopId, query);
    return stopWithArrivalsAndDepartures.getArrivalsAndDepartures();
}
Also used : StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean)

Example 4 with StopWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getArrivalsAndDeparturesForStop.

private List<ArrivalAndDepartureBean> getArrivalsAndDeparturesForStop(String stopId, long currentTime) {
    ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
    query.setTime(currentTime);
    query.setMinutesBefore(5 * 60);
    query.setMinutesAfter(5 * 60);
    StopWithArrivalsAndDeparturesBean stopWithArrivalsAndDepartures = _transitDataService.getStopWithArrivalsAndDepartures(stopId, query);
    return stopWithArrivalsAndDepartures.getArrivalsAndDepartures();
}
Also used : StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean)

Example 5 with StopWithArrivalsAndDeparturesBean

use of org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean in project onebusaway-application-modules by camsys.

the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.

public StopWithArrivalsAndDeparturesBean getArrivalsAndDeparturesByStopId(AgencyAndId id, ArrivalsAndDeparturesQueryBean query) {
    StopBean stop = _stopBeanService.getStopForId(id);
    if (stop == null)
        return null;
    List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
    List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stop, 100);
    List<StopBean> nearbyStops = new ArrayList<StopBean>();
    for (AgencyAndId nearbyStopId : nearbyStopIds) nearbyStops.add(_stopBeanService.getStopForId(nearbyStopId));
    List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
    return new StopWithArrivalsAndDeparturesBean(stop, arrivalsAndDepartures, nearbyStops, situations);
}
Also used : StopWithArrivalsAndDeparturesBean(org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean)

Aggregations

StopWithArrivalsAndDeparturesBean (org.onebusaway.transit_data.model.StopWithArrivalsAndDeparturesBean)5 ArrivalsAndDeparturesQueryBean (org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1 ArrivalAndDepartureBeanV1 (org.onebusaway.api.model.where.ArrivalAndDepartureBeanV1)1 StopWithArrivalsAndDeparturesBeanV1 (org.onebusaway.api.model.where.StopWithArrivalsAndDeparturesBeanV1)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 BlockStopTimeBean (org.onebusaway.transit_data.model.blocks.BlockStopTimeBean)1 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1 OnwardCallsStructure (uk.org.siri.siri.OnwardCallsStructure)1