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

add pagination to history() #19

Merged
merged 1 commit into from
Oct 30, 2023
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: conbenchcoms
Title: An API wrapper for conbench communications
Version: 0.0.7
Version: 0.0.8
Authors@R: c(
person("Jonathan", "Keane", , "[email protected]", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0001-7087-9776")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# conbenchcoms 0.0.8
* Remove `simplifyVector` and `flatten` arguments from `history`
* `history` now always returns a `tibble`
* `history` now paginates until all matching data is returned, which works only with Conbench servers of at least version [649a9ac](https://github.com/conbench/conbench/commit/649a9ac)

# conbenchcoms 0.0.7
* Remove `sha`, `simplifyVector`, and `flatten` arguments from `runs`
* Add `commit_hashes` argument to `runs`
Expand Down
25 changes: 19 additions & 6 deletions R/history.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#' Get history for a benchmark
#'
#' @param benchmark_id the hash of a benchmark to get the history for
#' @inheritParams jsonlite::fromJSON
#' @param benchmark_id the ID of a benchmark result to get the history for
#'
#' @return the response
#' @return a tibble of history
#' @export
history <- function(benchmark_id, simplifyVector = TRUE, flatten = TRUE, ...) {
history <- function(benchmark_id) {
req <- req_url_path_append(conbench_request(), "history", benchmark_id)

req <- req_url_query(req, page_size = 1000)
resp <- conbench_perform(req)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
data <- dplyr::as_tibble(json[["data"]])

while (!is.null(json[["metadata"]][["next_page_cursor"]])) {
req <- req_url_path_append(conbench_request(), "history", benchmark_id)
req <- req_url_query(
req,
page_size = 1000,
cursor = json[["metadata"]][["next_page_cursor"]]
)
resp <- conbench_perform(req)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
data <- dplyr::bind_rows(data, dplyr::as_tibble(json[["data"]]))
}

resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...)
data
}
12 changes: 3 additions & 9 deletions man/history.Rd

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": [
{
"benchmark_id": "hist-id",
"timestamp": "2022-04-07T21:11:19",
"unit": "s"
}
],
"metadata": {
"next_page_cursor": null
}
}
7 changes: 0 additions & 7 deletions tests/testthat/resp-class/localhost/api/history/hist-id.json

This file was deleted.

16 changes: 4 additions & 12 deletions tests/testthat/test-history.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@ with_mock_dir(test_path("logged-in"), {
test_that("history()", {
expect_GET(
history("C0C0A"),
"http://localhost/api/history/C0C0A"
"http://localhost/api/history/C0C0A?page_size=1000"
)
})
})


with_mock_dir(test_path("resp-class"), {
the_id <- "hist-id"
test_that("history() returns a data.frame", {
test_that("history() returns a tibble", {
the_history <- history(benchmark_id = the_id)
expect_s3_class(
the_history,
"data.frame"
"tbl_df"
)
expect_identical(the_id, the_history$benchmark_id)
})
test_that("history(...,simplifyVector = FALSE, flatten = FALSE) returns a list", {
the_list_history <- history(benchmark_id = the_id, simplifyVector = FALSE, flatten = FALSE)
expect_type(
the_list_history,
"list"
)
expect_identical(the_id, the_list_history[[1]]$benchmark_id)
})
})
})
Loading