All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.updater.bike_rental.datasources.SmooveBikeRentalDataSource Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.updater.bike_rental.datasources;

import com.fasterxml.jackson.databind.JsonNode;
import org.opentripplanner.routing.bike_rental.BikeRentalStation;
import org.opentripplanner.updater.bike_rental.BikeRentalDataSource;
import org.opentripplanner.updater.bike_rental.datasources.params.BikeRentalDataSourceParameters;
import org.opentripplanner.util.NonLocalizedString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Implementation of a BikeRentalDataSource for the Smoove GIR SabiWeb used in Helsinki.
 * @see BikeRentalDataSource
 */
class SmooveBikeRentalDataSource extends GenericJsonBikeRentalDataSource {

    private static final Logger log = LoggerFactory.getLogger(SmooveBikeRentalDataSource.class);

    public SmooveBikeRentalDataSource(BikeRentalDataSourceParameters config) {
        super(config,"result");
    }

    /**
     * 
     * {
     *    "result" : [
     *       {
     *          "name" : "004 Hamn",
     *          "operative" : true,
     *          "coordinates" : "60.167913,24.952269",
     *          "style" : "",
     *          "avl_bikes" : 1,
     *          "free_slots" : 11,
     *          "total_slots" : 12,
     *       },
     *       ...
     *    ]
     * }
     * 
*/ public BikeRentalStation makeStation(JsonNode node) { BikeRentalStation station = new BikeRentalStation(); station.id = node.path("name").asText().split("\\s", 2)[0]; station.name = new NonLocalizedString(node.path("name").asText().split("\\s", 2)[1]); String[] coordinates = node.path("coordinates").asText().split(","); try { station.y = Double.parseDouble(coordinates[0].trim()); station.x = Double.parseDouble(coordinates[1].trim()); } catch (NumberFormatException e) { // E.g. coordinates is empty log.warn("Error parsing bike rental station " + station.id, e); return null; } if (!node.path("operative").asText().equals("true")) { station.bikesAvailable = 0; station.spacesAvailable = 0; } else { station.bikesAvailable = node.path("avl_bikes").asInt(); station.spacesAvailable = node.path("free_slots").asInt(); } return station; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy