Search in sources :

Example 6 with BlockTripBean

use of org.onebusaway.transit_data.model.blocks.BlockTripBean 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 7 with BlockTripBean

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

the class SiriSupportV2 method fillMonitoredCall.

private static void fillMonitoredCall(MonitoredVehicleJourneyStructure monitoredVehicleJourney, BlockInstanceBean blockInstance, TripStatusBean tripStatus, StopBean monitoredCallStopBean, PresentationService presentationService, TransitDataService transitDataService, Map<String, TimepointPredictionRecord> stopLevelPredictions, boolean hasRealtimeData, DetailLevel detailLevel, long responseTimestamp) {
    List<BlockTripBean> blockTrips = blockInstance.getBlockConfiguration().getTrips();
    double distanceOfVehicleAlongBlock = 0;
    int blockTripStopsAfterTheVehicle = 0;
    boolean foundActiveTrip = false;
    for (int i = 0; i < blockTrips.size(); i++) {
        BlockTripBean blockTrip = blockTrips.get(i);
        if (!foundActiveTrip) {
            if (tripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
                double distanceAlongTrip = tripStatus.getDistanceAlongTrip();
                if (!hasRealtimeData) {
                    distanceAlongTrip = tripStatus.getScheduledDistanceAlongTrip();
                }
                distanceOfVehicleAlongBlock += distanceAlongTrip;
                foundActiveTrip = true;
            } else {
                // next.
                if (i + 1 < blockTrips.size()) {
                    distanceOfVehicleAlongBlock = blockTrips.get(i + 1).getDistanceAlongBlock();
                }
                // further
                continue;
            }
        }
        HashMap<String, Integer> visitNumberForStopMap = new HashMap<String, Integer>();
        for (BlockStopTimeBean stopTime : blockTrip.getBlockStopTimes()) {
            int visitNumber = getVisitNumber(visitNumberForStopMap, stopTime.getStopTime().getStop());
            // on future trips, count always.
            if (tripStatus.getActiveTrip().getId().equals(blockTrip.getTrip().getId())) {
                if (stopTime.getDistanceAlongBlock() >= distanceOfVehicleAlongBlock) {
                    blockTripStopsAfterTheVehicle++;
                } else {
                    // further
                    continue;
                }
            // future trip--bus hasn't reached this trip yet, so count
            // all stops
            } else {
                blockTripStopsAfterTheVehicle++;
            }
            // monitored call
            if (stopTime.getStopTime().getStop().getId().equals(monitoredCallStopBean.getId())) {
                if (!presentationService.isOnDetour(tripStatus)) {
                    monitoredVehicleJourney.setMonitoredCall(getMonitoredCallStructure(stopTime.getStopTime().getStop(), presentationService, stopTime.getDistanceAlongBlock() - blockTrip.getDistanceAlongBlock(), stopTime.getDistanceAlongBlock() - distanceOfVehicleAlongBlock, visitNumber, blockTripStopsAfterTheVehicle - 1, stopLevelPredictions.get(stopTime.getStopTime().getStop().getId()), detailLevel, responseTimestamp));
                }
                // we found our monitored call--stop
                return;
            }
        }
    }
}
Also used : BigInteger(java.math.BigInteger) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) HashMap(java.util.HashMap) BlockStopTimeBean(org.onebusaway.transit_data.model.blocks.BlockStopTimeBean)

Example 8 with BlockTripBean

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

the class BeanFactoryV2 method getBlockConfig.

public BlockConfigurationV2Bean getBlockConfig(BlockConfigurationBean blockConfig) {
    BlockConfigurationV2Bean bean = new BlockConfigurationV2Bean();
    bean.setActiveServiceIds(blockConfig.getActiveServiceIds());
    bean.setInactiveServiceIds(blockConfig.getInactiveServiceIds());
    List<BlockTripV2Bean> blockTrips = new ArrayList<BlockTripV2Bean>();
    for (BlockTripBean blockTrip : blockConfig.getTrips()) blockTrips.add(getBlockTrip(blockTrip));
    bean.setTrips(blockTrips);
    return bean;
}
Also used : BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) ArrayList(java.util.ArrayList) BlockTripV2Bean(org.onebusaway.api.model.transit.blocks.BlockTripV2Bean) BlockConfigurationV2Bean(org.onebusaway.api.model.transit.blocks.BlockConfigurationV2Bean)

Example 9 with BlockTripBean

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

the class BlockBeanServiceImpl method getBlockConfigurationAsBean.

private BlockConfigurationBean getBlockConfigurationAsBean(BlockConfigurationEntry blockConfiguration) {
    BlockConfigurationBean bean = new BlockConfigurationBean();
    ServiceIdActivation serviceIds = blockConfiguration.getServiceIds();
    AgencyAndId blockId = blockConfiguration.getBlock().getId();
    bean.setBlockId(AgencyAndIdLibrary.convertToString(blockId));
    List<String> activeServiceIds = new ArrayList<String>();
    for (LocalizedServiceId lsid : serviceIds.getActiveServiceIds()) activeServiceIds.add(AgencyAndIdLibrary.convertToString(lsid.getId()));
    bean.setActiveServiceIds(activeServiceIds);
    List<String> inactiveServiceIds = new ArrayList<String>();
    for (LocalizedServiceId lsid : serviceIds.getInactiveServiceIds()) inactiveServiceIds.add(AgencyAndIdLibrary.convertToString(lsid.getId()));
    bean.setInactiveServiceIds(inactiveServiceIds);
    List<BlockTripBean> tripBeans = new ArrayList<BlockTripBean>();
    for (BlockTripEntry blockTrip : blockConfiguration.getTrips()) tripBeans.add(getBlockTripAsBean(blockTrip));
    bean.setTrips(tripBeans);
    TimeZone tz = _agencyService.getTimeZoneForAgencyId(blockId.getAgencyId());
    bean.setTimeZone(tz.getID());
    return bean;
}
Also used : BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TimeZone(java.util.TimeZone) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationBean(org.onebusaway.transit_data.model.blocks.BlockConfigurationBean)

Example 10 with BlockTripBean

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

the class BlockBeanServiceImpl method getBlockLocationAsBean.

private ScheduledBlockLocationBean getBlockLocationAsBean(ScheduledBlockLocation blockLocation) {
    ScheduledBlockLocationBean bean = new ScheduledBlockLocationBean();
    if (blockLocation.getActiveTrip() != null) {
        BlockTripBean activeTrip = getBlockTripAsBean(blockLocation.getActiveTrip());
        bean.setActiveTrip(activeTrip);
    }
    bean.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
    bean.setInService(blockLocation.isInService());
    bean.setLocation(blockLocation.getLocation());
    bean.setScheduledTime(blockLocation.getScheduledTime());
    bean.setStopTimeIndex(blockLocation.getStopTimeIndex());
    return bean;
}
Also used : BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) ScheduledBlockLocationBean(org.onebusaway.transit_data.model.blocks.ScheduledBlockLocationBean)

Aggregations

BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)11 BlockStopTimeBean (org.onebusaway.transit_data.model.blocks.BlockStopTimeBean)7 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 BigInteger (java.math.BigInteger)4 StopBean (org.onebusaway.transit_data.model.StopBean)4 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)3 BigDecimal (java.math.BigDecimal)2 DecimalFormat (java.text.DecimalFormat)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)2 BlockInstanceBean (org.onebusaway.transit_data.model.blocks.BlockInstanceBean)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 BlockConfigurationV2Bean (org.onebusaway.api.model.transit.blocks.BlockConfigurationV2Bean)1 BlockTripV2Bean (org.onebusaway.api.model.transit.blocks.BlockTripV2Bean)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)1 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)1