From 5c2d1c27144964169cd048cc0d9cf37dc382584f Mon Sep 17 00:00:00 2001 From: u228298 Date: Fri, 18 Oct 2024 17:46:54 +0200 Subject: [PATCH] Remove consumption model from route() if mode is pedestrian - Lower RPS in route to 7 to avoid frequent status 429 --- NEWS.md | 3 ++- R/route.R | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4d3357d..3095741 100755 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/route.R b/R/route.R index 8889f17..7a83446 100644 --- a/R/route.R +++ b/R/route.R @@ -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 @@ -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)