Skip to content

Commit

Permalink
reforge to use api_get with new parameters to parse in text
Browse files Browse the repository at this point in the history
  • Loading branch information
BERTHET Clement (Externe) committed Feb 23, 2024
1 parent 9fc8d5f commit ee0afa3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ BugReports: https://github.com/rte-antares-rpackage/antaresEditObject/issues
Encoding: UTF-8
RoxygenNote: 7.2.2
Roxygen: list(markdown = TRUE)
Depends: antaresRead (>= 2.4.2)
Depends:
antaresRead (>= 2.4.2)
Imports:
assertthat,
cli,
Expand All @@ -51,3 +52,5 @@ Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
Remotes:
rte-antares-rpackage/antaresRead@Ant946/getjobs
56 changes: 29 additions & 27 deletions R/API.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ useVariant <- function(name, variant_id = NULL, opts = antaresRead::simOptions()
#' @param job_id The job identifier, if `NULL` (default), retrieve all jobs.
#' @template opts-arg
#'
#' @return A `data.table` with information about jobs.
#' @return A `data.frame` with information about jobs.
#' @export
#'
#' @importFrom data.table rbindlist
Expand All @@ -218,32 +218,34 @@ getJobs <- function(job_id = NULL, opts = antaresRead::simOptions()) {
assertthat::assert_that(inherits(opts, "simOptions"))
if (!is_api_study(opts))
stop("getJobs can only be used with Antares API.", call. = FALSE)
if (is.null(job_id)) {
jobs <- api_get(opts = opts, "launcher/jobs", default_endpoint = "v1")

# fix duplicated raw cause multiple elements for "owner"
jobs <- lapply(jobs,
rename_floor_list,
target_name = "owner")

jobs <- suppressWarnings(data.table::rbindlist(jobs, fill = TRUE))

add_col_names <- c("owner_id", "owner_name")
if(all(add_col_names %in% names(jobs))){
names_to_keep = setdiff(names(jobs),
add_col_names)
names_to_keep <- append(names_to_keep, add_col_names)
setcolorder(jobs, names_to_keep)
}else
suppressWarnings(data.table::rbindlist(jobs, fill = TRUE))
} else {
jobs <- api_get(opts = opts, paste0("launcher/jobs/", job_id), default_endpoint = "v1")

# fix duplicated raw cause multiple elements for "owner"
jobs <- rename_floor_list(target_name = "owner",
list_to_reforge = jobs)
data.table::as.data.table(jobs)
}
if (is.null(job_id))
.getjobs(opts = opts)

Check warning on line 222 in R/API.R

View check run for this annotation

Codecov / codecov/patch

R/API.R#L221-L222

Added lines #L221 - L222 were not covered by tests
else
.getjobs(opts = opts,
id_job = job_id)

Check warning on line 225 in R/API.R

View check run for this annotation

Codecov / codecov/patch

R/API.R#L224-L225

Added lines #L224 - L225 were not covered by tests
}

.getjobs <- function(opts, id_job=NULL){
# make endpoint with id or not
if(is.null(id_job))
custom_endpoint <- file.path("launcher", "jobs")

Check warning on line 231 in R/API.R

View check run for this annotation

Codecov / codecov/patch

R/API.R#L230-L231

Added lines #L230 - L231 were not covered by tests
else
custom_endpoint <- file.path("launcher", "jobs", id_job)

Check warning on line 233 in R/API.R

View check run for this annotation

Codecov / codecov/patch

R/API.R#L233

Added line #L233 was not covered by tests
# api call with text content
jobs <- api_get(opts = opts,
endpoint = custom_endpoint,
default_endpoint = "v1",
parse_result = "text")

Check warning on line 238 in R/API.R

View check run for this annotation

Codecov / codecov/patch

R/API.R#L235-L238

Added lines #L235 - L238 were not covered by tests
# reformat
if(!is.null(id_job))
jobs <- paste0("[",jobs,"]")

Check warning on line 241 in R/API.R

View check run for this annotation

Codecov / codecov/patch

R/API.R#L240-L241

Added lines #L240 - L241 were not covered by tests
# as DT to reformat names
jobs <- as.data.table(
jsonlite::fromJSON(jobs))
names(jobs) <- sub(pattern = "\\.",
replacement = "_",
x = names(jobs))
return(jobs)

Check warning on line 248 in R/API.R

View check run for this annotation

Codecov / codecov/patch

R/API.R#L243-L248

Added lines #L243 - L248 were not covered by tests
}


Expand Down
2 changes: 1 addition & 1 deletion man/getJobs.Rd

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

0 comments on commit ee0afa3

Please sign in to comment.