Search in sources :

Example 1 with BikeRentalStation

use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.

the class VCubDataSource method makeStation.

public BikeRentalStation makeStation(Map<String, String> attributes) {
    BikeRentalStation brstation = new BikeRentalStation();
    brstation.id = attributes.get("bm:GID").trim();
    String[] coordinates = attributes.get("bm:geometry").trim().split(" ");
    if (coordinates.length >= 2) {
        brstation.x = Double.parseDouble(coordinates[1]);
        brstation.y = Double.parseDouble(coordinates[0]);
    }
    if (brstation.x == 0 || brstation.y == 0)
        return null;
    brstation.name = new NonLocalizedString(attributes.get("bm:NOM"));
    boolean connected = "CONNECTEE".equalsIgnoreCase(attributes.get("bm:ETAT"));
    brstation.realTimeData = connected;
    String nbPlaces = attributes.get("bm:NBPLACES");
    if (nbPlaces != null)
        brstation.spacesAvailable = Integer.parseInt(nbPlaces);
    String nbVelos = attributes.get("bm:NBVELOS");
    if (nbVelos != null)
        brstation.bikesAvailable = Integer.parseInt(nbVelos);
    @SuppressWarnings("unused") String type = attributes.get("bm:TYPE");
    /*
         * Please see http://www.vcub.fr/stations-vcub-1 for more information on rules of VCUB vs
         * VCUB+. Apparently both network are compatible, VCUB+ only offer more renting options
         * which are not handled by OTP anyway.
         */
    brstation.networks = new HashSet<String>();
    brstation.networks.add("VCUB");
    brstation.networks.add("VCUB+");
    return brstation;
}
Also used : NonLocalizedString(org.opentripplanner.util.NonLocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 2 with BikeRentalStation

use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.

the class BikeRentalModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    LOG.info("Building bike rental stations from static source...");
    BikeRentalStationService service = graph.getService(BikeRentalStationService.class, true);
    if (!dataSource.update()) {
        LOG.warn("No bike rental found from the data source.");
        return;
    }
    Collection<BikeRentalStation> stations = dataSource.getStations();
    for (BikeRentalStation station : stations) {
        service.addBikeRentalStation(station);
        BikeRentalStationVertex vertex = new BikeRentalStationVertex(graph, station);
        new RentABikeOnEdge(vertex, vertex, station.networks);
        if (station.allowDropoff)
            new RentABikeOffEdge(vertex, vertex, station.networks);
    }
    LOG.info("Created " + stations.size() + " bike rental stations.");
}
Also used : RentABikeOnEdge(org.opentripplanner.routing.edgetype.RentABikeOnEdge) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) BikeRentalStationService(org.opentripplanner.routing.bike_rental.BikeRentalStationService) RentABikeOffEdge(org.opentripplanner.routing.edgetype.RentABikeOffEdge) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 3 with BikeRentalStation

use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.

the class TestBikeRentalStationSource method testKeolisRennes.

public void testKeolisRennes() {
    KeolisRennesBikeRentalDataSource rennesSource = new KeolisRennesBikeRentalDataSource();
    rennesSource.setUrl("file:src/test/resources/bike/keolis-rennes.xml");
    assertTrue(rennesSource.update());
    List<BikeRentalStation> rentalStations = rennesSource.getStations();
    assertEquals(4, rentalStations.size());
    for (BikeRentalStation rentalStation : rentalStations) {
        System.out.println(rentalStation);
    }
    BikeRentalStation stSulpice = rentalStations.get(0);
    assertEquals("ZAC SAINT SULPICE", stSulpice.name.toString());
    assertEquals("75", stSulpice.id);
    assertEquals(-1.63528, stSulpice.x);
    assertEquals(48.1321, stSulpice.y);
    assertEquals(24, stSulpice.spacesAvailable);
    assertEquals(6, stSulpice.bikesAvailable);
    BikeRentalStation kergus = rentalStations.get(3);
    assertEquals("12", kergus.id);
}
Also used : BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 4 with BikeRentalStation

use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.

the class TestShareBikeRentalStationSource method testShareBikeMissingSystemIDParameter.

public void testShareBikeMissingSystemIDParameter() throws UnsupportedEncodingException, MalformedURLException {
    ShareBikeRentalDataSource shareBikeSource = new ShareBikeRentalDataSource();
    shareBikeSource.setUrl("file:src/test/resources/bike/share-bike.json");
    assertTrue(shareBikeSource.update());
    List<BikeRentalStation> rentalStations = shareBikeSource.getStations();
    BikeRentalStation prinsen = rentalStations.get(0);
    // Should be random value
    assertFalse(prinsen.networks.contains("dummyid"));
}
Also used : BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 5 with BikeRentalStation

use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.

the class BikeRental method getBikeRentalStations.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + Q, MediaType.TEXT_XML + Q })
public BikeRentalStationList getBikeRentalStations(@QueryParam("lowerLeft") String lowerLeft, @QueryParam("upperRight") String upperRight, @PathParam("routerId") String routerId, @QueryParam("locale") String locale_param) {
    Router router = otpServer.getRouter(routerId);
    if (router == null)
        return null;
    BikeRentalStationService bikeRentalService = router.graph.getService(BikeRentalStationService.class);
    Locale locale;
    locale = ResourceBundleSingleton.INSTANCE.getLocale(locale_param);
    if (bikeRentalService == null)
        return new BikeRentalStationList();
    Envelope envelope;
    if (lowerLeft != null) {
        envelope = getEnvelope(lowerLeft, upperRight);
    } else {
        envelope = new Envelope(-180, 180, -90, 90);
    }
    Collection<BikeRentalStation> stations = bikeRentalService.getBikeRentalStations();
    List<BikeRentalStation> out = new ArrayList<>();
    for (BikeRentalStation station : stations) {
        if (envelope.contains(station.x, station.y)) {
            BikeRentalStation station_localized = station.clone();
            station_localized.locale = locale;
            out.add(station_localized);
        }
    }
    BikeRentalStationList brsl = new BikeRentalStationList();
    brsl.stations = out;
    return brsl;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) Router(org.opentripplanner.standalone.Router) BikeRentalStationService(org.opentripplanner.routing.bike_rental.BikeRentalStationService) Envelope(com.vividsolutions.jts.geom.Envelope) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

BikeRentalStation (org.opentripplanner.routing.bike_rental.BikeRentalStation)23 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)16 ArrayList (java.util.ArrayList)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 BikeRentalStationService (org.opentripplanner.routing.bike_rental.BikeRentalStationService)2 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)2 BikeRentalStationVertex (org.opentripplanner.routing.vertextype.BikeRentalStationVertex)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1 StopTimeEvent (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)1 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LineString (com.vividsolutions.jts.geom.LineString)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1