Search in sources :

Example 1 with Trip

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

the class StifTripLoaderSupport method getTripsForIdentifier.

public List<Trip> getTripsForIdentifier(TripIdentifier id) {
    /**
     * Lazy initialization
     */
    if (tripsByIdentifier == null) {
        tripsByIdentifier = new HashMap<TripIdentifier, List<Trip>>();
        Collection<Trip> allTrips = gtfsDao.getAllTrips();
        _totalTripCount = allTrips.size();
        int index = 0;
        for (Trip trip : allTrips) {
            if (index % 20000 == 0)
                _log.info("trip=" + index + " / " + allTrips.size());
            index++;
            TripIdentifier tripIdentifier = getTripAsIdentifier(trip);
            List<Trip> trips = tripsByIdentifier.get(tripIdentifier);
            if (trips == null) {
                trips = new ArrayList<Trip>();
                tripsByIdentifier.put(tripIdentifier, trips);
            }
            trips.add(trip);
        }
    }
    return tripsByIdentifier.get(id);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Trip

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

the class HastusGtfsFactory method processSchedules.

private void processSchedules() throws IOException, SAXException, ParseException {
    _midnight = _dateParse.parse("2000-01-01T00:00:00.000");
    List<PublicTimeTable> timetables = processScheduleDirectory(_scheduleInputPath, new ArrayList<PublicTimeTable>());
    logger.header(csv("schedules"), "booking_id,schedule_type,place_id,trip_sequence,trip_id,route_id,service_id,route_variation,stop_sequence,shape_id,trip_direction,direction_name");
    int timetableSize = timetables.size();
    for (PublicTimeTable timetable : timetables) {
        int directionIndex = 0;
        if (timetable == null || timetable.getPlaceInfos() == null)
            continue;
        for (PttPlaceInfo placeInfo : timetable.getPlaceInfos()) {
            Map<String, Integer> timepointPositions = getTimepointPositions(placeInfo);
            for (PttTrip pttTrip : placeInfo.getTrips()) {
                String tripIdRaw = timetable.getBookingIdentifier() + "-" + placeInfo.getScheduleType() + "-" + placeInfo.getId() + "-" + pttTrip.getSequence();
                AgencyAndId tripId = id(tripIdRaw);
                Route route = getRoute(timetable, placeInfo, pttTrip);
                AgencyAndId serviceId = getServiceId(timetable, placeInfo);
                String routeVariation = getRouteVariationForPlaceInfo(placeInfo);
                String stopSequenceId = constructSequenceId(pttTrip.getRouteId(), routeVariation, placeInfo.getScheduleType());
                AgencyAndId shapeId = id(stopSequenceId);
                RouteStopSequence stopSequence = _stopSequences.get(stopSequenceId);
                if (stopSequence == null) {
                    _log.info("unknown stop sequence: " + stopSequenceId);
                    continue;
                }
                Trip trip = new Trip();
                trip.setId(tripId);
                trip.setDirectionId(constructDirectionId(directionIndex, timetableSize, shapeId));
                trip.setRoute(route);
                trip.setServiceId(serviceId);
                trip.setShapeId(shapeId);
                trip.setTripHeadsign(placeInfo.getDirectionName());
                logger.log(csv("schedules"), timetable.getBookingIdentifier(), placeInfo.getScheduleType(), placeInfo.getId(), pttTrip.getSequence(), tripId, route.getId(), serviceId, routeVariation, stopSequenceId, shapeId, trip.getDirectionId(), placeInfo.getDirectionName());
                _dao.saveEntity(trip);
                processStopTimesForTrip(timepointPositions, pttTrip, tripIdRaw, stopSequence, trip);
            }
        }
        directionIndex++;
    }
    // Remove timepoints from stops.
    for (AgencyAndId timepointId : _timepointIds) {
        _log.info("Removing timepoint " + timepointId.toString());
        Stop notReallyAStop = _dao.getStopForId(timepointId);
        _dao.removeEntity(notReallyAStop);
    }
}
Also used : PublicTimeTable(org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable) PttTrip(org.onebusaway.admin.service.bundle.hastus.xml.PttTrip) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) PttTimingPoint(org.onebusaway.admin.service.bundle.hastus.xml.PttTimingPoint) Point(com.vividsolutions.jts.geom.Point) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) PttPlaceInfo(org.onebusaway.admin.service.bundle.hastus.xml.PttPlaceInfo) PttTrip(org.onebusaway.admin.service.bundle.hastus.xml.PttTrip) Route(org.onebusaway.gtfs.model.Route) PttRoute(org.onebusaway.admin.service.bundle.hastus.xml.PttRoute)

Example 3 with Trip

use of org.onebusaway.gtfs.model.Trip 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 4 with Trip

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

the class GenerateNarrativesTaskTest method testGenerateTripNarratives.

@Test
public void testGenerateTripNarratives() {
    Trip trip = new Trip();
    trip.setId(aid("trip"));
    trip.setRouteShortName("R1");
    trip.setTripHeadsign("Where are we going?");
    trip.setTripShortName("LOCAL");
    StopTime stopTime = new StopTime();
    stopTime.setRouteShortName("R1X");
    stopTime.setStopHeadsign("Here");
    Mockito.when(_gtfsDao.getAllTrips()).thenReturn(Arrays.asList(trip));
    Mockito.when(_gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stopTime));
    _task.generateTripNarratives(_provider);
    TripNarrative narrative = _provider.getNarrativeForTripId(trip.getId());
    assertEquals(trip.getRouteShortName(), narrative.getRouteShortName());
    assertEquals(trip.getTripHeadsign(), narrative.getTripHeadsign());
    assertEquals(trip.getTripShortName(), narrative.getTripShortName());
    StopEntryImpl stopEntry = stop("stop", 47.0, -122.0);
    TripEntryImpl tripEntry = trip("trip");
    StopTimeEntryImpl stopTimeEntry = stopTime(0, stopEntry, tripEntry, 0, 0.0);
    StopTimeNarrative stopTimeNarrative = _provider.getNarrativeForStopTimeEntry(stopTimeEntry);
    assertEquals(stopTime.getRouteShortName(), stopTimeNarrative.getRouteShortName());
    assertEquals(stopTime.getStopHeadsign(), stopTimeNarrative.getStopHeadsign());
}
Also used : StopTimeNarrative(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative) Trip(org.onebusaway.gtfs.model.Trip) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopTime(org.onebusaway.gtfs.model.StopTime) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 5 with Trip

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

the class BlockEntriesFactoryTest method testFixedScheduleBlocks.

@Test
public void testFixedScheduleBlocks() {
    LocalizedServiceId lsid = lsid("serviceId");
    StopEntryImpl stop = stop("stop");
    Trip tripA = new Trip();
    tripA.setId(aid("tripA"));
    tripA.setRoute(_route);
    tripA.setBlockId("blockA");
    TripEntryImpl tripEntryA = trip("tripA").setRoute(_routeEntry).setServiceId(lsid);
    _graph.putTripEntry(tripEntryA);
    addStopTime(tripEntryA, stopTime().setStop(stop));
    Trip tripB = new Trip();
    tripB.setId(aid("tripB"));
    tripB.setRoute(_route);
    tripB.setBlockId("blockA");
    TripEntryImpl tripEntryB = trip("tripB").setRoute(_routeEntry).setServiceId(lsid);
    _graph.putTripEntry(tripEntryB);
    addStopTime(tripEntryB, stopTime().setStop(stop));
    Trip tripC = new Trip();
    tripC.setId(aid("tripC"));
    tripC.setRoute(_route);
    tripC.setBlockId("blockB");
    TripEntryImpl tripEntryC = trip("tripC").setRoute(_routeEntry).setServiceId(lsid);
    _graph.putTripEntry(tripEntryC);
    addStopTime(tripEntryC, stopTime().setStop(stop));
    Mockito.when(_dao.getTripsForRoute(_route)).thenReturn(Arrays.asList(tripA, tripB, tripC));
    _graph.initialize();
    _factory.processBlocks(_graph);
    List<BlockEntryImpl> blocks = _graph.getBlocks();
    assertEquals(2, blocks.size());
    // jre8 changes this ordering so explicity search
    BlockEntryImpl block = find(blocks, "blockB");
    assertEquals(aid("blockB"), block.getId());
    assertSame(block, tripEntryC.getBlock());
    Mockito.verify(_blockConfigFactory).processBlockConfigurations(block, Arrays.asList(tripEntryC));
    // jre8 changes this ordering so explicity search
    block = find(blocks, "blockA");
    assertEquals(aid("blockA"), block.getId());
    assertSame(block, tripEntryA.getBlock());
    assertSame(block, tripEntryB.getBlock());
    Mockito.verify(_blockConfigFactory).processBlockConfigurations(block, Arrays.asList(tripEntryA, tripEntryB));
    Mockito.verifyNoMoreInteractions(_blockConfigFactory);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10