genet.utils.google_directions
session = FuturesSession(max_workers=2)
module-attribute
#
dump_all_api_requests_to_json(api_requests, output_dir, output_file_name=None)
#
Source code in src/genet/utils/google_directions.py
generate_requests(n, osm_tags=all)
#
Generates a dictionary describing pairs of nodes for which we need to request directions from Google directions API.
PARAMETER | DESCRIPTION |
---|---|
n
|
GeNet network.
TYPE:
|
osm_tags
|
OSM tags to subset the network on. Defaults to all (no subsetting). |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
Can only subset on tags for non-simplified networks. |
RETURNS | DESCRIPTION |
---|---|
dict
|
Generated requests.
TYPE:
|
Source code in src/genet/utils/google_directions.py
make_request(origin_attributes, destination_attributes, key, departure_time, traffic_model)
#
Source code in src/genet/utils/google_directions.py
map_results_to_edges(api_requests)
#
Source code in src/genet/utils/google_directions.py
parse_results(api_requests)
#
Goes through all api requests and parses results.
PARAMETER | DESCRIPTION |
---|---|
api_requests
|
generated and 'sent' api requests.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Requests with parsed results.
TYPE:
|
Source code in src/genet/utils/google_directions.py
parse_route(route)
#
Source code in src/genet/utils/google_directions.py
parse_routes(response, path_polyline)
#
Parses response contents to infer speed.
If response returned more than one route, it picks the one closest on average to the original request.
PARAMETER | DESCRIPTION |
---|---|
response
|
request content
TYPE:
|
path_polyline
|
original request path encoded list of lat lon tuples
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Parsed routes.
TYPE:
|
Source code in src/genet/utils/google_directions.py
read_api_requests(file_path)
#
Read the Google Directions API request results stored in the file_path
JSON file.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
path to the JSON file where the google directions api requests were saved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Loaded API request results
TYPE:
|
Source code in src/genet/utils/google_directions.py
send_requests(api_requests, departure_time, traffic_model=None, key=None, secret_name=None, region_name=None)
#
Source code in src/genet/utils/google_directions.py
send_requests_for_network(n, request_number_threshold, output_dir, departure_time, traffic_model=None, key=None, secret_name=None, region_name=None)
#
Generates, sends and parses results from Google Directions API for the car modal subgraph for network n.
You can pass your API key to this function under key
variable.
Alternatively, you can use AWS Secrets manager for storing your API and pass secret_name and region_name (make sure you are authenticated to your AWS account).
You can also export an environmental variable in your terminal $ export GOOGLE_DIR_API_KEY='your key'
.
PARAMETER | DESCRIPTION |
---|---|
n
|
GeNet Network.
TYPE:
|
request_number_threshold
|
max number of requests.
TYPE:
|
output_dir
|
output directory where to save the google directions api parsed data.
TYPE:
|
departure_time
|
specifies the desired time of departure, in seconds since midnight, January 1, 1970 UTC. i.e. unix time; if set to None, API will return results for average time-independent traffic conditions.
TYPE:
|
traffic_model
|
If given, specifies the assumptions to use when calculating time in traffic. For choices see https://developers.google.com/maps/documentation/directions/get-directions#traffic_model. Defaults to None. |
key
|
API key. Defaults to None. |
secret_name
|
If using AWS secrets manager, the name where your directions api key is stored. Defaults to None. |
region_name
|
The AWS region you operate in. Defaults to None. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
Can only make as many requests as |
RETURNS | DESCRIPTION |
---|---|
dict
|
API request results.
TYPE:
|