use of org.onebusaway.transit_data_federation.services.blocks.InstanceState 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.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method findBlockTripsInRange.
private void findBlockTripsInRange(ServiceIntervalBlock intervals, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, Collection<BlockInstance> instances) {
int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
int indexFrom = index(Arrays.binarySearch(intervals.getMaxDepartures(), scheduledTimeFrom));
int indexTo = index(Arrays.binarySearch(intervals.getMinArrivals(), scheduledTimeTo));
InstanceState state = new InstanceState(serviceDate.getTime());
for (int in = indexFrom; in < indexTo; in++) {
BlockTripEntry trip = trips.get(in);
BlockConfigurationEntry block = trip.getBlockConfiguration();
BlockInstance instance = new BlockInstance(block, state);
instances.add(instance);
}
}
use of org.onebusaway.transit_data_federation.services.blocks.InstanceState 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;
}
use of org.onebusaway.transit_data_federation.services.blocks.InstanceState 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;
}
use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.
the class ServiceAlertsServiceImplTest method testGetServiceAlertsForVehicleJourney.
@Test
public void testGetServiceAlertsForVehicleJourney() {
/**
* These alerts should match
*/
ServiceAlertRecord alert2 = new ServiceAlertRecord();
alert2.setAgencyId("1");
alert2.setServiceAlertId("B");
ServiceAlertsSituationAffectsClause affectsClause2 = new ServiceAlertsSituationAffectsClause();
affectsClause2.setAgencyId("1");
affectsClause2.setTripId("TripA");
alert2.getAllAffects().add(affectsClause2);
alert2 = _service.createOrUpdateServiceAlert(alert2);
ServiceAlertRecord alert3 = new ServiceAlertRecord();
alert3.setAgencyId("1");
alert3.setServiceAlertId("C");
ServiceAlertsSituationAffectsClause affectsClause3 = new ServiceAlertsSituationAffectsClause();
affectsClause3.setAgencyId("1");
affectsClause3.setRouteId("RouteX");
alert3.getAllAffects().add(affectsClause3);
alert3 = _service.createOrUpdateServiceAlert(alert3);
ServiceAlertRecord alert4 = new ServiceAlertRecord();
alert4.setAgencyId("1");
alert4.setServiceAlertId("D");
ServiceAlertsSituationAffectsClause affectsClause4 = new ServiceAlertsSituationAffectsClause();
affectsClause4.setAgencyId("1");
affectsClause4.setRouteId("RouteX");
affectsClause4.setDirectionId("1");
alert4.getAllAffects().add(affectsClause4);
alert4 = _service.createOrUpdateServiceAlert(alert4);
/**
* These alerts shouldn't match
*/
ServiceAlertRecord alert5 = new ServiceAlertRecord();
alert5.setAgencyId("1");
alert5.setServiceAlertId("E");
ServiceAlertsSituationAffectsClause affectsClause5 = new ServiceAlertsSituationAffectsClause();
affectsClause5.setAgencyId("1");
affectsClause5.setStopId("10021");
affectsClause5.setTripId("TripA");
alert5.getAllAffects().add(affectsClause5);
alert5 = _service.createOrUpdateServiceAlert(alert5);
ServiceAlertRecord alert6 = new ServiceAlertRecord();
alert6.setAgencyId("1");
alert6.setServiceAlertId("F");
ServiceAlertsSituationAffectsClause affectsClause6 = new ServiceAlertsSituationAffectsClause();
affectsClause6.setAgencyId("1");
affectsClause6.setStopId("10020");
affectsClause6.setTripId("TripB");
alert6.getAllAffects().add(affectsClause6);
alert6 = _service.createOrUpdateServiceAlert(alert6);
ServiceAlertRecord alert7 = new ServiceAlertRecord();
alert7.setAgencyId("1");
alert7.setServiceAlertId("G");
ServiceAlertsSituationAffectsClause affectsClause7 = new ServiceAlertsSituationAffectsClause();
affectsClause7.setAgencyId("1");
affectsClause7.setTripId("TripB");
alert7.getAllAffects().add(affectsClause7);
alert7 = _service.createOrUpdateServiceAlert(alert7);
ServiceAlertRecord alert8 = new ServiceAlertRecord();
alert8.setAgencyId("1");
alert8.setServiceAlertId("H");
ServiceAlertsSituationAffectsClause affectsClause8 = new ServiceAlertsSituationAffectsClause();
affectsClause8.setAgencyId("1");
affectsClause8.setRouteId("RouteY");
alert8.getAllAffects().add(affectsClause8);
alert8 = _service.createOrUpdateServiceAlert(alert8);
ServiceAlertRecord alert9 = new ServiceAlertRecord();
alert9.setAgencyId("1");
alert9.setServiceAlertId("I");
ServiceAlertsSituationAffectsClause affectsClause9 = new ServiceAlertsSituationAffectsClause();
affectsClause9.setAgencyId("1");
affectsClause9.setRouteId("RouteX");
affectsClause9.setDirectionId("0");
alert9.getAllAffects().add(affectsClause9);
alert9 = _service.createOrUpdateServiceAlert(alert9);
RouteEntryImpl route = route("RouteX");
routeCollection("RouteX", route);
StopEntryImpl stop = stop("10020", 47.0, -122.0);
TripEntryImpl trip = trip("TripA");
trip.setRoute(route);
trip.setDirectionId("1");
stopTime(0, stop, trip, time(8, 53), 0);
BlockEntryImpl block = block("block");
BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("a"), lsids()), trip);
BlockTripInstance blockTripInstance = new BlockTripInstance(blockConfig.getTrips().get(0), new InstanceState(System.currentTimeMillis()));
List<ServiceAlertRecord> alerts = _service.getServiceAlertsForVehicleJourney(System.currentTimeMillis(), blockTripInstance, new AgencyAndId("1", "1111"));
assertEquals(3, alerts.size());
assertTrue(alerts.contains(alert2));
assertTrue(alerts.contains(alert3));
assertTrue(alerts.contains(alert4));
}
Aggregations