Search in sources :

Example 6 with FrequencyBean

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

the class BeanFactoryV2 method reverseFrequency.

public FrequencyBean reverseFrequency(FrequencyV2Bean frequency) {
    FrequencyBean bean = new FrequencyBean();
    bean.setStartTime(frequency.getStartTime());
    bean.setEndTime(frequency.getEndTime());
    bean.setHeadway(frequency.getHeadway());
    bean.setExactTimes(frequency.getExactTimes());
    return bean;
}
Also used : FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean)

Example 7 with FrequencyBean

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

the class TripStatusBeanServiceImpl method getBlockLocationAsStatusBean.

@Override
public TripStatusBean getBlockLocationAsStatusBean(BlockLocation blockLocation, long time) {
    TripStatusBean bean = new TripStatusBean();
    bean.setStatus("default");
    BlockInstance blockInstance = blockLocation.getBlockInstance();
    long serviceDate = blockInstance.getServiceDate();
    bean.setServiceDate(serviceDate);
    bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
    bean.setLastLocationUpdateTime(blockLocation.getLastLocationUpdateTime());
    bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
    bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
    bean.setLocation(blockLocation.getLocation());
    bean.setOrientation(blockLocation.getOrientation());
    bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
    if (blockLocation.isLastKnownOrientationSet())
        bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
    bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
    BlockTripInstance activeTripInstance = blockLocation.getActiveTripInstance();
    if (activeTripInstance != null) {
        BlockTripEntry activeBlockTrip = activeTripInstance.getBlockTrip();
        bean.setScheduledDistanceAlongTrip(blockLocation.getScheduledDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        bean.setDistanceAlongTrip(blockLocation.getDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        TripEntry activeTrip = activeBlockTrip.getTrip();
        bean.setTotalDistanceAlongTrip(activeTrip.getTotalTripDistance());
        TripBean activeTripBean = _tripBeanService.getTripForId(activeTrip.getId());
        bean.setActiveTrip(activeTripBean);
        bean.setBlockTripSequence(activeBlockTrip.getSequence());
        if (blockLocation.isLastKnownDistanceAlongBlockSet()) {
            bean.setLastKnownDistanceAlongTrip(blockLocation.getLastKnownDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
        }
        FrequencyEntry frequencyLabel = activeTripInstance.getFrequencyLabel();
        if (frequencyLabel != null) {
            FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
            bean.setFrequency(fb);
        }
    } else {
        _log.warn("no active block trip for block location: blockInstance=" + blockLocation.getBlockInstance() + " time=" + time);
    }
    BlockStopTimeEntry closestStop = blockLocation.getClosestStop();
    if (closestStop != null) {
        StopTimeEntry stopTime = closestStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setClosestStop(stopBean);
        bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
    }
    BlockStopTimeEntry nextStop = blockLocation.getNextStop();
    if (nextStop != null) {
        StopTimeEntry stopTime = nextStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setNextStop(stopBean);
        bean.setNextStopTimeOffset(blockLocation.getNextStopTimeOffset());
        bean.setNextStopDistanceFromVehicle(blockLocation.getNextStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
    }
    BlockStopTimeEntry previousStop = blockLocation.getPreviousStop();
    if (previousStop != null) {
        StopTimeEntry stopTime = previousStop.getStopTime();
        StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
        bean.setPreviousStop(stopBean);
        bean.setPreviousStopTimeOffset(blockLocation.getPreviousStopTimeOffset());
        bean.setPreviousStopDistanceFromVehicle(blockLocation.getPreviousStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
    }
    EVehiclePhase phase = blockLocation.getPhase();
    if (phase != null)
        bean.setPhase(phase.toLabel());
    String status = blockLocation.getStatus();
    if (status != null)
        bean.setStatus(status);
    if (blockLocation.getVehicleType() != null)
        bean.setVehicleType(blockLocation.getVehicleType().toLabel());
    bean.setPredicted(blockLocation.isPredicted());
    AgencyAndId vid = blockLocation.getVehicleId();
    if (vid != null)
        bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
    if (activeTripInstance != null) {
        List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, activeTripInstance, blockLocation.getVehicleId());
        if (!situations.isEmpty())
            bean.setSituations(situations);
    }
    if (blockLocation.getTimepointPredictions() != null && blockLocation.getTimepointPredictions().size() > 0) {
        List<TimepointPredictionBean> timepointPredictions = new ArrayList<TimepointPredictionBean>();
        for (TimepointPredictionRecord tpr : blockLocation.getTimepointPredictions()) {
            TimepointPredictionBean tpb = new TimepointPredictionBean();
            tpb.setTimepointId(tpr.getTimepointId().toString());
            tpb.setTripId(tpr.getTripId().toString());
            tpb.setStopSequence(tpr.getStopSequence());
            tpb.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
            tpb.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
            timepointPredictions.add(tpb);
        }
        bean.setTimepointPredictions(timepointPredictions);
    }
    return bean;
}
Also used : TimepointPredictionBean(org.onebusaway.transit_data.model.trips.TimepointPredictionBean) BlockTripInstance(org.onebusaway.transit_data_federation.services.blocks.BlockTripInstance) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripBean(org.onebusaway.transit_data.model.trips.TripBean) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) EVehiclePhase(org.onebusaway.realtime.api.EVehiclePhase) FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 8 with FrequencyBean

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

the class FrequencyBeanLibrary method getBeanForFrequency.

public static FrequencyBean getBeanForFrequency(long serviceDate, FrequencyEntry frequency) {
    if (frequency == null)
        return null;
    FrequencyBean bean = new FrequencyBean();
    bean.setStartTime(serviceDate + frequency.getStartTime() * 1000);
    bean.setEndTime(serviceDate + frequency.getEndTime() * 1000);
    bean.setHeadway(frequency.getHeadwaySecs());
    bean.setExactTimes(frequency.getExactTimes());
    return bean;
}
Also used : FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean)

Aggregations

FrequencyBean (org.onebusaway.transit_data.model.schedule.FrequencyBean)8 TripBean (org.onebusaway.transit_data.model.trips.TripBean)6 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)4 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)4 ArrayList (java.util.ArrayList)3 StopBean (org.onebusaway.transit_data.model.StopBean)3 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)3 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 TripStopTimesBean (org.onebusaway.transit_data.model.TripStopTimesBean)2 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)2 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)2 EVehiclePhase (org.onebusaway.realtime.api.EVehiclePhase)1 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)1 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)1 TripStopTimeBean (org.onebusaway.transit_data.model.TripStopTimeBean)1 TimepointPredictionBean (org.onebusaway.transit_data.model.trips.TimepointPredictionBean)1 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)1