Search in sources :

Example 31 with NonLocalizedString

use of org.opentripplanner.util.NonLocalizedString in project OpenTripPlanner by opentripplanner.

the class ShareBikeRentalDataSource method makeStation.

/**
 * ShareBike format http://www.sharebike.com/
 *
 * URL for configuration:
 * http://map.webservice.sharebike.com:8888/json/MapService/LiveStationData?
 * APIKey=<Your API Key>&SystemID=<Bike System ID>
 *
 * Currently used in Norway (Oslo, Trondheim, Drammen) , Barcelona, Mexico
 * City, Milan, Stockholm, Antwerpen among others
 *
 * <pre>
 * {
 *		  "version": "1.1",
 *		  "result": {
 *		    "LastUpdated": "2016-01-18T13:55:25.610",
 *		    "LastUpdatedUTC": "2016-01-18T12:55:25.610",
 *		    "LiveStationData": [
 *		      {
 *		        "Address": "[Offline] storgata",
 *		        "AvailableBikeCount": "0",
 *		        "AvailableSlotCount": "0",
 *		        "LastContact": "",
 *		        "LastContactSeconds": "0",
 *		        "LastContactUTC": "1899-12-30T00:00:00",
 *		        "Latitude": "59.92758",
 *		        "Longitude": "10.71004",
 *		        "MinAvailableBikes": "0",
 *		        "MinAvailableSlots": "0",
 *		        "Online": false,
 *		        "SlotCount": "0",
 *		        "StationID": 1,
 *		        "StationName": "storgata"
 *		      },
 *		      ....
 * </pre>
 */
@Override
public BikeRentalStation makeStation(JsonNode rentalStationNode) {
    if (networkID == null) {
        // Get SystemID url parameter as StationIDs are not globally unique for
        // the ShareBike system
        List<String> systemIDs = urlParameters.get("SystemID");
        if (systemIDs != null && systemIDs.size() == 1) {
            networkID = systemIDs.get(0);
            log.info("Extracted query parameter 'SystemID 'from sharebike url: " + networkID);
        } else {
            networkID = UUID.randomUUID().toString();
            log.warn("No query parameter 'SystemID' in sharebike url, using random value " + networkID);
        }
    }
    if (!rentalStationNode.path("Online").asBoolean()) {
        log.debug("Station is offline: " + rentalStationNode.path("StationName").asText());
        return null;
    }
    BikeRentalStation brstation = new BikeRentalStation();
    brstation.networks = new HashSet<String>();
    brstation.networks.add(this.networkID);
    brstation.id = networkID + "_" + rentalStationNode.path("StationID").toString();
    brstation.x = rentalStationNode.path("Longitude").asDouble();
    brstation.y = rentalStationNode.path("Latitude").asDouble();
    brstation.name = new NonLocalizedString(rentalStationNode.path("StationName").asText("").trim());
    brstation.bikesAvailable = rentalStationNode.path("AvailableBikeCount").asInt();
    brstation.spacesAvailable = rentalStationNode.path("AvailableSlotCount").asInt();
    return brstation;
}
Also used : NonLocalizedString(org.opentripplanner.util.NonLocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation)

Aggregations

NonLocalizedString (org.opentripplanner.util.NonLocalizedString)31 BikeRentalStation (org.opentripplanner.routing.bike_rental.BikeRentalStation)15 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)10 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)10 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)8 GraphPath (org.opentripplanner.routing.spt.GraphPath)8 Test (org.junit.Test)7 Edge (org.opentripplanner.routing.graph.Edge)7 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)7 Coordinate (com.vividsolutions.jts.geom.Coordinate)6 HashSet (java.util.HashSet)6 State (org.opentripplanner.routing.core.State)6 LineString (com.vividsolutions.jts.geom.LineString)4 LinearLocation (com.vividsolutions.jts.linearref.LinearLocation)4 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)4 TemporaryFreeEdge (org.opentripplanner.routing.edgetype.TemporaryFreeEdge)4 ArrayList (java.util.ArrayList)3 Alert (org.opentripplanner.routing.alertpatch.Alert)3 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)3 Vertex (org.opentripplanner.routing.graph.Vertex)2