From 813c114a169e47016fd479a26d1d39b4fb82042d Mon Sep 17 00:00:00 2001 From: berthetclement Date: Thu, 6 Jun 2024 17:19:05 +0200 Subject: [PATCH 1/6] add private function group_values_meta_check() to check dim with meta data in opts + tests --- DESCRIPTION | 2 +- R/createBindingConstraint.R | 120 +++++++++++++++++- tests/testthat/test-createBindingConstraint.R | 58 +++++++-- 3 files changed, 170 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2e5cd967..eba4f2a8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,5 +54,5 @@ Suggests: rmarkdown VignetteBuilder: knitr Remotes: - rte-antares-rpackage/antaresRead@develop + rte-antares-rpackage/antaresRead@ant1777/dimbcgroup diff --git a/R/createBindingConstraint.R b/R/createBindingConstraint.R index e50a652c..e3cae615 100644 --- a/R/createBindingConstraint.R +++ b/R/createBindingConstraint.R @@ -1,3 +1,5 @@ +utils::globalVariables(c('V2', 'dim_study', 'dim_input', 'name_group')) + #' @title Create a binding constraint #' #' @description @@ -232,7 +234,13 @@ createBindingConstraint <- function(name, # v870 : check group and values # no check for add BC with NULL values - group_values_check(group_value = group, + # group_values_check(group_value = group, + # values_data = values, + # operator_check = operator, + # output_operator = values_operator, + # opts = opts) + + group_values_meta_check(group_value = group, values_data = values, operator_check = operator, output_operator = values_operator, @@ -623,6 +631,66 @@ group_values_check <- function(group_value, } } +# return data table object of group dimension +group_values_meta_check <- function(group_value, + values_data, + operator_check, + output_operator, + opts = antaresRead::simOptions()){ + + # no check if col dim ==1 + if(operator_check%in%"both"){ + if(dim(values_data$lt)[2] <= 1) + return() + }else{ + if(dim(values_data[[output_operator]])[2] <= 1) + return() + } + + # check dimension of new group (INPUT) + if(operator_check%in%"both"){ + lt_dim <- dim(values_data$lt)[2] + gt_dim <- dim(values_data$gt)[2] + if(lt_dim!=gt_dim) + stop("dimension of values are not similar ", + call. = FALSE) + p_col_new <- lt_dim + }else + p_col_new <- dim(values_data[[output_operator]])[2] + + # check meta + # study with no BC or virgin study + if(is.null(opts$binding)){ + cat("\nThere is no binding constraint in this study\n") + return() + } + + # read dimension + dim_bc_group <- opts$binding + + # group already exists ? + # no duplicate groups in the study + is_exists <- grepl(pattern = group_value, + x = dim_bc_group[, .SD, .SDcols = 1]) + + if(!is_exists){ + cat("\nNew/existing group : ", + paste0("'", group_value, "'"), + " will be created/updated with dimension : ", + paste0("[", p_col_new, "]"), + "\n") + return() + } + + # dimension of existing group + p_col <- dim_bc_group[name_group%in%group_value][["dim"]] + + if(p_col!=p_col_new) # & p_col!=0 + stop(paste0("Put right columns dimension : ", + p_col, " for existing 'group' : ", + group_value), call. = FALSE) +} + # v870 .valueCheck870 <- function(values, timeStep){ # check nrow Vs timeStep @@ -748,6 +816,11 @@ group_values_check <- function(group_value, createBindingConstraintBulk <- function(constraints, opts = antaresRead::simOptions()) { assertthat::assert_that(inherits(opts, "simOptions")) + + # check object dimension values only for versions >=8.7.0 + if(opts$antaresVersion>=870) + .check_bulk_object_dim(constraints = constraints, + opts = opts) ## Ini file pathIni <- file.path(opts$inputPath, "bindingconstraints/bindingconstraints.ini") bindingConstraints <- readIniFile(pathIni, stringsAsFactors = FALSE) @@ -781,4 +854,49 @@ createBindingConstraintBulk <- function(constraints, } +# control group dimensions in bulk object + # control object with study +.check_bulk_object_dim <- function(constraints, + opts = antaresRead::simOptions()){ + assertthat::assert_that(inherits(constraints, "list")) + + # check input object + all_dim_group <- do.call("rbind", lapply(constraints, function(x){ + data.table(name_group <- x$group, + dim_group <- dim(x$values[[1]])[2])}) + ) + + # no duplicated + all_dim_group <- unique(all_dim_group) + select_dim <- all_dim_group[V2>1] + + # count + t_df <- table(select_dim) + check_row <- rowSums(t_df) + + if(any(check_row>1)) + stop("Problem dimension with group : ", + paste0(names(check_row[check_row>1]), sep = " "), + call. = FALSE) + + # check input object with study + if(is.null(opts$binding)) + return() + else{ + merge_groups <- merge.data.table(x = opts$binding, + y = select_dim, + by.x ="name_group", + by.y = "V1") + + names(merge_groups) <- c("name_group", "dim_study", "dim_input") + + # check diff + diff_dim <- merge_groups[dim_study!=dim_input] + + if(nrow(diff_dim)>0) + stop("Problem dimension with group in Study: ", + paste0(diff_dim$name_group, sep = " "), + call. = FALSE) + } +} diff --git a/tests/testthat/test-createBindingConstraint.R b/tests/testthat/test-createBindingConstraint.R index 223d2837..4932de28 100644 --- a/tests/testthat/test-createBindingConstraint.R +++ b/tests/testthat/test-createBindingConstraint.R @@ -361,9 +361,8 @@ test_that("createBindingConstraint (default group value) v8.7", { enabled = FALSE, timeStep = "daily", operator = "both", - coefficients = c("at%fr" = 1), - opts = opts_test - ), regexp = "Put right columns dimension" + coefficients = c("at%fr" = 1)), + regexp = "Put right columns dimension" ) }) @@ -399,9 +398,7 @@ testthat::test_that("createBindingConstraint with new group v8.7",{ timeStep = "hourly", operator = "less", group = name_group, - coefficients = c("at%fr" = 1), - opts = opts_test - ) + coefficients = c("at%fr" = 1)) # ADD binding with multi cols df_multi_col <- scenar_values["lt"] @@ -571,12 +568,57 @@ test_that("createBindingConstraintBulk v8.7", { # tests testthat::expect_true("constraints_bulk1" %in% - names(readBindingConstraints(opts = opts_test))) + names(readBindingConstraints())) testthat::expect_true("constraints_bulk10" %in% - names(readBindingConstraints(opts = opts_test))) + names(readBindingConstraints())) + + + + test_that("test bad dimension object INPUT v8.7", { + bad_object <- list( + name = paste0("constraints_bulkBAD"), + id = paste0("constraints_bulkBAD"), + values = scenar_values_daily, + enabled = FALSE, + timeStep = "hourly", + operator = "both", + coefficients = list("at%fr" = 1), + group= "group_bulk", + overwrite = TRUE + ) + + bad_object <- append(list(bad_object), bindings_constraints) + + expect_error( + createBindingConstraintBulk(bad_object), + regexp = "Problem dimension with group" + ) + + }) }) + +test_that("test bad dimension object INPUT v8.7", { + bad_object <- list( + name = paste0("constraints_bulkBAD"), + id = paste0("constraints_bulkBAD"), + values = scenar_values_daily, + enabled = FALSE, + timeStep = "hourly", + operator = "both", + coefficients = list("at%fr" = 1), + group= "group_bulk", + overwrite = TRUE + ) + + expect_error( + createBindingConstraintBulk(list(bad_object)), + regexp = "Problem dimension with group" + ) + +}) + # remove temporary study ---- deleteStudy() From 9d2cd028d3c8df2ba688e1072ef122db376b5ff4 Mon Sep 17 00:00:00 2001 From: berthetclement Date: Mon, 10 Jun 2024 15:01:23 +0200 Subject: [PATCH 2/6] update version and news.md --- DESCRIPTION | 2 +- NEWS.md | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index eba4f2a8..98d12d71 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: antaresEditObject Type: Package Title: Edit an 'Antares' Simulation -Version: 0.7.0 +Version: 0.7.1 Authors@R: c( person("Tatiana", "Vargas", email = "tatiana.vargas@rte-france.com", role = c("aut", "cre")), person("Frederic", "Breant", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 09d5d8c4..60767e08 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,14 @@ -# antaresEditObject 0.7.0 (development) +# antaresEditObject 0.7.1 (development) -> Second-member coupling constraint scenarios +### Breaking changes : + +* `createBindingConstraint()` / `editBindingConstraint()` uses metadata to check the group size of time series. +* `createBindingConstraintBulk()` checks consistency of groups passed as parameters and consistency with the study. + + +# antaresEditObject 0.7.0 + +> Scenarized RHS for binding constraints NEW FEATURES (Antares v8.7, cf. Antares v8.7 changelog) : From 0caed19fa85dfee9e278cc46a46f26b577bb6357 Mon Sep 17 00:00:00 2001 From: berthetclement Date: Mon, 10 Jun 2024 15:02:47 +0200 Subject: [PATCH 3/6] update createbinding + bulk + doc + test --- NAMESPACE | 2 +- R/createBindingConstraint.R | 226 ++++++------------ man/createBindingConstraint.Rd | 51 +--- man/createBindingConstraintBulk.Rd | 98 ++++++++ man/removeBindingConstraint.Rd | 1 + tests/testthat/test-createBindingConstraint.R | 32 ++- 6 files changed, 209 insertions(+), 201 deletions(-) create mode 100644 man/createBindingConstraintBulk.Rd diff --git a/NAMESPACE b/NAMESPACE index a0d8efa9..a71abf72 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,7 +50,7 @@ export(getJobLogs) export(getJobs) export(getPlaylist) export(getVariantCommands) -export(group_values_check) +export(group_values_meta_check) export(importZipStudyWeb) export(is_antares_v7) export(is_antares_v820) diff --git a/R/createBindingConstraint.R b/R/createBindingConstraint.R index e3cae615..a78855ef 100644 --- a/R/createBindingConstraint.R +++ b/R/createBindingConstraint.R @@ -7,7 +7,6 @@ utils::globalVariables(c('V2', 'dim_study', 'dim_input', 'name_group')) #' `r lifecycle::badge("experimental")` #' #' Create a new binding constraint in an Antares study. -#' `createBindingConstraintBulk()` allow to create multiple constraints at once. #' #' #' @param name The name for the binding constraint. @@ -74,28 +73,6 @@ utils::globalVariables(c('V2', 'dim_study', 'dim_input', 'name_group')) #' "area1%area3" = "2%3") #' ) #' -#' # Create multiple constraints -#' -#' # Prepare data for constraints -#' bindings_constraints <- lapply( -#' X = seq_len(100), -#' FUN = function(i) { -#' # use arguments of createBindingConstraint() -#' # all arguments must be provided ! -#' list( -#' name = paste0("constraints", i), -#' id = paste0("constraints", i), -#' values = matrix(data = rep(0, 8760 * 3), ncol = 3), -#' enabled = FALSE, -#' timeStep = "hourly", -#' operator = "both", -#' coefficients = list("area1%area2" = 1), -#' overwrite = TRUE -#' ) -#' } -#' ) -#' # create all constraints -#' createBindingConstraintBulk(bindings_constraints) #' #' # >= v8.7.0 : #' @@ -122,27 +99,6 @@ utils::globalVariables(c('V2', 'dim_study', 'dim_input', 'name_group')) #' values = values_data, #' overwrite = TRUE) #' -#' # create multiple constraints -#' bindings_constraints <- lapply( -#' X = seq_len(10), -#' FUN = function(i) { -#' # use arguments of createBindingConstraint() -#' # all arguments must be provided ! -#' list( -#' name = paste0("constraints_bulk", i), -#' id = paste0("constraints_bulk", i), -#' values = values_data, -#' enabled = FALSE, -#' timeStep = "hourly", -#' operator = "both", -#' coefficients = list("at%fr" = 1), -#' group= "group_bulk", -#' overwrite = TRUE -#' ) -#' } -#' ) -#' -#' createBindingConstraintBulk(bindings_constraints) #' } createBindingConstraint <- function(name, id = tolower(name), @@ -233,13 +189,7 @@ createBindingConstraint <- function(name, call. = FALSE) # v870 : check group and values - # no check for add BC with NULL values - # group_values_check(group_value = group, - # values_data = values, - # operator_check = operator, - # output_operator = values_operator, - # opts = opts) - + # no check for add BC with NULL values group_values_meta_check(group_value = group, values_data = values, operator_check = operator, @@ -527,9 +477,10 @@ createBindingConstraint_ <- function(bindingConstraints, } - #' @title Check dimension of time series for binding constraints -#' @description Only needed for study version >= 870 +#' @description Only needed for study version >= 870 +#' +#' Dimension of groups are compared with meta parameter `binding` returned by [antaresRead::simOptions()] #' @param group_value `character` name of group #' @param values_data `list` values used by the constraint #' @param operator_check `character` parameter "operator" @@ -538,100 +489,6 @@ createBindingConstraint_ <- function(bindingConstraints, #' @template opts #' @export #' @keywords internal -group_values_check <- function(group_value, - values_data, - operator_check, - output_operator, - opts = antaresRead::simOptions()){ - - # no check if col dim ==1 - if(operator_check%in%"both"){ - if(dim(values_data$lt)[2] <= 1) - return() - }else{ - if(dim(values_data[[output_operator]])[2] <= 1) - return() - } - - - # read existing binding constraint - # /!\/!\ function return "default values" (vector of 0) - existing_bc <- readBindingConstraints(opts = opts) - - # study with no BC or virgin study - if(is.null(existing_bc)) - return() - - ## - # group creation - ## - - # check existing group Versus new group - existing_groups <- unlist( - lapply(existing_bc, - function(x){ - x[["properties"]][["group"]]}) - ) - search_group_index <- grep(pattern = group_value, - x = existing_groups) - - # new group ? - new_group <- identical(search_group_index, - integer(0)) - if(new_group) - message("New group ", "'", group_value, "'", " will be created") - - # check dimension values existing group Versus new group - if(!new_group){ - # check dimension of existing group - p_col <- sapply(existing_bc[search_group_index], - function(x){ - op <- x[["properties"]][["operator"]] - if(!op %in%"both") - dim(x[["values"]])[2] - else{ - lt_dim <- dim(x[["values"]][["less"]])[2] - gt_dim <- dim(x[["values"]][["greater"]])[2] - if(lt_dim!=gt_dim) - stop("dimension of values are not similar for constraint : ", - x$properties$id, call. = FALSE) - lt_dim - } - }) - - # keep dimension >1 - names(p_col) <- NULL - if(identical(p_col[p_col>1], - integer(0))){ - message("actual dimension of group : ", group_value, " is NULL or 1") - return(NULL) # continue process to write data - }else - p_col <- unique(p_col[p_col>1]) - message("actual dimension of group : ", group_value, " is ", p_col) - - # check dimension of new group - if(operator_check%in%"both"){ - lt_dim <- dim(values_data$lt)[2] - gt_dim <- dim(values_data$gt)[2] - if(lt_dim!=gt_dim) - stop("dimension of values are not similar ", - call. = FALSE) - p_col_new <- lt_dim - }else - p_col_new <- dim(values_data[[output_operator]])[2] - - # # no values provided - # if(is.null(p_col_new)) - # p_col_new <- 0 - - if(p_col!=p_col_new) # & p_col!=0 - stop(paste0("Put right columns dimension : ", - p_col, " for existing 'group' : ", - group_value), call. = FALSE) - } -} - -# return data table object of group dimension group_values_meta_check <- function(group_value, values_data, operator_check, @@ -806,13 +663,84 @@ group_values_meta_check <- function(group_value, } } - +#' @title Create multiple binding constraint at once. +#' @description #' `r lifecycle::badge("experimental")` +#' `r antaresEditObject:::badge_api_no()` #' @param constraints A `list` of several named `list` containing data to create binding constraints. #' **Warning** all arguments for creating a binding constraints must be provided, see examples. +#' @template opts +#' @family binding constraints functions +#' +#' @details +#' According to Antares version, usage may vary : +#' +#' **>= v8.7.0** : +#' - For each constraint name, one file .txt containing `_lt.txt, _gt.txt, _eq.txt`. +#' +#' - Parameter `values` must be named `list` ("lt", "gt", "eq") containing `data.frame` scenarized. +#' +#' - Add parameter `group` in input list `constraints` +#' +#' see example section below. #' @export #' -#' @rdname createBindingConstraint +#' @examples +#' \dontrun{ +#' # For Study version < v8.7.0 +#' # Create multiple constraints +#' +#' # Prepare data for constraints +#' bindings_constraints <- lapply( +#' X = seq_len(100), +#' FUN = function(i) { +#' # use arguments of createBindingConstraint() +#' # all arguments must be provided ! +#' list( +#' name = paste0("constraints", i), +#' id = paste0("constraints", i), +#' values = matrix(data = rep(0, 8760 * 3), ncol = 3), +#' enabled = FALSE, +#' timeStep = "hourly", +#' operator = "both", +#' coefficients = list("area1%area2" = 1), +#' overwrite = TRUE +#' ) +#' } +#' ) +#' # create all constraints +#' createBindingConstraintBulk(bindings_constraints) +#' +#' # For Study version >= v8.7.0 (add parameter `group`) +#' +#' # data values (hourly) +#' df <- matrix(data = rep(0, 8760 * 3), ncol = 3) +#' values_data <- list(lt=df, +#' gt= df) +#' +#' # create multiple constraints +#' bindings_constraints <- lapply( +#' X = seq_len(10), +#' FUN = function(i) { +#' # use arguments of createBindingConstraint() +#' # all arguments must be provided ! +#' list( +#' name = paste0("constraints_bulk", i), +#' id = paste0("constraints_bulk", i), +#' values = values_data, +#' enabled = FALSE, +#' timeStep = "hourly", +#' operator = "both", +#' coefficients = list("at%fr" = 1), +#' group= "group_bulk", +#' overwrite = TRUE +#' ) +#' } +#' ) +#' +#' createBindingConstraintBulk(bindings_constraints) +#' } +#' createBindingConstraintBulk <- function(constraints, opts = antaresRead::simOptions()) { assertthat::assert_that(inherits(opts, "simOptions")) diff --git a/man/createBindingConstraint.Rd b/man/createBindingConstraint.Rd index 3566141f..7114c8f3 100644 --- a/man/createBindingConstraint.Rd +++ b/man/createBindingConstraint.Rd @@ -2,7 +2,6 @@ % Please edit documentation in R/createBindingConstraint.R \name{createBindingConstraint} \alias{createBindingConstraint} -\alias{createBindingConstraintBulk} \title{Create a binding constraint} \usage{ createBindingConstraint( @@ -19,8 +18,6 @@ createBindingConstraint( overwrite = FALSE, opts = antaresRead::simOptions() ) - -createBindingConstraintBulk(constraints, opts = antaresRead::simOptions()) } \arguments{ \item{name}{The name for the binding constraint.} @@ -51,9 +48,6 @@ weight or weight with offset.} \item{opts}{List of simulation parameters returned by the function \code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationPath()}}} - -\item{constraints}{A \code{list} of several named \code{list} containing data to create binding constraints. -\strong{Warning} all arguments for creating a binding constraints must be provided, see examples.} } \value{ An updated list containing various information about the simulation. @@ -63,7 +57,6 @@ An updated list containing various information about the simulation. \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} Create a new binding constraint in an Antares study. -\code{createBindingConstraintBulk()} allow to create multiple constraints at once. } \details{ According to Antares version, usage may vary : @@ -102,28 +95,6 @@ createBindingConstraint( "area1\%area3" = "2\%3") ) -# Create multiple constraints - -# Prepare data for constraints -bindings_constraints <- lapply( - X = seq_len(100), - FUN = function(i) { - # use arguments of createBindingConstraint() - # all arguments must be provided ! - list( - name = paste0("constraints", i), - id = paste0("constraints", i), - values = matrix(data = rep(0, 8760 * 3), ncol = 3), - enabled = FALSE, - timeStep = "hourly", - operator = "both", - coefficients = list("area1\%area2" = 1), - overwrite = TRUE - ) - } -) -# create all constraints -createBindingConstraintBulk(bindings_constraints) # >= v8.7.0 : @@ -150,31 +121,11 @@ createBindingConstraint(name = "bc_example", values = values_data, overwrite = TRUE) -# create multiple constraints -bindings_constraints <- lapply( - X = seq_len(10), - FUN = function(i) { - # use arguments of createBindingConstraint() - # all arguments must be provided ! - list( - name = paste0("constraints_bulk", i), - id = paste0("constraints_bulk", i), - values = values_data, - enabled = FALSE, - timeStep = "hourly", - operator = "both", - coefficients = list("at\%fr" = 1), - group= "group_bulk", - overwrite = TRUE - ) - } -) - -createBindingConstraintBulk(bindings_constraints) } } \seealso{ Other binding constraints functions: +\code{\link{createBindingConstraintBulk}()}, \code{\link{editBindingConstraint}()}, \code{\link{removeBindingConstraint}()} } diff --git a/man/createBindingConstraintBulk.Rd b/man/createBindingConstraintBulk.Rd new file mode 100644 index 00000000..223c0c9b --- /dev/null +++ b/man/createBindingConstraintBulk.Rd @@ -0,0 +1,98 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/createBindingConstraint.R +\name{createBindingConstraintBulk} +\alias{createBindingConstraintBulk} +\title{Create multiple binding constraint at once.} +\usage{ +createBindingConstraintBulk(constraints, opts = antaresRead::simOptions()) +} +\arguments{ +\item{constraints}{A \code{list} of several named \code{list} containing data to create binding constraints. +\strong{Warning} all arguments for creating a binding constraints must be provided, see examples.} + +\item{opts}{List of simulation parameters returned by the function +\code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationPath()}}} +} +\value{ +An updated list containing various information about the simulation. +} +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} +\ifelse{html}{\figure{badge_api_no.svg}{options: alt='Antares API NO'}}{Antares API: \strong{NO}} +} +\details{ +According to Antares version, usage may vary : + +\strong{>= v8.7.0} : +\itemize{ +\item For each constraint name, one file .txt containing \verb{_lt.txt, _gt.txt, _eq.txt}. +\item Parameter \code{values} must be named \code{list} ("lt", "gt", "eq") containing \code{data.frame} scenarized. +\item Add parameter \code{group} in input list \code{constraints} +} + +see example section below. +} +\examples{ +\dontrun{ +# For Study version < v8.7.0 +# Create multiple constraints + +# Prepare data for constraints +bindings_constraints <- lapply( + X = seq_len(100), + FUN = function(i) { + # use arguments of createBindingConstraint() + # all arguments must be provided ! + list( + name = paste0("constraints", i), + id = paste0("constraints", i), + values = matrix(data = rep(0, 8760 * 3), ncol = 3), + enabled = FALSE, + timeStep = "hourly", + operator = "both", + coefficients = list("area1\%area2" = 1), + overwrite = TRUE + ) + } +) +# create all constraints +createBindingConstraintBulk(bindings_constraints) + +# For Study version >= v8.7.0 (add parameter `group`) + +# data values (hourly) +df <- matrix(data = rep(0, 8760 * 3), ncol = 3) +values_data <- list(lt=df, + gt= df) + +# create multiple constraints +bindings_constraints <- lapply( + X = seq_len(10), + FUN = function(i) { + # use arguments of createBindingConstraint() + # all arguments must be provided ! + list( + name = paste0("constraints_bulk", i), + id = paste0("constraints_bulk", i), + values = values_data, + enabled = FALSE, + timeStep = "hourly", + operator = "both", + coefficients = list("at\%fr" = 1), + group= "group_bulk", + overwrite = TRUE + ) + } +) + +createBindingConstraintBulk(bindings_constraints) +} + +} +\seealso{ +Other binding constraints functions: +\code{\link{createBindingConstraint}()}, +\code{\link{editBindingConstraint}()}, +\code{\link{removeBindingConstraint}()} +} +\concept{binding constraints functions} diff --git a/man/removeBindingConstraint.Rd b/man/removeBindingConstraint.Rd index 5caf004d..0754a89c 100644 --- a/man/removeBindingConstraint.Rd +++ b/man/removeBindingConstraint.Rd @@ -51,6 +51,7 @@ removeBindingConstraint(group = group_to_delete) } \seealso{ Other binding constraints functions: +\code{\link{createBindingConstraintBulk}()}, \code{\link{createBindingConstraint}()}, \code{\link{editBindingConstraint}()} } diff --git a/tests/testthat/test-createBindingConstraint.R b/tests/testthat/test-createBindingConstraint.R index 4932de28..c853400f 100644 --- a/tests/testthat/test-createBindingConstraint.R +++ b/tests/testthat/test-createBindingConstraint.R @@ -226,6 +226,36 @@ sapply(studies, function(study) { expect_warning(removeBindingConstraint(name = "myimaginaryconstraint")) }) + ## bulk ---- + test_that("createBindingConstraintBulk v710", { + # Prepare data for constraints + bindings_constraints <- lapply( + X = seq_len(5), + FUN = function(i) { + # use arguments of createBindingConstraint() + # all arguments must be provided ! + list( + name = paste0("constraints_bulk", i), + id = paste0("constraints_bulk", i), + values = matrix(data = rep(1, 8760 * 3), ncol = 3), + enabled = FALSE, + timeStep = "hourly", + operator = "both", + coefficients = list("a%b" = 1), + overwrite = TRUE + ) + } + ) + # create all constraints + createBindingConstraintBulk(bindings_constraints) + + # tests + testthat::expect_true("constraints_bulk1" %in% + names(readBindingConstraints())) + testthat::expect_true("constraints_bulk5" %in% + names(readBindingConstraints())) + }) + # remove temporary study unlink(x = file.path(pathstd, "test_case"), recursive = TRUE) @@ -600,7 +630,7 @@ test_that("createBindingConstraintBulk v8.7", { -test_that("test bad dimension object INPUT v8.7", { +test_that("test bad dimension object with existing object in study v8.7", { bad_object <- list( name = paste0("constraints_bulkBAD"), id = paste0("constraints_bulkBAD"), From 6ccf111bb3493c354c19af4fe3b2d3dfa480cea4 Mon Sep 17 00:00:00 2001 From: berthetclement Date: Mon, 10 Jun 2024 15:03:13 +0200 Subject: [PATCH 4/6] update editBindingConstraint with new private function to check group dim --- R/editBindingConstraint.R | 10 +++++----- man/editBindingConstraint.Rd | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/R/editBindingConstraint.R b/R/editBindingConstraint.R index 84ce11d0..39a61e56 100644 --- a/R/editBindingConstraint.R +++ b/R/editBindingConstraint.R @@ -172,11 +172,11 @@ editBindingConstraint <- function(name, # check group values if(!is.null(values)) - group_values_check(group_value = group, - values_data = values, - operator_check = operator, - output_operator = values_operator, - opts = opts) + group_values_meta_check(group_value = group, + values_data = values, + operator_check = operator, + output_operator = values_operator, + opts = opts) } diff --git a/man/editBindingConstraint.Rd b/man/editBindingConstraint.Rd index d2536510..0ceb8c74 100644 --- a/man/editBindingConstraint.Rd +++ b/man/editBindingConstraint.Rd @@ -115,6 +115,7 @@ editBindingConstraint(name = "myconstraint", } \seealso{ Other binding constraints functions: +\code{\link{createBindingConstraintBulk}()}, \code{\link{createBindingConstraint}()}, \code{\link{removeBindingConstraint}()} } From de99e4823abeca81364ccffb2ba958d29852d34a Mon Sep 17 00:00:00 2001 From: berthetclement Date: Mon, 10 Jun 2024 15:03:43 +0200 Subject: [PATCH 5/6] replace function to check dim by group_values_meta_check --- man/{group_values_check.Rd => group_values_meta_check.Rd} | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) rename man/{group_values_check.Rd => group_values_meta_check.Rd} (79%) diff --git a/man/group_values_check.Rd b/man/group_values_meta_check.Rd similarity index 79% rename from man/group_values_check.Rd rename to man/group_values_meta_check.Rd index 1e4e1899..9b6c0c5b 100644 --- a/man/group_values_check.Rd +++ b/man/group_values_meta_check.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/createBindingConstraint.R -\name{group_values_check} -\alias{group_values_check} +\name{group_values_meta_check} +\alias{group_values_meta_check} \title{Check dimension of time series for binding constraints} \usage{ -group_values_check( +group_values_meta_check( group_value, values_data, operator_check, @@ -31,5 +31,7 @@ An updated list containing various information about the simulation. } \description{ Only needed for study version >= 870 + +Dimension of groups are compared with meta parameter \code{binding} returned by \code{\link[antaresRead:simOptions]{antaresRead::simOptions()}} } \keyword{internal} From 984294134337dea0382b8bb820c22ccb9e9ddee8 Mon Sep 17 00:00:00 2001 From: berthetclement Date: Mon, 10 Jun 2024 16:14:33 +0200 Subject: [PATCH 6/6] update DESCRIPTION file remotes --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 98d12d71..c7541562 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -54,5 +54,5 @@ Suggests: rmarkdown VignetteBuilder: knitr Remotes: - rte-antares-rpackage/antaresRead@ant1777/dimbcgroup + rte-antares-rpackage/antaresRead@develop