Skip to content

Commit

Permalink
change stop by warning and return same data table in local and API mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MAHOUDI Abdallah (Externe) committed Mar 4, 2024
1 parent 104074e commit 34cf591
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions R/readClusterDesc.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ readClusterSTDesc <- function(opts = simOptions()) {

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")

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){
Expand All @@ -123,9 +129,11 @@ readClusterSTDesc <- function(opts = simOptions()) {
clusters[, .SD, .SDcols = order(names(clusters))]
},jsoncld, names(jsoncld), SIMPLIFY = FALSE), fill = TRUE)

if(length(res) == 0)
stop("Cannot find cluster description.", call. = FALSE)

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 <- res[, .SD, .SDcols = c("area", "name", "group", names(res)[!names(res) %in%c("area", "name", "group")])]

}else{
Expand All @@ -146,7 +154,10 @@ readClusterSTDesc <- function(opts = simOptions()) {

}

if(length(res) == 0) stop("Cannot find cluster description.", call. = FALSE)
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")
Expand Down

0 comments on commit 34cf591

Please sign in to comment.