forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from HSLdevcom/DT-2950
Dt 2950
- Loading branch information
Showing
5 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/org/opentripplanner/updater/bike_rental/SamocatScooterRentalDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.opentripplanner.updater.bike_rental; | ||
|
||
import org.opentripplanner.routing.bike_rental.BikeRentalStation; | ||
import org.opentripplanner.util.NonLocalizedString; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashSet; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
/** | ||
* Implementation of a BikeRentalDataSource for the Samocat scooter rental service used in Helsinki. | ||
* Since scooters rental works similarly as bike rental, there is no point to create own data structures | ||
* for them. | ||
* @see BikeRentalDataSource | ||
*/ | ||
public class SamocatScooterRentalDataSource extends GenericJsonBikeRentalDataSource { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SamocatScooterRentalDataSource.class); | ||
|
||
private String networkName; | ||
|
||
public SamocatScooterRentalDataSource(String networkName) { | ||
super("results"); | ||
this.networkName = defaultIfEmpty(networkName, "samocat"); | ||
} | ||
|
||
private String defaultIfEmpty(String value, String defaultValue) { | ||
if (value == null || value.isEmpty()) | ||
return defaultValue; | ||
|
||
return value; | ||
} | ||
|
||
/** | ||
* <pre> | ||
* { | ||
* "count": 10, | ||
* "next": null, | ||
* "previous": null, | ||
* "results": [ | ||
* { | ||
* "type": "Feature", | ||
* "geometry": { | ||
* "type": "Point", | ||
* "coordinates": [ | ||
* 60.167913, | ||
* 24.952269 | ||
* ] | ||
* }, | ||
* "properties": { | ||
* "station_id": "0309", | ||
* "city": "Helsinki", | ||
* "country": "Finland", | ||
* "address": "some address", | ||
* "rack_sum": 12, | ||
* "free_racks": 2, | ||
* "available_devices": 1 | ||
* } | ||
* } | ||
* ] | ||
* } | ||
* </pre> | ||
*/ | ||
public BikeRentalStation makeStation(JsonNode node) { | ||
BikeRentalStation station = new BikeRentalStation(); | ||
JsonNode properties = node.path("properties"); | ||
JsonNode coordinates = node.path("geometry").path("coordinates"); | ||
station.id = properties.path("station_id").asText(); | ||
station.name = new NonLocalizedString(properties.path("address").asText()); | ||
station.state = "Station on"; | ||
station.networks = new HashSet<String>(); | ||
station.networks.add(this.networkName); | ||
try { | ||
if (coordinates.get(0).isNull() || coordinates.isNull()) { | ||
return null; | ||
} | ||
station.x = coordinates.get(0).asDouble(); | ||
station.y = coordinates.get(1).asDouble(); | ||
station.bikesAvailable = properties.path("available_devices").asInt(); | ||
station.spacesAvailable = properties.path("free_racks").asInt(); | ||
return station; | ||
} catch (NumberFormatException e) { | ||
// E.g. coordinates is empty | ||
log.info("Error parsing bike rental station " + station.id, e); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
"count": 3, | ||
"next": null, | ||
"previous": null, | ||
"results": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
24.9355143, | ||
60.1637284 | ||
] | ||
}, | ||
"properties": { | ||
"station_id": "0451", | ||
"city": "Helsinki", | ||
"country": "FI", | ||
"address": "Testikuja 3", | ||
"rack_sum": 12, | ||
"free_racks": 0, | ||
"available_devices": 0 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
24.958877, | ||
60.194449 | ||
] | ||
}, | ||
"properties": { | ||
"station_id": "0450", | ||
"city": "Helsinki", | ||
"country": "FI", | ||
"address": "Footie 3", | ||
"rack_sum": 12, | ||
"free_racks": 3, | ||
"available_devices": 4 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
24.9537278, | ||
60.2177349 | ||
] | ||
}, | ||
"properties": { | ||
"station_id": "3451", | ||
"city": "Helsinki", | ||
"country": "FI", | ||
"address": "Bartie 10", | ||
"rack_sum": 12, | ||
"free_racks": 5, | ||
"available_devices": 1 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
null, | ||
null | ||
] | ||
}, | ||
"properties": { | ||
"station_id": "3451", | ||
"city": "Helsinki", | ||
"country": "FI", | ||
"address": "Nulltie 1", | ||
"rack_sum": 12, | ||
"free_racks": 5, | ||
"available_devices": 1 | ||
} | ||
} | ||
] | ||
} |