Skip to content

Commit

Permalink
Ant856/bug (#135)
Browse files Browse the repository at this point in the history
* change default value for list_pollutants by NULL. change condition for if and ad stop if list_pollutant used for antaresVersion >= 860. +test if list_pollutant not a list
  • Loading branch information
Nekmek7 authored Feb 27, 2024
1 parent e82e39c commit 31a0c8c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ NEW FEATURES :
### Breaking changes

* `setPlaylist()` optimized for the API mode
- returned an updated list of simulation parameters returned by the function `setSimulationPath()` and `setSimulationPathAPI()`
- returned an updated list of simulation parameters returned by the function `setSimulationPath()` and `setSimulationPathAPI()`.
* `createCluster()` parameter `list_pollutants` default value to NULL.
* `createBindingConstraint()` parameter `coefficients` must be alphabetically ordered.

BUGFIXES :
Expand All @@ -17,7 +18,7 @@ BUGFIXES :
* Fix `setPlaylist()` works in API and local mode with weights.
* Fix `getPlaylist()` works in API and local mode with weights.
* Fix `createDSR()` in API mode : daily binding constraint takes 366 rows.
* Fix `createCluster()` parameter `list_pollutants` stop for Antares Version < 860.
* 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`.

# antaresEditObject 0.6.1
Expand Down
22 changes: 9 additions & 13 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_pollutants = list_pollutants_values(),
list_pollutants = NULL,
time_series = NULL,
prepro_data = NULL,
prepro_modulation = NULL,
Expand All @@ -166,28 +166,24 @@ createCluster <- function(area,
# check study parameters
assertthat::assert_that(inherits(opts, "simOptions"))

# static name of list parameters of pulluants
# static name of list parameters of pollutants
name_list_param_poll <- names(list_pollutants_values())

# check v860
# check list pulluants parameters
# check list pollutants parameters
if(opts$antaresVersion >= 860){
if(!is.null(list_pollutants) & !assert_that(inherits(list_pollutants, "list")))
if(!is.null(list_pollutants) & !(class(list_pollutants) == "list"))
stop("Parameter 'list_pollutants' must be a 'list'")

if(!all(names(list_pollutants) %in% name_list_param_poll))
stop(append("Parameter 'list_pollutants' 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_pollutants, is.null)
all_null <- all(unlist(all_null))

if(all_null)
list_pollutants <- NULL
}

else{
if(!is.null(list_pollutants))
stop("antaresVersion should be >= v8.6.0 to use parameter 'list_pollutants'.")
}


# statics groups
thermal_group <- c("Gas",
Expand Down
8 changes: 6 additions & 2 deletions R/editCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ editClusterRES <- function(area,
cluster_name <- paste(area, cluster_name, sep = "_")

# v860 pollutants
if(opts$antaresVersion >= 860)
if(opts$antaresVersion >= 860){
params_cluster <- append(params_cluster, list_pollutants)

}
else{
if(!is.null(list_pollutants))
stop("antaresVersion should be >= v8.6.0 to use parameter 'list_pollutants'.")
}
# Handle case sensitivity in name of clusters API
clusters <- names(readIni(file.path("input", cluster_type, "clusters", area, "list"),
opts= opts))
Expand Down
2 changes: 1 addition & 1 deletion man/createCluster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test-createCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ test_that("Create cluster with pollutants params (new feature v8.6)",{
testthat::expect_equal(all(is.na(values_default)), TRUE)
})

bad_pollutants_param <- "not_a_list"
testthat::expect_error(createCluster(
area = getAreas()[1],
cluster_name = "bad_cluster",
group = "Other",
unitcount = as.integer(1),
nominalcapacity = 100,
list_pollutants = bad_pollutants_param,
opts = opts_test), regexp = "'list_pollutants' must be a 'list'")

pollutants_params <- list(
"nh3"= 0.25, "nox"= 0.45, "pm2_5"= 0.25,
"pm5"= 0.25, "pm10"= 0.25, "nmvoc"= 0.25, "so2"= 0.25,
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-editCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ opts_test <- antaresRead::setSimulationPath(study_temp_path, "input")

test_that("Edit cluster with pollutants params (new feature v8.6)",{

bad_pollutants_param <- "not_a_list"
testthat::expect_error(createCluster(
area = getAreas()[1],
cluster_name = "mycluster_pollutant",
group = "Other",
unitcount = as.integer(1),
nominalcapacity = 100,
list_pollutants = bad_pollutants_param,
opts = opts_test), regexp = "'list_pollutants' must be a 'list'")

pollutants_params <- list(
"nh3"= 0.25, "nox"= 0.45, "pm2_5"= 0.25,
"pm5"= 0.25, "pm10"= 0.25, "nmvoc"= 0.25, "so2"= 0.25,
Expand Down

0 comments on commit 31a0c8c

Please sign in to comment.