diff --git a/DESCRIPTION b/DESCRIPTION index b6b6979d..da20bb6a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: antaresRead Type: Package Title: Import, Manipulate and Explore the Results of an 'Antares' Simulation -Version: 2.5.2 +Version: 2.6.1 Authors@R: c( person("Tatiana", "Vargas", email = "tatiana.vargas@rte-france.com", role = c("aut", "cre")), person("Jalal-Edine", "ZAWAM", role = "aut"), @@ -48,6 +48,7 @@ Suggests: parallel, htmltools RoxygenNote: 7.2.2 +Roxygen: list(markdown = TRUE) VignetteBuilder: knitr Encoding: UTF-8 biocViews: Infrastructure, DataImport diff --git a/NAMESPACE b/NAMESPACE index b4ed506a..1badafdd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -51,6 +51,7 @@ export(readAntaresClusters) export(readBindingConstraints) export(readClusterDesc) export(readClusterResDesc) +export(readClusterSTDesc) export(readDigestFile) export(readIni) export(readIniAPI) diff --git a/NEWS.md b/NEWS.md index 7a269b3c..992a76e1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,18 +1,49 @@ > Copyright © 2016 RTE Réseau de transport d’électricité - -# antaresRead 2.5.3 +# antaresRead 2.7.0 ### Breaking changes (Antares v8.7) : * Existing function `readBindingConstraints()` (cf. Antares v8.7 changelog) -# antaresRead 2.5.2 -BREAKING CHANGES: +# antaresRead 2.6.1 (devlopment) + +BUGFIXES : + +* `setSimulationPathAPI()` : + - returns an API exception if the requested study ID is incorrect + - `simulation` the simulation parameter works with negative values within the limit of the number of simulations +* correction in `readClusterDesc()` calls to add "opts" + + +# antaresRead 2.6.0 + +NEW FEATURES (Antares v8.6, cf. Antares v8.6 changelog) : + +* `readClusterSTDesc()` read "short-term storage" clusters parameters (input files of an antares study) + + +BREAKING CHANGES (Antares v8.6) : + +* `readInputTS()` is now compatible to read time series with : + - "short-term storage" + - "mingen" (pmin hydro value) +* `setSimulationPath()` has new parameter `areasWithSTClusters` (name of area with "st-storage" cluster) + + +BUGFIXES : * `setSimulationPathAPI` generate new global parameter `sleep` to add timer to API request +* Correction of `.importOutput()` to use `readAntares()` with `parallel == TRUE` in shiny application +* `setSimulationPathAPI()` delete a redundant API request +* `readClusterDesc()` minor fix in API mode + fix if no cluster exists => return specific error message +* `readIniAPI()` read well file `generaldata` for sections "playlist" and "variables selection" + + +DATA : +* A test study in tar.gz format is available in version `v8.6.0` # antaresRead 2.5.1 diff --git a/R/API-methods.R b/R/API-methods.R index 7f5f7f88..36ade82f 100644 --- a/R/API-methods.R +++ b/R/API-methods.R @@ -55,7 +55,16 @@ api_get <- function(opts, endpoint, ..., default_endpoint = "v1/studies") { #fix for skipping 404 when some output is missing url_elements <- strsplit(result$url, "%2F")[[1]] condition_status_check <- !(!is.na(url_elements[4]) & url_elements[4] %in% c("economy","adequacy") & result$status_code == 404) - if (condition_status_check) stop_for_status(result) else warn_for_status(result) + if(condition_status_check){ + mess_error <- content(result) + if(!is.null(names(mess_error))) + mess_error <- paste0("\n[Description] : ", mess_error$description, + "\n[Exception] : ", mess_error$exception) + else + mess_error <- NULL + stop_for_status(result, task = mess_error) + }else + warn_for_status(result) content(result) } @@ -90,7 +99,13 @@ api_post <- function(opts, endpoint, ..., default_endpoint = "v1/studies") { config = config, ... ) - stop_for_status(result) + api_content <- content(result) + if(!is.null(names(api_content))) + api_content <- paste0("\n[Description] : ", api_content$description, + "\n[Exception] : ", api_content$exception) + else + api_content <- NULL + stop_for_status(result, task = api_content) content(result) } diff --git a/R/giveSize.R b/R/giveSize.R index 2903246b..4b941253 100644 --- a/R/giveSize.R +++ b/R/giveSize.R @@ -171,7 +171,7 @@ setRam <- function(x){ clusWithData <- data.table() if(!is.null(clusters)) { - clusWithData <- tryCatch(readClusterDesc(), error = function(e) data.table()) + clusWithData <- tryCatch(readClusterDesc(opts = opts), error = function(e) data.table()) if("all" %in% clusters){ enabled <- TRUE if("enabled" %in% names(clusWithData)) diff --git a/R/importInput.R b/R/importInput.R index 9419e0de..9dea2ad0 100644 --- a/R/importInput.R +++ b/R/importInput.R @@ -157,6 +157,12 @@ inputTimeStep = "hourly", type = "matrix") } +# "mingen" (v860) +.importmingen <- function(area, timeStep, opts, ...){ + .importInputTS(area, timeStep, opts, "hydro/series/%s/mingen.txt", "mingen", + inputTimeStep = "hourly", type = "matrix") +} + .importHydroStorageInput <- function(area, timeStep, opts, ...) { inputTimeStepV <- ifelse(opts$antaresVersion >= 650, yes = "daily", no = "monthly") .importInputTS(area, timeStep, opts, "hydro/series/%s/mod.txt", "hydroStorage", @@ -421,3 +427,94 @@ # out <- gsub(" ", "%20", out) # } + +# "st-storage" (v860) +.importSTStorage <- function(area, timeStep, opts, ...){ + + if (!area %in% opts$areasWithSTClusters) + return(NULL) + + if(!"api" %in% opts$typeLoad){ + clusters <- list.files( + file.path(opts$inputPath, + "st-storage/series", + area) + ) + + # "st-storage" have 5 txt files output for each cluster + list_names_txt_files <- unique( + list.files( + file.path(opts$inputPath, + "st-storage/series", + area, + clusters) + ) + ) + + list_names_less_txt <- sub(pattern = ".txt", + replacement = "", + x = list_names_txt_files) + + } else { + list_info_clusters <- read_secure_json( + file.path(opts$inputPath, + "st-storage/series", + area), + token = opts$token, + timeout = opts$timeout, + config = opts$httr_config + ) + + clusters <- names(list_info_clusters) + + files_names <- names(list_info_clusters[[1]]) + + list_names_txt_files <- paste0(files_names, ".txt") + list_names_less_txt <- files_names + } + + # read TS for every cluster + ldply(clusters, function(cl) { + pattern <- paste0("%s/%s/%%s/", + list_names_txt_files) + filePatterns <- sprintf(pattern, + "st-storage/series", area) + + res <- lapply(filePatterns, + function(.x){ + index_name_file <- which(filePatterns %in% .x) + + res_temp <- .importInputTS(area= cl, + timeStep= timeStep, + opts= opts, + fileNamePattern= .x, + colnames= "st-storage", + inputTimeStep = "hourly", + type = "matrix") + res_temp$name_file <- list_names_less_txt[index_name_file] + res_temp + }) + + res <- rbindlist(res) + + if (is.null(res)) + return(NULL) + + res$area <- area + res$cluster <- cl + + setcolorder(res, + c("area", + "cluster", + "timeId", + setdiff( + names(res), + c("area", + "cluster", + "timeId"))) + ) + }) + + # added a column "name_file" to tag the file name + +} \ No newline at end of file diff --git a/R/importOutput.R b/R/importOutput.R index 2b48133a..f2ae8b60 100644 --- a/R/importOutput.R +++ b/R/importOutput.R @@ -139,7 +139,7 @@ res <- llply( 1:nrow(args), function(i) { - incProgress(1/n, detail = paste0("Importing ", folder, " data")) + if(showProgress){ incProgress(1/n, detail = paste0("Importing ", folder, " data")) } data <- NULL try({ if (!sameNames) { diff --git a/R/readAntaresClusters.R b/R/readAntaresClusters.R index 058d8ce5..9717d70a 100644 --- a/R/readAntaresClusters.R +++ b/R/readAntaresClusters.R @@ -18,7 +18,7 @@ readAntaresClusters <- function(clusters, selected = c("production", "NP Cost", stop("Cannot use 'readAntaresClusters' in 'Input' mode.") ##Add check control for all - allClusters <- readClusterDesc()[, c("area","cluster")] + allClusters <- readClusterDesc(opts = opts)[, c("area","cluster")] ind_cluster <- which(tolower(allClusters$cluster) %in% .checkArg(tolower(clusters), tolower(unique(allClusters$cluster)), "clusters %s do not exist in the simulation.")) diff --git a/R/readClusterDesc.R b/R/readClusterDesc.R index e49eaed3..4f0e9195 100644 --- a/R/readClusterDesc.R +++ b/R/readClusterDesc.R @@ -32,6 +32,8 @@ #' \code{readClusterDesc} : read thermal clusters #' #' \code{readClusterResDesc} : read renewable clusters (Antares >= V8.1) +#' +#' \code{readClusterSTDesc} : read st-storage clusters (Antares >= V8.6) #' #' @examples #' @@ -43,6 +45,9 @@ #' # renewable #' readClusterResDesc() #' +#' # st-storage +#' readClusterSTDesc() +#' #' # By default, the function reads cluster descriptions for the default study, #' # but it is possible to specify another study with parameter "opts" #' sim1 <- setSimulationPath() @@ -69,10 +74,22 @@ readClusterResDesc <- function(opts = simOptions()) { is.null(opts$parameters$`other preferences`$`renewable-generation-modelling`)){ stop("readClusterDesc is available only on studies with 'renewable-generation-modelling' = 'clusters' (and Antares >= 8.1)", call. = FALSE) } - .readClusterDesc(opts = simOptions(), dir = "renewables/clusters") + .readClusterDesc(opts = opts, dir = "renewables/clusters") } +#' @export +#' +#' @rdname readClusterDesc +readClusterSTDesc <- function(opts = simOptions()) { + if (opts$antaresVersion < 860) { + stop("readClusterSTDesc is available only on Antares >= 8.6)", call. = FALSE) + } + .readClusterDesc(opts = opts, dir = "st-storage/clusters") +} + + + .readClusterDesc <- function(opts = simOptions(), dir = "thermal/clusters") { @@ -104,7 +121,10 @@ readClusterResDesc <- function(opts = simOptions()) { if(nrow(clusters)==0)return(NULL) clusters$area <- Y1 clusters[, .SD, .SDcols = order(names(clusters))] - },jsoncld, names(jsoncld)), fill = TRUE) + },jsoncld, names(jsoncld), SIMPLIFY = FALSE), fill = TRUE) + + if(length(res) == 0) + stop("Cannot find cluster description.", call. = FALSE) res <- res[, .SD, .SDcols = c("area", "name", "group", names(res)[!names(res) %in%c("area", "name", "group")])] diff --git a/R/readIniFile.R b/R/readIniFile.R index 07bf05fc..0c94d228 100644 --- a/R/readIniFile.R +++ b/R/readIniFile.R @@ -97,7 +97,7 @@ readIniFile <- function(file, stringsAsFactors = FALSE) { #' @export #' @rdname read-ini readIniAPI <- function(study_id, path, host, token = NULL) { - api_get( + api_get_ini_file <- api_get( opts = list(host = host, token = token), endpoint = paste0(study_id, "/raw"), query = list( @@ -105,4 +105,50 @@ readIniAPI <- function(study_id, path, host, token = NULL) { formatted = TRUE ) ) + # reformat list contains unnamed list + .format_list(api_get_ini_file) +} + +# reformat list from JSON format +.format_list <- function(list_x){ + # check list to find sub list + check_class_list <- lapply(list_x, function(x) + lapply(x, class) %in% "list") + + is_true_list <- lapply(check_class_list, function(x) + any(x %in% TRUE)) + + index_true <- which(is_true_list %in% TRUE) + + # reformat sub list + list_to_reformat <- list_x[index_true] + + list_to_reformat <- lapply(list_to_reformat, function(x){ + index_list <- which( + lapply(x, class) %in% "list") + + # reformat only unnamed list + if(is.name(x[index_list])) + return(x) + else{ + elements <- unlist(x[index_list], use.names = FALSE) + if(class(elements)%in%"character"){ + elements <- paste("'", elements, "'", sep="", collapse=",") + elements <- paste0("[", elements, "]") + }else{ + elements <- paste0(elements, collapse= ",") + elements <- paste0("[", elements, "]") + } + x[index_list] <- elements + x + } + }) + + # return original list + if(identical(index_true, integer(0))) + list_x + else + # return list reformated + append(list_x[-index_true], + list_to_reformat) } diff --git a/R/readInputClusters.R b/R/readInputClusters.R index d902c274..61dc812d 100644 --- a/R/readInputClusters.R +++ b/R/readInputClusters.R @@ -41,7 +41,7 @@ readInputThermal <- function(clusters = NULL, thermalModulation = FALSE, thermal if (!foreach::getDoParRegistered()) stop("Parallelized importation impossible. Please register a parallel backend, for instance with function 'registerDoParallel'") } - allAreasClusters <- readClusterDesc()[area %in% opts$areasWithClusters, c("area", "cluster")] + allAreasClusters <- readClusterDesc(opts = opts)[area %in% opts$areasWithClusters, c("area", "cluster")] allClusters <- unique(allAreasClusters$cluster) # Manage special value "all" if(identical(clusters, "all")) clusters <- allClusters @@ -139,7 +139,7 @@ readInputRES <- function(clusters = NULL, opts = simOptions(), if (!foreach::getDoParRegistered()) stop("Parallelized importation impossible. Please register a parallel backend, for instance with function 'registerDoParallel'") } - allAreasClusters <- readClusterResDesc()[area %in% opts$areasWithResClusters, c("area", "cluster")] + allAreasClusters <- readClusterResDesc(opts = opts)[area %in% opts$areasWithResClusters, c("area", "cluster")] allClusters <- unique(allAreasClusters$cluster) # Manage special value "all" if(identical(clusters, "all")) clusters <- allClusters diff --git a/R/readInputTS.R b/R/readInputTS.R index c5a91e1d..e93ef009 100644 --- a/R/readInputTS.R +++ b/R/readInputTS.R @@ -3,6 +3,8 @@ #' Read Input time series #' #' @description +#' `r antaresRead:::badge_api_ok()` +#' #' \code{readInputTS} is a function that reads time series from an antares #' project. But contrary to \code{\link{readAntares}}, it only reads time series #' stored in the input folder, so it can work in "input" mode. @@ -15,6 +17,9 @@ #' vector of areas names for which run of river time series must be read. #' @param hydroStorage #' vector of areas names for which hydrolic storage time series must be read. +#' @param mingen +#' vector of areas names for which Hydro Pmin time series must be read. +#' (only for Antares version >= 860) #' @param hydroStorageMaxPower #' vector of areas names for which hydrolic storage maximum power time series must be read. #' @param wind @@ -29,6 +34,9 @@ #' vector of links names for which links characteristics time series must be read #' @param resProduction #' vector of areas names for which renewables clusters production time series must be read. +#' @param st_storage +#' vector of areas names for which st-storage clusters production time series must be read. +#' #' @inheritParams readAntares #' #' @return @@ -72,10 +80,11 @@ #' #' @export readInputTS <- function(load = NULL, thermalAvailabilities = NULL, ror = NULL, - hydroStorage = NULL, hydroStorageMaxPower = NULL, + mingen= NULL, hydroStorage = NULL, hydroStorageMaxPower = NULL, wind = NULL, solar = NULL, misc = NULL, reserve = NULL, linkCapacity = NULL, resProduction = NULL, + st_storage= NULL, opts = simOptions(), timeStep = c("hourly", "daily", "weekly", "monthly", "annual"), simplify = TRUE, parallel = FALSE, @@ -85,14 +94,17 @@ readInputTS <- function(load = NULL, thermalAvailabilities = NULL, ror = NULL, # Can the importation be parallelized ? if (parallel) { - if(!requireNamespace("foreach")) stop("Parallelized importation impossible. Please install the 'foreach' package and a parallel backend provider like 'doParallel'.") - if (!foreach::getDoParRegistered()) stop("Parallelized importation impossible. Please register a parallel backend, for instance with function 'registerDoParallel'") + if(!requireNamespace("foreach")) + stop("Parallelized importation impossible. Please install the 'foreach' package and a parallel backend provider like 'doParallel'.") + if (!foreach::getDoParRegistered()) + stop("Parallelized importation impossible. Please register a parallel backend, for instance with function 'registerDoParallel'") } # Manage special value "all" if(identical(load, "all")) load <- opts$areaList if(identical(thermalAvailabilities, "all")) thermalAvailabilities <- opts$areasWithClusters if(identical(ror, "all")) ror <- opts$areaList + if(identical(mingen, "all")) mingen <- opts$areaList if(identical(hydroStorage, "all")) hydroStorage <- opts$areaList if(identical(hydroStorageMaxPower, "all")) hydroStorageMaxPower <- opts$areaList if(identical(wind, "all")) wind <- opts$areaList @@ -101,7 +113,9 @@ readInputTS <- function(load = NULL, thermalAvailabilities = NULL, ror = NULL, if(identical(reserve, "all")) reserve <- opts$areaList if(identical(linkCapacity, "all")) linkCapacity <- opts$linkList if(identical(resProduction, "all")) resProduction <- opts$areasWithResClusters + if(identical(st_storage, "all")) st_storage <- opts$areasWithSTClusters + # check if study is compatible with "renewables" if((!is.null(opts$parameters$`other preferences`$`renewable-generation-modelling`) && !opts$parameters$`other preferences`$`renewable-generation-modelling` %in% "clusters") || is.null(opts$parameters$`other preferences`$`renewable-generation-modelling`)){ @@ -111,9 +125,20 @@ readInputTS <- function(load = NULL, thermalAvailabilities = NULL, ror = NULL, resProduction <- NULL } + # check if study is compatible with "st-storage" (v860) + # check if study is compatible with "mingen" (v860) + if(!opts$antaresVersion >= 860){ + if(!is.null(st_storage)){ + warning("'st-storage' clusters production time series can only be imported on studies with Antares >= 8.6.0") + st_storage <- NULL + } + if(!is.null(mingen)){ + warning("'mingen' Pmin time series can only be imported on studies with Antares >= 8.6.0") + mingen <- NULL + } + } - ###Check links in study - + #Check links in study if(!all(linkCapacity%in%opts$linkList)){ link_miss <- linkCapacity[!linkCapacity%in%opts$linkList] @@ -151,6 +176,7 @@ readInputTS <- function(load = NULL, thermalAvailabilities = NULL, ror = NULL, .addOutputToRes("load", load, .importLoad) .addOutputToRes("thermalAvailabilities", thermalAvailabilities, .importThermalAvailabilities) .addOutputToRes("ror", ror, .importROR) + .addOutputToRes("mingen", mingen, .importmingen) .addOutputToRes("hydroStorage", hydroStorage, .importHydroStorageInput) .addOutputToRes("hydroStorageMaxPower", hydroStorageMaxPower, .importHydroStorageMaxPower) .addOutputToRes("wind", wind, .importWind) @@ -159,6 +185,7 @@ readInputTS <- function(load = NULL, thermalAvailabilities = NULL, ror = NULL, .addOutputToRes("reserve", reserve, .importReserves) .addOutputToRes("linkCapacity", linkCapacity, .importLinkCapacity) .addOutputToRes("resProduction", resProduction, .importResProduction) + .addOutputToRes("st-storage", st_storage, .importSTStorage) if (length(res) == 0) stop("At least one argument of readInputTS has to be defined.") diff --git a/R/setSimulationPath.R b/R/setSimulationPath.R index 427c3e07..5df538e3 100644 --- a/R/setSimulationPath.R +++ b/R/setSimulationPath.R @@ -246,8 +246,13 @@ setSimulationPath <- function(path, simulation = NULL) { .giv_sim <- function(simulation, simNames, path){ if (is.numeric(simulation)) { - if (simulation > 0) sim <- simNames[simulation] - else sim <- rev(simNames)[abs(simulation)] + if(abs(simulation)>length(simNames)) + stop(paste0("Parameter 'simulation' is greater than + the number of simulations (", length(simNames), ")"), call. = FALSE) + if (simulation > 0) + sim <- simNames[simulation] + else + sim <- rev(simNames)[abs(simulation)] } else { if (any(simNames == simulation)) sim <- simulation else { @@ -380,6 +385,12 @@ setSimulationPath <- function(path, simulation = NULL) { file.exists(f) && file.info(f)$size > 0 }) + # Areas with st-storatge clusters + areaHasSTClusters <- vapply(areaList, FUN.VALUE = logical(1), function(a) { + f <- file.path(inputPath, "st-storage/clusters", a, "list.ini") + file.exists(f) && file.info(f)$size > 0 + }) + res <- list( mode = "Input", antaresVersion = antaresVersion, @@ -389,6 +400,7 @@ setSimulationPath <- function(path, simulation = NULL) { linksDef = linksDef, areasWithClusters = areaList[areaHasClusters], areasWithResClusters = areaList[areaHasResClusters], + areasWithSTClusters = areaList[areaHasSTClusters], parameters = params ) diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 00000000..4ac4d8b5 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,6 @@ +badge_api_ok <- function() { + "\\ifelse{html}{\\figure{badge_api_ok.svg}{options: alt='Antares API OK'}}{Antares API: \\strong{OK}}" +} +badge_api_no <- function() { + "\\ifelse{html}{\\figure{badge_api_no.svg}{options: alt='Antares API NO'}}{Antares API: \\strong{NO}}" +} \ No newline at end of file diff --git a/R/utils_api.R b/R/utils_api.R index b58bb064..921e2715 100644 --- a/R/utils_api.R +++ b/R/utils_api.R @@ -47,7 +47,7 @@ read_secure_json <- function(url, token = NULL, timeout = 60, config = list()) { outputPath <- file.path(path, "output") if(is.null(simulation) | (!is.null(simulation) && !simulation %in% c(0, "input"))){ outputContent <- names(read_secure_json(paste0(outputPath, "&depth=4"), ...)) - simNames <- setdiff(basename(outputContent), "maps") + simNames <- setdiff(basename(outputContent), c("maps", "logs")) } if (length(simNames) == 0) { if (length(simulation) > 0 && !simulation %in% c(0, "input")) { @@ -196,6 +196,7 @@ read_secure_json <- function(url, token = NULL, timeout = 60, config = list()) { simDataPath = simDataPath, name = as.character(info$name), mode = as.character(info$mode), + simDate = info$date, synthesis = synthesis, yearByYear = yearByYear, scenarios = scenarios, @@ -256,10 +257,9 @@ read_secure_json <- function(url, token = NULL, timeout = 60, config = list()) { }, allLinks, names(allLinks))) + # info <- read_secure_json(studyPath, ...) - info <- read_secure_json(studyPath, ...) - - antaresVersion <- info$study$antares$version + antaresVersion <- paths$version params <- read_secure_json(file.path(studyPath, "settings", "generaldata"), ...) # Areas with clusters @@ -289,19 +289,44 @@ read_secure_json <- function(url, token = NULL, timeout = 60, config = list()) { }) } } - - - list( - mode = "Input", - antaresVersion = antaresVersion, - areaList = areaList, - districtList = districtList, - linkList = as.character(linksDef$link), - linksDef = linksDef, - areasWithClusters = areaList[areaHasClusters], - areasWithResClusters = areaList[areaHasResClusters], - parameters = params - ) + + # Areas with st-storage (>=860) + if(paths$version>=860){ + clusterSTList <- read_secure_json(file.path(inputPath, "st-storage", "clusters", "&depth=4"), ...) + areaHasSTClusters <- vapply(areaList, FUN.VALUE = logical(1), function(a) { + TF <- FALSE + try({ + f <- clusterSTList[[a]]$list + if(!is.null(f))return(TRUE) + }) + return(TF) + }) + + # return + list( + mode = "Input", + antaresVersion = antaresVersion, + areaList = areaList, + districtList = districtList, + linkList = as.character(linksDef$link), + linksDef = linksDef, + areasWithClusters = areaList[areaHasClusters], + areasWithResClusters = areaList[areaHasResClusters], + areasWithSTClusters = areaList[areaHasSTClusters], + parameters = params + ) + }else + list( + mode = "Input", + antaresVersion = antaresVersion, + areaList = areaList, + districtList = districtList, + linkList = as.character(linksDef$link), + linksDef = linksDef, + areasWithClusters = areaList[areaHasClusters], + areasWithResClusters = areaList[areaHasResClusters], + parameters = params + ) } # valid_url <- function(url_in, t = 2){ @@ -346,28 +371,47 @@ setSimulationPathAPI <- function(host, study_id, token, simulation = NULL, timeout = timeout, config = httr_config ) }, error = function(e){ - stop("Can't connect to API. Please verify host & token") + # catch message from api_get() (from API) + stop(e) }) + # generic tests (legacy) if(isTRUE(all.equal(names(check_study), "detail"))){ stop("Can't connect to API. Please verify token") } + # generic tests (legacy) if(!study_id %in% check_study$id){ stop("Can't find your 'study_id' on the API") } - res <- .getPathsAPI(host, study_id, simulation, token = token, timeout = timeout, config = httr_config) + res <- .getPathsAPI(host, + study_id, + simulation, + token = token, + timeout = timeout, + config = httr_config) - res$studyName <- read_secure_json(file.path(res$studyPath, "study"), token = token, timeout = timeout, config = httr_config)$antares$caption + res$studyName <- check_study$name + + res$version <- check_study$version # If "input mode", read options from the input folder, else read them from # the simulation folder. if (is.null(res$simPath) | length(res$simPath) == 0) { - res <- append(res, .getInputOptionsAPI(res, token = token, timeout = timeout, config = httr_config)) + res <- append(res, + .getInputOptionsAPI(res, + token = token, + timeout = timeout, + config = httr_config)) } else { res$simPath <- URLencode(res$simPath) - res <- append(res, .getSimOptionsAPI(res, host, token = token, timeout = timeout, config = httr_config)) + res <- append(res, + .getSimOptionsAPI(res, + host, + token = token, + timeout = timeout, + config = httr_config)) } # dates, TimeId min and max @@ -394,6 +438,9 @@ setSimulationPathAPI <- function(host, study_id, token, simulation = NULL, res$httr_config <- httr_config res$modeAPI <- "sync" + # delete version to keep only "antares_version" + res$version <- NULL + # timer for api commande execute res$sleep <- 0.5 diff --git a/docs/404.html b/docs/404.html index 26c9ca66..75add493 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@
@@ -98,7 +98,7 @@