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

Make metadata easier to use. #121

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CFAEpiNow2Pipeline (development version)

* Change formatting of metadata values to be atomic.
* Add `blob_storage_container` as a field to the metadata.
* Use empty string for paths when non-existant.
* Populated the default values of the metadata to be saved.
* Creating a Config class to make syncing configuration differences easier.
* Add a JSON reader for the Config class.
Expand Down
15 changes: 11 additions & 4 deletions R/pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ orchestrate_pipeline <- function(config_path,
# `pipeline_success` is set to false, which will be stored in the
# metadata in the next PR.
pipeline_success <- rlang::try_fetch(
execute_model_logic(config, output_dir),
execute_model_logic(config, output_dir, blob_storage_container),
error = function(con) {
cli::cli_warn("Pipeline run failed",
parent = con,
Expand Down Expand Up @@ -152,7 +152,7 @@ orchestrate_pipeline <- function(config_path,
#'
#' @rdname pipeline
#' @export
execute_model_logic <- function(config, output_dir) {
execute_model_logic <- function(config, output_dir, blob_storage_container) {
natemcintosh marked this conversation as resolved.
Show resolved Hide resolved
cases_df <- read_data(
data_path = config@data@path,
disease = config@disease,
Expand Down Expand Up @@ -218,7 +218,7 @@ execute_model_logic <- function(config, output_dir) {
data_path = ifelse(
# is_empty checks for NULL and empty data structures
rlang::is_empty(config@data@path),
config@data@path, ""
"", config@data@path
),
natemcintosh marked this conversation as resolved.
Show resolved Hide resolved
model = config@model,
disease = config@disease,
Expand All @@ -227,7 +227,14 @@ execute_model_logic <- function(config, output_dir) {
production_date = config@production_date,
max_reference_date = config@max_reference_date,
min_reference_date = config@min_reference_date,
exclusions = config@exclusions@path,
exclusions = ifelse(
rlang::is_empty(config@exclusions@path),
"", config@exclusions@path
),
blob_storage_container = ifelse(
rlang::is_empty(blob_storage_container),
"", blob_storage_container
),
run_at = format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z")
)

Expand Down
5 changes: 4 additions & 1 deletion R/write_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ write_model_outputs <- function(
model_path = model_path
)
)
jsonlite::write_json(metadata, metadata_path, pretty = TRUE)
jsonlite::write_json(
metadata, metadata_path,
pretty = TRUE, auto_unbox = TRUE
)
cli::cli_alert_success("Wrote metadata to {.path {metadata_path}}")
},
error = function(cnd) {
Expand Down
2 changes: 1 addition & 1 deletion man/pipeline.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/helper-expect_pipeline_files_written.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ expect_pipeline_files_written <- function(
expect_true(file.exists(metadata_path))
metadata <- jsonlite::read_json(metadata_path)
expect_gt(length(metadata), 0)

# Check that each field passes `rlang::is_atomic()`
for (field in names(metadata)) {
expect_true(rlang::is_atomic(metadata[[field]]))
}
}
6 changes: 4 additions & 2 deletions tests/testthat/test-pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ test_that("Process pipeline produces expected outputs and returns success", {
# Act
pipeline_success <- execute_model_logic(
config = config,
output_dir = output_dir
output_dir = output_dir,
blob_storage_container = "blah"
)
expect_true(pipeline_success)

Expand Down Expand Up @@ -107,7 +108,8 @@ test_that("Runs on config from generator as of 2024-11-26", {
# Act
pipeline_success <- execute_model_logic(
config = config,
output_dir = output_dir
output_dir = output_dir,
blob_storage_container = "blah"
)
expect_true(pipeline_success)

Expand Down
Loading