Skip to content

Commit

Permalink
Api/st storage (#96)
Browse files Browse the repository at this point in the history
* maj tests v860 with new templates study v860

* createClusterST block API + tests

* editClusterST API work in progress

* createCluster fix polluants parameter to list (new function added to create list of polluants) + fix default value for API

* st-storage add new function (internal) to standardize name of cluster for API

* createClusterST fix api call parameter

* removeCluster() fix for st-storage

* createClusterST reworking function with new parameters + tests + doc

* editClusterST reworking with new parameter + tests + doc

* storage_values_default new function for list of default parameter used in creation/edition

* createClusterST fix create data files + tests
  • Loading branch information
berthetclement authored Aug 30, 2023
1 parent 77119bf commit 8447c4a
Show file tree
Hide file tree
Showing 14 changed files with 878 additions and 225 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export(getPlaylist)
export(getVariantCommands)
export(is_antares_v7)
export(is_antares_v820)
export(list_polluants_values)
export(mockSimulationAPI)
export(nodalOptimizationOptions)
export(propertiesLinkOptions)
Expand All @@ -70,6 +71,7 @@ export(searchStudy)
export(setAPImode)
export(setPlaylist)
export(setSolverPath)
export(storage_values_default)
export(updateAdequacySettings)
export(updateGeneralSettings)
export(updateInputSettings)
Expand Down
12 changes: 11 additions & 1 deletion R/API-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,15 @@ api_get_variants <- function(id, opts) {
)
}


# standardization of character strings for the API
# (e.g. cluster names, links, etc.)
transform_name_to_id <- function(name, lower = TRUE, id_dash = FALSE) {
valid_id <- gsub("[^a-zA-Z0-9_(),& -]+", " ", name)
valid_id <- trimws(valid_id)
if(lower)
valid_id <- tolower(valid_id)
if(id_dash)
valid_id <- gsub("-", "_", valid_id)
return(valid_id)
}

37 changes: 34 additions & 3 deletions R/createCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ createCluster <- function(area,
cluster_name,
group = "Other",
...,
list_polluants = NULL,
list_polluants = list_polluants_values(),
time_series = NULL,
prepro_data = NULL,
prepro_modulation = NULL,
Expand All @@ -167,8 +167,7 @@ createCluster <- function(area,
assertthat::assert_that(inherits(opts, "simOptions"))

# static name of list parameters of pulluants
name_list_param_poll <- c("nh3", "nox", "pm2_5", "pm5", "pm10",
"nmvoc", "so2", "op1", "op2", "op3", "op4", "op5", "co2")
name_list_param_poll <- names(list_polluants_values())

# check v860
# check list pulluants parameters
Expand All @@ -179,6 +178,14 @@ createCluster <- function(area,
if(!all(names(list_polluants) %in% name_list_param_poll))
stop(append("Parameter 'list_polluants' must be named with the following elements: ",
paste0(name_list_param_poll, collapse= ", ")))

# check if all elements are NULL => replace by NULL
# API (only) can't create with NULL values
all_null <- lapply(list_polluants, is.null)
all_null <- all(unlist(all_null))

if(all_null)
list_polluants <- NULL
}


Expand Down Expand Up @@ -456,3 +463,27 @@ createClusterRES <- function(area,
# )


#' Output polluants list for thermal clusters
#'
#' @param multi_values put values to init list values, default as `NULL`
#'
#' @return a named list
#' @export
#'
#' @examples
#' list_polluants_values()
list_polluants_values <- function(multi_values = NULL) {
list("nh3"= multi_values,
"nox"= multi_values,
"pm2_5"= multi_values,
"pm5"= multi_values,
"pm10"= multi_values,
"nmvoc"= multi_values,
"so2"= multi_values,
"op1"= multi_values,
"op2"= multi_values,
"op3"= multi_values,
"op4"= multi_values,
"op5"= multi_values,
"co2"= multi_values)
}
Loading

0 comments on commit 8447c4a

Please sign in to comment.