Skip to content

Commit

Permalink
createClusterST fix create data files + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BERTHET Clement Ext committed Aug 30, 2023
1 parent bfa54b9 commit b495feb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,15 @@ createClusterST <- function(area,
x = k, row.names = FALSE, col.names = FALSE, sep = "\t",
file = file.path(inputPath, "st-storage", "series", tolower(area), tolower(cluster_name), paste0(storage_value[[name]]$string, ".txt"))
)
}
} else {
# write data
fwrite(
x = get(name), row.names = FALSE, col.names = FALSE, sep = "\t",
file = file.path(inputPath, "st-storage", "series", tolower(area),
tolower(cluster_name),
paste0(storage_value[[name]]$string, ".txt"))
)
}
}

# Update simulation options object
Expand Down
35 changes: 35 additions & 0 deletions tests/testthat/test-createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,41 @@ if (opts_test$antaresVersion >= 860){
# check default values
testthat::expect_equal(df_ref_default_value$mean, test_txt_value$mean)


## creation cluster (explicit data) ----
val <- 0.7
val_mat <- matrix(val, 8760)

opts_test <- createClusterST(area = area_test,
cluster_name = "test_storage",
storage_parameters = storage_values_default()[1],
PMAX_injection = val_mat,
PMAX_withdrawal = val_mat,
inflows = val_mat,
lower_rule_curve = val_mat,
upper_rule_curve = val_mat,
overwrite = TRUE,
opts = opts_test)

## check name cluster created
namecluster_check <- paste(area_test, "test_storage", sep = "_")
testthat::expect_true(namecluster_check %in%
levels(readClusterSTDesc(opts = opts_test)$cluster))

## check data

# read series (with readInputTS)
st_ts <- readInputTS(st_storage = "all", opts = opts_test)

# check to find 5 names files created previously
filter_st_ts <- st_ts[cluster %in% namecluster_check,
list(mean=mean(`st-storage`)),
by=name_file]

testthat::expect_true(all(filter_st_ts$name_file %in%
original_files_names))
testthat::expect_equal(val, unique(filter_st_ts$mean))


## remove cluster----
# RemoveClusterST (if no cluster => function read return error => see readClusterDesc tests)
Expand Down

0 comments on commit b495feb

Please sign in to comment.