Skip to content

Commit

Permalink
feat: adapt and pass through FPRE real estate data from `user_results…
Browse files Browse the repository at this point in the history
…` into `50_Outputs` (#93)

* copy real estate files to output dir

* Increment version number to 0.4.1.9001

* PUt all RE studff in one block

* )Add handling for PA2024CH Real Estate Reports

* Add handling for RE Reports table

* Pass actual language to report params

* Ensure that `re_files_df` exists, even when no RE

* Create directory before writing files to it

* Remove extra comma

Was causing error, as an empty argument

* Use existing RE data parameter

---------

Co-authored-by: Alex Axthelm <aaxthelm@RMI.org>
Co-authored-by: Alex Axthelm <alex@alexaxthelm.com>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 8b5f1af commit 21e4ab0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pacta.portfolio.report
Title: pacta.portfolio.report
Version: 0.4.1.9000
Version: 0.4.1.9001
Authors@R:
c(person(given = "Monika",
family = "Furdyna",
Expand Down
64 changes: 45 additions & 19 deletions R/create_interactive_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ create_interactive_report <-
file.copy(inst_path("webfonts"), to = output_dir, overwrite = TRUE, recursive = TRUE)
file.copy(inst_path("font"), to = output_dir, overwrite = TRUE, recursive = TRUE)

if (length(list.files(real_estate_dir)) > 0) {
if (dir.exists(path(real_estate_dir, "img"))) {
file.copy(path(real_estate_dir, "img"), to = fs::path(output_dir), overwrite = TRUE, recursive = TRUE)
file.copy(path(real_estate_dir, "img"), to = fs::path(template_dir, "rmd"), overwrite = TRUE, recursive = TRUE)
}
}

survey_dir <- fs::path(survey_dir, toupper(language_select))
if (dir.exists(survey_dir)) {
dir.create(fs::path(output_dir, "survey"), showWarnings = FALSE)
Expand Down Expand Up @@ -464,11 +457,51 @@ create_interactive_report <-
re_data_input <- NULL
re_config_data <- NULL

# confirm with Wim as to whether the dir won't exist if there are no results to print
re_files_df <- NULL
if (length(list.files(real_estate_dir)) > 0) {
real_estate_flag <- TRUE
re_data_input <- jsonlite::read_json(fs::path(real_estate_dir, "data/data.json"))
re_config_data <- jsonlite::read_json(fs::path(real_estate_dir, "data/config.json"))

# Note that filtering to `reports` key here.
real_estate_files <- jsonlite::read_json(
file.path(real_estate_dir, "reports.json")
)[["reports"]]

for (report_type in names(real_estate_files)) {
xx <- real_estate_files[[report_type]]
for (yy in xx) {
portfolio_type <- yy[["portfolio_type"]]
portfolio_id <- dplyr::coalesce(yy[["portfolio_id"]], NA_integer_)
for (report_language in c("de", "fr")) {
this_report <- data.frame(
report_type = report_type,
portfolio_type = portfolio_type,
portfolio_id = portfolio_id,
report_language = report_language,
description = yy[[report_language]][["description"]],
source_file = fs::path(
real_estate_dir, yy[[report_language]][["file"]]
),
link = fs::path(
"real_estate",
basename(yy[[report_language]][["file"]])
),
stringsAsFactors = FALSE
)
re_files_df <- dplyr::bind_rows(re_files_df, this_report)
}
}
}

fs::dir_create(
path = dirname(fs::path(output_dir, re_files_df[["link"]])),
recurse = TRUE
)
fs::file_copy(
path = re_files_df[["source_file"]],
new_path = fs::path(output_dir, re_files_df[["link"]]),
overwrite = TRUE
)

}


Expand Down Expand Up @@ -517,13 +550,6 @@ create_interactive_report <-

working_template_dir <- fs::path(temporary_dir, basename(template_dir))

# This selects the language for the real estate chapter which is only available in DE and FR
if (language_select %in% c("EN", "DE")) {
re_language <- "de"
} else {
re_language <- "fr"
}

suppressMessages(
bookdown::render_book(
input = working_template_dir,
Expand All @@ -536,9 +562,9 @@ create_interactive_report <-
survey_flag = survey_flag,
survey_data = survey_data,
re_config_data = re_config_data,
re_data_input = re_data_input,
re_data_input = re_files_df,
portfolio_parameters = portfolio_parameters,
language = re_language
language = language_select
)
)
)
Expand Down

0 comments on commit 21e4ab0

Please sign in to comment.