Skip to content

Commit

Permalink
resolve conflicts news.md
Browse files Browse the repository at this point in the history
Merge branch 'develop' of https://github.com/rte-antares-rpackage/antaresRead into ant1959

# Conflicts:
#	NEWS.md
  • Loading branch information
berthetclement committed Aug 30, 2024
2 parents e7d7b7a + 64e60ba commit a016bfc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ importFrom(plyr,llply)
importFrom(purrr,quietly)
importFrom(shiny,getDefaultReactiveDomain)
importFrom(shiny,incProgress)
importFrom(shiny,isRunning)
importFrom(shiny,withProgress)
importFrom(stats,as.formula)
importFrom(stats,setNames)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NEW FEATURES:
It contains a table with group dimensions of time series for binding constraints.
* `readAntares()` new parameter **clustersST** to read (output simulation) short-term clusters
* New function `readAntaresSTClusters()`

* `fread_antares()` shiny compatible with a conditional processing of the error messages

BREAKING CHANGES :

Expand All @@ -25,6 +25,7 @@ BUGFIXES :
* `readInputThermal()` return data from file data.txt with `thermalData` parameter
* `setSimulationPath()` has also the parameter **areasWithSTClusters** in 'output' mode
* `setSimulationPathAPI()`: control the existence of the output folder **links** or **areas** before reading the data (upgrade Antares Web)
* `readClusterDesc()` / `readClusterResDesc()` / `readClusterSTDesc()` return a data.table in API mode


# antaresRead 2.7.0
Expand Down
41 changes: 33 additions & 8 deletions R/readClusterDesc.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,17 @@ readClusterSTDesc <- function(opts = simOptions()) {
"st-storage/clusters" = "st-storages"
)

if(api_study){

if (api_study) {
# api request with all columns
list_clusters = api_get(
list_clusters <- api_get(
opts = opts,
endpoint = paste0(opts$study_id, "/table-mode/", table_type),
query = list(
columns = ""
)
query = list(columns = "")
)

return(list_clusters)
dt_clusters <- .convert_list_clusterDesc_to_datatable(list_clusters)

return(dt_clusters)
}

# "text" mode
Expand All @@ -124,7 +123,7 @@ readClusterSTDesc <- function(opts = simOptions()) {
# READ cluster properties
properties <- get_input_cluster_properties(table_type = table_type,
opts = opts)

# read properties for each area
res <- plyr::llply(areas, function(x, prop_ref=properties) {
clusters <- readIniFile(file.path(path, x, "list.ini"))
Expand Down Expand Up @@ -225,3 +224,29 @@ get_input_cluster_properties <- function(table_type, opts){

return(wide_ref)
}


.convert_list_clusterDesc_to_datatable <- function(list_clusters) {

if (length(list_clusters) == 0) {
return(data.table())
}

rows_cluster <- lapply(names(list_clusters), FUN = function(cl_name) {

row_cluster <- as.data.frame(list_clusters[[cl_name]])
row_cluster[,c("area", "cluster")] <- unlist(strsplit(cl_name, split = " / "))

return(row_cluster)
}
)

df_clusters <- do.call("rbind", rows_cluster)
id_cols <- intersect(c("area", "cluster", "group"), colnames(df_clusters))
additional_cols <- setdiff(colnames(df_clusters), id_cols)
df_clusters <- df_clusters[,c(id_cols, additional_cols)]
df_clusters$cluster <- as.factor(tolower(df_clusters$cluster))
colnames(df_clusters) <- tolower(colnames(df_clusters))

return(as.data.table(df_clusters))
}
6 changes: 5 additions & 1 deletion R/utils_api.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' @importFrom utils URLencode
#' @importFrom shiny isRunning
fread_antares <- function(opts, file, ...) {
if (identical(opts$typeLoad, "api")) {
file <- gsub("\\.txt$", "", file)
Expand All @@ -9,7 +10,10 @@ fread_antares <- function(opts, file, ...) {
)
suppressWarnings(
tryCatch(fread(response, ...), error = function(e){
message(file); message(e)
if(isRunning())
e <- as.character(e)
message(file)
message(e)
}))
} else {
suppressWarnings(
Expand Down

0 comments on commit a016bfc

Please sign in to comment.