From 09ea1299d08c41168bdef6cb4810b98c648a2607 Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Thu, 26 Sep 2024 10:48:15 +0200 Subject: [PATCH 01/10] copy real estate files to output dir --- R/create_interactive_report.R | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index b832929..4c46668 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -106,10 +106,11 @@ create_interactive_report <- 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) - } + fs::dir_copy( + fs::path(real_estate_dir, "pdf"), + fs::path(output_dir, "real_estate"), + overwrite = TRUE + ) } survey_dir <- fs::path(survey_dir, toupper(language_select)) @@ -119,6 +120,13 @@ create_interactive_report <- file.copy(survey_files, to = fs::path(output_dir, "survey"), overwrite = TRUE, recursive = TRUE) } + # real estate path --------------------------------------------------------- + + real_estate_file <- fs::path(output_dir, "real_estate") |> + fs::dir_info() |> + dplyr::filter(grepl("es_.*_de", path)) |> + dplyr::pull(path) + # translations ------------------------------------------------------------- dictionary <- choose_dictionary_language( @@ -467,8 +475,6 @@ create_interactive_report <- # confirm with Wim as to whether the dir won't exist if there are no results to print 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")) } @@ -533,6 +539,7 @@ create_interactive_report <- params = list( portfolio_results_flag = portfolio_results_flag, real_estate_flag = real_estate_flag, + real_estate_file = real_estate_file, survey_flag = survey_flag, survey_data = survey_data, re_config_data = re_config_data, From 111e5a913a2692b2642bdad5eb76ed046de3d705 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 26 Sep 2024 15:28:36 +0200 Subject: [PATCH 02/10] Increment version number to 0.4.1.9001 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f3e41e2..34bbd00 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", From 860e85a4cb4aeaca362502174341ef688ccd18dd Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 26 Sep 2024 15:29:33 +0200 Subject: [PATCH 03/10] PUt all RE studff in one block --- R/create_interactive_report.R | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index 4c46668..be3a17f 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -105,14 +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) { - fs::dir_copy( - fs::path(real_estate_dir, "pdf"), - fs::path(output_dir, "real_estate"), - overwrite = TRUE - ) - } - survey_dir <- fs::path(survey_dir, toupper(language_select)) if (dir.exists(survey_dir)) { dir.create(fs::path(output_dir, "survey"), showWarnings = FALSE) @@ -120,13 +112,6 @@ create_interactive_report <- file.copy(survey_files, to = fs::path(output_dir, "survey"), overwrite = TRUE, recursive = TRUE) } - # real estate path --------------------------------------------------------- - - real_estate_file <- fs::path(output_dir, "real_estate") |> - fs::dir_info() |> - dplyr::filter(grepl("es_.*_de", path)) |> - dplyr::pull(path) - # translations ------------------------------------------------------------- dictionary <- choose_dictionary_language( @@ -475,6 +460,15 @@ create_interactive_report <- # confirm with Wim as to whether the dir won't exist if there are no results to print if (length(list.files(real_estate_dir)) > 0) { real_estate_flag <- TRUE + fs::dir_copy( + fs::path(real_estate_dir, "pdf"), + fs::path(output_dir, "real_estate"), + overwrite = TRUE + ) + real_estate_file <- fs::path(output_dir, "real_estate") |> + fs::dir_info() |> + dplyr::filter(grepl("es_.*_de", path)) |> + dplyr::pull(path) } From b78fdbdeb73d45b554116e2e82d511c37f2a9ce8 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Thu, 26 Sep 2024 17:24:55 +0200 Subject: [PATCH 04/10] )Add handling for PA2024CH Real Estate Reports --- R/create_interactive_report.R | 46 +++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index be3a17f..f8e862d 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -460,15 +460,45 @@ create_interactive_report <- # confirm with Wim as to whether the dir won't exist if there are no results to print if (length(list.files(real_estate_dir)) > 0) { real_estate_flag <- TRUE - fs::dir_copy( - fs::path(real_estate_dir, "pdf"), - fs::path(output_dir, "real_estate"), + + # Note that filtering to `reports` key here. + real_estate_files <- jsonlite::read_json( + file.path(real_estate_dir, "reports.json") + )[["reports"]] + + re_files_df <- NULL + 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"]] + ), + output_file = fs::path( + output_dir, "real_estate", + basename(yy[[report_language]][["file"]]) + ), + stringsAsFactors = FALSE + ) + re_files_df <- dplyr::bind_rows(re_files_df, this_report) + } + } + } + + fs::file_copy( + path = re_files_df[["source_file"]], + new_path = re_files_df[["output_file"]], overwrite = TRUE ) - real_estate_file <- fs::path(output_dir, "real_estate") |> - fs::dir_info() |> - dplyr::filter(grepl("es_.*_de", path)) |> - dplyr::pull(path) + } @@ -533,7 +563,7 @@ create_interactive_report <- params = list( portfolio_results_flag = portfolio_results_flag, real_estate_flag = real_estate_flag, - real_estate_file = real_estate_file, + re_files_df = re_files_df, survey_flag = survey_flag, survey_data = survey_data, re_config_data = re_config_data, From 56202124302557630cbeb0ffe6a614508ec43ed1 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 27 Sep 2024 11:40:53 +0200 Subject: [PATCH 05/10] Add handling for RE Reports table --- R/create_interactive_report.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index f8e862d..efda07d 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -482,8 +482,8 @@ create_interactive_report <- source_file = fs::path( real_estate_dir, yy[[report_language]][["file"]] ), - output_file = fs::path( - output_dir, "real_estate", + link = fs::path( + "real_estate", basename(yy[[report_language]][["file"]]) ), stringsAsFactors = FALSE @@ -495,7 +495,7 @@ create_interactive_report <- fs::file_copy( path = re_files_df[["source_file"]], - new_path = re_files_df[["output_file"]], + new_path = fs::path(output_dir, re_files_df[["link"]]), overwrite = TRUE ) From 1a0166b71dd7856225b6d0c3b09e2cc01e79b95f Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 27 Sep 2024 12:12:33 +0200 Subject: [PATCH 06/10] Pass actual language to report params --- R/create_interactive_report.R | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index efda07d..7add20a 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -547,13 +547,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, @@ -569,7 +562,7 @@ create_interactive_report <- re_config_data = re_config_data, re_data_input = re_data_input, portfolio_parameters = portfolio_parameters, - language = re_language + language = language_select, ) ) ) From 062db6628ced009dcbca2ad342bc70b2326b5926 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 27 Sep 2024 15:34:09 +0200 Subject: [PATCH 07/10] Ensure that `re_files_df` exists, even when no RE --- R/create_interactive_report.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index 7add20a..7ab984c 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -457,7 +457,7 @@ 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 @@ -466,7 +466,6 @@ create_interactive_report <- file.path(real_estate_dir, "reports.json") )[["reports"]] - re_files_df <- NULL for (report_type in names(real_estate_files)) { xx <- real_estate_files[[report_type]] for (yy in xx) { From ed500f34bce7960472d728ba72ffcc83c838974f Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 27 Sep 2024 15:47:11 +0200 Subject: [PATCH 08/10] Create directory before writing files to it --- R/create_interactive_report.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index 7ab984c..a0924cf 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -492,6 +492,10 @@ create_interactive_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"]]), From d6521379ac567b84968503029268bd626dc5beb8 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 27 Sep 2024 16:29:02 +0200 Subject: [PATCH 09/10] Remove extra comma Was causing error, as an empty argument --- R/create_interactive_report.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index a0924cf..a8ac076 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -565,7 +565,7 @@ create_interactive_report <- re_config_data = re_config_data, re_data_input = re_data_input, portfolio_parameters = portfolio_parameters, - language = language_select, + language = language_select ) ) ) From 78d47203f1133569ae2e264a8bf02f8cd92ef997 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Fri, 27 Sep 2024 17:27:49 +0200 Subject: [PATCH 10/10] Use existing RE data parameter --- R/create_interactive_report.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/create_interactive_report.R b/R/create_interactive_report.R index a8ac076..9bb22d4 100644 --- a/R/create_interactive_report.R +++ b/R/create_interactive_report.R @@ -559,11 +559,10 @@ create_interactive_report <- params = list( portfolio_results_flag = portfolio_results_flag, real_estate_flag = real_estate_flag, - re_files_df = re_files_df, 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 = language_select )