use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTask method getTripNarrative.
private TripNarrative getTripNarrative(Trip trip) {
String headsign = trip.getTripHeadsign();
if (headsign == null) {
Route route = trip.getRoute();
headsign = route.getLongName();
}
TripNarrative.Builder builder = TripNarrative.builder();
builder.setRouteShortName(deduplicate(trip.getRouteShortName()));
builder.setTripHeadsign(deduplicate(headsign));
builder.setTripShortName(deduplicate(trip.getTripShortName()));
return builder.create();
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.
the class HastusGtfsFactory method getRoute.
private Route getRoute(PublicTimeTable timetable, PttPlaceInfo placeInfo, PttTrip pttTrip) {
AgencyAndId routeId = id(pttTrip.getRouteId());
Route route = _dao.getRouteForId(routeId);
if (route == null) {
PttRoute pttRoute = getRouteForId(timetable, pttTrip.getRouteId());
route = new Route();
route.setAgency(_agency);
route.setId(routeId);
route.setShortName(pttRoute.getId());
route.setLongName(pttRoute.getDescription());
route.setType(3);
_dao.saveEntity(route);
}
return route;
}
use of org.onebusaway.gtfs.model.Route 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);
}
}
use of org.onebusaway.gtfs.model.Route 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");
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.
the class RouteEntriesFactory method processRoutes.
public void processRoutes(TransitGraphImpl graph) {
Collection<Route> routes = _gtfsDao.getAllRoutes();
int numRoutes = routes.size();
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(numRoutes);
int routeIndex = 0;
for (Route route : routes) {
if (routeIndex % logInterval == 0) {
_log.info("route processed: " + routeIndex + "/" + numRoutes);
}
routeIndex++;
processRoute(graph, route);
}
graph.refreshRouteMapping();
}
Aggregations