forked from ropensci/ruODK
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ropensci:main' into main
- Loading branch information
Showing
61 changed files
with
605 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ utils::globalVariables(c( | |
"path", | ||
"type", | ||
"variable", | ||
"xx" | ||
"xx", | ||
"xml_form_id" | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#' Download server audit logs for one submission. | ||
#' | ||
#' `r lifecycle::badge("experimental")` | ||
#' | ||
#' This function is the workhorse for the vectorised function | ||
#' submission_audit_get, | ||
#' which gets all server audit logs for a list of submission IDs. | ||
#' | ||
#' Note this function returns a nested list containing any repeating subgroups. | ||
#' As the presence and length of repeating subgroups is non-deterministic and | ||
#' entirely depends on the completeness of the submission data, we cannot | ||
#' rectangle them any further here. Rectangling requires knowledge of the form | ||
#' schema and the completeness of submission data. | ||
#' | ||
#' `r lifecycle::badge("stable")` | ||
#' | ||
#' @template param-iid | ||
#' @template param-pid | ||
#' @template param-fid | ||
#' @template param-url | ||
#' @template param-auth | ||
#' @template param-retries | ||
#' @return A nested list of submission data. | ||
# nolint start | ||
#' @seealso \url{https://odkcentral.docs.apiary.io/#reference/forms-and-submissions/submissions/retrieving-submission-xml} | ||
# nolint end | ||
#' @family utilities | ||
#' @export | ||
#' @examples | ||
#' \dontrun{ | ||
#' # See vignette("setup") for setup and authentication options | ||
#' # ruODK::ru_setup(svc = "....svc", un = "[email protected]", pw = "...") | ||
#' | ||
#' # With explicit credentials, see tests | ||
#' sl <- submission_list() | ||
#' | ||
#' sub <- get_one_submission_audit(sl$instance_id[[1]]) | ||
#' listviewer::jsonedit(sub) | ||
#' | ||
#' # The details for one submission depend on the form fields | ||
#' length(sub) | ||
#' # > 11 | ||
#' | ||
#' # The items are the field names. Repeated groups have the same name. | ||
#' names(sub) | ||
#' # > "meta" "encounter_start_datetime" "reporter" | ||
#' # > "device_id" "location" "habitat" | ||
#' # > "vegetation_structure" "perimeter" "taxon_encounter" | ||
#' # > "taxon_encounter" "encounter_end_datetime" | ||
#' } | ||
get_one_submission_audit <- function(iid, | ||
pid = get_default_pid(), | ||
fid = get_default_fid(), | ||
url = get_default_url(), | ||
un = get_default_un(), | ||
pw = get_default_pw(), | ||
retries = get_retries()) { | ||
yell_if_missing(url, un, pw, pid = pid, fid = fid, iid = iid) | ||
httr::RETRY( | ||
"GET", | ||
glue::glue( | ||
"{url}/v1/projects/{pid}/forms/", | ||
"{URLencode(fid, reserved = TRUE)}/submissions/{iid}/audits" | ||
), | ||
httr::authenticate(un, pw), | ||
times = retries | ||
) %>% | ||
yell_if_error(., url, un, pw) %>% | ||
httr::content(.) | ||
# %>% | ||
# tibble::as_tibble() %>% | ||
# tidyr::unnest_wider() | ||
} | ||
|
||
#' Get submission audits for a list of submission instance IDs. | ||
#' | ||
#' `r lifecycle::badge("experimental")` | ||
#' | ||
#' Uses \code{\link{get_one_submission_audit}} on a list of submission | ||
#' instance IDs | ||
#' (`iid`) as returned from \code{\link{submission_list}$instance_id}. | ||
#' By giving the list of `iid` to download explicitly, that list can be | ||
#' modified using information not accessible to `ruODK`, | ||
#' e.g. `iid` can be restricted to "only not already downloaded submissions". | ||
#' | ||
#' To get the combined submission audit logs for one form | ||
#' as one single, concatenated `audit.csv` file, use `submission_export`. | ||
#' | ||
#' @param iid A list of submission instance IDs, e.g. from | ||
#' \code{\link{submission_list}$instance_id}. | ||
#' @template param-pid | ||
#' @template param-fid | ||
#' @template param-url | ||
#' @template param-auth | ||
#' @template param-retries | ||
#' @return A nested list of submission audit logs. | ||
# nolint start | ||
#' @seealso \url{https://odkcentral.docs.apiary.io/#reference/forms-and-submissions/submissions/retrieving-submission-xml} | ||
# nolint end | ||
#' @family submission-management | ||
#' @export | ||
#' @examples | ||
#' \dontrun{ | ||
#' # Step 1: Setup ruODK with OData Service URL (has url, pid, fid) | ||
#' ruODK::ru_setup(svc = "...") | ||
#' | ||
#' # Step 2: List all submissions of form | ||
#' sl <- submission_list() | ||
#' | ||
#' # Step 3: Get submission audit logs | ||
#' sa <- submission_audit_get(sl$instance_id) | ||
#' } | ||
submission_audit_get <- function(iid, | ||
pid = get_default_pid(), | ||
fid = get_default_fid(), | ||
url = get_default_url(), | ||
un = get_default_un(), | ||
pw = get_default_pw(), | ||
retries = get_retries()) { | ||
yell_if_missing(url, un, pw, pid = pid, fid = fid, iid = iid) | ||
tibble::tibble( | ||
iid = iid, | ||
pid = pid, | ||
fid = fid, | ||
url = url, | ||
un = un, | ||
pw = pw, | ||
retries = retries | ||
) %>% | ||
purrr::pmap(ruODK::get_one_submission_audit) | ||
} | ||
|
||
# usethis::use_test("submission_get_audit") # nolint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,7 @@ | |
#' \dontrun{ | ||
#' # Set default credentials, see vignette("setup") | ||
#' ruODK::ru_setup( | ||
#' svc = paste0( | ||
#' "https://sandbox.central.getodk.org/v1/projects/14/", | ||
#' "forms/build_Flora-Quadrat-0-2_1558575936.svc" | ||
#' ), | ||
#' svc = ..., | ||
#' un = "[email protected]", | ||
#' pw = "..." | ||
#' ) | ||
|
@@ -96,7 +93,7 @@ submission_list <- function(pid = get_default_pid(), | |
) %>% | ||
janitor::clean_names() %>% | ||
dplyr::mutate_at( | ||
dplyr::vars(dplyr::contains("at")), # assume datetimes are named "_at" | ||
dplyr::vars(dplyr::contains("_at")), # assume datetimes are named "_at" | ||
~ isodt_to_local(., orders = orders, tz = tz) | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.