Search in sources :

Example 1 with ServiceIdActivation

use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation 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 ServiceIdActivation

use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation 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 3 with ServiceIdActivation

use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.

the class BlockTripInstanceLibraryTest method test.

@Test
public void test() {
    BlockEntryImpl block = UnitTestingSupport.block("block");
    TripEntryImpl tripA = UnitTestingSupport.trip("tripA");
    TripEntryImpl tripB = UnitTestingSupport.trip("tripB");
    UnitTestingSupport.stopTime(0, null, tripA, 0, 0);
    UnitTestingSupport.stopTime(0, null, tripB, 0, 0);
    ServiceIdActivation serviceIds = UnitTestingSupport.serviceIds("sid");
    BlockConfigurationEntry blockConfig = UnitTestingSupport.blockConfiguration(block, serviceIds, tripA, tripB);
    BlockInstance blockInstanceA = new BlockInstance(blockConfig, 123L);
    BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripA"));
    assertSame(tripA, blockTripInstance.getBlockTrip().getTrip());
    assertEquals(123L, blockTripInstance.getServiceDate());
    blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripB"));
    assertSame(tripB, blockTripInstance.getBlockTrip().getTrip());
    assertEquals(123L, blockTripInstance.getServiceDate());
    blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripC"));
    assertNull(blockTripInstance);
}
Also used : ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 4 with ServiceIdActivation

use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.

the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds03.

@Test
public void testGetServiceDatesForServiceIds03() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sC", "sD"), lsids());
    Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
    assertEquals(1, dates.size());
    assertTrue(dates.contains(new ServiceDate(2010, 9, 13).getAsDate(timeZone())));
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Test(org.junit.Test)

Example 5 with ServiceIdActivation

use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.

the class ExtendedCalendarServiceImplTest method testGetPreviousServiceDatesForArrivalInterval.

@Test
public void testGetPreviousServiceDatesForArrivalInterval() {
    BlockEntry blockA = block("blockA");
    blockConfiguration(blockA, serviceIds(lsids("sA"), lsids()));
    List<BlockEntry> blocks = Arrays.asList(blockA);
    Mockito.when(_transitGraphDao.getAllBlocks()).thenReturn(blocks);
    _service.start();
    ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids());
    int inFrom = time(8, 00);
    int inTo = time(20, 00);
    ServiceInterval interval = new ServiceInterval(inFrom, inFrom, inTo, inTo);
    long time = dateAsLong("2010-09-11 21:30");
    List<Date> dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
    assertEquals(1, dates.size());
    assertEquals(date("2010-09-11 00:00"), dates.get(0));
    time = dateAsLong("2010-09-11 18:00");
    dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
    assertEquals(1, dates.size());
    assertEquals(date("2010-09-11 00:00"), dates.get(0));
    time = dateAsLong("2010-09-11 07:00");
    dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
    assertEquals(1, dates.size());
    assertEquals(date("2010-09-10 00:00"), dates.get(0));
    time = dateAsLong("2010-09-10 21:30");
    dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
    assertEquals(1, dates.size());
    assertEquals(date("2010-09-10 00:00"), dates.get(0));
    time = dateAsLong("2010-09-10 18:00");
    dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
    assertEquals(1, dates.size());
    assertEquals(date("2010-09-10 00:00"), dates.get(0));
    time = dateAsLong("2010-09-10 07:00");
    dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
    assertEquals(0, dates.size());
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceInterval(org.onebusaway.gtfs.model.calendar.ServiceInterval) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Test(org.junit.Test)

Aggregations

ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)31 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)19 Test (org.junit.Test)17 Date (java.util.Date)16 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)8 HashSet (java.util.HashSet)7 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)7 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)7 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)7 ArrayList (java.util.ArrayList)6 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)6 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)6 Set (java.util.Set)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)5 FactoryMap (org.onebusaway.collections.FactoryMap)4 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)4 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)4 TimeZone (java.util.TimeZone)3