Search in sources :

Example 1 with PttTrip

use of org.onebusaway.admin.service.bundle.hastus.xml.PttTrip 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) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) PttTimingPoint(org.onebusaway.admin.service.bundle.hastus.xml.PttTimingPoint) Point(org.locationtech.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)

Aggregations

LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 Point (org.locationtech.jts.geom.Point)1 PttPlaceInfo (org.onebusaway.admin.service.bundle.hastus.xml.PttPlaceInfo)1 PttRoute (org.onebusaway.admin.service.bundle.hastus.xml.PttRoute)1 PttTimingPoint (org.onebusaway.admin.service.bundle.hastus.xml.PttTimingPoint)1 PttTrip (org.onebusaway.admin.service.bundle.hastus.xml.PttTrip)1 PublicTimeTable (org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Route (org.onebusaway.gtfs.model.Route)1 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)1 Stop (org.onebusaway.gtfs.model.Stop)1 Trip (org.onebusaway.gtfs.model.Trip)1