Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug readClusterDesc when no cluster + cover ST and RES case #241

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ BUGFIXES :
BREAKING CHANGES :

* `api_get()` has a new parameter to control JSON file parsing
* `readClusterDesc()` return empty dataTable and warning if no cluster in Antares study.
* `readClusterDesc()`/ `readClusterRESDesc()` / `readClusterSTDesc()`
return empty dataTable and warning if no cluster in Antares study.

# antaresRead 2.6.0

Expand Down
49 changes: 31 additions & 18 deletions R/readClusterDesc.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
}



.readClusterDesc <- function(opts = simOptions(),
dir = "thermal/clusters") {

Expand All @@ -107,13 +106,10 @@

path <- file.path(opts$inputPath, dir)

columns = c("group","enabled","must_run","unit_count","nominal_capacity",
"min_stable_power","spinning","min_up_time","min_down_time",
"co2","marginal_cost","fixed_cost","startup_cost","market_bid_cost",
"spread_cost","ts_gen","volatility_forced","volatility_planned",
"law_forced","law_planned")
columns <- .generate_columns_by_type(dir = dir)

if(opts$typeLoad == 'api'){

jsoncld <- read_secure_json(paste0(path, "&depth=4"), token = opts$token, timeout = opts$timeout, config = opts$httr_config)
res <- rbindlist(mapply(function(X1, Y1){
clusters <- rbindlist(
Expand All @@ -131,10 +127,11 @@

if(length(res) == 0){
warning("No cluster description available.", call. = FALSE)
res <- setNames(data.table(matrix(nrow = 0, ncol = 22)), c("area", "cluster", columns))
res <- setNames(data.table(matrix(nrow = 0, ncol = 2 + length(columns))), c("area", "cluster", columns))

Check warning on line 130 in R/readClusterDesc.R

View check run for this annotation

Codecov / codecov/patch

R/readClusterDesc.R#L130

Added line #L130 was not covered by tests
}else{
res <- res[, .SD, .SDcols = c("area", "name", "group", names(res)[!names(res) %in%c("area", "name", "group")])]

Check warning on line 132 in R/readClusterDesc.R

View check run for this annotation

Codecov / codecov/patch

R/readClusterDesc.R#L132

Added line #L132 was not covered by tests
}

res <- res[, .SD, .SDcols = c("area", "name", "group", names(res)[!names(res) %in%c("area", "name", "group")])]


}else{

Expand All @@ -152,17 +149,33 @@
clusters[, c(ncol(clusters), 1:(ncol(clusters) - 1))]
})

if(length(res) == 0){
warning("No cluster description available.", call. = FALSE)
res <- setNames(data.table(matrix(nrow = 0, ncol = 2 + length(columns))), c("area", "cluster", columns))

Check warning on line 154 in R/readClusterDesc.R

View check run for this annotation

Codecov / codecov/patch

R/readClusterDesc.R#L153-L154

Added lines #L153 - L154 were not covered by tests
}else{
res <- as.data.table(res)
setnames(res, "name", "cluster")

res$cluster <- as.factor(tolower(res$cluster))
}
}

if(length(res) == 0){
warning("No cluster description available.", call. = FALSE)
res <- setNames(data.table(matrix(nrow = 0, ncol = 22)), c("area", "cluster", columns))
}

res <- as.data.table(res)
setnames(res, "name", "cluster")
res
}

.generate_columns_by_type <- function(dir = c("thermal/clusters", "renewables/clusters", "st-storage/clusters")) {

res$cluster <- as.factor(tolower(res$cluster))

res
columns <- switch(
dir,
"thermal/clusters" = c("group","enabled","must_run","unit_count","nominal_capacity",
"min_stable_power","spinning","min_up_time","min_down_time",
"co2","marginal_cost","fixed_cost","startup_cost","market_bid_cost",
"spread_cost","ts_gen","volatility_forced","volatility_planned",
"law_forced","law_planned"),

"renewables/clusters" = c("group","ts_interpretation","enabled","unit_count","nominal_capacity")
#"st-storage/clusters" = #ATTENTE DEV COTé API
)
return(columns)
}
Loading