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

COP 25 Branch DP-1259 #127

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: datapackr-app
Type: Shiny App
Title: Self-service app for parsing and validation of Target Setting Tools
Version: 3.0.3
Date: 2024-11-25
Version: 4.0.0
Date: 2024-12-05
Authors@R: c( person("Jason", "Pickering", email =
"[email protected]", role = c("aut", "cre")),
person("Chris", "Nemarich", email =
Expand Down
2 changes: 1 addition & 1 deletion R/downloadDataPack.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ downloadDataPack <- function(d,
}
#Update BEFORE go live in December
if (d$info$cop_year == "2025") {
support_file <- fetchSupportFiles("support_files/psnuxim_model_data_24.rds")
support_file <- fetchSupportFiles("support_files/psnuxim_model_data_25.rds")
}

if (!file.exists(support_file)) {
Expand Down
2 changes: 2 additions & 0 deletions R/downloadFlatPack.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ downloadFlatPack <- function(d) {
openxlsx::writeData(wb = wb,
sheet = "DATIM export", x = datim_export)

if (d$info$cop_year < 2025) {
#Add previous cop year's year 2 data for comparison
#Using try catch as a pseudo if else here, If an error is thrown, do not create the tab
tryCatch({previousY2 = fetchY2File(d$info$cop_year, d$info$sane_name)
Expand All @@ -86,6 +87,7 @@ downloadFlatPack <- function(d) {
return(NULL)
}
)
}

return(wb)
}
74 changes: 26 additions & 48 deletions R/sendDATIMExportToS3.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
sendDATIMExportToS3 <- function(d) {
#Write the flatpacked output
tmp <- tempfile()

# Selects the correct dataset to send to PAW if the tool has a PSNUxIM tab
datim_export <- datapackr::createPAWExport(d)

#Need better error checking here.
write.table(
datim_export,
file = tmp,
quote = FALSE,
sep = "|",
row.names = FALSE,
na = "",
fileEncoding = "UTF-8"
)

# Load the file as a raw binary
read_file <- file(tmp, "rb")
raw_file <- readBin(read_file, "raw", n = file.size(tmp))
close(read_file)

object_tags <- createS3BucketTags(d)

object_name <- paste0("datim_export/",gsub("^20", "cop",d$info$cop_year),
"/",d$info$sane_name,".csv")

s3 <- paws::s3()

r <- tryCatch({
foo <- s3$put_object(Bucket = Sys.getenv("AWS_S3_BUCKET"),
Body = raw_file,
Key = object_name,
Tagging = object_tags,
ContentType = "text/csv")
futile.logger::flog.info("DATIM Export sent to S3", name = "datapack")
TRUE
},
error = function(err) {
futile.logger::flog.info("DATIM Export could not be sent to S3", name = "datapack")
futile.logger::flog.info(err, name = "datapack")
FALSE
})

unlink(tmp)

return(r)
sendDATIMExportToS3 <- function(d, job_type) {

raw_file <-
datapackr::writePDAPExportCSV(d, job_type = job_type)


file_location <-
datapackr::uploadDATIMExportToPDAP(raw_file = raw_file,
job_type = job_type,
content_type = "text/csv")
print(file_location)

resp <-
datapackr::initiatePDAPJob(
job_type = job_type,
datim_export = file_location,
org_unit_id = d$info$country_uids,
period = paste0(d$info$cop_year, "Oct")
)
if (resp$status_code == 200L) {
futile.logger::flog.info(paste0("Job type ", job_type, " successfully initiated."), name = "datapack")
return(TRUE)
} else {
futile.logger::flog.error(paste0("Failed to inititate ", job_type, "job type."), name = "datapack")
return(FALSE)
}
}
28 changes: 24 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ getVersionInfo <- function() {
paste(., "</p></div>")
}

getReleaseDate <- function() {

currDCF <- read.dcf("DESCRIPTION")
currReleaseDate <- currDCF[1, "Date"]

paste0("Release Date: ", currReleaseDate) %>%
paste('<div style="font-size:small;text-align: center;"><p>', .) %>%
paste(., "</p></div>")
}

fetchModelFile <- function(model_path="support_files/datapack_model_data.rds") {

can_read_file <- file.access(model_path, 4) == 0
Expand Down Expand Up @@ -78,13 +88,23 @@ fetchSupportFiles <- function(path, locally=T) {
return(file_name2)
}

fetchY2File <- function(cop_year, country) {

Y2_path= paste0("datim_export/cop", (cop_year - 1) %% 100 , "/", country, "_Y2.csv")
# fetchY2File <- function(cop_year, country) {
#
# Y2_path= paste0("datim_export/cop", (cop_year - 1) %% 100 , "/", country, "_Y2.csv")
#
# datapackr::interactive_print("Fetching last COP year's Year 2 data from S3")
# Y2File <- fetchSupportFiles(Y2_path, locally=F)
#
# return(Y2File)
# }
# Wed Dec 4 13:29:06 2024 - IDK if we actually need to update this since no y2 for 2025
fetchY2File <- function(cop_year, country_uids) {

cop_year <- paste0(cop_year, "Oct")
Y2_path <- datapackr::getExistingFileS3Location("year_two_targets", cop_year, country_uids)

datapackr::interactive_print("Fetching last COP year's Year 2 data from S3")
Y2File <- fetchSupportFiles(Y2_path, locally=F)

return(Y2File)
}

Expand Down
694 changes: 335 additions & 359 deletions manifest.json

Large diffs are not rendered by default.

Loading