Skip to content

Commit

Permalink
Release/cran063 (#158)
Browse files Browse the repository at this point in the history
* init develop branch with ci/cd and dev branch remotes

* correct test in createCluster after breaking change in antaresRead (#147)

* correct test in createCluster after breaking change in antaresRead

* Ant959 (#152)

* api_command_execute() updated to fix bad message for variant and reforged
no need to pass a string as parameter to be evaluated

* Allow cartesian for NTC part (#149)

* ant1494 (#150)

* Same row is repeated in scenarioBuilder() matrix output for each area

* Check cluster name for short-term storage (#153)

* Create a function to check if a short-term storage cluster exists : check_cluster_name()
* Control cluster existence for short-term storage before action (create, edit, remove)
* Create a function to generate a cluster name : generate_cluster_name()

* Ant1435 (#151)

* Allow the user to use symbol or full name for series argument in updateScenarioBuilder()

* Add control before actions in removeLink(), removeCluster(), removeArea()  (#154)

* Add function to control the existence of a link, a cluster or an area in a binding constraint coefficient
* Comment tests in failure for createPSP() and create DSR()
* Add comments, factorize code, use cluster_name already lowerized in .removeCluster()

* Add note in documentation (#156)

* Fix bug removing prepro directory in .removeCluster with thermal mode (#155)

* Remove expected files for thermal mode in the prepro subdirectory

* Add unit tests to check that expected files are deleted for removeCluster(), removeClusterRES() and removeClusterST()

* Enrich tests to check that directory area is  there for the N-1 first clusters

* release patch version 0.6.3
  • Loading branch information
berthetclement authored Apr 30, 2024
1 parent d92d496 commit f13f052
Show file tree
Hide file tree
Showing 25 changed files with 1,273 additions and 300 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: antaresEditObject
Type: Package
Title: Edit an 'Antares' Simulation
Version: 0.6.2
Version: 0.6.3
Authors@R: c(
person("Tatiana", "Vargas", email = "tatiana.vargas@rte-france.com", role = c("aut", "cre")),
person("Frederic", "Breant", role = "aut"),
Expand Down Expand Up @@ -52,4 +52,3 @@ Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr

1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ importFrom(antaresRead,getAreas)
importFrom(antaresRead,getLinks)
importFrom(antaresRead,readBindingConstraints)
importFrom(antaresRead,readClusterDesc)
importFrom(antaresRead,readClusterSTDesc)
importFrom(antaresRead,readIni)
importFrom(antaresRead,readIniAPI)
importFrom(antaresRead,readIniFile)
Expand Down
28 changes: 23 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# antaresEditObject 0.6.2
* Fix test to remove rev dep to `antaresRead` (see `cran-comments.md` for details)

# antaresEditObject 0.6.1

# antaresEditObject 0.6.3

NEW FEATURES :

Expand All @@ -17,6 +16,16 @@ NEW FEATURES :
* `createCluster()` parameter `list_pollutants` default value to NULL.
* `createBindingConstraint()` parameter `coefficients` must be alphabetically ordered.
* `.createCluster()` default matrix in API mode.
* `removeArea()` :
- control the existence of an area in a binding constraint coefficient before deletion
- no longer deletes a binding constraint
* `removeLink()` : control the existence of a link a in a binding constraint coefficient before deletion
* `removeCluster()` : control the existence of a cluster a in a binding constraint coefficient before deletion
* `createClusterST()` : add a control to check if a cluster exists before running actions.
* `editClusterST()` : add a control to check if a cluster exists before running actions.
* `.removeCluster()` : add a control to check if a cluster exists before running actions in st-storage mode.
* Update documentation for scenarioBuilder : user must enable/disable `custom-scenario` property in `generaldata.ini` by himself


BUGFIXES :

Expand All @@ -26,11 +35,20 @@ BUGFIXES :
* Fix `createDSR()` in API mode : daily binding constraint takes 366 rows.
* Fix `createCluster()` and `editCluster()` parameter `list_pollutants` stop if Antares Version < 8.6.0
* `getJobs()` no longer returns duplicates and displays the two new columns `owner_id` and `owner_name`.
* Allow the user to set symbol or full name as argument series in `updateScenarioBuilder()`
* `scenarioBuilder()` matrix has the same row repeated if the area is not rand
* Fix `createLink()` to update opts in API mode.
* Fix `editClusterST()` : can not edit a cluster if it does not exist in API mode.
* `updateScenarioBuilder()` works for NTC part : allow cartesian in the merge.
* `api_command_execute()` :
- no longer deletes a command
- displays a success message for a study or variant
* `removeCluster()` no longer deletes everything in the folder prepro

# antaresEditObject 0.6.1

# antaresEditObject 0.6.2
* Fix test to remove rev dep to `antaresRead` (see `cran-comments.md` for details)

# antaresEditObject 0.6.1
* `writeInputTS()` allows the user to set a link with the separator ' - ' (ex: 'area1 - area2')


Expand Down
43 changes: 16 additions & 27 deletions R/API-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,41 +187,30 @@ api_command_execute <- function(command, opts, text_alert = "{msg_api}") {
"'command' must be a command generated with api_command_generate() or api_commands_generate()"
)
}
api_post(opts, paste0(opts$study_id, "/commands"), body = body, encode = "raw")

# send command for study or variant
api_post(opts,
paste0(opts$study_id, "/commands"),
body = body,
encode = "raw")

# extract command name to put message
command_name <- jsonlite::fromJSON(body, simplifyVector = TRUE)
command_name <- command_name$action
msg_api=" " # HACK /!\
cli::cli_alert_success(paste0(text_alert, "success"))

# one more "PUT" "/generate" for variant only
if (is_variant(opts)) {
api_put(opts, paste0(opts$study_id, "/generate"))
result <- api_get(opts, paste0(opts$study_id, "/task"))
while(is.null(result$result)) {
if(is.null(opts$sleep))
Sys.sleep(0.5)
else
Sys.sleep(opts$sleep)
result <- api_get(opts, paste0(opts$study_id, "/task"))
}
result_log <- jsonlite::fromJSON(result$logs[[length(result$logs)]]$message, simplifyVector = FALSE)
msg_api <- result_log$message
if (is.null(msg_api) | identical(msg_api, ""))
msg_api <- "<no feedback from API>"
if (identical(result_log$success, TRUE)) {
if (!is_quiet())
cli::cli_alert_success(text_alert)
}
if (identical(result_log$success, FALSE)) {
if (!is_quiet())
cli::cli_alert_danger(text_alert)
api_delete(opts, paste0(opts$study_id, "/commands/", result_log$id))
stop(paste0("\n", msg_api),
call. = FALSE)
if (!is_quiet())
cli::cli_alert_warning("Command has been deleted")
}
return(invisible(result$result$success))
return(invisible(TRUE))
}
}





# utils -------------------------------------------------------------------

#' @importFrom antaresRead api_get
Expand Down
8 changes: 4 additions & 4 deletions R/createArea.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ createArea <- function(name,
api_command_register(cmd, opts = opts)
`if`(
should_command_be_executed(opts),
api_command_execute(cmd, opts = opts, text_alert = "{.emph create_area}: {msg_api}"),
api_command_execute(cmd, opts = opts, text_alert = "{.emph create_area}: "),
cli_command_registered("create_area")
)

Expand All @@ -72,7 +72,7 @@ createArea <- function(name,
api_command_register(cmd, opts = opts)
`if`(
should_command_be_executed(opts),
api_command_execute(cmd, opts = opts, text_alert = "Create area's nodal optimization option: {msg_api}"),
api_command_execute(cmd, opts = opts, text_alert = "Create area's nodal optimization option: "),
cli_command_registered("update_config")
)
}
Expand All @@ -85,7 +85,7 @@ createArea <- function(name,
api_command_register(cmd, opts = opts)
`if`(
should_command_be_executed(opts),
api_command_execute(cmd, opts = opts, text_alert = "Create area's filtering: {msg_api}"),
api_command_execute(cmd, opts = opts, text_alert = "Create area's filtering: "),
cli_command_registered("update_config")
)
}
Expand All @@ -99,7 +99,7 @@ createArea <- function(name,
api_command_register(cmd, opts = opts)
`if`(
should_command_be_executed(opts),
api_command_execute(cmd, opts = opts, text_alert = "Create area's adequacy patch mode: {msg_api}"),
api_command_execute(cmd, opts = opts, text_alert = "Create area's adequacy patch mode: "),
cli_command_registered("update_config")
)
}
Expand Down
31 changes: 23 additions & 8 deletions R/createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,28 @@ createClusterST <- function(area,
" you should be using one of: ", paste(st_storage_group, collapse = ", ")
)

# check area exsiting in current study
check_area_name(area, opts)
# check area existing in current study
area <- tolower(area)
check_area_name(area, opts)

# To avoid failure in an unit test (API is mocked) we add this block
api_study <- is_api_study(opts)
if (api_study && is_api_mocked(opts)) {
cluster_exists <- FALSE
} else {
cluster_exists <- check_cluster_name(area, cluster_name, add_prefix, opts)
}

if (!api_study) {
if (cluster_exists & !overwrite) {
stop("Cluster already exists. Overwrite it with overwrite option or edit it with editClusterST().")
}
}
if (api_study) {
if (cluster_exists) {
stop("Cluster already exists. Edit it with editClusterST().")
}
}
##
# check parameters (ini file)
##
Expand Down Expand Up @@ -144,13 +162,12 @@ createClusterST <- function(area,

# check syntax ini parameters
params_cluster <- hyphenize_names(storage_parameters)
if (add_prefix)
cluster_name <- paste(area, cluster_name, sep = "_")
cluster_name <- generate_cluster_name(area, cluster_name, add_prefix)
params_cluster <- c(list(name = cluster_name, group = group),params_cluster)

################# -
# API block
if (is_api_study(opts)) {
if (api_study) {
# format name for API
cluster_name <- transform_name_to_id(cluster_name)
params_cluster$name <- cluster_name
Expand Down Expand Up @@ -214,9 +231,7 @@ createClusterST <- function(area,
# read previous content of ini
previous_params <- readIniFile(file = path_clusters_ini)

if (tolower(cluster_name) %in% tolower(names(previous_params)) & !overwrite){
stop(paste(cluster_name, "already exist"))
} else if (tolower(cluster_name) %in% tolower(names(previous_params)) & overwrite){
if (tolower(cluster_name) %in% tolower(names(previous_params)) & overwrite){
ind_cluster <- which(tolower(names(previous_params)) %in% tolower(cluster_name))[1]
previous_params[[ind_cluster]] <- params_cluster
names(previous_params)[[ind_cluster]] <- cluster_name
Expand Down
25 changes: 13 additions & 12 deletions R/editClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ editClusterST <- function(area,
add_prefix = TRUE,
opts = antaresRead::simOptions()) {

# basics checks
# basic checks
assertthat::assert_that(inherits(opts, "simOptions"))
check_active_ST(opts, check_dir = TRUE)
check_area_name(area, opts)

api_study <- is_api_study(opts)
# To avoid failure in an unit test (API is mocked) we add this block
if (api_study && is_api_mocked(opts)) {
cluster_exists <- TRUE
} else {
cluster_exists <- check_cluster_name(area, cluster_name, add_prefix, opts)
}
cl_name_msg <- generate_cluster_name(area, cluster_name, add_prefix)
assertthat::assert_that(cluster_exists, msg = paste0("Cluster '", cl_name_msg, "' does not exist. It can not be edited."))
# statics groups
st_storage_group <- c("PSP_open",
"PSP_closed",
Expand Down Expand Up @@ -79,16 +88,15 @@ editClusterST <- function(area,
# make list of parameters
area <- tolower(area)
if(!(is.null(params_cluster)&&is.null(group))){
if (add_prefix)
cluster_name <- paste(area, cluster_name, sep = "_")
cluster_name <- generate_cluster_name(area, cluster_name, add_prefix)
params_cluster <- c(list(name = cluster_name, group = group),
params_cluster)
}
if(is.null(group))
params_cluster$group <- NULL

##### API block ----
if (is_api_study(opts)) {
if (api_study) {
# format name for API
cluster_name <- transform_name_to_id(cluster_name)

Expand Down Expand Up @@ -141,7 +149,7 @@ editClusterST <- function(area,
path_clusters_ini <- file.path(opts$inputPath,
"st-storage",
"clusters",
tolower(area),
area,
"list.ini")
if (!file.exists(path_clusters_ini))
stop("'", cluster_name, "' in area '", area, "' doesn't seems to exist.")
Expand All @@ -153,13 +161,6 @@ editClusterST <- function(area,
# read previous content of ini
previous_params <- readIniFile(file = path_clusters_ini)

if (!tolower(cluster_name) %in% tolower(names(previous_params))){
stop(
"'", cluster_name, "' doesn't exist, it can't be edited. You can create cluster with createCluster().",
call. = FALSE
)
}

# select existing cluster
ind_cluster <- which(tolower(names(previous_params)) %in%
tolower(cluster_name))[1]
Expand Down
Loading

0 comments on commit f13f052

Please sign in to comment.