diff --git a/r_app/CI_report_dashboard_planet.Rmd b/r_app/CI_report_dashboard_planet.Rmd index 76c27c3..3a4f482 100644 --- a/r_app/CI_report_dashboard_planet.Rmd +++ b/r_app/CI_report_dashboard_planet.Rmd @@ -144,10 +144,16 @@ CI_quadrant <- readRDS(here(cumulative_CI_vals_dir,"All_pivots_Cumulative_CI_qua # rename(pivot_quadrant = field) -path_to_week_current = here(weekly_CI_mosaic, paste0("week_",week, "_", year, ".tif")) -path_to_week_minus_1 = here(weekly_CI_mosaic, paste0("week_",week_minus_1, "_", year_1, ".tif")) -path_to_week_minus_2 = here(weekly_CI_mosaic, paste0("week_",week_minus_2, "_", year_2, ".tif")) -path_to_week_minus_3 = here(weekly_CI_mosaic, paste0("week_",week_minus_3, "_", year_3, ".tif")) +# path_to_week_current = here(weekly_CI_mosaic, paste0("week_",week, "_", year, ".tif")) +# path_to_week_minus_1 = here(weekly_CI_mosaic, paste0("week_",week_minus_1, "_", year_1, ".tif")) +# path_to_week_minus_2 = here(weekly_CI_mosaic, paste0("week_",week_minus_2, "_", year_2, ".tif")) +# path_to_week_minus_3 = here(weekly_CI_mosaic, paste0("week_",week_minus_3, "_", year_3, ".tif")) + +path_to_week_current = get_week_path(weekly_CI_mosaic, today, 0) +path_to_week_minus_1 = get_week_path(weekly_CI_mosaic, today, -1) +path_to_week_minus_2 = get_week_path(weekly_CI_mosaic, today, -2) +path_to_week_minus_3 = get_week_path(weekly_CI_mosaic, today, -3) + log_message("required mosaic paths") log_message(paste("path to week current",path_to_week_current)) diff --git a/r_app/Rplots.pdf b/r_app/Rplots.pdf index ea4cd70..b361f10 100644 Binary files a/r_app/Rplots.pdf and b/r_app/Rplots.pdf differ diff --git a/r_app/report_utils.R b/r_app/report_utils.R index fdb042a..065d782 100644 --- a/r_app/report_utils.R +++ b/r_app/report_utils.R @@ -211,4 +211,25 @@ cum_ci_plot2 <- function(pivotName){ annotate("text", x = midpoint_date, y = 2, label = "No data available", size = 6, hjust = 0.5) subchunkify(g, 3.2, 10) -} \ No newline at end of file +} + +get_week_path <- function(mosaic_path, input_date, week_offset) { + # Convert input_date to Date object (in case it's a string) + input_date <- as.Date(input_date) + + # Get the start of the week for the input date (adjust to Monday as the start of the week) + start_of_week <- floor_date(input_date, unit = "week", week_start = 1) + # Calculate the new date after applying the week offset + target_date <- start_of_week + weeks(week_offset) + + # Get the week number and year of the target date + target_week <- sprintf("%02d", isoweek(target_date)) # Left-pad week number with a zero if needed + target_year <- isoyear(target_date) + + # Generate the file path for the target week + path_to_week <- here(mosaic_path, paste0("week_", target_week, "_", target_year, ".tif")) + + # Return the path + return(path_to_week) +} +