This commit is contained in:
Martin Folkerts 2024-06-25 13:37:15 +02:00
parent cf5e2fea70
commit af1135e52a
6 changed files with 43 additions and 23 deletions

View file

@ -47,7 +47,7 @@ public function saveProjectReport()
$this->validate([ $this->validate([
'formData.week' => ['required', 'integer', 'min:1', 'max:53'], 'formData.week' => ['required', 'integer', 'min:1', 'max:53'],
'formData.year' => 'required|integer|min:2020|max:'.now()->addYear()->year, '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) $newReport = Project::find($this->project_id)

View file

@ -50,7 +50,7 @@ public function saveProjectReport()
$this->validate([ $this->validate([
'formData.end_date' => ['required','date','before:today'], 'formData.end_date' => ['required','date','before:today'],
'formData.offset' => 'required|integer|min:1|max:1000', '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) $newReport = Project::find($this->project->id)

View file

@ -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_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) 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') # 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() # 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') # 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() # 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') # 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() 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') message('2024')
CI_all <- rbind(Data_2023, Data_2024) #CI_all <- rbind(Data_2023, Data_2024)
CI_all <- Data_2024
message('CI_all created') message('CI_all created')
#CI_all <- Data_2023 #CI_all <- Data_2023

View file

@ -272,10 +272,29 @@ ci_plot <- function(pivotName){
} }
cum_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" # pivotName = "1.1"
data_ci <- CI_quadrant %>% filter(Field == pivotName) data_ci <- CI_quadrant %>% filter(Field == pivotName)

Binary file not shown.

View file

@ -8,15 +8,15 @@ if(project_dir == "chemba"){
field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(pivot, pivot_quadrant)%>% 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", 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")) 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() 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() # 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)) 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( pivots_dates0 <- readRDS(here(harvest_dir, "harvest_data_new")) %>% filter(
@ -46,7 +46,7 @@ if(project_dir == "chemba"){
library(readxl) library(readxl)
message("Yield data for Xinavane") message("Yield data for Xinavane")
field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson")) %>% dplyr::select(-Pivot) 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() 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", col_types = c("numeric", "text", "skip", "text", "numeric", "numeric", "numeric", "numeric", "date",
"numeric", "skip", "numeric")) %>% "numeric", "skip", "numeric")) %>%
rename( rename(
Year = 1, year = 1,
Field = 2, field = 2,
sub_area = 3, sub_area = 3,
hectares = 4, hectares = 4,
tons = 5, tons = 5,
tcha = 6, tcha = 6,
tchy = 7, tchy = 7,
Season_end = 8, season_end = 8,
Age = 9, age = 9,
ratoon = 10 ratoon = 10
) %>% ) %>%
mutate(Season_end = ymd(Season_end), mutate(Season_end = ymd(season_end),
Season_start = as.Date(Season_end - (duration(months = Age))), Season_start = as.Date(season_end - (duration(months = age))),
subField = Field) #don't forget to add 2022 as a year for the 'curent' season subField = Field) #don't forget to add 2022 as a year for the 'curent' season
pivots_dates0 <- pivots_dates0 %>% pivots_dates0 <- pivots_dates0 %>%
mutate(Year = Year + 6) mutate(year = year + 6)
# Add 6 years to Season_end column # Add 6 years to Season_end column
pivots_dates0 <- pivots_dates0 %>% 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 # Add 6 years to Season_start column
pivots_dates0 <- pivots_dates0 %>% 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 { } else {