Search in sources :

Example 11 with ServiceIdActivation

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

the class BlockConfigurationEntriesFactory method processBlockConfigurations.

public void processBlockConfigurations(BlockEntryImpl block, List<TripEntryImpl> tripsInBlock) {
    Map<LocalizedServiceId, List<TripEntryImpl>> tripsByServiceId = getTripsByServiceId(block, tripsInBlock);
    List<ServiceIdActivation> combinations = _serviceIdOverlapCache.getOverlappingServiceIdCombinations(tripsByServiceId.keySet());
    ArrayList<BlockConfigurationEntry> configurations = new ArrayList<BlockConfigurationEntry>();
    for (ServiceIdActivation serviceIds : combinations) {
        BlockConfigurationEntryImpl.Builder builder = processTripsForServiceIdConfiguration(block, tripsByServiceId, serviceIds);
        configurations.add(builder.create());
    }
    Collections.sort(configurations, _blockConfigurationComparator);
    configurations.trimToSize();
    if (configurations.isEmpty())
        _log.warn("no active block configurations found for block: " + block.getId());
    block.setConfigurations(configurations);
}
Also used : LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) ArrayList(java.util.ArrayList) BlockConfigurationEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl) ArrayList(java.util.ArrayList) List(java.util.List) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 12 with ServiceIdActivation

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

the class ServiceIdOverlapCache method computeCombinationsInternal.

private List<ServiceIdActivation> computeCombinationsInternal(Set<LocalizedServiceId> serviceIds) {
    Map<ServiceDate, Set<LocalizedServiceId>> serviceIdsByServiceDate = new FactoryMap<ServiceDate, Set<LocalizedServiceId>>(new HashSet<LocalizedServiceId>());
    for (LocalizedServiceId lsid : serviceIds) {
        AgencyAndId serviceId = lsid.getId();
        for (ServiceDate serviceDate : _calendarService.getServiceDatesForServiceId(serviceId)) serviceIdsByServiceDate.get(serviceDate).add(lsid);
    }
    Set<Set<LocalizedServiceId>> sets = new HashSet<Set<LocalizedServiceId>>();
    sets.addAll(serviceIdsByServiceDate.values());
    List<ServiceIdActivation> combinations = new ArrayList<ServiceIdActivation>();
    for (Set<LocalizedServiceId> activeServiceIds : sets) {
        Set<LocalizedServiceId> inactiveServiceIds = new HashSet<LocalizedServiceId>();
        for (Set<LocalizedServiceId> combo2 : sets) {
            if (isSubset(activeServiceIds, combo2))
                inactiveServiceIds.addAll(combo2);
        }
        inactiveServiceIds.removeAll(activeServiceIds);
        combinations.add(new ServiceIdActivation(list(activeServiceIds), list(inactiveServiceIds)));
    }
    Collections.sort(combinations);
    return combinations;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Set(java.util.Set) HashSet(java.util.HashSet) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) HashSet(java.util.HashSet)

Example 13 with ServiceIdActivation

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

the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds01.

@Test
public void testGetServiceDatesForServiceIds01() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids("sB"));
    Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
    assertEquals(1, dates.size());
    assertTrue(dates.contains(new ServiceDate(2010, 9, 10).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 14 with ServiceIdActivation

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

the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds04.

@Test
public void testGetServiceDatesForServiceIds04() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA", "sC"), lsids());
    Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
    assertEquals(0, dates.size());
}
Also used : 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 15 with ServiceIdActivation

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

the class ExtendedCalendarServiceImplTest method testGetNextServiceDatesForDepartureInterval.

@Test
public void testGetNextServiceDatesForDepartureInterval() {
    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-10 09:30");
    List<Date> dates = _service.getNextServiceDatesForDepartureInterval(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.getNextServiceDatesForDepartureInterval(serviceIds, interval, time);
    assertEquals(1, dates.size());
    assertEquals(date("2010-09-11 00:00"), dates.get(0));
    time = dateAsLong("2010-09-11 21:30");
    dates = _service.getNextServiceDatesForDepartureInterval(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