Search in sources :

Example 71 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class DeduplicateServiceIdsStrategyTest method test.

@Test
public void test() throws IOException {
    _gtfs.putTrips(2, "r0", "sid0,sid1");
    _gtfs.putCalendars(2, "start_date=20120630", "end_date=20121224", "mask=1111100");
    GtfsMutableRelationalDao dao = _gtfs.read();
    assertEquals(2, dao.getAllCalendars().size());
    _strategy.run(_context, dao);
    assertEquals(1, dao.getAllCalendars().size());
    AgencyAndId serviceId = new AgencyAndId("a0", "sid0");
    assertNotNull(dao.getCalendarForServiceId(serviceId));
    for (Trip trip : dao.getAllTrips()) {
        assertEquals(serviceId, trip.getServiceId());
    }
    assertNull(dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1")));
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 72 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class TrimTripTransformStrategyTest method testMatching.

@Test
public void testMatching() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(6);
    _gtfs.putRoutes(2);
    _gtfs.putTrips(2, "r0,r1", "sid0");
    _gtfs.putStopTimes("t0,t1", "s0,s1,s2,s3,s4,s5");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new PropertyValueEntityMatch(new PropertyPathExpression("route.id.id"), new SimpleValueMatcher("r1"))));
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    {
        Trip trip = dao.getTripForId(new AgencyAndId("a0", "t0"));
        List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
        assertEquals(6, stopTimes.size());
    }
    {
        Trip trip = dao.getTripForId(new AgencyAndId("a0", "t1-s4"));
        List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
        assertEquals(4, stopTimes.size());
        assertEquals("s0", stopTimes.get(0).getStop().getId().getId());
        assertEquals("s3", stopTimes.get(3).getStop().getId().getId());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) SimpleValueMatcher(org.onebusaway.gtfs_transformer.match.SimpleValueMatcher) PropertyPathExpression(org.onebusaway.collections.beans.PropertyPathExpression) List(java.util.List) PropertyValueEntityMatch(org.onebusaway.gtfs_transformer.match.PropertyValueEntityMatch) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) Test(org.junit.Test)

Example 73 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsRelationalDaoImpl method getTripAgencyIdsReferencingServiceId.

@Override
public List<String> getTripAgencyIdsReferencingServiceId(AgencyAndId serviceId) {
    if (_tripAgencyIdsByServiceId == null) {
        Map<AgencyAndId, Set<String>> agencyIdsByServiceIds = new HashMap<AgencyAndId, Set<String>>();
        for (Trip trip : getAllTrips()) {
            AgencyAndId tripId = trip.getId();
            String tripAgencyId = tripId.getAgencyId();
            AgencyAndId tripServiceId = trip.getServiceId();
            Set<String> agencyIds = agencyIdsByServiceIds.get(tripServiceId);
            if (agencyIds == null) {
                agencyIds = new HashSet<String>();
                agencyIdsByServiceIds.put(tripServiceId, agencyIds);
            }
            agencyIds.add(tripAgencyId);
        }
        _tripAgencyIdsByServiceId = new HashMap<AgencyAndId, List<String>>();
        for (Map.Entry<AgencyAndId, Set<String>> entry : agencyIdsByServiceIds.entrySet()) {
            AgencyAndId tripServiceId = entry.getKey();
            List<String> agencyIds = new ArrayList<String>(entry.getValue());
            Collections.sort(agencyIds);
            _tripAgencyIdsByServiceId.put(tripServiceId, agencyIds);
        }
    }
    List<String> agencyIds = _tripAgencyIdsByServiceId.get(serviceId);
    if (agencyIds == null)
        agencyIds = new ArrayList<String>();
    return agencyIds;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Set(java.util.Set) HashSet(java.util.HashSet) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 74 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsRelationalDaoImpl method getTripsForBlockId.

@Override
public List<Trip> getTripsForBlockId(AgencyAndId blockId) {
    if (_tripsByBlockId == null) {
        _tripsByBlockId = new HashMap<AgencyAndId, List<Trip>>();
        for (Trip trip : getAllTrips()) {
            if (trip.getBlockId() != null) {
                AgencyAndId bid = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
                List<Trip> trips = _tripsByBlockId.get(bid);
                if (trips == null) {
                    trips = new ArrayList<Trip>();
                    _tripsByBlockId.put(bid, trips);
                }
                trips.add(trip);
            }
        }
    }
    return list(_tripsByBlockId.get(blockId));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List)

Example 75 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class PropertyMethodResolverImplTest method testRouteTripsVirtualMethod.

@Test
public void testRouteTripsVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Route route = new Route();
    route.setId(new AgencyAndId("1", "r0"));
    _dao.saveEntity(route);
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "t0"));
    trip.setRoute(route);
    _dao.saveEntity(trip);
    PropertyMethod method = _resolver.getPropertyMethod(Route.class, "trips");
    assertEquals(Arrays.asList(trip), method.invoke(route));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)102 Test (org.junit.Test)63 Trip (org.onebusaway.gtfs.model.Trip)37 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)25 Stop (org.onebusaway.gtfs.model.Stop)24 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)17 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)16 ArrayList (java.util.ArrayList)15 Route (org.onebusaway.gtfs.model.Route)15 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)15 Agency (org.onebusaway.gtfs.model.Agency)13 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)12 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)11 HashSet (java.util.HashSet)10 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 List (java.util.List)9 Frequency (org.onebusaway.gtfs.model.Frequency)9 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)7 Set (java.util.Set)6