Search in sources :

Example 1 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class StopScheduleBeanServiceImpl method groupStopTimeInstancesByRouteCollectionId.

private void groupStopTimeInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> stopTimesByRouteCollectionId, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
    Map<AgencyAndId, Set<FrequencyEntry>> frequencyLabelsByRouteCollectionId = new FactoryMap<AgencyAndId, Set<FrequencyEntry>>(new HashSet<FrequencyEntry>());
    for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) {
        ServiceIdActivation serviceIds = index.getServiceIds();
        Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
        if (!serviceDates.contains(date))
            continue;
        Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
        for (BlockStopTimeEntry stopTime : index.getStopTimes()) {
            BlockTripEntry blockTrip = stopTime.getTrip();
            TripEntry trip = blockTrip.getTrip();
            AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
            FrequencyEntry frequencyLabel = trip.getFrequencyLabel();
            InstanceState state = new InstanceState(serviceDate.getTime(), frequencyLabel);
            StopTimeInstance sti = new StopTimeInstance(stopTime, state);
            if (frequencyLabel == null) {
                stopTimesByRouteCollectionId.get(routeCollectionId).add(sti);
            } else if (frequencyLabelsByRouteCollectionId.get(routeCollectionId).add(frequencyLabel)) {
                frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
            }
        }
    }
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Set(java.util.Set) HashSet(java.util.HashSet) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 2 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class StopTimeServiceImpl method getStopTimesForStopAndServiceDateAndTimeRange.

private int getStopTimesForStopAndServiceDateAndTimeRange(HasIndexedBlockStopTimes index, Date serviceDate, Date from, Date to, List<StopTimeInstance> instances) {
    List<BlockStopTimeEntry> blockStopTimes = index.getStopTimes();
    int relativeFrom = effectiveTime(serviceDate, from);
    int relativeTo = effectiveTime(serviceDate, to);
    int fromIndex = GenericBinarySearch.search(index, blockStopTimes.size(), relativeFrom, IndexAdapters.BLOCK_STOP_TIME_DEPARTURE_INSTANCE);
    int toIndex = GenericBinarySearch.search(index, blockStopTimes.size(), relativeTo, IndexAdapters.BLOCK_STOP_TIME_ARRIVAL_INSTANCE);
    InstanceState state = new InstanceState(serviceDate.getTime());
    for (int in = fromIndex; in < toIndex; in++) {
        BlockStopTimeEntry blockStopTime = blockStopTimes.get(in);
        instances.add(new StopTimeInstance(blockStopTime, state));
    }
    return fromIndex;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 3 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class StopTimeServiceImpl method getStopTimeInstancesInTimeRange.

@Override
public List<StopTimeInstance> getStopTimeInstancesInTimeRange(StopEntry stopEntry, Date from, Date to, EFrequencyStopTimeBehavior frequencyBehavior) {
    List<StopTimeInstance> stopTimeInstances = new ArrayList<StopTimeInstance>();
    for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) {
        Collection<Date> serviceDates = _calendarService.getServiceDatesWithinRange(index.getServiceIds(), index.getServiceInterval(), from, to);
        for (Date serviceDate : serviceDates) {
            getStopTimesForStopAndServiceDateAndTimeRange(index, serviceDate, from, to, stopTimeInstances);
        }
    }
    List<FrequencyStopTripIndex> frequencyStopTripIndices = _blockIndexService.getFrequencyStopTripIndicesForStop(stopEntry);
    for (FrequencyStopTripIndex index : frequencyStopTripIndices) {
        Collection<Date> serviceDates = _calendarService.getServiceDatesWithinRange(index.getServiceIds(), index.getServiceInterval(), from, to);
        for (Date serviceDate : serviceDates) {
            getFrequenciesForStopAndServiceIdsAndTimeRange(index, serviceDate, from, to, stopTimeInstances, frequencyBehavior);
        }
    }
    return stopTimeInstances;
}
Also used : FrequencyStopTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyStopTripIndex) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) AbstractBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.AbstractBlockStopTimeIndex) ArrayList(java.util.ArrayList) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate)

Example 4 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class StopTimeServiceImpl method getNextBlockSequenceDeparturesForStop.

@Override
public List<StopTimeInstance> getNextBlockSequenceDeparturesForStop(StopEntry stopEntry, long time, boolean includePrivateSerivce) {
    List<StopTimeInstance> stopTimeInstances = new ArrayList<StopTimeInstance>();
    List<BlockStopSequenceIndex> blockStopTripIndices = _blockIndexService.getStopSequenceIndicesForStop(stopEntry);
    for (BlockStopSequenceIndex index : blockStopTripIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.BLOCK_STOP_TIME_DEPARTURE_INSTANCE);
            if (fromIndex < index.size()) {
                BlockStopTimeEntry blockStopTime = index.getBlockStopTimeForIndex(fromIndex);
                InstanceState state = new InstanceState(serviceDate.getTime());
                StopTimeInstance sti = new StopTimeInstance(blockStopTime, state);
                stopTimeInstances.add(sti);
            }
        }
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
            List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
            if (fromIndex < index.size()) {
                FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(fromIndex);
                BlockStopTimeEntry bst = entry.getStopTime();
                FrequencyEntry frequency = entry.getFrequency();
                InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
                int stopTimeOffset = entry.getStopTimeOffset();
                int frequencyOffset = computeFrequencyOffset(relativeFrom, bst, frequency, stopTimeOffset, true);
                StopTimeInstance sti = new StopTimeInstance(bst, state, frequencyOffset);
                stopTimeInstances.add(sti);
            }
        }
    }
    return stopTimeInstances;
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 5 with StopTimeInstance

use of org.onebusaway.transit_data_federation.model.StopTimeInstance in project onebusaway-application-modules by camsys.

the class UserReportingServiceImpl method getRecordAsBean.

private TripProblemReportBean getRecordAsBean(TripProblemReportRecord record) {
    AgencyAndId stopId = record.getStopId();
    AgencyAndId tripId = record.getTripId();
    TripProblemReportBean bean = new TripProblemReportBean();
    bean.setCode(record.getCode());
    bean.setId(record.getId());
    bean.setServiceDate(record.getServiceDate());
    bean.setStatus(record.getStatus());
    bean.setLabel(record.getLabel());
    bean.setStopId(AgencyAndIdLibrary.convertToString(stopId));
    bean.setTime(record.getTime());
    bean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
    bean.setUserComment(record.getUserComment());
    bean.setUserLat(record.getUserLat());
    bean.setUserLon(record.getUserLon());
    bean.setUserLocationAccuracy(record.getUserLocationAccuracy());
    bean.setUserOnVehicle(record.isUserOnVehicle());
    bean.setUserVehicleNumber(record.getUserVehicleNumber());
    bean.setPredicted(record.isPredicted());
    bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
    bean.setDistanceAlongBlock(record.getDistanceAlongBlock());
    bean.setScheduleDeviation(record.getScheduleDeviation());
    bean.setVehicleLat(record.getVehicleLat());
    bean.setVehicleLon(record.getVehicleLon());
    if (stopId != null) {
        try {
            bean.setStop(_stopBeanService.getStopForId(stopId));
        } catch (NoSuchStopServiceException ex) {
        }
    }
    if (tripId != null) {
        bean.setTrip(_tripBeanService.getTripForId(tripId));
    }
    if (tripId != null && stopId != null) {
        TripEntry trip = _graph.getTripEntryForId(tripId);
        StopEntry stop = _graph.getStopEntryForId(stopId);
        if (trip != null && stop != null) {
            AgencyAndId vehicleId = record.getMatchedVehicleId();
            if (vehicleId == null)
                vehicleId = record.getVehicleId();
            ArrivalAndDepartureQuery query = new ArrivalAndDepartureQuery();
            query.setStop(stop);
            query.setStopSequence(-1);
            query.setTrip(trip);
            query.setServiceDate(record.getServiceDate());
            query.setVehicleId(vehicleId);
            query.setTime(record.getTime());
            ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
            if (instance != null) {
                StopTimeInstance sti = instance.getStopTimeInstance();
                StopTimeInstanceBean stopTimeBean = _stopTimeBeanService.getStopTimeInstanceAsBean(sti);
                bean.setStopTime(stopTimeBean);
            }
        }
    }
    return bean;
}
Also used : StopTimeInstanceBean(org.onebusaway.transit_data.model.StopTimeInstanceBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) ArrivalAndDepartureQuery(org.onebusaway.transit_data_federation.services.ArrivalAndDepartureQuery) NoSuchStopServiceException(org.onebusaway.exceptions.NoSuchStopServiceException) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) TripProblemReportBean(org.onebusaway.transit_data.model.problems.TripProblemReportBean)

Aggregations

StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)25 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)16 Date (java.util.Date)15 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)13 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)12 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)10 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)9 ArrayList (java.util.ArrayList)8 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)8 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)7 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)6 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)6 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)5 ScheduledBlockLocationServiceImpl (org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl)5 VehicleLocationRecordCacheImpl (org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl)5 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)5 Test (org.junit.Test)4 FactoryMap (org.onebusaway.collections.FactoryMap)4