Search in sources :

Example 1 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class ServiceDateUserType method nullSafeSet.

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
        st.setNull(index, SQL_TYPES[0]);
    } else {
        ServiceDate serviceDate = (ServiceDate) value;
        st.setString(index, serviceDate.getAsString());
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate)

Example 2 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate 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 3 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-application-modules by camsys.

the class StopScheduleBeanServiceImpl method getServiceIdsByDate.

/**
 **
 * Private Methods
 ***
 */
private SortedMap<ServiceDate, Set<ServiceIdActivation>> getServiceIdsByDate(Set<ServiceIdActivation> allServiceIds) {
    SortedMap<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = new TreeMap<ServiceDate, Set<ServiceIdActivation>>();
    serviceIdsByDate = FactoryMap.createSorted(serviceIdsByDate, new HashSet<ServiceIdActivation>());
    for (ServiceIdActivation serviceIds : allServiceIds) {
        Set<ServiceDate> dates = _calendarService.getServiceDatesForServiceIds(serviceIds);
        for (ServiceDate date : dates) {
            serviceIdsByDate.get(date).add(serviceIds);
        }
    }
    return serviceIdsByDate;
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Set(java.util.Set) HashSet(java.util.HashSet) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 4 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibrary method getTripDescriptorAsBlockDescriptor.

private BlockDescriptor getTripDescriptorAsBlockDescriptor(MonitoredResult result, TripDescriptor trip, long currentTime) {
    if (!trip.hasTripId()) {
        return null;
    }
    TripEntry tripEntry = _entitySource.getTrip(trip.getTripId());
    if (tripEntry == null) {
        if (result != null) {
            _log.debug("reporting unmatched trip with id=" + trip.getTripId());
            result.addUnmatchedTripId(trip.getTripId());
        } else {
            _log.warn("no trip found with id=" + trip.getTripId());
        }
        return null;
    }
    ServiceDate serviceDate = null;
    BlockInstance instance;
    BlockEntry block = tripEntry.getBlock();
    if (trip.hasStartDate() && !"0".equals(trip.getStartDate())) {
        try {
            serviceDate = ServiceDate.parseString(trip.getStartDate());
        } catch (ParseException ex) {
            _log.warn("Could not parse service date " + trip.getStartDate(), ex);
        }
    }
    if (serviceDate != null) {
        instance = _blockCalendarService.getBlockInstance(block.getId(), serviceDate.getAsDate().getTime());
        if (instance == null) {
            _log.warn("block " + block.getId() + " does not exist on service date " + serviceDate);
            return null;
        }
    } else {
        long timeFrom = currentTime - 30 * 60 * 1000;
        long timeTo = currentTime + 30 * 60 * 1000;
        List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(block.getId(), timeFrom, timeTo);
        if (instances.isEmpty()) {
            instances = _blockCalendarService.getClosestActiveBlocks(block.getId(), currentTime);
        }
        if (instances.isEmpty()) {
            _log.warn("could not find any active instances for the specified block=" + block.getId() + " trip=" + trip);
            return null;
        }
        instance = instances.get(0);
    }
    if (serviceDate == null) {
        serviceDate = new ServiceDate(new Date(instance.getServiceDate()));
    }
    BlockDescriptor blockDescriptor = new BlockDescriptor();
    blockDescriptor.setBlockInstance(instance);
    blockDescriptor.setStartDate(serviceDate);
    if (trip.hasScheduleRelationship()) {
        blockDescriptor.setScheduleRelationshipValue(trip.getScheduleRelationship().toString());
    }
    int tripStartTime = 0;
    int blockStartTime = 0;
    if (trip.hasStartTime() && !"0".equals(trip.getStartTime())) {
        try {
            tripStartTime = StopTimeFieldMappingFactory.getStringAsSeconds(trip.getStartTime());
        } catch (InvalidStopTimeException iste) {
            _log.error("invalid stopTime of " + trip.getStartTime() + " for trip " + trip);
        }
        blockStartTime = getBlockStartTimeForTripStartTime(instance, tripEntry.getId(), tripStartTime);
        blockDescriptor.setStartTime(blockStartTime);
    }
    return blockDescriptor;
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) InvalidStopTimeException(org.onebusaway.gtfs.serialization.mappings.InvalidStopTimeException) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ParseException(java.text.ParseException) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Example 5 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate 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)

Aggregations

ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)134 Test (org.junit.Test)49 Date (java.util.Date)46 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)45 ArrayList (java.util.ArrayList)23 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)23 Calendar (java.util.Calendar)22 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)22 HashSet (java.util.HashSet)17 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)14 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)13 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)13 Set (java.util.Set)11 Trip (org.onebusaway.gtfs.model.Trip)11 TimeZone (java.util.TimeZone)10 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)9 Agency (org.onebusaway.gtfs.model.Agency)8 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)7