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;
}
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.");
}
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);
}
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"));
}
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;
}
Aggregations