Search in sources :

Example 1 with PublicTimeTable

use of org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable in project onebusaway-application-modules by camsys.

the class HastusGtfsFactory method processSchedule.

private PublicTimeTable processSchedule(File path) throws IOException, SAXException {
    Digester digester = new Digester();
    digester.addObjectCreate("PublicTimeTable", PublicTimeTable.class);
    digester.addBeanPropertySetter("PublicTimeTable/VehicleSchedule/BookingIdentifier", "bookingIdentifier");
    digester.addBeanPropertySetter("PublicTimeTable/VehicleSchedule/Type", "type");
    digester.addBeanPropertySetter("PublicTimeTable/VehicleSchedule/Scenario", "scenario");
    digester.addObjectCreate("PublicTimeTable/Route", PttRoute.class);
    digester.addBeanPropertySetter("PublicTimeTable/Route/Identifier", "id");
    digester.addBeanPropertySetter("PublicTimeTable/Route/Description", "description");
    digester.addBeanPropertySetter("PublicTimeTable/Route/PublicIdentifier", "publicId");
    digester.addBeanPropertySetter("PublicTimeTable/Route/FirstDirectionName", "firstDirectionName");
    digester.addBeanPropertySetter("PublicTimeTable/Route/SecondDirectionName", "secondDirectionName");
    digester.addSetNext("PublicTimeTable/Route", "addRoute");
    digester.addObjectCreate("PublicTimeTable/PttPlaceInfo", PttPlaceInfo.class);
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/Identifier", "id");
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/Description", "description");
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/ScheduleType", "scheduleType");
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/DirectionName", "directionName");
    digester.addSetNext("PublicTimeTable/PttPlaceInfo", "addPlaceInfo");
    digester.addObjectCreate("PublicTimeTable/PttPlaceInfo/Trip", PttTrip.class);
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/Trip/RouteIdentifier", "routeId");
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/Trip/SequenceNo", "sequence");
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/Trip/trp_route_public", "routePublicId");
    digester.addSetNext("PublicTimeTable/PttPlaceInfo/Trip", "addTrip");
    digester.addObjectCreate("PublicTimeTable/PttPlaceInfo/Trip/TimingPoint", PttTimingPoint.class);
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/Trip/TimingPoint/PositionInPattern", "positionInPattern");
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/Trip/TimingPoint/PassingTime", "passingTime");
    digester.addSetNext("PublicTimeTable/PttPlaceInfo/Trip/TimingPoint", "addTimingPoint");
    digester.addObjectCreate("PublicTimeTable/PttPlaceInfo/PttPlaceInfoPlace", PttPlaceInfoPlace.class);
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/PttPlaceInfoPlace/PositionInPattern", "positionInPattern");
    digester.addBeanPropertySetter("PublicTimeTable/PttPlaceInfo/PttPlaceInfoPlace/PlaceIdentifier", "id");
    digester.addSetNext("PublicTimeTable/PttPlaceInfo/PttPlaceInfoPlace", "addPlace");
    return (PublicTimeTable) digester.parse(path);
}
Also used : PublicTimeTable(org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable) Digester(org.apache.commons.digester.Digester)

Example 2 with PublicTimeTable

use of org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable 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 PublicTimeTable

use of org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable in project onebusaway-application-modules by camsys.

the class HastusGtfsFactory method processScheduleDirectory.

private List<PublicTimeTable> processScheduleDirectory(File path, List<PublicTimeTable> results) throws IOException, SAXException {
    if (path.isFile() && path.getName().endsWith(".xml")) {
        PublicTimeTable timetable = processSchedule(path);
        results.add(timetable);
    } else if (path.isDirectory()) {
        for (File file : path.listFiles()) processScheduleDirectory(file, results);
    }
    return results;
}
Also used : PublicTimeTable(org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable) File(java.io.File)

Aggregations

PublicTimeTable (org.onebusaway.admin.service.bundle.hastus.xml.PublicTimeTable)3 LineString (com.vividsolutions.jts.geom.LineString)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 Point (com.vividsolutions.jts.geom.Point)1 File (java.io.File)1 Digester (org.apache.commons.digester.Digester)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 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