Skip to content

Commit

Permalink
Remove consumption model from route() if mode is pedestrian
Browse files Browse the repository at this point in the history
- Lower RPS in route to 7 to avoid frequent status 429
  • Loading branch information
munterfi committed Oct 18, 2024
1 parent 692c566 commit 5c2d1c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# version 1.0.1

- Avoid consumption model to be added to request when transport mode is pedestrian (closes [#167](https://github.com/munterfi/hereR/issues/167)).
- Prevent the consumption model from being added to the request when the transport mode is set to `"pedestrian"` in `isoline()` and `route()` functions (closes [#167](https://github.com/munterfi/hereR/issues/167)).
- Adjust the rate limit in `route()` to 7 requests per second (RPS). Although HERE's documentation specifies a 10 RPS limit, it has been lowered to 7 RPS to avoid frequent 429 "Too Many Requests" errors.

# version 1.0.0

Expand Down
34 changes: 18 additions & 16 deletions R/route.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,23 @@ route <- function(origin, destination, datetime = Sys.time(), arrival = FALSE,
)
}

# Add consumption model if specified, otherwise set to default electric vehicle
if (is.null(consumption_model)) {
url <- paste0(
url,
"&ev[freeFlowSpeedTable]=0,0.239,27,0.239,45,0.259,60,0.196,75,0.207,90,0.238,100,0.26,110,0.296,120,0.337,130,0.351,250,0.351",
"&ev[trafficSpeedTable]=0,0.349,27,0.319,45,0.329,60,0.266,75,0.287,90,0.318,100,0.33,110,0.335,120,0.35,130,0.36,250,0.36",
"&ev[ascent]=9",
"&ev[descent]=4.3",
"&ev[auxiliaryConsumption]=1.8"
)
} else {
url <- paste0(
url,
consumption_model
)
if (transport_mode != "pedestrian") {
# Add consumption model if specified, otherwise set to default electric vehicle
if (is.null(consumption_model)) {
url <- paste0(
url,
"&ev[freeFlowSpeedTable]=0,0.239,27,0.239,45,0.259,60,0.196,75,0.207,90,0.238,100,0.26,110,0.296,120,0.337,130,0.351,250,0.351",
"&ev[trafficSpeedTable]=0,0.349,27,0.319,45,0.329,60,0.266,75,0.287,90,0.318,100,0.33,110,0.335,120,0.35,130,0.36,250,0.36",
"&ev[ascent]=9",
"&ev[descent]=4.3",
"&ev[auxiliaryConsumption]=1.8"
)
} else {
url <- paste0(
url,
consumption_model
)
}
}

# Request polyline and summary
Expand Down Expand Up @@ -177,7 +179,7 @@ route <- function(origin, destination, datetime = Sys.time(), arrival = FALSE,
# Request and get content
data <- .async_request(
url = url,
rps = 10
rps = 7
)
if (length(data) == 0) {
return(NULL)
Expand Down

0 comments on commit 5c2d1c2

Please sign in to comment.