Search in sources :

Example 16 with BikeRentalStation

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;
}
Also used : NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 17 with BikeRentalStation

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);
}
Also used : BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 18 with BikeRentalStation

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;
}
Also used : NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Example 19 with BikeRentalStation

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;
    }
}
Also used : NonLocalizedString(org.opentripplanner.util.NonLocalizedString) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with BikeRentalStation

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;
    }
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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