Skip to content

Commit

Permalink
Add model fit and calibrate ids into the datapack download
Browse files Browse the repository at this point in the history
  • Loading branch information
r-ash committed Dec 10, 2024
1 parent 9f4de2c commit 2a3f626
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions R/downloads.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ hintr_prepare_agyw_download <- function(output, pjnz,
#' @param path Path to save output file
#' @param vmmc_file Optional file object, with path, filename and hash for
#' VMMC input
#' @param ids List of naomi web app queue ids for putting into metadata
#'
#' @return Path to output file and metadata for file
#' @export
hintr_prepare_datapack_download <- function(output,
path = tempfile(fileext = ".xlsx"),
vmmc_file = NULL) {
vmmc_file = NULL,
ids = NULL) {
assert_model_output_version(output)
progress <- new_simple_progress()
progress$update_progress("PROGRESS_DOWNLOAD_SPECTRUM")
Expand All @@ -157,7 +159,7 @@ hintr_prepare_datapack_download <- function(output,
model_output$output_package,
model_output$output_package$fit$model_options$psnu_level,
vmmc_datapack)
datapack_metadata <- build_datapack_metadata(model_output$output_package)
datapack_metadata <- build_datapack_metadata(model_output$output_package, ids)
writexl::write_xlsx(list(data = datapack_output, metadata = datapack_metadata),
path = path)
list(
Expand Down
10 changes: 8 additions & 2 deletions R/pepfar-datapack.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,24 @@ build_datapack_output <- function(naomi_output, psnu_level, dmppt2_output) {
)
}

build_datapack_metadata <- function(naomi_output) {
build_datapack_metadata <- function(naomi_output, ids) {
meta_period <- get_period_metadata(
c(naomi_output$fit$model_options$calendar_quarter_t1,
naomi_output$fit$model_options$calendar_quarter_t2,
naomi_output$fit$model_options$calendar_quarter_t3,
naomi_output$fit$model_options$calendar_quarter_t4,
naomi_output$fit$model_options$calendar_quarter_t5))

info <- attr(naomi_output, "info")
inputs <- read.csv(text = info$inputs.csv, header = FALSE)

version <- data.frame("version", utils::packageVersion("naomi"))
all_data <- list(version, inputs)

if (!is.null(ids)) {
all_data <- list(version, ids, inputs, meta_period)
} else {
all_data <- list(version, inputs, meta_period)
}

max_cols <- max(vapply(all_data, ncol, numeric(1)))
col_names <- vapply(seq_len(max_cols), function(i) paste0("V", i), character(1))
Expand Down

0 comments on commit 2a3f626

Please sign in to comment.