diff --git a/laravel_app/app/Livewire/Projects/ReportManager.php b/laravel_app/app/Livewire/Projects/ReportManager.php index d6cb7b8..da792da 100644 --- a/laravel_app/app/Livewire/Projects/ReportManager.php +++ b/laravel_app/app/Livewire/Projects/ReportManager.php @@ -47,7 +47,7 @@ public function saveProjectReport() $this->validate([ 'formData.week' => ['required', 'integer', 'min:1', 'max:53'], 'formData.year' => 'required|integer|min:2020|max:'.now()->addYear()->year, - 'formData' => [new AllMosaicsPresentRule($this->project_id)], +// 'formData' => [new AllMosaicsPresentRule($this->project_id)], ]); $newReport = Project::find($this->project_id) diff --git a/laravel_app/app/Livewire/Projects/Tabs/Report.php b/laravel_app/app/Livewire/Projects/Tabs/Report.php index 3d20812..3fcf8b6 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Report.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Report.php @@ -50,7 +50,7 @@ public function saveProjectReport() $this->validate([ 'formData.end_date' => ['required','date','before:today'], 'formData.offset' => 'required|integer|min:1|max:1000', - 'formData' => [new AllMosaicsPresentRule($this->project->id)], +// 'formData' => [new AllMosaicsPresentRule($this->project->id)], ]); $newReport = Project::find($this->project->id) diff --git a/r_app/2_CI_data_prep.R b/r_app/2_CI_data_prep.R index 38cf09c..30b436a 100644 --- a/r_app/2_CI_data_prep.R +++ b/r_app/2_CI_data_prep.R @@ -782,7 +782,7 @@ pivot_stats_long <- pivot_stats2 %>% # # pivot_select_model_Data_2022 <- harvesting_data %>% filter(Year == 2022) %>% pull(field) -pivot_select_model_Data_2023 <- harvesting_data %>% filter(year == 2023) %>% filter(!is.na(season_start)) %>% pull(sub_field) +# pivot_select_model_Data_2023 <- harvesting_data %>% filter(year == 2023) %>% filter(!is.na(season_start)) %>% pull(sub_field) pivot_select_model_Data_2024 <- harvesting_data %>% filter(year == 2024)%>% filter(!is.na(season_start)) %>% pull(sub_field) @@ -832,13 +832,14 @@ extract_CI_data <- function(field_names, harvesting_data, field_CI_data, season) # message('2021') # Data_2022 <- map(pivot_select_model_Data_2022, ~ extract_CI_data(.x, harvesting_data = harvesting_data, field_CI_data = pivot_stats_long, season = 2022)) %>% list_rbind() # message('2022') -Data_2023 <- map(pivot_select_model_Data_2023, ~ extract_CI_data(.x, harvesting_data = harvesting_data, field_CI_data = pivot_stats_long, season = 2023)) %>% list_rbind() -message('2023') +# Data_2023 <- map(pivot_select_model_Data_2023, ~ extract_CI_data(.x, harvesting_data = harvesting_data, field_CI_data = pivot_stats_long, season = 2023)) %>% list_rbind() +# message('2023') Data_2024 <- map(pivot_select_model_Data_2024, ~ extract_CI_data(.x, harvesting_data = harvesting_data, field_CI_data = pivot_stats_long, season = 2024)) %>% list_rbind() message('2024') -CI_all <- rbind(Data_2023, Data_2024) +#CI_all <- rbind(Data_2023, Data_2024) +CI_all <- Data_2024 message('CI_all created') #CI_all <- Data_2023 diff --git a/r_app/CI_report_dashboard_planet.Rmd b/r_app/CI_report_dashboard_planet.Rmd index 784e285..44eb7cf 100644 --- a/r_app/CI_report_dashboard_planet.Rmd +++ b/r_app/CI_report_dashboard_planet.Rmd @@ -272,10 +272,29 @@ ci_plot <- function(pivotName){ } - - - cum_ci_plot <- function(pivotName){ + # pivotName <- "4042903" + # Generate a sequence of dates for the last 12 months + end_date <- Sys.Date() + start_date <- end_date %m-% months(11) # 11 months ago from end_date + date_seq <- seq.Date(from = start_date, to = end_date, by = "month") + midpoint_date <- start_date + (end_date - start_date) / 2 + # Create the empty plot + g <- ggplot() + + scale_x_date(limits = c(start_date, end_date), date_breaks = "1 month", date_labels = "%m-%Y") + + scale_y_continuous(limits = c(0, 4)) + + labs(title = paste("14 day rolling MEAN CI rate - Field ", pivotName), + x = "Date", y = "CI Rate") + + theme(axis.text.x = element_text(angle = 60, hjust = 1), + legend.justification = c(1, 0), legend.position = c(1, 0), + legend.title = element_text(size = 8), + legend.text = element_text(size = 8)) + + annotate("text", x = midpoint_date, y = 2, label = "No data available", size = 6, hjust = 0.5) + subchunkify(g, 3.2, 10) +} + + +cum_ci_plot2 <- function(pivotName){ # pivotName = "1.1" data_ci <- CI_quadrant %>% filter(Field == pivotName) diff --git a/r_app/Rplots.pdf b/r_app/Rplots.pdf index 5562fc0..c58e7b4 100644 Binary files a/r_app/Rplots.pdf and b/r_app/Rplots.pdf differ diff --git a/r_app/parameters_project.R b/r_app/parameters_project.R index 7e64fe8..42ca9e1 100644 --- a/r_app/parameters_project.R +++ b/r_app/parameters_project.R @@ -8,15 +8,15 @@ if(project_dir == "chemba"){ field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(pivot, pivot_quadrant)%>% mutate(sub_area = case_when(pivot %in% c("1.1", "1.2", "1.3", "1.4", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11", "1.12", "1.13", "1.14" , "1.16" , "1.17" , "1.18" , "6.1", "6.2", "DL1.1", "DL1.3") ~ "estate", TRUE ~ "Cooperative")) - names(field_boundaries_sf) <- c("Field", "subField", "geometry", "sub_area") + names(field_boundaries_sf) <- c("field", "sub_field", "geometry", "sub_area") field_boundaries <- field_boundaries_sf %>% vect() - names(field_boundaries) <- c("Field", "subField", "sub_area") + names(field_boundaries) <- c("field", "sub_field", "sub_area") # field_boundaries_merged <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(pivot, pivot_quadrant) %>% group_by(pivot) %>% summarise() %>% vect() joined_spans <-st_read(here(data_dir, "span.geojson")) %>% st_transform(crs(field_boundaries_sf)) - names(joined_spans) <- c("Field", "area", "radius", "spans", "span", "geometry") + names(joined_spans) <- c("field", "area", "radius", "spans", "span", "geometry") pivots_dates0 <- readRDS(here(harvest_dir, "harvest_data_new")) %>% filter( @@ -46,7 +46,7 @@ if(project_dir == "chemba"){ library(readxl) message("Yield data for Xinavane") field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(-Pivot) - names(field_boundaries_sf) <- c("Field", "subField", "geometry") + names(field_boundaries_sf) <- c("field", "sub_field", "geometry") field_boundaries <- field_boundaries_sf %>% vect() @@ -57,34 +57,34 @@ if(project_dir == "chemba"){ col_types = c("numeric", "text", "skip", "text", "numeric", "numeric", "numeric", "numeric", "date", "numeric", "skip", "numeric")) %>% rename( - Year = 1, - Field = 2, + year = 1, + field = 2, sub_area = 3, hectares = 4, tons = 5, tcha = 6, tchy = 7, - Season_end = 8, - Age = 9, + season_end = 8, + age = 9, ratoon = 10 ) %>% - mutate(Season_end = ymd(Season_end), - Season_start = as.Date(Season_end - (duration(months = Age))), + mutate(Season_end = ymd(season_end), + Season_start = as.Date(season_end - (duration(months = age))), subField = Field) #don't forget to add 2022 as a year for the 'curent' season pivots_dates0 <- pivots_dates0 %>% - mutate(Year = Year + 6) + mutate(year = year + 6) # Add 6 years to Season_end column pivots_dates0 <- pivots_dates0 %>% - mutate(Season_end = Season_end + years(6)) + mutate(season_end = season_end + years(6)) # Add 6 years to Season_start column pivots_dates0 <- pivots_dates0 %>% - mutate(Season_start = Season_start + years(6)) + mutate(season_start = season_start + years(6)) - harvesting_data <- pivots_dates0 %>% dplyr::select(c("Field","subField", "Year", "Season_start","Season_end", "Age" , "sub_area", "tcha")) + harvesting_data <- pivots_dates0 %>% dplyr::select(c("field","sub_field", "year", "season_start","season_end", "age" , "sub_area", "tcha")) } else {