Search in sources :

Example 11 with StopEntry

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

the class GenerateNarrativesTask method generateStopNarratives.

public void generateStopNarratives(NarrativeProviderImpl provider) {
    Map<AgencyAndId, List<ProjectedPoint>> shapePointCache = new HashMap<AgencyAndId, List<ProjectedPoint>>();
    int index = 0;
    Collection<Stop> allStops = _gtfsDao.getAllStops();
    Map<AgencyAndId, Stop> stopsById = MappingLibrary.mapToValue(allStops, "id");
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allStops.size());
    for (StopEntry stopEntry : _transitGraphDao.getAllStops()) {
        if (index % logInterval == 0)
            _log.info("stops=" + index);
        index++;
        Stop stop = stopsById.get(stopEntry.getId());
        StopNarrative.Builder narrative = StopNarrative.builder();
        narrative.setCode(deduplicate(stop.getCode()));
        narrative.setDescription(deduplicate(stop.getDesc()));
        narrative.setName(deduplicate(stop.getName()));
        narrative.setUrl(deduplicate(stop.getUrl()));
        String direction = computeStopDirection(provider, shapePointCache, stop, stopEntry);
        narrative.setDirection(deduplicate(direction));
        provider.setNarrativeForStop(stopEntry.getId(), narrative.create());
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) DoubleArrayList(cern.colt.list.DoubleArrayList) List(java.util.List) ArrayList(java.util.ArrayList) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative)

Example 12 with StopEntry

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

the class GenerateStopSearchIndexTask method buildIndex.

private void buildIndex() throws IOException, ParseException {
    IndexWriter writer = new IndexWriter(_bundle.getStopSearchIndexPath(), new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
    for (StopEntry stopEntry : _transitGraphDao.getAllStops()) {
        StopNarrative narrative = _narrativeService.getStopForId(stopEntry.getId());
        Document document = getStopAsDocument(stopEntry, narrative);
        writer.addDocument(document);
    }
    writer.optimize();
    writer.close();
    _refreshService.refresh(RefreshableResources.STOP_SEARCH_DATA);
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) Document(org.apache.lucene.document.Document)

Example 13 with StopEntry

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

the class ShapeGeospatialIndexTask method buildShapeSpatialIndex.

private Map<CoordinateBounds, List<AgencyAndId>> buildShapeSpatialIndex() {
    Map<CoordinatePoint, Set<AgencyAndId>> shapeIdsByGridCellCorner = new FactoryMap<CoordinatePoint, Set<AgencyAndId>>(new HashSet<AgencyAndId>());
    CoordinateBounds fullBounds = new CoordinateBounds();
    for (StopEntry stop : _transitGraphDao.getAllStops()) {
        if (stop.getStopLat() > MIN_LAT_LON && stop.getStopLon() > MIN_LAT_LON && stop.getStopLat() < MAX_LAT_LON && stop.getStopLon() < MAX_LAT_LON) {
            fullBounds.addPoint(stop.getStopLat(), stop.getStopLon());
        } else {
            _log.error("rejecting stop " + stop + " for invalid (lat,lon)=" + stop.getStopLat() + ", " + stop.getStopLon());
        }
    }
    if (fullBounds.isEmpty()) {
        return Collections.emptyMap();
    }
    double centerLat = (fullBounds.getMinLat() + fullBounds.getMaxLat()) / 2;
    double centerLon = (fullBounds.getMinLon() + fullBounds.getMaxLon()) / 2;
    CoordinateBounds gridCellExample = SphericalGeometryLibrary.bounds(centerLat, centerLon, _gridSize / 2);
    double latStep = gridCellExample.getMaxLat() - gridCellExample.getMinLat();
    double lonStep = gridCellExample.getMaxLon() - gridCellExample.getMinLon();
    _log.info("generating shape point geospatial index...");
    Set<AgencyAndId> allShapeIds = getAllShapeIds();
    for (AgencyAndId shapeId : allShapeIds) {
        ShapePoints shapePoints = _shapePointHelper.getShapePointsForShapeId(shapeId);
        for (int i = 0; i < shapePoints.getSize(); i++) {
            double lat = shapePoints.getLatForIndex(i);
            double lon = shapePoints.getLonForIndex(i);
            addGridCellForShapePoint(shapeIdsByGridCellCorner, lat, lon, latStep, lonStep, shapeId);
            /**
             * If there is a particularly long stretch between shape points, we want
             * to fill in grid cells in-between
             */
            if (i > 0) {
                double prevLat = shapePoints.getLatForIndex(i - 1);
                double prevLon = shapePoints.getLonForIndex(i - 1);
                double totalDistance = SphericalGeometryLibrary.distance(prevLat, prevLon, lat, lon);
                for (double d = _gridSize; d < totalDistance; d += _gridSize) {
                    double r = d / totalDistance;
                    double latPart = (lat - prevLat) * r + prevLat;
                    double lonPart = (lon - prevLon) * r + prevLon;
                    addGridCellForShapePoint(shapeIdsByGridCellCorner, latPart, lonPart, latStep, lonStep, shapeId);
                }
            }
        }
    }
    _log.info("block shape geospatial nodes: " + shapeIdsByGridCellCorner.size());
    Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByGridCell = new HashMap<CoordinateBounds, List<AgencyAndId>>();
    for (Map.Entry<CoordinatePoint, Set<AgencyAndId>> entry : shapeIdsByGridCellCorner.entrySet()) {
        CoordinatePoint p = entry.getKey();
        CoordinateBounds bounds = new CoordinateBounds(p.getLat(), p.getLon(), p.getLat() + latStep, p.getLon() + lonStep);
        List<AgencyAndId> shapeIds = new ArrayList<AgencyAndId>(entry.getValue());
        shapeIdsByGridCell.put(bounds, shapeIds);
    }
    return shapeIdsByGridCell;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) HashSet(java.util.HashSet) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 14 with StopEntry

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

the class UserReportingServiceImpl method getRecordAsBean.

private TripProblemReportBean getRecordAsBean(TripProblemReportRecord record) {
    AgencyAndId stopId = record.getStopId();
    AgencyAndId tripId = record.getTripId();
    TripProblemReportBean bean = new TripProblemReportBean();
    bean.setCode(record.getCode());
    bean.setId(record.getId());
    bean.setServiceDate(record.getServiceDate());
    bean.setStatus(record.getStatus());
    bean.setLabel(record.getLabel());
    bean.setStopId(AgencyAndIdLibrary.convertToString(stopId));
    bean.setTime(record.getTime());
    bean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
    bean.setUserComment(record.getUserComment());
    bean.setUserLat(record.getUserLat());
    bean.setUserLon(record.getUserLon());
    bean.setUserLocationAccuracy(record.getUserLocationAccuracy());
    bean.setUserOnVehicle(record.isUserOnVehicle());
    bean.setUserVehicleNumber(record.getUserVehicleNumber());
    bean.setPredicted(record.isPredicted());
    bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
    bean.setDistanceAlongBlock(record.getDistanceAlongBlock());
    bean.setScheduleDeviation(record.getScheduleDeviation());
    bean.setVehicleLat(record.getVehicleLat());
    bean.setVehicleLon(record.getVehicleLon());
    if (stopId != null) {
        try {
            bean.setStop(_stopBeanService.getStopForId(stopId));
        } catch (NoSuchStopServiceException ex) {
        }
    }
    if (tripId != null) {
        bean.setTrip(_tripBeanService.getTripForId(tripId));
    }
    if (tripId != null && stopId != null) {
        TripEntry trip = _graph.getTripEntryForId(tripId);
        StopEntry stop = _graph.getStopEntryForId(stopId);
        if (trip != null && stop != null) {
            AgencyAndId vehicleId = record.getMatchedVehicleId();
            if (vehicleId == null)
                vehicleId = record.getVehicleId();
            ArrivalAndDepartureQuery query = new ArrivalAndDepartureQuery();
            query.setStop(stop);
            query.setStopSequence(-1);
            query.setTrip(trip);
            query.setServiceDate(record.getServiceDate());
            query.setVehicleId(vehicleId);
            query.setTime(record.getTime());
            ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
            if (instance != null) {
                StopTimeInstance sti = instance.getStopTimeInstance();
                StopTimeInstanceBean stopTimeBean = _stopTimeBeanService.getStopTimeInstanceAsBean(sti);
                bean.setStopTime(stopTimeBean);
            }
        }
    }
    return bean;
}
Also used : StopTimeInstanceBean(org.onebusaway.transit_data.model.StopTimeInstanceBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) ArrivalAndDepartureQuery(org.onebusaway.transit_data_federation.services.ArrivalAndDepartureQuery) NoSuchStopServiceException(org.onebusaway.exceptions.NoSuchStopServiceException) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) TripProblemReportBean(org.onebusaway.transit_data.model.problems.TripProblemReportBean)

Example 15 with StopEntry

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

the class WhereGeospatialServiceImplTest method test.

@Test
public void test() {
    WhereGeospatialServiceImpl service = new WhereGeospatialServiceImpl();
    TransitGraphDao dao = Mockito.mock(TransitGraphDao.class);
    service.setTransitGraphDao(dao);
    StopEntry stopA = stop("a", -0.5, -0.5);
    StopEntry stopB = stop("b", -0.5, 0.5);
    StopEntry stopC = stop("c", 0.5, -0.5);
    StopEntry stopD = stop("d", 0.5, 0.5);
    List<StopEntry> allStops = Arrays.asList(stopA, stopB, stopC, stopD);
    Mockito.when(dao.getAllStops()).thenReturn(allStops);
    service.initialize();
    List<AgencyAndId> stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 0, 0));
    assertEquals(1, stops.size());
    assertTrue(stops.contains(stopA.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(0, -1, 1, 0));
    assertEquals(1, stops.size());
    assertTrue(stops.contains(stopC.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 0));
    assertEquals(2, stops.size());
    assertTrue(stops.contains(stopA.getId()));
    assertTrue(stops.contains(stopC.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 1));
    assertEquals(4, stops.size());
    assertTrue(stops.contains(stopA.getId()));
    assertTrue(stops.contains(stopB.getId()));
    assertTrue(stops.contains(stopC.getId()));
    assertTrue(stops.contains(stopD.getId()));
    stops = service.getStopsByBounds(new CoordinateBounds(0.8, 0.8, 1, 1));
    assertEquals(0, stops.size());
}
Also used : TransitGraphDao(org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Aggregations

StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)54 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)28 ArrayList (java.util.ArrayList)15 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)14 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)12 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)12 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)10 List (java.util.List)9 FactoryMap (org.onebusaway.collections.FactoryMap)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Test (org.junit.Test)8 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopBean (org.onebusaway.transit_data.model.StopBean)4