R/utils.R

Defines functions available_seasons most_recent_season is_sequential

# Identify sessions with sequential future resolving
is_sequential <- function() inherits(future::plan(), "sequential")

# Initialize first available season in data repository
first_season <- "2008-09"

# Find most recent college basketball season
most_recent_season <- function() {
  end <- ifelse(as.numeric(substr(Sys.Date(), 6, 7)) >= 11, # if greater or equal to November
                as.numeric(substr(Sys.Date(), 1, 4)) + 1,
                as.numeric(substr(Sys.Date(), 1, 4)))

  season <- paste0(end - 1, "-", substr(end, 3, 4))
  return(season)
}

# Find available college basketball seasons in data repository
available_seasons <- function() {
  last_season <- most_recent_season()

  seasons <- as.numeric(substr(first_season, 1, 4)):as.numeric(substr(last_season, 1, 4))

  return(paste0(seasons, "-", substr(seasons + 1, 3, 4)))
}

#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL
JackLich10/gamezoneR documentation built on April 24, 2023, 4:15 p.m.