Search in sources :

Example 21 with ServiceIdActivation

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

the class StopTimeServiceImpl method extendIntervalWithIndex.

private void extendIntervalWithIndex(ServiceDate serviceDate, Range interval, AbstractBlockStopTimeIndex index) {
    ServiceIdActivation serviceIds = index.getServiceIds();
    Date date = serviceDate.getAsDate(serviceIds.getTimeZone());
    if (_calendarService.areServiceIdsActiveOnServiceDate(serviceIds, date)) {
        ServiceInterval in = index.getServiceInterval();
        long tFrom = date.getTime() + in.getMinDeparture() * 1000;
        long tTo = date.getTime() + in.getMaxDeparture() * 1000;
        interval.addValue(tFrom);
        interval.addValue(tTo);
    }
}
Also used : 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)

Example 22 with ServiceIdActivation

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

the class BlockConfigurationEntryImplTest method test.

@Test
public void test() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids("sB"));
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.1, -122.0);
    BlockEntryImpl block = block("blockA");
    TripEntryImpl tripA = trip("tripA", 1000);
    TripEntryImpl tripB = trip("tripB", 2000);
    TripEntryImpl tripC = trip("tripB", 1500);
    List<TripEntry> trips = Arrays.asList((TripEntry) tripA, tripB, tripC);
    StopTimeEntryImpl st1 = stopTime(1, stopA, tripA, time(6, 30), time(6, 35), 200);
    StopTimeEntryImpl st2 = stopTime(2, stopB, tripA, time(7, 00), time(7, 10), 800);
    StopTimeEntryImpl st3 = stopTime(3, stopB, tripB, time(7, 30), time(7, 35), 400);
    StopTimeEntryImpl st4 = stopTime(4, stopA, tripB, time(8, 00), time(8, 07), 1600);
    StopTimeEntryImpl st5 = stopTime(5, stopA, tripC, time(8, 30), time(8, 35), 300);
    StopTimeEntryImpl st6 = stopTime(6, stopB, tripC, time(9, 00), time(9, 02), 1200);
    Builder builder = BlockConfigurationEntryImpl.builder();
    builder.setBlock(block);
    builder.setTrips(trips);
    builder.setServiceIds(serviceIds);
    builder.setTripGapDistances(new double[] { 10.0, 20.0, 0.0 });
    BlockConfigurationEntry entry = builder.create();
    assertSame(block, entry.getBlock());
    assertSame(serviceIds, entry.getServiceIds());
    assertEquals(4530.0, entry.getTotalBlockDistance(), 0.0);
    /**
     **
     * Trips
     ***
     */
    List<BlockTripEntry> blockTrips = entry.getTrips();
    assertEquals(3, blockTrips.size());
    BlockTripEntry blockTrip = blockTrips.get(0);
    assertEquals(0, blockTrip.getSequence());
    assertEquals(0, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(0, blockTrip.getAccumulatedSlackTime());
    assertEquals(0.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertSame(blockTrips.get(1), blockTrip.getNextTrip());
    assertNull(blockTrip.getPreviousTrip());
    blockTrip = blockTrips.get(1);
    assertEquals(1, blockTrip.getSequence());
    assertEquals(2, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(15 * 60, blockTrip.getAccumulatedSlackTime());
    assertEquals(1010.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertSame(blockTrips.get(2), blockTrip.getNextTrip());
    assertSame(blockTrips.get(0), blockTrip.getPreviousTrip());
    blockTrip = blockTrips.get(2);
    assertEquals(2, blockTrip.getSequence());
    assertEquals(4, blockTrip.getAccumulatedStopTimeIndex());
    assertEquals(35 * 60, blockTrip.getAccumulatedSlackTime());
    assertEquals(3030.0, blockTrip.getDistanceAlongBlock(), 0.0);
    assertNull(blockTrip.getNextTrip());
    assertSame(blockTrips.get(1), blockTrip.getPreviousTrip());
    /**
     **
     * Stop Times
     ***
     */
    List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
    assertEquals(6, stopTimes.size());
    BlockStopTimeEntry bst = stopTimes.get(0);
    assertEquals(0, bst.getAccumulatedSlackTime());
    assertEquals(0, bst.getBlockSequence());
    assertEquals(200, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st1, bst.getStopTime());
    assertSame(blockTrips.get(0), bst.getTrip());
    bst = stopTimes.get(1);
    assertEquals(300, bst.getAccumulatedSlackTime());
    assertEquals(1, bst.getBlockSequence());
    assertEquals(800, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st2, bst.getStopTime());
    assertSame(blockTrips.get(0), bst.getTrip());
    bst = stopTimes.get(2);
    assertEquals(15 * 60, bst.getAccumulatedSlackTime());
    assertEquals(2, bst.getBlockSequence());
    assertEquals(1410, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st3, bst.getStopTime());
    assertSame(blockTrips.get(1), bst.getTrip());
    bst = stopTimes.get(3);
    assertEquals(20 * 60, bst.getAccumulatedSlackTime());
    assertEquals(3, bst.getBlockSequence());
    assertEquals(2610, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st4, bst.getStopTime());
    assertSame(blockTrips.get(1), bst.getTrip());
    bst = stopTimes.get(4);
    assertEquals(35 * 60, bst.getAccumulatedSlackTime());
    assertEquals(4, bst.getBlockSequence());
    assertEquals(3330, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st5, bst.getStopTime());
    assertSame(blockTrips.get(2), bst.getTrip());
    bst = stopTimes.get(5);
    assertEquals(40 * 60, bst.getAccumulatedSlackTime());
    assertEquals(5, bst.getBlockSequence());
    assertEquals(4230, bst.getDistanceAlongBlock(), 0.0);
    assertSame(st6, bst.getStopTime());
    assertSame(blockTrips.get(2), bst.getTrip());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Builder(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl.Builder) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) 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) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) Test(org.junit.Test)

Example 23 with ServiceIdActivation

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

the class ServiceIdOverlapCacheTest method test.

@Test
public void test() {
    CalendarService calendarService = Mockito.mock(CalendarService.class);
    TimeZone tz = TimeZone.getDefault();
    AgencyAndId serviceIdA = new AgencyAndId("1", "serviceIdA");
    AgencyAndId serviceIdB = new AgencyAndId("1", "serviceIdB");
    AgencyAndId serviceIdC = new AgencyAndId("1", "serviceIdC");
    AgencyAndId serviceIdD = new AgencyAndId("1", "serviceIdD");
    LocalizedServiceId lsidA = new LocalizedServiceId(serviceIdA, tz);
    LocalizedServiceId lsidB = new LocalizedServiceId(serviceIdB, tz);
    LocalizedServiceId lsidC = new LocalizedServiceId(serviceIdC, tz);
    LocalizedServiceId lsidD = new LocalizedServiceId(serviceIdD, tz);
    Set<ServiceDate> serviceDatesA = set(new ServiceDate(2010, 9, 10), new ServiceDate(2010, 9, 11));
    Set<ServiceDate> serviceDatesB = set(new ServiceDate(2010, 9, 11), new ServiceDate(2010, 9, 12));
    Set<ServiceDate> serviceDatesC = set(new ServiceDate(2010, 9, 12), new ServiceDate(2010, 9, 13));
    Set<ServiceDate> serviceDatesD = set(new ServiceDate(2010, 9, 13));
    Mockito.when(calendarService.getServiceDatesForServiceId(serviceIdA)).thenReturn(serviceDatesA);
    Mockito.when(calendarService.getServiceDatesForServiceId(serviceIdB)).thenReturn(serviceDatesB);
    Mockito.when(calendarService.getServiceDatesForServiceId(serviceIdC)).thenReturn(serviceDatesC);
    Mockito.when(calendarService.getServiceDatesForServiceId(serviceIdD)).thenReturn(serviceDatesD);
    ServiceIdOverlapCache cache = new ServiceIdOverlapCache();
    cache.setCalendarService(calendarService);
    List<ServiceIdActivation> combinations = cache.getOverlappingServiceIdCombinations(set(lsidA, lsidB, lsidC, lsidD));
    assertEquals(4, combinations.size());
    ServiceIdActivation combo = combinations.get(0);
    assertEquals(Arrays.asList(lsidA, lsidB), combo.getActiveServiceIds());
    assertEquals(Arrays.asList(), combo.getInactiveServiceIds());
    combo = combinations.get(1);
    assertEquals(Arrays.asList(lsidB, lsidC), combo.getActiveServiceIds());
    assertEquals(Arrays.asList(), combo.getInactiveServiceIds());
    combo = combinations.get(2);
    assertEquals(Arrays.asList(lsidC, lsidD), combo.getActiveServiceIds());
    assertEquals(Arrays.asList(), combo.getInactiveServiceIds());
    combo = combinations.get(3);
    assertEquals(Arrays.asList(lsidA), combo.getActiveServiceIds());
    assertEquals(Arrays.asList(lsidB), combo.getInactiveServiceIds());
    combinations = cache.getOverlappingServiceIdCombinations(set(lsidA, lsidB, lsidC, lsidD));
    Mockito.verify(calendarService, Mockito.times(1)).getServiceDatesForServiceId(serviceIdA);
    Mockito.verify(calendarService, Mockito.times(1)).getServiceDatesForServiceId(serviceIdB);
    Mockito.verify(calendarService, Mockito.times(1)).getServiceDatesForServiceId(serviceIdC);
    Mockito.verify(calendarService, Mockito.times(1)).getServiceDatesForServiceId(serviceIdD);
}
Also used : TimeZone(java.util.TimeZone) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceIdOverlapCache(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.ServiceIdOverlapCache) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) Test(org.junit.Test)

Example 24 with ServiceIdActivation

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

the class ExtendedCalendarServiceImpl method determineAllServiceIds.

private Set<ServiceIdActivation> determineAllServiceIds() {
    Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
    for (BlockEntry block : _transitGraphDao.getAllBlocks()) {
        for (BlockConfigurationEntry blockConfig : block.getConfigurations()) {
            ServiceIdActivation serviceIds = blockConfig.getServiceIds();
            allServiceIds.add(serviceIds);
        }
    }
    return allServiceIds;
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) HashSet(java.util.HashSet)

Example 25 with ServiceIdActivation

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

the class ExtendedCalendarServiceImpl method cacheServiceDatesForServiceIds.

private void cacheServiceDatesForServiceIds() {
    if (_serviceDateRangeCache != null) {
        _serviceDateRangeCache.removeAll();
    }
    _serviceDatesByServiceIds.clear();
    Set<ServiceIdActivation> allServiceIds = determineAllServiceIds();
    Date lowerBounds = null;
    if (_serviceDateLowerBoundsInWeeks != -1) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.WEEK_OF_YEAR, -_serviceDateLowerBoundsInWeeks);
        lowerBounds = c.getTime();
    }
    Date upperBounds = null;
    if (_serviceDateUpperBoundsInWeeks != -1) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.WEEK_OF_YEAR, _serviceDateUpperBoundsInWeeks);
        upperBounds = c.getTime();
    }
    for (ServiceIdActivation serviceIds : allServiceIds) {
        List<Date> dates = computeServiceDatesForServiceIds(serviceIds, lowerBounds, upperBounds);
        _serviceDatesByServiceIds.put(serviceIds, dates);
    }
}
Also used : Calendar(java.util.Calendar) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate)

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