Implemented the changed for ISO numbering to 90 script (generated the simple word file)
This commit is contained in:
parent
cc38d25a54
commit
5be79bcc87
|
|
@ -119,8 +119,10 @@ kpi_data_dir <- file.path("..", "laravel_app", "storage", "app", project_dir, "r
|
|||
date_suffix <- format(as.Date(report_date), "%Y%m%d")
|
||||
|
||||
# Calculate current week from report_date using ISO 8601 week numbering
|
||||
current_week <- as.numeric(format(as.Date(report_date), "%V"))
|
||||
week_suffix <- paste0("week", current_week)
|
||||
report_date_obj <- as.Date(report_date)
|
||||
current_week <- lubridate::isoweek(report_date_obj)
|
||||
current_iso_year <- lubridate::isoyear(report_date_obj)
|
||||
week_suffix <- paste0("week", sprintf("%02d", current_week), "_", current_iso_year)
|
||||
|
||||
# Candidate filenames we expect (exact and common variants)
|
||||
expected_summary_names <- c(
|
||||
|
|
@ -307,46 +309,39 @@ Sys.setlocale("LC_TIME", "C")
|
|||
today <- as.character(report_date)
|
||||
mail_day_as_character <- as.character(mail_day)
|
||||
|
||||
# Calculate report dates and weeks using ISO 8601 week numbering
|
||||
# Calculate report dates and weeks using ISO 8601 week numbering (consistent with scripts 40 & 80)
|
||||
report_date_obj <- as.Date(today)
|
||||
current_week <- as.numeric(format(report_date_obj, "%V"))
|
||||
year <- as.numeric(format(report_date_obj, "%Y"))
|
||||
current_week <- lubridate::isoweek(report_date_obj)
|
||||
current_iso_year <- lubridate::isoyear(report_date_obj)
|
||||
year <- lubridate::isoyear(report_date_obj) # Use ISO year, not calendar year
|
||||
|
||||
# Calculate dates for weekly analysis
|
||||
week_start <- report_date_obj - ((as.numeric(format(report_date_obj, "%w")) + 1) %% 7)
|
||||
# Calculate dates for weekly analysis (Monday-based, consistent with ISO 8601)
|
||||
week_start <- lubridate::floor_date(report_date_obj, unit = "week", week_start = 1)
|
||||
week_end <- week_start + 6
|
||||
|
||||
# Calculate week days (copied from 05 script for compatibility)
|
||||
report_date_as_week_day <- weekdays(lubridate::ymd(today))
|
||||
days_of_week <- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
|
||||
# Calculate previous week dates using date arithmetic (handles year boundaries automatically)
|
||||
today_minus_1 <- as.character(report_date_obj - 7)
|
||||
today_minus_2 <- as.character(report_date_obj - 14)
|
||||
today_minus_3 <- as.character(report_date_obj - 21)
|
||||
|
||||
# Calculate initial week number
|
||||
week <- lubridate::week(today)
|
||||
safe_log(paste("Initial week calculation:", week, "today:", today))
|
||||
# Calculate week numbers for previous weeks using date arithmetic
|
||||
prev_week_1_date <- report_date_obj - 7
|
||||
prev_week_2_date <- report_date_obj - 14
|
||||
prev_week_3_date <- report_date_obj - 21
|
||||
|
||||
# Calculate previous dates for comparisons
|
||||
today_minus_1 <- as.character(lubridate::ymd(today) - 7)
|
||||
today_minus_2 <- as.character(lubridate::ymd(today) - 14)
|
||||
today_minus_3 <- as.character(lubridate::ymd(today) - 21)
|
||||
week_minus_1 <- lubridate::isoweek(prev_week_1_date)
|
||||
week_minus_1_year <- lubridate::isoyear(prev_week_1_date)
|
||||
|
||||
# Adjust week calculation based on mail day
|
||||
if (which(days_of_week == report_date_as_week_day) > which(days_of_week == mail_day_as_character)) {
|
||||
safe_log("Adjusting weeks because of mail day")
|
||||
week <- lubridate::week(today) + 1
|
||||
today_minus_1 <- as.character(lubridate::ymd(today))
|
||||
today_minus_2 <- as.character(lubridate::ymd(today) - 7)
|
||||
today_minus_3 <- as.character(lubridate::ymd(today) - 14)
|
||||
}
|
||||
week_minus_2 <- lubridate::isoweek(prev_week_2_date)
|
||||
week_minus_2_year <- lubridate::isoyear(prev_week_2_date)
|
||||
|
||||
# Calculate week numbers for previous weeks
|
||||
week_minus_1 <- week - 1
|
||||
week_minus_2 <- week - 2
|
||||
week_minus_3 <- week - 3
|
||||
week_minus_3 <- lubridate::isoweek(prev_week_3_date)
|
||||
week_minus_3_year <- lubridate::isoyear(prev_week_3_date)
|
||||
|
||||
# Format current week with leading zeros
|
||||
week <- sprintf("%02d", week)
|
||||
week <- sprintf("%02d", current_week)
|
||||
|
||||
safe_log(paste("Report week:", current_week, "Year:", year))
|
||||
safe_log(paste("Report week:", current_week, "ISO Year:", current_iso_year))
|
||||
safe_log(paste("Week range:", week_start, "to", week_end))
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue