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());
}
}
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);
}
}
}
}
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;
}
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;
}
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;
}
Aggregations