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

Ant946/getjobs #117

Merged
merged 7 commits into from
Feb 27, 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
4 changes: 3 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,4 @@ Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr

1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ BUGFIXES :
* Fix `setPlaylist()` works in API and local mode with weights.
* Fix `getPlaylist()` works in API and local mode with weights.
* Fix `createDSR()` in API mode : daily binding constraint takes 366 rows
* `getJobs()` no longer returns duplicates and displays the two new columns `owner_id` and `owner_name`.


# antaresEditObject 0.6.1
Expand Down
35 changes: 28 additions & 7 deletions R/API.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,34 @@
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")
suppressWarnings(data.table::rbindlist(jobs, fill = TRUE))
} else {
jobs <- api_get(opts = opts, paste0("launcher/jobs/", job_id), default_endpoint = "v1")
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
25 changes: 24 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,28 @@
}
}


# reorder a list into a simple named list
# target a named list within the list, then move items up one step in the main list
rename_floor_list <- function(target_name, list_to_reforge){
assertthat::assert_that(inherits(target_name, "character"))
assertthat::assert_that(inherits(list_to_reforge, "list"))

Check warning on line 93 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L92-L93

Added lines #L92 - L93 were not covered by tests

if(target_name %in% names(list_to_reforge)){
if(class(list_to_reforge[[target_name]]) %in% "list"){
target_elements <- list_to_reforge[[target_name]]
names(target_elements) <- paste(target_name, names(target_elements), sep = "_")

Check warning on line 98 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L95-L98

Added lines #L95 - L98 were not covered by tests

# overwrite list
list_to_reforge[[target_name]] <- NULL
list_to_reforge <- append(list_to_reforge, target_elements)

Check warning on line 102 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L101-L102

Added lines #L101 - L102 were not covered by tests

return(list_to_reforge)

Check warning on line 104 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L104

Added line #L104 was not covered by tests
}else{
list_to_reforge[[target_name]] <- NULL
return(list_to_reforge)

Check warning on line 107 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L106-L107

Added lines #L106 - L107 were not covered by tests
}

}else
return(list_to_reforge)

Check warning on line 111 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L111

Added line #L111 was not covered by tests
}

Loading