Search in sources :

Example 1 with Agency

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

the class GenerateNarrativesTask method generateAgencyNarratives.

public void generateAgencyNarratives(NarrativeProviderImpl provider) {
    for (Agency agency : _gtfsDao.getAllAgencies()) {
        AgencyNarrative.Builder narrative = AgencyNarrative.builder();
        narrative.setLang(deduplicate(agency.getLang()));
        narrative.setName(deduplicate(agency.getName()));
        narrative.setPhone(deduplicate(agency.getPhone()));
        narrative.setEmail(deduplicate(agency.getEmail()));
        narrative.setTimezone(deduplicate(agency.getTimezone()));
        narrative.setUrl(deduplicate(agency.getUrl()));
        narrative.setEmail(agency.getEmail());
        narrative.setFareUrl(agency.getFareUrl());
        String disclaimer = _modifications.getModificationForTypeAndId(AgencyNarrative.class, agency.getId(), "disclaimer");
        if (disclaimer != null)
            narrative.setDisclaimer(disclaimer);
        Boolean privateService = _modifications.getModificationForTypeAndId(AgencyNarrative.class, agency.getId(), "privatService");
        if (privateService != null)
            narrative.setPrivateService(privateService);
        provider.setNarrativeForAgency(agency.getId(), narrative.create());
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) AgencyNarrative(org.onebusaway.transit_data_federation.model.narrative.AgencyNarrative)

Example 2 with Agency

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

the class FixedRouteDataValidationTask method process.

private void process() throws Exception {
    _log.info("Creating fixed route data validation report with sourceUrl=" + getSourceUrl());
    logger.header(FILENAME, "Mode,Route,Headsign,Direction,# of stops,# of weekday trips,# of Sat trips,# of Sunday trips");
    // Use next Wednesday date (including today) to serve as weekday check date.
    LocalDate firstMon = getFirstDay(DateTimeConstants.MONDAY);
    LocalDate firstTues = getFirstDay(DateTimeConstants.TUESDAY);
    LocalDate firstWed = getFirstDay(DateTimeConstants.WEDNESDAY);
    LocalDate firstThur = getFirstDay(DateTimeConstants.THURSDAY);
    LocalDate firstFri = getFirstDay(DateTimeConstants.FRIDAY);
    LocalDate firstSat = getFirstDay(DateTimeConstants.SATURDAY);
    LocalDate firstSun = getFirstDay(DateTimeConstants.SUNDAY);
    // Get the service ids for weekdays, Saturdays, and Sundays
    Set<AgencyAndId> weekdaySvcIds = new HashSet<>();
    Set<AgencyAndId> saturdaySvcIds = new HashSet<>();
    Set<AgencyAndId> sundaySvcIds = new HashSet<>();
    // Check service ids
    Collection<ServiceCalendar> calendars = _dao.getAllCalendars();
    for (ServiceCalendar calendar : calendars) {
        Date svcStartDate = calendar.getStartDate().getAsDate();
        LocalDate jodaStartDate = new LocalDate(svcStartDate);
        Date svcEndDate = calendar.getEndDate().getAsDate();
        LocalDate jodaEndDate = new LocalDate(svcEndDate);
        if (calendar.getMonday() == 1 && !firstMon.isBefore(jodaStartDate) && !firstMon.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getTuesday() == 1 && !firstTues.isBefore(jodaStartDate) && !firstTues.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getWednesday() == 1 && !firstWed.isBefore(jodaStartDate) && !firstWed.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getThursday() == 1 && !firstThur.isBefore(jodaStartDate) && !firstThur.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getFriday() == 1 && !firstFri.isBefore(jodaStartDate) && !firstFri.isAfter(jodaEndDate)) {
            weekdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getSaturday() == 1 && !firstSat.isBefore(jodaStartDate) && !firstSat.isAfter(jodaEndDate)) {
            saturdaySvcIds.add(calendar.getServiceId());
        }
        if (calendar.getSunday() == 1 && !firstSun.isBefore(jodaStartDate) && !firstSun.isAfter(jodaEndDate)) {
            sundaySvcIds.add(calendar.getServiceId());
        }
    }
    Map<String, List<String>> reportModes = getReportModes();
    Collection<Agency> agencies = _dao.getAllAgencies();
    for (String currentMode : reportModes.keySet()) {
        List<String> currentRoutes = reportModes.get(currentMode);
        for (Agency agency : agencies) {
            boolean getAllRoutes = false;
            // If currentRoutes[0] is agency id, get all the routes for that agency
            if (currentRoutes.get(0).equals(agency.getId())) {
                getAllRoutes = true;
            }
            List<Route> routes = _dao.getRoutesForAgency(agency);
            for (Route route : routes) {
                int[] wkdayTrips = null;
                int[] satTrips = null;
                int[] sunTrips = null;
                Map<String, TripTotals> tripMap = new HashMap<>();
                AgencyAndId routeId = route.getId();
                if (currentRoutes.contains(routeId.toString()) || getAllRoutes) {
                    List<Trip> trips = _dao.getTripsForRoute(route);
                    for (Trip trip : trips) {
                        List<StopTime> stopTimes = _dao.getStopTimesForTrip(trip);
                        int stopCt = stopTimes.size();
                        if (stopCt > MAX_STOP_CT) {
                            stopCt = MAX_STOP_CT;
                        }
                        TripTotals tripTotals = null;
                        if (tripMap.containsKey(trip.getTripHeadsign())) {
                            tripTotals = tripMap.get(trip.getTripHeadsign());
                        } else {
                            tripTotals = new TripTotals();
                            tripMap.put(trip.getTripHeadsign(), tripTotals);
                        }
                        /*
               * TODO: if stopCt exceeds array sizes, resize arrays
               */
                        if (trip.getDirectionId() == null || trip.getDirectionId().equals("0")) {
                            wkdayTrips = tripTotals.wkdayTrips_0;
                            satTrips = tripTotals.satTrips_0;
                            sunTrips = tripTotals.sunTrips_0;
                        } else {
                            wkdayTrips = tripTotals.wkdayTrips_1;
                            satTrips = tripTotals.satTrips_1;
                            sunTrips = tripTotals.sunTrips_1;
                        }
                        AgencyAndId tripSvcId = trip.getServiceId();
                        if (weekdaySvcIds.contains(tripSvcId)) {
                            ++wkdayTrips[stopCt];
                        } else if (saturdaySvcIds.contains(tripSvcId)) {
                            ++satTrips[stopCt];
                        } else if (sundaySvcIds.contains(tripSvcId)) {
                            ++sunTrips[stopCt];
                        }
                        tripMap.put(trip.getTripHeadsign(), tripTotals);
                    }
                    String routeName = route.getShortName() + "-" + route.getDesc();
                    for (String headSign : tripMap.keySet()) {
                        TripTotals tripTotals = tripMap.get(headSign);
                        String dir_0 = "0";
                        String dir_1 = "1";
                        for (int i = 0; i < MAX_STOP_CT; ++i) {
                            if (tripTotals.wkdayTrips_0[i] > 0 || tripTotals.satTrips_0[i] > 0 || tripTotals.sunTrips_0[i] > 0) {
                                logger.logCSV(FILENAME, currentMode + "," + routeName + "," + headSign + "," + dir_0 + "," + i + "," + tripTotals.wkdayTrips_0[i] + "," + tripTotals.satTrips_0[i] + "," + tripTotals.sunTrips_0[i]);
                                // Only display direction on its first line
                                dir_0 = "";
                                // Only display headsign on its first line
                                headSign = "";
                                // Only display route on its first line
                                routeName = "";
                                // Only display mode on its first line
                                currentMode = "";
                            }
                        }
                        for (int i = 0; i < MAX_STOP_CT; ++i) {
                            if (tripTotals.wkdayTrips_1[i] > 0 || tripTotals.satTrips_1[i] > 0 || tripTotals.sunTrips_1[i] > 0) {
                                logger.logCSV(FILENAME, currentMode + "," + routeName + "," + headSign + "," + dir_1 + "," + i + "," + tripTotals.wkdayTrips_1[i] + "," + tripTotals.satTrips_1[i] + "," + tripTotals.sunTrips_1[i]);
                                // Only display direction on its first line
                                dir_1 = "";
                                // Only display headsign on its first line
                                headSign = "";
                                // Only display route on its first line
                                routeName = "";
                                // Only display mode on its first line
                                currentMode = "";
                            }
                        }
                    }
                }
            }
        }
        logger.logCSV(FILENAME, ",,,,,,,,");
    }
    _log.info("finished fixed route data validation report");
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) LocalDate(org.joda.time.LocalDate) ArrayList(java.util.ArrayList) List(java.util.List) Route(org.onebusaway.gtfs.model.Route) HashSet(java.util.HashSet) StopTime(org.onebusaway.gtfs.model.StopTime) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) LocalDate(org.joda.time.LocalDate) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 3 with Agency

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

the class GtfsStatisticsTask method run.

public void run() {
    File basePath = _bundle.getPath();
    _log.info("Starting GTFS stats to basePath=" + basePath);
    GtfsStatisticsService service = new GtfsStatisticsService(_dao);
    logger.header(FILENAME, "id,name,route_count,trip_count,stop_count,stop_times_count,calendar_service_start,calendar_service_end,calendar_start_date,calendar_end_date");
    // per agency status
    Collection<Agency> agencies = service.getAllAgencies();
    for (Agency agency : agencies) {
        _log.info("processing stats for agency: " + agency.getId() + " (" + agency.getName() + ")");
        String stats = insertAgencyName(service.getStatisticAsCSV(agency.getId()), agency.getName());
        logger.logCSV(FILENAME, stats);
    }
    // overall stats/totals
    Statistic all = new Statistic();
    Agency allAgency = new Agency();
    allAgency.setId(ALL_AGENCIES);
    all.setAgencyId(ALL_AGENCIES);
    all.setRouteCount(service.getRouteCount());
    all.setTripCount(service.getTripCount());
    all.setStopCount(service.getStopCount());
    all.setStopTimeCount(service.getStopTimesCount());
    all.setCalendarStartDate(service.getCalendarServiceRangeStart());
    all.setCalendarEndDate(service.getCalendarServiceRangeEnd());
    String stats = insertAgencyName(GtfsStatisticsService.formatStatisticAsCSV(all), "");
    logger.logCSV(FILENAME, stats);
    _log.info("exiting");
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) Statistic(com.conveyal.gtfs.model.Statistic) GtfsStatisticsService(com.conveyal.gtfs.service.impl.GtfsStatisticsService) File(java.io.File)

Example 4 with Agency

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

the class TripEntriesFactory method processTrip.

private TripEntryImpl processTrip(TransitGraphImpl graph, Trip trip) {
    List<StopTime> stopTimes = _gtfsDao.getStopTimesForTrip(trip);
    // A trip without stop times is a trip we don't care about
    if (stopTimes.isEmpty())
        return null;
    ShapePoints shapePoints = null;
    if (trip.getShapeId() != null)
        shapePoints = _shapePointsHelper.getShapePointsForShapeId(trip.getShapeId());
    Agency agency = trip.getRoute().getAgency();
    TimeZone tz = TimeZone.getTimeZone(agency.getTimezone());
    LocalizedServiceId lsid = new LocalizedServiceId(trip.getServiceId(), tz);
    TripEntryImpl tripEntry = new TripEntryImpl();
    tripEntry.setId(trip.getId());
    tripEntry.setDirectionId(unique(trip.getDirectionId()));
    tripEntry.setServiceId(unique(lsid));
    // back it up
    if (!(shapePoints == null || shapePoints.isEmpty()))
        tripEntry.setShapeId(unique(trip.getShapeId()));
    List<StopTimeEntryImpl> stopTimesForTrip = _stopTimeEntriesFactory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
    // Also:  only set the trip if there are stops for it
    if (stopTimesForTrip == null || stopTimesForTrip.size() < 2) {
        _log.error("trip " + trip.getId() + " missing stops!");
        return null;
    }
    double tripDistance = getTripDistance(stopTimesForTrip, shapePoints);
    tripEntry.setTotalTripDistance(tripDistance);
    tripEntry.setStopTimes(cast(stopTimesForTrip));
    graph.putTripEntry(tripEntry);
    return tripEntry;
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) TimeZone(java.util.TimeZone) Agency(org.onebusaway.gtfs.model.Agency) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 5 with Agency

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

the class StopTimeEntriesFactoryTest method testThreeInARowDuplicateRemoval.

@Test
public void testThreeInARowDuplicateRemoval() {
    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));
    Stop stopD = new Stop();
    stopD.setId(aid("stopD"));
    graph.putStopEntry(stop("stopD", 47.66947942216854, -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(9, 00));
    stC.setDepartureTime(time(9, 05));
    stC.setStopSequence(102);
    stC.setStop(stopC);
    stC.setTrip(trip);
    StopTime stD = new StopTime();
    stD.setId(103);
    stD.setArrivalTime(time(11, 00));
    stD.setDepartureTime(time(11, 05));
    stD.setStopSequence(103);
    stD.setStop(stopD);
    stD.setTrip(trip);
    StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
    factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    List<StopTime> stopTimes = Arrays.asList(stA, stB, stC, stD);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    shapePointsFactory.addPoint(47.66947942216854, -122.37545336180114);
    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, 45), entry.getArrivalTime());
    assertEquals(time(9, 28, 45), 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, 34), entry.getArrivalTime());
    assertEquals(time(10, 00, 34), entry.getDepartureTime());
    assertEquals(2, entry.getSequence());
    assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(0, entry.getSlackTime());
    entry = entries.get(3);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(11, 00), entry.getArrivalTime());
    assertEquals(time(11, 05), entry.getDepartureTime());
    assertEquals(3, entry.getSequence());
    assertEquals(2877.69, entry.getShapeDistTraveled(), 0.1);
    assertEquals(60 * 5, 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