Skip to content

Commit

Permalink
editBindingConstraint() fix bug with parameter "operator" (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
berthetclement authored Jan 7, 2025
1 parent eaf833a commit c5b09f5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 9 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ NEW FEATURES (Antares v9.0) :

* `createStudy()` takes into account the new format of Antares studies (e.g. 9.0, 9.15 instead of 900, 915)

BUGFIXES :

* `editBindingConstraint()` :
- `operator` parameter set to NULL, by default, no longer causes an error.
- To add values, the `operator` parameter is now required.
- For a study version >= 832, the `filter-year-by-year` and `filter-synthesis` properties are retained in the .ini file if they are not modified.


GITHUB ACTIONS :

Expand Down
23 changes: 15 additions & 8 deletions R/editBindingConstraint.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ editBindingConstraint <- function(name,

# Marginal price granularity (v8.3.2)
if (opts$antaresVersion >= 832){
iniParams <- append(iniParams,
list(`filter-year-by-year` = bc_update$`filter-year-by-year`,
`filter-synthesis` = bc_update$`filter-synthesis`))
if(!is.null(filter_year_by_year))
iniParams$`filter-year-by-year` <- filter_year_by_year
if(!is.null(filter_synthesis))
Expand All @@ -164,19 +167,23 @@ editBindingConstraint <- function(name,
else
group <- "default"

values_operator <- switch(operator,
less = "lt",
equal = "eq",
greater = "gt",
both = c("lt", "gt"))

# check group values
if(!is.null(values))
# check group values (depend of "operator")
if(!is.null(values)){
if(!is.null(operator))
values_operator <- switch(operator,
less = "lt",
equal = "eq",
greater = "gt",
both = c("lt", "gt"))
else
stop("To modify the 'values' you must enter the 'operator' parameter (e.g operator = \"both\")")

group_values_meta_check(group_value = group,
values_data = values,
operator_check = operator,
output_operator = values_operator,
opts = opts)
}

}

Expand Down
52 changes: 51 additions & 1 deletion tests/testthat/test-editBindingConstraint.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test_that("editBindingConstraint v710", {

})

# v870 ----
# v870 Scenarized RHS ----

# read script to generate study v8.7.0
sourcedir_last_study <- system.file("study_test_generator/generate_test_study_870.R",
Expand Down Expand Up @@ -66,6 +66,56 @@ scenar_values_daily <- list(lt= lt_data,
gt= gt_data,
eq= eq_data)

## default group ----
test_that("editBindingConstraint paramater one by one", {

name_bc <- "bc_minimal"
createBindingConstraint(name = name_bc)

# read
bc_read <- readBindingConstraints()

# edit nothing
editBindingConstraint(name = name_bc)

# read updated
bc_read_updated <- readBindingConstraints()

# test if is identical
testthat::expect_equal(bc_read, bc_read_updated)

# edit ["values"] (created by default with "both")
# "operator" muy be filled
testthat::expect_error(
editBindingConstraint(name = name_bc,
values = scenar_values_hourly[c("lt", "gt")]),
regexp = "To modify the 'values' you must enter the 'operator'"
)

editBindingConstraint(name = name_bc,
operator = "both",
values = scenar_values_hourly[c("lt", "gt")])

# read updated
bc_read_updated <- readBindingConstraints()

# test dim
dim_bc <- dim(bc_read_updated$bc_minimal$values$less)
testthat::expect_equal(dim_bc[2], 10)

# edit ["enabled "] (TRUE by default)
editBindingConstraint(name = name_bc,
enabled = FALSE)

# read updated
bc_read_updated <- readBindingConstraints()

testthat::expect_equal(bc_read_updated$bc_minimal$properties$enabled, FALSE)



})

## default group ----
test_that("editBindingConstraint with 'default' group v8.7.0", {
# INIT with creation BC
Expand Down

0 comments on commit c5b09f5

Please sign in to comment.