Search in sources :

Example 1 with Frequency

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

the class EntityRetentionGraph method retainTrip.

private void retainTrip(Trip trip, boolean retainUp) {
    if (retainUp) {
        for (StopTime stopTime : _dao.getStopTimesForTrip(trip)) retainUp(stopTime);
        if (_retainBlocks && trip.getBlockId() != null) {
            AgencyAndId blockId = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
            retainUp(new BlockIdKey(blockId));
        }
        for (Frequency frequency : _dao.getFrequenciesForTrip(trip)) retainUp(frequency);
    } else {
        retainDown(trip.getRoute());
        retainDown(new ServiceIdKey(trip.getServiceId()));
        AgencyAndId shapeId = trip.getShapeId();
        if (shapeId != null && shapeId.hasValues())
            retainDown(new ShapeIdKey(shapeId));
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ShapeIdKey(org.onebusaway.gtfs_transformer.collections.ShapeIdKey) Frequency(org.onebusaway.gtfs.model.Frequency) ServiceIdKey(org.onebusaway.gtfs_transformer.collections.ServiceIdKey) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 2 with Frequency

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

the class GtfsRelationalDaoImplTest method testBart.

@Test
public void testBart() throws IOException {
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    GtfsTestData.readGtfs(dao, GtfsTestData.getBartGtfs(), "BART");
    List<String> tripAgencyIds = dao.getTripAgencyIdsReferencingServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(1, tripAgencyIds.size());
    assertEquals("BART", tripAgencyIds.get(0));
    Agency agency = dao.getAgencyForId("BART");
    List<Route> routes = dao.getRoutesForAgency(agency);
    assertEquals(10, routes.size());
    agency = dao.getAgencyForId("AirBART");
    routes = dao.getRoutesForAgency(agency);
    assertEquals(1, routes.size());
    Route route = dao.getRouteForId(new AgencyAndId("BART", "01"));
    List<Trip> trips = dao.getTripsForRoute(route);
    assertEquals(225, trips.size());
    Trip trip = dao.getTripForId(new AgencyAndId("BART", "15PB1"));
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(12, stopTimes.size());
    // Ensure the stopTimes are in stop sequence order
    for (int i = 0; i < stopTimes.size() - 1; i++) assertTrue(stopTimes.get(i).getStopSequence() < stopTimes.get(i + 1).getStopSequence());
    Stop stop = dao.getStopForId(new AgencyAndId("BART", "DBRK"));
    stopTimes = dao.getStopTimesForStop(stop);
    assertEquals(584, stopTimes.size());
    List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(new AgencyAndId("BART", "airbart-dn.csv"));
    assertEquals(50, shapePoints.size());
    for (int i = 0; i < shapePoints.size() - 1; i++) assertTrue(shapePoints.get(i).getSequence() < shapePoints.get(i + 1).getSequence());
    trip = dao.getTripForId(new AgencyAndId("AirBART", "M-FSAT1DN"));
    List<Frequency> frequencies = dao.getFrequenciesForTrip(trip);
    assertEquals(1, frequencies.size());
    Frequency frequency = frequencies.get(0);
    assertEquals(5 * 60 * 60, frequency.getStartTime());
    assertEquals(6 * 60 * 60, frequency.getEndTime());
    assertEquals(trip, frequency.getTrip());
    assertEquals(1200, frequency.getHeadwaySecs());
    ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
    List<ServiceCalendarDate> calendarDates = dao.getCalendarDatesForServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(7, calendarDates.size());
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Frequency(org.onebusaway.gtfs.model.Frequency) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 3 with Frequency

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

the class HibernateGtfsRelationalImplBartTest method testFrequenciesForTrip.

@Test
public void testFrequenciesForTrip() {
    Trip trip = _dao.getTripForId(new AgencyAndId("AirBART", "M-FSAT1DN"));
    List<Frequency> frequencies = _dao.getFrequenciesForTrip(trip);
    assertEquals(1, frequencies.size());
    Frequency frequency = frequencies.get(0);
    assertEquals(5 * 60 * 60, frequency.getStartTime());
    assertEquals(6 * 60 * 60, frequency.getEndTime());
    assertEquals(trip, frequency.getTrip());
    assertEquals(1200, frequency.getHeadwaySecs());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Frequency(org.onebusaway.gtfs.model.Frequency) Test(org.junit.Test)

Example 4 with Frequency

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

the class GtfsMappingTest method testFrequency.

@Test
public void testFrequency() throws CsvEntityIOException, IOException {
    _reader.setDefaultAgencyId("1");
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "trip"));
    _reader.injectEntity(trip);
    StringBuilder b = new StringBuilder();
    b.append("trip_id,start_time,end_time,headway_secs,exact_times\n");
    b.append("trip,08:30:00,09:45:00,300,1\n");
    _reader.readEntities(Frequency.class, new StringReader(b.toString()));
    Frequency frequency = _dao.getFrequencyForId(1);
    assertEquals(30600, frequency.getStartTime());
    assertEquals(35100, frequency.getEndTime());
    assertEquals(1, frequency.getExactTimes());
    assertEquals(300, frequency.getHeadwaySecs());
    assertSame(trip, frequency.getTrip());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StringReader(java.io.StringReader) Frequency(org.onebusaway.gtfs.model.Frequency) Test(org.junit.Test)

Example 5 with Frequency

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

the class AddEntityTest method test.

@Test
public void test() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(1);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0");
    addModification("{'op':'add','obj':{'class':'Frequency','trip':'t0','startTime':'08:00:00','endTime':'10:00:00','headwaySecs':600}}");
    GtfsRelationalDao dao = transform();
    Collection<Frequency> frequencies = dao.getAllFrequencies();
    assertEquals(1, frequencies.size());
    Frequency frequency = frequencies.iterator().next();
    assertSame(dao.getTripForId(new AgencyAndId("a0", "t0")), frequency.getTrip());
    assertEquals(StopTimeFieldMappingFactory.getStringAsSeconds("08:00:00"), frequency.getStartTime());
    assertEquals(StopTimeFieldMappingFactory.getStringAsSeconds("10:00:00"), frequency.getEndTime());
    assertEquals(600, frequency.getHeadwaySecs());
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Frequency(org.onebusaway.gtfs.model.Frequency) Test(org.junit.Test)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 Frequency (org.onebusaway.gtfs.model.Frequency)9 Test (org.junit.Test)8 Trip (org.onebusaway.gtfs.model.Trip)6 StopTime (org.onebusaway.gtfs.model.StopTime)4 Agency (org.onebusaway.gtfs.model.Agency)3 Route (org.onebusaway.gtfs.model.Route)3 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)3 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)3 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)3 Stop (org.onebusaway.gtfs.model.Stop)3 Transfer (org.onebusaway.gtfs.model.Transfer)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 StringReader (java.io.StringReader)2 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)2 FareRule (org.onebusaway.gtfs.model.FareRule)2 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)2 File (java.io.File)1 Block (org.onebusaway.gtfs.model.Block)1 FeedInfo (org.onebusaway.gtfs.model.FeedInfo)1