use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class GbfsBikeRentalDataSource method getStations.
@Override
public List<BikeRentalStation> getStations() {
// Index all the station status entries on their station ID.
Map<String, BikeRentalStation> statusLookup = new HashMap<>();
for (BikeRentalStation station : stationStatusSource.getStations()) {
statusLookup.put(station.id, station);
}
// Iterate over all known stations, and if we have any status information add it to those station objects.
for (BikeRentalStation station : stationSource.getStations()) {
if (!statusLookup.containsKey(station.id))
continue;
BikeRentalStation status = statusLookup.get(station.id);
station.bikesAvailable = status.bikesAvailable;
station.spacesAvailable = status.spacesAvailable;
}
// Copy the full list of station objects (with status updates) into a List, appending the floating bike stations.
List<BikeRentalStation> stations = new LinkedList<>(stationSource.getStations());
stations.addAll(floatingBikeSource.getStations());
return stations;
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class TestShareBikeRentalStationSource method testShareBike.
public void testShareBike() throws UnsupportedEncodingException, MalformedURLException {
ShareBikeRentalDataSource shareBikeSource = new ShareBikeRentalDataSource();
shareBikeSource.setUrl("file:src/test/resources/bike/share-bike.json?SystemID=dummyid");
assertTrue(shareBikeSource.update());
List<BikeRentalStation> rentalStations = shareBikeSource.getStations();
assertEquals(17, rentalStations.size());
for (BikeRentalStation rentalStation : rentalStations) {
System.out.println(rentalStation);
}
BikeRentalStation prinsen = rentalStations.get(0);
assertTrue(prinsen.networks.contains("dummyid"));
assertEquals("01", prinsen.name.toString());
assertEquals("dummyid_1", prinsen.id);
assertEquals(10.392981, prinsen.x);
assertEquals(63.426637, prinsen.y);
assertEquals(9, prinsen.spacesAvailable);
assertEquals(6, prinsen.bikesAvailable);
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class BixiBikeRentalDataSource method makeStation.
public BikeRentalStation makeStation(Map<String, String> attributes) {
if (!"true".equals(attributes.get("installed"))) {
return null;
}
BikeRentalStation brstation = new BikeRentalStation();
brstation.id = attributes.get("id");
brstation.x = Double.parseDouble(attributes.get("long"));
brstation.y = Double.parseDouble(attributes.get("lat"));
brstation.name = new NonLocalizedString(attributes.get("name"));
brstation.bikesAvailable = Integer.parseInt(attributes.get("nbBikes"));
brstation.spacesAvailable = Integer.parseInt(attributes.get("nbEmptyDocks"));
return brstation;
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class CityBikesBikeRentalDataSource method parseJson.
private void parseJson(String data) throws ParserConfigurationException, SAXException, IOException {
ArrayList<BikeRentalStation> out = new ArrayList<BikeRentalStation>();
// Jackson ObjectMapper to read in JSON
// TODO: test against real data
ObjectMapper mapper = new ObjectMapper();
for (JsonNode stationNode : mapper.readTree(data)) {
BikeRentalStation brStation = new BikeRentalStation();
// We need string IDs but they are in JSON as numbers. Avoid null from textValue(). See pull req #1450.
brStation.id = String.valueOf(stationNode.get("id").intValue());
brStation.x = stationNode.get("lng").doubleValue() / 1000000.0;
brStation.y = stationNode.get("lat").doubleValue() / 1000000.0;
brStation.name = new NonLocalizedString(stationNode.get("name").textValue());
brStation.bikesAvailable = stationNode.get("bikes").intValue();
brStation.spacesAvailable = stationNode.get("free").intValue();
if (brStation != null && brStation.id != null) {
out.add(brStation);
}
}
synchronized (this) {
stations = out;
}
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class GenericJsonBikeRentalDataSource method parseJSON.
private void parseJSON(InputStream dataStream) throws JsonProcessingException, IllegalArgumentException, IOException {
ArrayList<BikeRentalStation> out = new ArrayList<BikeRentalStation>();
String rentalString = convertStreamToString(dataStream);
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(rentalString);
if (!jsonParsePath.equals("")) {
String delimiter = "/";
String[] parseElement = jsonParsePath.split(delimiter);
for (int i = 0; i < parseElement.length; i++) {
rootNode = rootNode.path(parseElement[i]);
}
if (rootNode.isMissingNode()) {
throw new IllegalArgumentException("Could not find jSON elements " + jsonParsePath);
}
}
for (int i = 0; i < rootNode.size(); i++) {
JsonNode node = rootNode.get(i);
if (node == null) {
continue;
}
BikeRentalStation brstation = makeStation(node);
if (brstation != null)
out.add(brstation);
}
synchronized (this) {
stations = out;
}
}
Aggregations