Search in sources :

Example 36 with Agency

use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.

the class StopConsolidationSuggestionsTask method run.

@Override
public void run() {
    try {
        double distanceThreshold = 20;
        _log.info("begin stop consolidation suggestions with distanceThreshold=" + distanceThreshold);
        TreeUnionFind<AgencyAndId> existingConsolidatedStops = new TreeUnionFind<AgencyAndId>();
        existingConsolidatedStops = loadExistingConsolidatedStops(CONSOLIDATED_URL);
        TreeUnionFind<AgencyAndId> union = new TreeUnionFind<AgencyAndId>();
        List<Collection<Stop>> allStops = new ArrayList<Collection<Stop>>();
        for (Agency agency : _dao.getAllAgencies()) {
            Collection<Stop> stops = getStopsForAgency(_dao, agency);
            for (Collection<Stop> previousStops : allStops) {
                for (Stop stopA : previousStops) {
                    for (Stop stopB : stops) {
                        double d = SphericalGeometryLibrary.distance(stopA.getLat(), stopA.getLon(), stopB.getLat(), stopB.getLon());
                        if (d < distanceThreshold && !existingConsolidatedStops.isSameSet(stopA.getId(), stopB.getId())) {
                            union.union(stopA.getId(), stopB.getId());
                        }
                    }
                }
            }
            allStops.add(stops);
        }
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
        _logger.header("stop_consolidation_suggestions.csv", "new_stops,existing_stops");
        for (Set<AgencyAndId> set : union.getSetMembers()) {
            StringBuffer newStopBuffer = new StringBuffer();
            StringBuffer existingStopBuffer = new StringBuffer();
            Set<Sentry> existing = new HashSet<Sentry>();
            boolean first = true;
            for (AgencyAndId stopId : set) {
                if (first)
                    first = false;
                else {
                    writer.print(' ');
                    newStopBuffer.append(" ");
                }
                if (existingConsolidatedStops.contains(stopId)) {
                    existing.add(existingConsolidatedStops.find(stopId));
                }
                writer.print(AgencyAndIdLibrary.convertToString(stopId));
                newStopBuffer.append(AgencyAndIdLibrary.convertToString(stopId));
            }
            writer.println();
            for (Sentry sentry : existing) {
                writer.println("  => " + existingConsolidatedStops.members(sentry));
                existingStopBuffer.append(existingConsolidatedStops.members(sentry));
            }
            _logger.log("stop_consolidation_suggestions.csv", newStopBuffer.toString(), existingStopBuffer.toString());
            writer.flush();
        }
        _log.info("end stop consolidation suggestions");
    } catch (Exception any) {
        _log.error("exception:", any);
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TreeUnionFind(org.onebusaway.utility.collections.TreeUnionFind) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Collection(java.util.Collection) OutputStreamWriter(java.io.OutputStreamWriter) Sentry(org.onebusaway.utility.collections.TreeUnionFind.Sentry) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet)

Example 37 with Agency

use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.

the class GenerateNarrativesTaskTest method testGenerateAgencyNarratives.

@Test
public void testGenerateAgencyNarratives() {
    Agency agency = new Agency();
    agency.setId("1");
    agency.setLang("en");
    agency.setName("Agency");
    agency.setPhone("555-1234");
    agency.setTimezone("America/New_York");
    agency.setUrl("http://agency.gov/");
    Mockito.when(_gtfsDao.getAllAgencies()).thenReturn(Arrays.asList(agency));
    Modification mod = new Modification();
    mod.setType(AgencyNarrative.class);
    mod.setId("1");
    mod.setProperty("disclaimer");
    mod.setValue("Use at your own risk.");
    _modifications.setModifications(Arrays.asList(mod));
    _task.generateAgencyNarratives(_provider);
    AgencyNarrative narrative = _provider.getNarrativeForAgencyId("1");
    assertEquals(mod.getValue(), narrative.getDisclaimer());
    assertEquals(agency.getLang(), narrative.getLang());
    assertEquals(agency.getName(), narrative.getName());
    assertEquals(agency.getPhone(), narrative.getPhone());
    assertEquals(agency.getTimezone(), narrative.getTimezone());
    assertEquals(agency.getUrl(), narrative.getUrl());
}
Also used : Modification(org.onebusaway.transit_data_federation.model.modifications.Modification) Agency(org.onebusaway.gtfs.model.Agency) AgencyNarrative(org.onebusaway.transit_data_federation.model.narrative.AgencyNarrative) Test(org.junit.Test)

Example 38 with Agency

use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.

the class AgencyEntriesFactoryTest method testProcessAgencies.

@Test
public void testProcessAgencies() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agencyA = new Agency();
    agencyA.setId("A");
    Agency agencyB = new Agency();
    agencyB.setId("B");
    Mockito.when(gtfsDao.getAllAgencies()).thenReturn(Arrays.asList(agencyA, agencyB));
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntriesFactory factory = new AgencyEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processAgencies(graph);
    AgencyEntry agencyEntryA = graph.getAgencyForId("A");
    assertEquals("A", agencyEntryA.getId());
    AgencyEntry agencyEntryB = graph.getAgencyForId("B");
    assertEquals("B", agencyEntryB.getId());
    List<AgencyEntry> agencies = graph.getAllAgencies();
    assertEquals(2, agencies.size());
    assertTrue(agencies.contains(agencyEntryA));
    assertTrue(agencies.contains(agencyEntryB));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Agency(org.onebusaway.gtfs.model.Agency) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Test(org.junit.Test)

Example 39 with Agency

use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.

the class RouteEntriesFactoryTest method testProcessRoutes.

@Test
public void testProcessRoutes() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agency = new Agency();
    agency.setId("A");
    Route routeA = new Route();
    routeA.setAgency(agency);
    routeA.setId(new AgencyAndId("A", "routeA"));
    Route routeB = new Route();
    routeB.setAgency(agency);
    routeB.setId(new AgencyAndId("A", "routeB"));
    Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(routeA, routeB));
    TransitGraphImpl graph = new TransitGraphImpl();
    RouteEntriesFactory factory = new RouteEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRoutes(graph);
    RouteEntryImpl routeEntryA = graph.getRouteForId(routeA.getId());
    RouteEntryImpl routeEntryB = graph.getRouteForId(routeB.getId());
    List<RouteEntry> routes = graph.getAllRoutes();
    assertEquals(2, routes.size());
    assertTrue(routes.contains(routeEntryA));
    assertTrue(routes.contains(routeEntryB));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 40 with Agency

use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.

the class StopTimeEntriesFactoryTest method testDuplicateRemoval.

@Test
public void testDuplicateRemoval() {
    TransitGraphImpl graph = new TransitGraphImpl();
    Stop stopA = new Stop();
    stopA.setId(aid("stopA"));
    graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
    Stop stopB = new Stop();
    stopB.setId(aid("stopB"));
    graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
    Stop stopC = new Stop();
    stopC.setId(aid("stopC"));
    graph.putStopEntry(stop("stopC", 47.66847942216854, -122.37545336180114));
    graph.refreshStopMapping();
    Agency agency = new Agency();
    agency.setId("1");
    agency.setTimezone("America/Los_Angeles");
    Route route = new Route();
    route.setAgency(agency);
    Trip trip = new Trip();
    trip.setRoute(route);
    trip.setServiceId(aid("serviceId"));
    TripEntryImpl tripEntry = trip("trip");
    StopTime stA = new StopTime();
    stA.setId(100);
    stA.setArrivalTime(time(9, 00));
    stA.setDepartureTime(time(9, 05));
    stA.setStopSequence(100);
    stA.setStop(stopA);
    stA.setTrip(trip);
    StopTime stB = new StopTime();
    stB.setId(101);
    stB.setArrivalTime(time(9, 00));
    stB.setDepartureTime(time(9, 05));
    stB.setStopSequence(101);
    stB.setStop(stopB);
    stB.setTrip(trip);
    StopTime stC = new StopTime();
    stC.setId(102);
    stC.setArrivalTime(time(10, 00));
    stC.setDepartureTime(time(10, 05));
    stC.setStopSequence(102);
    stC.setStop(stopC);
    stC.setTrip(trip);
    StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
    factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    List<StopTime> stopTimes = Arrays.asList(stA, stB, stC);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    ShapePoints shapePoints = shapePointsFactory.create();
    List<StopTimeEntryImpl> entries = factory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
    assertEquals(stopTimes.size(), entries.size());
    StopTimeEntryImpl entry = entries.get(0);
    assertEquals(0, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 00), entry.getArrivalTime());
    assertEquals(time(9, 05), entry.getDepartureTime());
    assertEquals(0, entry.getSequence());
    assertEquals(181.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(5 * 60, entry.getSlackTime());
    entry = entries.get(1);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 28, 31), entry.getArrivalTime());
    assertEquals(time(9, 28, 31), entry.getDepartureTime());
    assertEquals(1, entry.getSequence());
    assertEquals(738.7, entry.getShapeDistTraveled(), 0.1);
    assertEquals(0, entry.getSlackTime());
    entry = entries.get(2);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(10, 00), entry.getArrivalTime());
    assertEquals(time(10, 05), entry.getDepartureTime());
    assertEquals(2, entry.getSequence());
    assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(5 * 60, entry.getSlackTime());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntriesFactory(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) DistanceAlongShapeLibrary(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Aggregations

Agency (org.onebusaway.gtfs.model.Agency)57 Test (org.junit.Test)28 Route (org.onebusaway.gtfs.model.Route)21 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 Trip (org.onebusaway.gtfs.model.Trip)19 Stop (org.onebusaway.gtfs.model.Stop)18 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)9 ArrayList (java.util.ArrayList)8 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)7 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)7 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)6 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)5 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)5 StopPattern (org.opentripplanner.model.StopPattern)5 Graph (org.opentripplanner.routing.graph.Graph)5