-
Notifications
You must be signed in to change notification settings - Fork 7
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
Align datapack sitetool code #44
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5c91d37
Fixes for regional data packs
jason-p-pickering 77ac72d
The dreaded auto-increment feature of UIDs ending in numbers strikes …
jason-p-pickering 14c7a78
Abstract regional/country data packs
jason-p-pickering 6c405b6
Typo
jason-p-pickering 505af16
Change variable names
jason-p-pickering 5d6819e
Very poor choice of variable names...
jason-p-pickering b3f7446
Feels janky
jason-p-pickering 6aae23c
Consolidate method for checking OU information
jason-p-pickering 288a9f0
Remove duplicate method
jason-p-pickering 1d1de3b
Fix wrong function call
jason-p-pickering c278e3b
Update DataPackConfiguration for West Africa
jason-p-pickering 1a67805
Changing config file for single country PNG data pack
jason-p-pickering 98646e9
Update configuration file again for PNG
jason-p-pickering 0f092b6
Use the UID which is present in the DP/ST when performing a comparison.
jason-p-pickering d74b97c
Weapons of mass commit
jacksonsj f3bccfb
Align Site Tool processing
jacksonsj 1c52d1f
Fix handling of empty sheets
jacksonsj ed33e5d
Tag Country info
jacksonsj 5c70538
Add integrity checks to unPackSNUxIM
jacksonsj ad4897b
Update documentation
jacksonsj eeefacc
Update
jacksonsj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#' @export | ||
#' @importFrom magrittr %>% %<>% | ||
#' @title checkColStructure(d) | ||
#' | ||
#' @description Checks structural integrity of columns on critical sheets for | ||
#' submitted Data Pack or Site Tool. | ||
#' | ||
#' @param d Datapackr object. | ||
#' @param sheet Sheet to check | ||
#' | ||
#' @return d | ||
#' | ||
checkColStructure <- function(d, sheet) { | ||
msg <- NULL | ||
|
||
if (sheet == "SNU x IM") { | ||
data = d$data$SNUxIM | ||
} else { | ||
data = d$data$extract | ||
} | ||
|
||
submission_cols <- names(data) %>% | ||
tibble::as_tibble() %>% | ||
dplyr::select(indicator_code = value) %>% | ||
dplyr::mutate(submission_order = as.integer(1:(dplyr::n()))) | ||
|
||
if (d$info$tool == "Data Pack") { | ||
schema <- datapackr::data_pack_schema | ||
} else if (d$info$tool == "Site Tool") { | ||
schema <- datapackr::site_tool_schema | ||
} else {stop("Cannot process that kind of tool.")} | ||
|
||
col_check <- schema %>% | ||
dplyr::filter(sheet_name == sheet | ||
& !(sheet == "SNU x IM" & indicator_code == "Mechanism1")) %>% | ||
dplyr::select(indicator_code, template_order = col) %>% | ||
dplyr::full_join(submission_cols, by = c("indicator_code" = "indicator_code")) %>% | ||
dplyr::mutate(order_check = template_order == submission_order) | ||
|
||
## Alert to missing cols | ||
if (any(is.na(col_check$submission_order))) { | ||
missing_cols <- col_check %>% | ||
dplyr::filter(is.na(submission_order)) %>% | ||
dplyr::pull(indicator_code) | ||
msg <- paste0("In tab", sheet, | ||
" MISSING COLUMNS (Did you delete or rename these columns?): ", | ||
paste(missing_cols, collapse = ", "),"") | ||
d$info$warningMsg <- append(msg, d$info$warningMsg) | ||
} | ||
|
||
return(d) | ||
} |
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,93 @@ | ||
#' @importFrom magrittr %>% %<>% | ||
#' @title checkOUinfo(d) | ||
#' | ||
#' @description Cross-checks and updates PEPFAR Operating Unit name and id as | ||
#' read from Data Pack or Site Tool submission file. | ||
#' | ||
#' @param d datapackr list object containing at least d$keychain$submission_path. | ||
#' @return A datapackr list object, \code{d}, storing a unique UID and Name for | ||
#' the PEPFAR Operating Unit related to the submitted Data Pack or Site Tool. | ||
checkOUinfo <- function(d) { | ||
# Get OU name and uid | ||
d$info$datapack_uid <- | ||
names(readxl::read_excel( | ||
d$keychain$submission_path, | ||
sheet = "Home", | ||
range = "B25" | ||
)) | ||
|
||
datapack_region_name <- | ||
names(readxl::read_excel( | ||
d$keychain$submission_path, | ||
sheet = "Home", | ||
range = "B20" | ||
)) | ||
|
||
regional_country_name <- | ||
names(readxl::read_excel( | ||
d$keychain$submission_path, | ||
sheet = "Home", | ||
range = "B21" | ||
)) | ||
|
||
is_regional_country_pack<-length(regional_country_name) != 0 | ||
|
||
d$info$datapack_name<-ifelse( is_regional_country_pack,regional_country_name,datapack_region_name ) | ||
|
||
regional_country <-ifelse( is_regional_country_pack, "countryName","DataPack_name") | ||
|
||
regional_country_uid<-ifelse(is_regional_country_pack, "countryUID", "model_uid") | ||
|
||
# Check ou_name and ou_uid match | ||
|
||
verifyDataPackNameWithUID<-function(d,regional_country_uid,regional_country ) { | ||
|
||
regional_country_uid <- rlang::sym(regional_country_uid) | ||
regional_country <- rlang::sym(regional_country) | ||
|
||
datapack_name <- datapackr::configFile %>% | ||
dplyr::filter(!!regional_country_uid == d$info$datapack_uid) %>% | ||
dplyr::select(!!regional_country) %>% | ||
dplyr::pull(!!regional_country) %>% | ||
unique() | ||
|
||
#If we get nothing here (like the UID does not exist, we need to bail early) | ||
if ( length(datapack_name) == 0 ) { | ||
stop("Unknown DataPack Name. Please contact the DataPack Support Team!") | ||
} | ||
|
||
|
||
|
||
datapack_uid <- datapackr::configFile %>% | ||
dplyr::filter(!!regional_country == d$info$datapack_name) %>% | ||
dplyr::select(!!regional_country_uid) %>% | ||
dplyr::pull(!!regional_country_uid) %>% | ||
unique() | ||
|
||
#If we get nothing here (like the UID does not exist, we need to bail early) | ||
if ( length(datapack_uid) == 0 ) { | ||
stop("Unknown DataPack UID. Please contact the DataPack Support Team!") | ||
} | ||
|
||
|
||
# If OU name and UID do not match, force identification via user prompt in Console | ||
if (d$info$datapack_name != datapack_name | | ||
d$info$datapack_uid != datapack_uid) { | ||
msg <- | ||
"The OU UID and OU name used in this submission don't match up!" | ||
interactive_print(msg) | ||
d$info$warningMsg <- append(msg, d$info$warningMsg) | ||
if (interactive()) { | ||
d$info$datapack_name <- selectOU() | ||
} else { | ||
stop(msg) | ||
} | ||
} | ||
|
||
d | ||
|
||
} | ||
|
||
verifyDataPackNameWithUID(d,regional_country_uid,regional_country) | ||
|
||
} |
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,56 @@ | ||
#' @export | ||
#' @title Check tab structure of tool submitted for validation. | ||
#' | ||
#' @description Checks structural integrity of tabs for submitted tool. | ||
#' | ||
#' @param d Datapackr object. | ||
#' | ||
#' @return d | ||
#' | ||
checkStructure <- function(d) { | ||
# Check structural integrity of Workbook tabs | ||
msg <- NULL | ||
|
||
submission_sheets <- | ||
readxl::excel_sheets(d$keychain$submission_path) %>% | ||
tibble::enframe(name = NULL) %>% | ||
dplyr::select(sheet_name = value) %>% | ||
dplyr::mutate(submission_order = as.integer(1:(dplyr::n()))) | ||
|
||
# Check all tabs present and accounted for | ||
if (d$info$tool == "Data Pack") { | ||
schema <- datapackr::data_pack_schema | ||
} else if (d$info$tool == "Site Tool") { | ||
schema <- datapackr::site_tool_schema | ||
} | ||
#TODO Add once https://github.com/pepfar-datim/datapackr/issues/43 resolved | ||
#else if (d$info$tool == "Mechanism Map") { | ||
# schema <- datapackr::mech_map_schema | ||
# } | ||
|
||
sheets_check <- schema %>% | ||
dplyr::select(sheet_name, template_order = sheet_num) %>% | ||
dplyr::distinct() %>% | ||
dplyr::left_join(submission_sheets, by = c("sheet_name")) %>% | ||
dplyr::mutate(order_check = template_order == submission_order) | ||
|
||
d$info$sheets_info <- sheets_check | ||
|
||
## Alert to missing Sheets | ||
info_msg <- "Checking for any missing tabs..." | ||
interactive_print(info_msg) | ||
|
||
if (any(is.na(sheets_check$submission_order))) { | ||
missing_sheets <- sheets_check %>% | ||
dplyr::filter(is.na(submission_order)) %>% | ||
dplyr::pull(sheet_name) | ||
|
||
msg <- paste0( | ||
"MISSING SHEETS (Did you delete or rename these tabs?): ", | ||
paste0(missing_sheets, collapse = ", "), "") | ||
d$info$warning_msg <- append(msg,d$info$warning_msg) | ||
} | ||
|
||
return(d) | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyway we could get this out as a hardcode and into a schema/configuration?