Fix alert table and finish first translation iteration
This commit is contained in:
parent
54c4b3f93b
commit
c0092d90a9
|
|
@ -2,13 +2,13 @@
|
|||
params:
|
||||
ref: "word-styles-reference-var1.docx"
|
||||
output_file: "CI_report.docx"
|
||||
report_date: "2026-02-04" #!r Sys.Date()
|
||||
report_date: "2026-02-18" #!r Sys.Date()
|
||||
data_dir: "tpc"
|
||||
mail_day: "Wednesday"
|
||||
borders: FALSE
|
||||
ci_plot_type: "both"
|
||||
colorblind_friendly: TRUE
|
||||
lang: "en"
|
||||
language: "en"
|
||||
facet_by_season: FALSE
|
||||
x_axis_unit: "days"
|
||||
output:
|
||||
|
|
@ -28,7 +28,7 @@ ci_plot_type <- params$ci_plot_type
|
|||
colorblind_friendly <- params$colorblind_friendly
|
||||
facet_by_season <- params$facet_by_season
|
||||
x_axis_unit <- params$x_axis_unit
|
||||
lang <- params$lang
|
||||
language <- params$language
|
||||
```
|
||||
|
||||
```{r load_libraries, message=FALSE, warning=FALSE, include=FALSE}
|
||||
|
|
@ -484,9 +484,9 @@ tryCatch({
|
|||
|
||||
# Try to select the translations for this report, otherwise fall back to English
|
||||
tryCatch({
|
||||
if (lang %in% names(translations)) {
|
||||
lang_col <- lang
|
||||
safe_log(paste0("Loaded localisation for '", lang,"'"))
|
||||
if (language %in% names(translations)) {
|
||||
lang_col <- language
|
||||
safe_log(paste0("Loaded localisation for '", language,"'"))
|
||||
} else {
|
||||
lang_col <- "en"
|
||||
safe_log(paste("Specified language not supported, defaulting to 'en'"), "WARNING")
|
||||
|
|
@ -730,7 +730,7 @@ generate_field_alerts <- function(field_details_table) {
|
|||
}
|
||||
|
||||
# Check for required columns
|
||||
required_cols <- c("Field", "Field Size (acres)", "Growth Uniformity", "Yield Forecast (t/ha)",
|
||||
required_cols <- c("Field", "Growth Uniformity", "Yield Forecast (t/ha)",
|
||||
"Gap Score", "Decline Risk", "Patchiness Risk", "Mean CI", "CV Value", "Moran's I")
|
||||
missing_cols <- setdiff(required_cols, colnames(field_details_table))
|
||||
|
||||
|
|
@ -750,7 +750,6 @@ generate_field_alerts <- function(field_details_table) {
|
|||
# Aggregate data for the field
|
||||
field_summary <- field_data %>%
|
||||
summarise(
|
||||
field_size = sum(`Field Size (acres)`, na.rm = TRUE),
|
||||
uniformity_levels = paste(unique(`Growth Uniformity`), collapse = "/"),
|
||||
avg_yield_forecast = mean(`Yield Forecast (t/ha)`, na.rm = TRUE),
|
||||
max_gap_score = max(`Gap Score`, na.rm = TRUE),
|
||||
|
|
@ -785,21 +784,21 @@ generate_field_alerts <- function(field_details_table) {
|
|||
|
||||
# Generate alerts based on priority level
|
||||
if (priority_level == 1) {
|
||||
field_alerts <- c(field_alerts, "Priority field - recommend inspection")
|
||||
field_alerts <- c(field_alerts, t("priority"))
|
||||
} else if (priority_level == 2) {
|
||||
field_alerts <- c(field_alerts, "Monitor - check when convenient")
|
||||
field_alerts <- c(field_alerts, t("monitor"))
|
||||
}
|
||||
# Priority 3: No alert (no stress)
|
||||
|
||||
# Keep other alerts for decline risk, patchiness risk, gap score
|
||||
if (field_summary$highest_decline_risk %in% c("High", "Very-high")) {
|
||||
field_alerts <- c(field_alerts, "Growth decline observed")
|
||||
field_alerts <- c(field_alerts, t("growth_decline"))
|
||||
}
|
||||
if (field_summary$highest_patchiness_risk == "High") {
|
||||
field_alerts <- c(field_alerts, "High patchiness detected - recommend scouting")
|
||||
field_alerts <- c(field_alerts, t("high_patchiness"))
|
||||
}
|
||||
if (field_summary$max_gap_score > 20) {
|
||||
field_alerts <- c(field_alerts, "Gaps present - recommend review")
|
||||
field_alerts <- c(field_alerts, t("gaps_present"))
|
||||
}
|
||||
|
||||
# Only add alerts if there are any (skip fields with no alerts)
|
||||
|
|
@ -845,8 +844,8 @@ if (exists("field_details_table") && !is.null(field_details_table) && nrow(field
|
|||
if ("Gap_Score" %in% names(field_details_for_alerts)) {
|
||||
field_details_for_alerts <- field_details_for_alerts %>% dplyr::rename(`Gap Score` = Gap_Score)
|
||||
}
|
||||
if ("Growth_Uniformity" %in% names(field_details_for_alerts)) {
|
||||
field_details_for_alerts <- field_details_for_alerts %>% dplyr::rename(`Growth Uniformity` = Growth_Uniformity)
|
||||
if ("Uniformity_Category" %in% names(field_details_for_alerts)) {
|
||||
field_details_for_alerts <- field_details_for_alerts %>% dplyr::rename(`Growth Uniformity` = Uniformity_Category)
|
||||
}
|
||||
if ("Decline_Risk" %in% names(field_details_for_alerts)) {
|
||||
field_details_for_alerts <- field_details_for_alerts %>% dplyr::rename(`Decline Risk` = Decline_Risk)
|
||||
|
|
@ -1663,7 +1662,7 @@ if (!exists("field_details_table") || is.null(field_details_table) || nrow(field
|
|||
|
||||
```{r include=FALSE}
|
||||
# Tries to get the CI graph in different language, otherwise falls back on English
|
||||
target_img <- paste0("CI_graph_example_", lang, ".png")
|
||||
target_img <- paste0("CI_graph_example_", language, ".png")
|
||||
img_path <- ifelse(file.exists(target_img), target_img, "CI_graph_example.png")
|
||||
```
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue