From fa1d35ab21996a1a12f7b01f5020d497edbdc83a Mon Sep 17 00:00:00 2001 From: robinlovelace Date: Wed, 13 Mar 2024 07:00:57 +0000 Subject: [PATCH 1/2] Remove email option, unused, fix #89 --- R/batch.R | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/R/batch.R b/R/batch.R index eda65bb..13806b1 100644 --- a/R/batch.R +++ b/R/batch.R @@ -27,7 +27,6 @@ #' @param includeJsonOutput int (1|0) #' Whether to include a column in the resulting CSV data giving the full JSON output from the API, rather than just summary #' information like distance and time. -#' @param emailOnCompletion Email on completion? #' @param username string #' Your CycleStreets account username. In due course this will be replaced with an OAuth token. #' @param password string @@ -41,6 +40,8 @@ #' pause: Pause job #' continue: Continue (re-open) job #' terminate: Terminate job and delete data +#' @param successThreshold int (0-100) The percentage of routes that must be successfully +#' calculated before the job is considered complete. #' @param delete_job Delete the job? TRUE by default to avoid clogged servers #' @param cols_to_keep Columns to return in output sf object #' @param segments logical, return segments TRUE/FALSE/"both" @@ -91,9 +92,9 @@ batch = function( maxDistance = 5000, filename = "test", includeJsonOutput = 1, - emailOnCompletion = "you@example.com", username = Sys.getenv("CYCLESTREETS_UN"), password = Sys.getenv("CYCLESTREETS_PW"), + successThreshold = 90, base_url = "https://api.cyclestreets.net/v2/batchroutes.createjob", pat = Sys.getenv("CYCLESTREETS_BATCH"), silent = TRUE, @@ -126,11 +127,11 @@ batch = function( maxDistance, filename, includeJsonOutput, - emailOnCompletion, username, password, base_url, id, + successThreshold, pat, silent = silent ) @@ -271,13 +272,13 @@ batch_routes = function( maxDistance = 5000, filename = "test", includeJsonOutput = 1, - emailOnCompletion = "you@example.com", username = Sys.getenv("CYCLESTREETS_UN"), password = Sys.getenv("CYCLESTREETS_PW"), base_url = "https://api.cyclestreets.net/v2/batchroutes.createjob", id = 1, pat, - silent = TRUE + silent = TRUE, + successThreshold ) { batch_url = paste0(base_url, "?key=", pat) desire_lines_to_send = desire_lines["id"] @@ -296,9 +297,9 @@ batch_routes = function( maxDistance = maxDistance, filename = filename, includeJsonOutput = includeJsonOutput, - emailOnCompletion = emailOnCompletion, username = username, - password = password + password = password, + successThreshold ) message("POSTing the request to create and start the job") if(!silent) { From 88c94cca0ccdb8ad9980e502088f7affc79accdc Mon Sep 17 00:00:00 2001 From: robinlovelace Date: Wed, 13 Mar 2024 07:23:02 +0000 Subject: [PATCH 2/2] Document --- man/batch.Rd | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/man/batch.Rd b/man/batch.Rd index 42bd264..6fce4d7 100644 --- a/man/batch.Rd +++ b/man/batch.Rd @@ -18,9 +18,9 @@ batch( maxDistance = 5000, filename = "test", includeJsonOutput = 1, - emailOnCompletion = "you@example.com", username = Sys.getenv("CYCLESTREETS_UN"), password = Sys.getenv("CYCLESTREETS_PW"), + successThreshold = 90, base_url = "https://api.cyclestreets.net/v2/batchroutes.createjob", pat = Sys.getenv("CYCLESTREETS_BATCH"), silent = TRUE, @@ -71,8 +71,6 @@ Whether to plan in both directions, i.e. A-B as well as B-A. Whether to include a column in the resulting CSV data giving the full JSON output from the API, rather than just summary information like distance and time.} -\item{emailOnCompletion}{Email on completion?} - \item{username}{string Your CycleStreets account username. In due course this will be replaced with an OAuth token.} @@ -80,6 +78,9 @@ Your CycleStreets account username. In due course this will be replaced with an Your CycleStreets account password. You can set it with Sys.setenv(CYCLESTREETS_PW="xxxxxx")} +\item{successThreshold}{int (0-100) The percentage of routes that must be successfully +calculated before the job is considered complete.} + \item{base_url}{The base url from which to construct API requests (with default set to main server)} @@ -114,6 +115,7 @@ routes_id = batch(desire_lines, username = "robinlovelace", wait = FALSE) # Wait for some time, around a minute or 2 routes_wait = batch(id = routes_id, username = "robinlovelace", wait = TRUE, delete_job = FALSE) names(routes_wait) +sapply(routes_wait, class) plot(routes_wait) plot(desire_lines$geometry[4]) plot(routes_wait$geometry[routes_wait$route_number == "4"], add = TRUE) @@ -128,7 +130,9 @@ routes_id = batch(desire_lines_huge, username = "robinlovelace", wait = FALSE) names(routes) plot(routes$geometry) plot(desire_lines$geometry, add = TRUE, col = "red") -routes = batch(desire_lines, username = "robinlovelace", wait_time = 5) +routes = batch(desire_lines, username = "robinlovelace", wait_time = 5, segments = FALSE) +segments = batch(desire_lines, username = "robinlovelace", wait_time = 5, segments = TRUE) +both = batch(desire_lines, username = "robinlovelace", wait_time = 5, segments = "both") # profvis::profvis(batch_read("test-data.csv.gz")) } }