Search in sources :

Example 26 with Stop

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

the class EntityRetentionGraph method retainStop.

private void retainStop(Stop stop, boolean retainUp) {
    if (retainUp) {
        for (StopTime stopTime : _dao.getStopTimesForStop(stop)) retainUp(stopTime);
    } else {
        String parentStationId = stop.getParentStation();
        if (parentStationId != null) {
            AgencyAndId id = stop.getId();
            Stop parent = _dao.getStopForId(new AgencyAndId(id.getAgencyId(), parentStationId));
            retainDown(parent);
        }
        /**
       * Need to make sure a stop's agency is included as well, since the agency
       * might not be included by any routes serving that stop
       */
        AgencyAndId stopId = stop.getId();
        String agencyId = stopId.getAgencyId();
        Agency agency = _dao.getAgencyForId(agencyId);
        if (agency != null) {
            retainDown(agency);
        }
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 27 with Stop

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

the class StopTimesFactoryStrategy method getTimesForStops.

private int[] getTimesForStops(List<Stop> stops) {
    double totalDistance = 0;
    double[] distances = new double[stops.size()];
    Stop prevStop = null;
    for (int i = 0; i < stops.size(); ++i) {
        Stop stop = stops.get(i);
        if (prevStop != null) {
            totalDistance += SphericalGeometryLibrary.distance(stop.getLat(), stop.getLon(), prevStop.getLat(), prevStop.getLon());
        }
        distances[i] = totalDistance;
        prevStop = stop;
    }
    int startTimeSecs = StopTimeFieldMappingFactory.getStringAsSeconds(startTime);
    int endTimeSecs = StopTimeFieldMappingFactory.getStringAsSeconds(endTime);
    int duration = endTimeSecs - startTimeSecs;
    int[] times = new int[stops.size()];
    for (int i = 0; i < stops.size(); ++i) {
        times[i] = startTimeSecs + (int) (distances[i] / totalDistance * duration);
    }
    return times;
}
Also used : Stop(org.onebusaway.gtfs.model.Stop)

Example 28 with Stop

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

the class GtfsDaoImplTest method testBart.

@Test
public void testBart() throws IOException {
    GtfsDaoImpl dao = new GtfsDaoImpl();
    GtfsTestData.readGtfs(dao, GtfsTestData.getBartGtfs(), "BART");
    Collection<Agency> agencies = dao.getAllAgencies();
    assertEquals(2, agencies.size());
    Agency agency = dao.getAgencyForId("BART");
    assertEquals("BART", agency.getId());
    Collection<ServiceCalendarDate> calendarDates = dao.getAllCalendarDates();
    assertEquals(32, calendarDates.size());
    ServiceCalendarDate calendarDate = dao.getCalendarDateForId(1);
    assertEquals(new AgencyAndId("BART", "SUN"), calendarDate.getServiceId());
    assertEquals(new ServiceDate(2009, 1, 1), calendarDate.getDate());
    assertEquals(1, calendarDate.getExceptionType());
    Collection<ServiceCalendar> calendars = dao.getAllCalendars();
    assertEquals(5, calendars.size());
    ServiceCalendar calendar = dao.getCalendarForId(1);
    assertEquals(new AgencyAndId("BART", "WKDY"), calendar.getServiceId());
    assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
    assertEquals(new ServiceDate(2010, 12, 31), calendar.getEndDate());
    assertEquals(1, calendar.getMonday());
    assertEquals(1, calendar.getTuesday());
    assertEquals(1, calendar.getWednesday());
    assertEquals(1, calendar.getThursday());
    assertEquals(1, calendar.getFriday());
    assertEquals(0, calendar.getSaturday());
    assertEquals(0, calendar.getSunday());
    Collection<FareAttribute> fareAttributes = dao.getAllFareAttributes();
    assertEquals(106, fareAttributes.size());
    FareAttribute fareAttribute = dao.getFareAttributeForId(new AgencyAndId("BART", "30"));
    assertEquals(new AgencyAndId("BART", "30"), fareAttribute.getId());
    Collection<FareRule> fareRules = dao.getAllFareRules();
    assertEquals(1849, fareRules.size());
    FareRule fareRule = dao.getFareRuleForId(1);
    assertEquals(new AgencyAndId("BART", "98"), fareRule.getFare().getId());
    Collection<Frequency> frequencies = dao.getAllFrequencies();
    assertEquals(6, frequencies.size());
    Frequency frequency = dao.getFrequencyForId(1);
    assertEquals(new AgencyAndId("AirBART", "M-FSAT1DN"), frequency.getTrip().getId());
    Collection<Route> routes = dao.getAllRoutes();
    assertEquals(11, routes.size());
    Route route = dao.getRouteForId(new AgencyAndId("BART", "01"));
    assertEquals(new AgencyAndId("BART", "01"), route.getId());
    Collection<ShapePoint> shapePoints = dao.getAllShapePoints();
    assertEquals(105, shapePoints.size());
    ShapePoint shapePoint = dao.getShapePointForId(1);
    assertEquals(new AgencyAndId("BART", "airbart-dn.csv"), shapePoint.getShapeId());
    Collection<Stop> stops = dao.getAllStops();
    assertEquals(46, stops.size());
    Stop stop = dao.getStopForId(new AgencyAndId("BART", "DBRK"));
    assertEquals("Downtown Berkeley BART", stop.getName());
    Collection<StopTime> stopTimes = dao.getAllStopTimes();
    assertEquals(33270, stopTimes.size());
    StopTime stopTime = stopTimes.iterator().next();
    assertEquals(18000, stopTime.getArrivalTime());
    Collection<Transfer> transfers = dao.getAllTransfers();
    assertEquals(4, transfers.size());
    Transfer transfer = dao.getTransferForId(1);
    assertEquals(1, transfer.getTransferType());
    Collection<Trip> trips = dao.getAllTrips();
    assertEquals(1620, trips.size());
    Trip trip = dao.getTripForId(new AgencyAndId("BART", "15PB1"));
    assertEquals(new AgencyAndId("BART", "WKDY"), trip.getServiceId());
}
Also used : FareAttribute(org.onebusaway.gtfs.model.FareAttribute) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) FareRule(org.onebusaway.gtfs.model.FareRule) Transfer(org.onebusaway.gtfs.model.Transfer) Frequency(org.onebusaway.gtfs.model.Frequency) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 29 with Stop

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

the class GtfsRelationalDaoImplTest method testStationSubStops.

@Test
public void testStationSubStops() {
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    Stop st = new Stop();
    st.setLocationType(1);
    st.setId(new AgencyAndId("X", "ST"));
    dao.saveEntity(st);
    Stop st1 = new Stop();
    st1.setLocationType(0);
    st1.setId(new AgencyAndId("X", "ST1"));
    st1.setParentStation("ST");
    dao.saveEntity(st1);
    Stop st2 = new Stop();
    st2.setLocationType(0);
    st2.setId(new AgencyAndId("X", "ST2"));
    st2.setParentStation("ST");
    dao.saveEntity(st2);
    Stop st3 = new Stop();
    st3.setLocationType(0);
    st3.setId(new AgencyAndId("X", "ST3"));
    dao.saveEntity(st3);
    List<Stop> sts = dao.getStopsForStation(st);
    assertTrue(sts.contains(st1));
    assertTrue(sts.contains(st2));
    assertTrue(!sts.contains(st3));
    assertEquals(sts.size(), 2);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

Example 30 with Stop

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

the class ExtensionsTest method testExtensionRead.

@Test
public void testExtensionRead() throws IOException {
    MockGtfs gtfs = MockGtfs.create();
    gtfs.putMinimal();
    gtfs.putStops(2, "label=a,b");
    DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
    factory.addExtension(Stop.class, StopExtension.class);
    GtfsReader reader = new GtfsReader();
    reader.setEntitySchemaFactory(factory);
    GtfsMutableRelationalDao dao = gtfs.read(reader);
    Stop stop = dao.getStopForId(new AgencyAndId("a0", "s0"));
    StopExtension extension = stop.getExtension(StopExtension.class);
    assertEquals("a", extension.getLabel());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) Test(org.junit.Test) GtfsWriterTest(org.onebusaway.gtfs.serialization.GtfsWriterTest)

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)40 Test (org.junit.Test)29 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)24 StopTime (org.onebusaway.gtfs.model.StopTime)11 Trip (org.onebusaway.gtfs.model.Trip)11 Agency (org.onebusaway.gtfs.model.Agency)8 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)7 Route (org.onebusaway.gtfs.model.Route)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)6 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)5 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)5 FareRule (org.onebusaway.gtfs.model.FareRule)4 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CsvEntityContextImpl (org.onebusaway.csv_entities.CsvEntityContextImpl)3 Frequency (org.onebusaway.gtfs.model.Frequency)3 Transfer (org.onebusaway.gtfs.model.Transfer)3