Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api/st storage #96

Merged
merged 12 commits into from
Aug 30, 2023
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 @@ -248,5 +248,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
Loading