Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWilliams-NOAA committed Nov 17, 2024
1 parent 5b97181 commit 19cf1d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
17 changes: 8 additions & 9 deletions R/catch_to_sheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @examples
#' /dontrun{
#' catch_to_sheet(year=2023, data=goa_nov_catch, area='goa')
#' catch_to_sheet(year=2024, data=goa_nov_catch, area='goa')
#' }
catch_to_sheet <- function(year, data, area){
googlesheets4::gs4_auth()
Expand Down Expand Up @@ -50,11 +50,11 @@ catch_to_sheet <- function(year, data, area){
bsai_levels = c("BSAI", "EBS", "BS", "AI", "Bogoslof", "BSAI/GOA", "EAI", "EAI/BS", "CAI", "WAI", "EBS/EAI", "CAI/WAI")

# data ----
# data <- vroom::vroom("C:/Users/Ben.Williams/Downloads/catch_table_nov_pt.csv")
data <- vroom::vroom(here::here("dev", 2024, "catch_table_nov_pt.csv"))
if(area=='goa'){
df <- googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/1uHmCuY3GXfSBCbsP61nAQeATBfoslXeS3PQNLlioWIk/edit#gid=1812144961",
sheet = "goa",
col_types = "cccddddddcc")
col_types = "cccddddddccc")
} else {
df <- googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/1uHmCuY3GXfSBCbsP61nAQeATBfoslXeS3PQNLlioWIk/edit#gid=1812144961",
sheet = "bsai",
Expand Down Expand Up @@ -95,6 +95,7 @@ catch_to_sheet <- function(year, data, area){

# calculate the total catches for most stocks
dat %>%
tidyr::drop_na(stock)
dplyr::mutate(area = ifelse(area=='GOA-wide' & stock=="orox", 'W/C', area)) %>%
dplyr::filter(!(stock %in% c("pollock", "sablefish", "dsr")), !(grepl("GOA-wide", area))) %>%
dplyr::group_split(year, stock) %>%
Expand Down Expand Up @@ -155,22 +156,20 @@ catch_to_sheet <- function(year, data, area){
df %>%
dplyr::mutate(year = as.numeric(year)) %>%
dplyr::filter(!(year %in% yr)) %>%
bind_rows(dat %>%
dplyr::bind_rows(dat %>%
dplyr::filter(stock %in% c("dsr") | grepl("GOA-wide", area), stock!='orox') %>%
dplyr::mutate(area = ifelse(area!= "GOA-wide", "Total", area)) %>%
dplyr::group_by(stock, year, area) %>%
dplyr::summarise(catch = sum(catch), .groups="drop") %>%
bind_rows(tots, sable, poll, pop, nork)) %>%
dplyr::bind_rows(tots, sable, poll, pop, nork)) %>%
dplyr::mutate(stock = factor(stock, levels = goa_species$stock),
area = factor(area, levels = goa_levels)) %>%
dplyr::arrange(stock, year, area) %>%
dplyr::select(catch) -> ct


googlesheets4::range_write(ct, ss="https://docs.google.com/spreadsheets/d/1uHmCuY3GXfSBCbsP61nAQeATBfoslXeS3PQNLlioWIk/edit#gid=1812144961",
sheet = "goa",
range = "I")

googlesheets4::sheet_write(ct, ss="https://docs.google.com/spreadsheets/d/1uHmCuY3GXfSBCbsP61nAQeATBfoslXeS3PQNLlioWIk/edit#gid=1812144961",
sheet = "goa")
}


18 changes: 8 additions & 10 deletions R/spec_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' spec_table(year, month = "sep", area = "goa", catch_date="11/9/2023")
#' }
#'
spec_table <- function(year, month = "sep", area = "goa", catch_date="11/9/2023") {
spec_table <- function(year, month = "nov", area = "goa", catch_date="11/1/2024") {

if(!(area %in% c("goa", "bsai"))){
stop("area must be 'goa' or 'bsai'")
Expand Down Expand Up @@ -69,9 +69,8 @@ spec_table <- function(year, month = "sep", area = "goa", catch_date="11/9/2023"
# data
if(area=="goa"){
df = googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/1uHmCuY3GXfSBCbsP61nAQeATBfoslXeS3PQNLlioWIk/edit#gid=0",
sheet = "goa",
col_types = "cccddddddcc") %>%
dplyr::select(-biomass, -rec_age, -completed, -checked)
sheet = "goa") %>%
dplyr::select(-biomass, -rec_age, -completed, -check, -check_2)
} else {
df = googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/1uHmCuY3GXfSBCbsP61nAQeATBfoslXeS3PQNLlioWIk/edit?pli=1#gid=276255793",
sheet = "bsai",
Expand Down Expand Up @@ -140,13 +139,12 @@ spec_table <- function(year, month = "sep", area = "goa", catch_date="11/9/2023"

} else if(area=='goa' & month=='nov'){
df %>%
filter
dplyr::filter(year %in% (yr):(yr+2)) %>%
tidyr::pivot_wider(names_from = year, values_from = c(-stock, -area, -year)) %>%
dplyr::filter(year %in% (yr-1):(yr+2)) %>%
tidyr::pivot_wider(names_from = year, values_from = c(-species, -area, -year)) %>%
dplyr::select(dplyr::any_of(nov_names)) %>%
dplyr::left_join(bsai_species) %>%
dplyr::mutate(stock = id,
stock = ifelse(stock=="sablefish" & area=="AK-wide", "Alaska-wide OFL and ABC", stock)) %>%
dplyr::left_join(goa_species) %>%
dplyr::mutate(species = id,
species = ifelse(stock=="sablefish" & area=="AK-wide", "Alaska-wide OFL and ABC", stock)) %>%
dplyr::select(-id) %>%
dplyr::mutate(stock = factor(stock, levels = bsai_species$id),
area = factor(area, levels = bsai_levels)) -> dat
Expand Down

0 comments on commit 19cf1d4

Please sign in to comment.